Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved. |
| 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
| 25 | * James P. Ketrenos <ipw2100-admin@linux.intel.com> |
| 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/version.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/dma-mapping.h> |
| 36 | #include <linux/delay.h> |
| 37 | #include <linux/skbuff.h> |
| 38 | #include <linux/netdevice.h> |
| 39 | #include <linux/wireless.h> |
| 40 | #include <linux/firmware.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 41 | #include <linux/etherdevice.h> |
| 42 | #include <linux/if_arp.h> |
| 43 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 44 | #include <net/mac80211.h> |
| 45 | |
| 46 | #include <asm/div64.h> |
| 47 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 48 | #include "iwl-4965.h" |
| 49 | #include "iwl-helpers.h" |
| 50 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 51 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 52 | u32 iwl4965_debug_level; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 53 | #endif |
| 54 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 55 | static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv, |
| 56 | struct iwl4965_tx_queue *txq); |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 57 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 58 | /****************************************************************************** |
| 59 | * |
| 60 | * module boiler plate |
| 61 | * |
| 62 | ******************************************************************************/ |
| 63 | |
| 64 | /* module parameters */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 65 | static int iwl4965_param_disable_hw_scan; /* def: 0 = use 4965's h/w scan */ |
| 66 | static int iwl4965_param_debug; /* def: 0 = minimal debug log messages */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 67 | static int iwl4965_param_disable; /* def: enable radio */ |
| 68 | static int iwl4965_param_antenna; /* def: 0 = both antennas (use diversity) */ |
| 69 | int iwl4965_param_hwcrypto; /* def: using software encryption */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 70 | static int iwl4965_param_qos_enable = 1; /* def: 1 = use quality of service */ |
| 71 | int iwl4965_param_queues_num = IWL_MAX_NUM_QUEUES; /* def: 16 Tx queues */ |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 72 | int iwl4965_param_amsdu_size_8K; /* def: enable 8K amsdu size */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * module name, copyright, version, etc. |
| 76 | * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk |
| 77 | */ |
| 78 | |
| 79 | #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux" |
| 80 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 81 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 82 | #define VD "d" |
| 83 | #else |
| 84 | #define VD |
| 85 | #endif |
| 86 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 87 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 88 | #define VS "s" |
| 89 | #else |
| 90 | #define VS |
| 91 | #endif |
| 92 | |
Reinette Chatre | b9e0b44 | 2008-02-08 16:39:11 -0800 | [diff] [blame] | 93 | #define IWLWIFI_VERSION "1.2.26k" 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 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 118 | static const struct ieee80211_supported_band *iwl4965_get_hw_mode( |
| 119 | struct iwl4965_priv *priv, enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 120 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 121 | return priv->hw->wiphy->bands[band]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 124 | static int iwl4965_is_empty_essid(const char *essid, int essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 125 | { |
| 126 | /* Single white space is for Linksys APs */ |
| 127 | if (essid_len == 1 && essid[0] == ' ') |
| 128 | return 1; |
| 129 | |
| 130 | /* Otherwise, if the entire essid is 0, we assume it is hidden */ |
| 131 | while (essid_len) { |
| 132 | essid_len--; |
| 133 | if (essid[essid_len] != '\0') |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | return 1; |
| 138 | } |
| 139 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 140 | static const char *iwl4965_escape_essid(const char *essid, u8 essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 141 | { |
| 142 | static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
| 143 | const char *s = essid; |
| 144 | char *d = escaped; |
| 145 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 146 | if (iwl4965_is_empty_essid(essid, essid_len)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 147 | memcpy(escaped, "<hidden>", sizeof("<hidden>")); |
| 148 | return escaped; |
| 149 | } |
| 150 | |
| 151 | essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE); |
| 152 | while (essid_len--) { |
| 153 | if (*s == '\0') { |
| 154 | *d++ = '\\'; |
| 155 | *d++ = '0'; |
| 156 | s++; |
| 157 | } else |
| 158 | *d++ = *s++; |
| 159 | } |
| 160 | *d = '\0'; |
| 161 | return escaped; |
| 162 | } |
| 163 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 164 | static void iwl4965_print_hex_dump(int level, void *p, u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 165 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 166 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 167 | if (!(iwl4965_debug_level & level)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 168 | return; |
| 169 | |
| 170 | print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1, |
| 171 | p, len, 1); |
| 172 | #endif |
| 173 | } |
| 174 | |
| 175 | /*************** DMA-QUEUE-GENERAL-FUNCTIONS ***** |
| 176 | * DMA services |
| 177 | * |
| 178 | * Theory of operation |
| 179 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 180 | * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer |
| 181 | * of buffer descriptors, each of which points to one or more data buffers for |
| 182 | * the device to read from or fill. Driver and device exchange status of each |
| 183 | * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty |
| 184 | * entries in each circular buffer, to protect against confusing empty and full |
| 185 | * queue states. |
| 186 | * |
| 187 | * The device reads or writes the data in the queues via the device's several |
| 188 | * DMA/FIFO channels. Each queue is mapped to a single DMA channel. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 189 | * |
| 190 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 191 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 192 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 193 | * Tx queue resumed. |
| 194 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 195 | * The 4965 operates with up to 17 queues: One receive queue, one transmit |
| 196 | * queue (#4) for sending commands to the device firmware, and 15 other |
| 197 | * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels. |
Ben Cahill | e385144 | 2007-11-29 11:10:07 +0800 | [diff] [blame] | 198 | * |
| 199 | * See more detailed info in iwl-4965-hw.h. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 200 | ***************************************************/ |
| 201 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 202 | int iwl4965_queue_space(const struct iwl4965_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 203 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 204 | int s = q->read_ptr - q->write_ptr; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 205 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 206 | if (q->read_ptr > q->write_ptr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 207 | s -= q->n_bd; |
| 208 | |
| 209 | if (s <= 0) |
| 210 | s += q->n_window; |
| 211 | /* keep some reserve to not confuse empty and full situations */ |
| 212 | s -= 2; |
| 213 | if (s < 0) |
| 214 | s = 0; |
| 215 | return s; |
| 216 | } |
| 217 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 218 | /** |
| 219 | * iwl4965_queue_inc_wrap - increment queue index, wrap back to beginning |
| 220 | * @index -- current index |
| 221 | * @n_bd -- total number of entries in queue (must be power of 2) |
| 222 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 223 | static inline int iwl4965_queue_inc_wrap(int index, int n_bd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 224 | { |
| 225 | return ++index & (n_bd - 1); |
| 226 | } |
| 227 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 228 | /** |
| 229 | * iwl4965_queue_dec_wrap - decrement queue index, wrap back to end |
| 230 | * @index -- current index |
| 231 | * @n_bd -- total number of entries in queue (must be power of 2) |
| 232 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 233 | static inline int iwl4965_queue_dec_wrap(int index, int n_bd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 234 | { |
| 235 | return --index & (n_bd - 1); |
| 236 | } |
| 237 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 238 | 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] | 239 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 240 | return q->write_ptr > q->read_ptr ? |
| 241 | (i >= q->read_ptr && i < q->write_ptr) : |
| 242 | !(i < q->read_ptr && i >= q->write_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 245 | 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] | 246 | { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 247 | /* 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] | 248 | if (is_huge) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 249 | return q->n_window; /* must be power of 2 */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 250 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 251 | /* Otherwise, use normal size buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 252 | return index & (q->n_window - 1); |
| 253 | } |
| 254 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 255 | /** |
| 256 | * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes |
| 257 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 258 | 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] | 259 | int count, int slots_num, u32 id) |
| 260 | { |
| 261 | q->n_bd = count; |
| 262 | q->n_window = slots_num; |
| 263 | q->id = id; |
| 264 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 265 | /* count must be power-of-two size, otherwise iwl4965_queue_inc_wrap |
| 266 | * and iwl4965_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 267 | BUG_ON(!is_power_of_2(count)); |
| 268 | |
| 269 | /* slots_num must be power-of-two size, otherwise |
| 270 | * get_cmd_index is broken. */ |
| 271 | BUG_ON(!is_power_of_2(slots_num)); |
| 272 | |
| 273 | q->low_mark = q->n_window / 4; |
| 274 | if (q->low_mark < 4) |
| 275 | q->low_mark = 4; |
| 276 | |
| 277 | q->high_mark = q->n_window / 8; |
| 278 | if (q->high_mark < 2) |
| 279 | q->high_mark = 2; |
| 280 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 281 | q->write_ptr = q->read_ptr = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 286 | /** |
| 287 | * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue |
| 288 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 289 | static int iwl4965_tx_queue_alloc(struct iwl4965_priv *priv, |
| 290 | struct iwl4965_tx_queue *txq, u32 id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 291 | { |
| 292 | struct pci_dev *dev = priv->pci_dev; |
| 293 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 294 | /* Driver private data, only for Tx (not command) queues, |
| 295 | * not shared with device. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 296 | if (id != IWL_CMD_QUEUE_NUM) { |
| 297 | txq->txb = kmalloc(sizeof(txq->txb[0]) * |
| 298 | TFD_QUEUE_SIZE_MAX, GFP_KERNEL); |
| 299 | if (!txq->txb) { |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 300 | IWL_ERROR("kmalloc for auxiliary BD " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 301 | "structures failed\n"); |
| 302 | goto error; |
| 303 | } |
| 304 | } else |
| 305 | txq->txb = NULL; |
| 306 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 307 | /* Circular buffer of transmit frame descriptors (TFDs), |
| 308 | * shared with device */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 309 | txq->bd = pci_alloc_consistent(dev, |
| 310 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX, |
| 311 | &txq->q.dma_addr); |
| 312 | |
| 313 | if (!txq->bd) { |
| 314 | IWL_ERROR("pci_alloc_consistent(%zd) failed\n", |
| 315 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX); |
| 316 | goto error; |
| 317 | } |
| 318 | txq->q.id = id; |
| 319 | |
| 320 | return 0; |
| 321 | |
| 322 | error: |
| 323 | if (txq->txb) { |
| 324 | kfree(txq->txb); |
| 325 | txq->txb = NULL; |
| 326 | } |
| 327 | |
| 328 | return -ENOMEM; |
| 329 | } |
| 330 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 331 | /** |
| 332 | * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue |
| 333 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 334 | int iwl4965_tx_queue_init(struct iwl4965_priv *priv, |
| 335 | struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 336 | { |
| 337 | struct pci_dev *dev = priv->pci_dev; |
| 338 | int len; |
| 339 | int rc = 0; |
| 340 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 341 | /* |
| 342 | * Alloc buffer array for commands (Tx or other types of commands). |
| 343 | * For the command queue (#4), allocate command space + one big |
| 344 | * command for scan, since scan command is very huge; the system will |
| 345 | * not have two scans at the same time, so only one is needed. |
Tomas Winkler | bb54244 | 2007-12-05 20:59:59 +0200 | [diff] [blame] | 346 | * For normal Tx queues (all other queues), no super-size command |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 347 | * space is needed. |
| 348 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 349 | len = sizeof(struct iwl4965_cmd) * slots_num; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 350 | if (txq_id == IWL_CMD_QUEUE_NUM) |
| 351 | len += IWL_MAX_SCAN_SIZE; |
| 352 | txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd); |
| 353 | if (!txq->cmd) |
| 354 | return -ENOMEM; |
| 355 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 356 | /* Alloc driver data array and TFD circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 357 | rc = iwl4965_tx_queue_alloc(priv, txq, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 358 | if (rc) { |
| 359 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 360 | |
| 361 | return -ENOMEM; |
| 362 | } |
| 363 | txq->need_update = 0; |
| 364 | |
| 365 | /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 366 | * iwl4965_queue_inc_wrap and iwl4965_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 367 | 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] | 368 | |
| 369 | /* Initialize queue's high/low-water marks, and head/tail indexes */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 370 | 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] | 371 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 372 | /* Tell device where to find queue */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 373 | iwl4965_hw_tx_queue_init(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 374 | |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 379 | * iwl4965_tx_queue_free - Deallocate DMA queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 380 | * @txq: Transmit queue to deallocate. |
| 381 | * |
| 382 | * Empty queue by removing and destroying all BD's. |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 383 | * Free all buffers. |
| 384 | * 0-fill, but do not free "txq" descriptor structure. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 385 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 386 | 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] | 387 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 388 | struct iwl4965_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 389 | struct pci_dev *dev = priv->pci_dev; |
| 390 | int len; |
| 391 | |
| 392 | if (q->n_bd == 0) |
| 393 | return; |
| 394 | |
| 395 | /* first, empty all BD's */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 396 | for (; q->write_ptr != q->read_ptr; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 397 | q->read_ptr = iwl4965_queue_inc_wrap(q->read_ptr, q->n_bd)) |
| 398 | iwl4965_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 399 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 400 | len = sizeof(struct iwl4965_cmd) * q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 401 | if (q->id == IWL_CMD_QUEUE_NUM) |
| 402 | len += IWL_MAX_SCAN_SIZE; |
| 403 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 404 | /* De-alloc array of command/tx buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 405 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 406 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 407 | /* De-alloc circular buffer of TFDs */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 408 | if (txq->q.n_bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 409 | pci_free_consistent(dev, sizeof(struct iwl4965_tfd_frame) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 410 | txq->q.n_bd, txq->bd, txq->q.dma_addr); |
| 411 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 412 | /* De-alloc array of per-TFD driver data */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 413 | if (txq->txb) { |
| 414 | kfree(txq->txb); |
| 415 | txq->txb = NULL; |
| 416 | } |
| 417 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 418 | /* 0-fill queue descriptor structure */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 419 | memset(txq, 0, sizeof(*txq)); |
| 420 | } |
| 421 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 422 | 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] | 423 | |
| 424 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 425 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 426 | * the functionality provided here |
| 427 | */ |
| 428 | |
| 429 | /**************************************************************/ |
| 430 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 431 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 432 | /** |
| 433 | * iwl4965_remove_station - Remove driver's knowledge of station. |
| 434 | * |
| 435 | * NOTE: This does not remove station from device's station table. |
| 436 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 437 | 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] | 438 | { |
| 439 | int index = IWL_INVALID_STATION; |
| 440 | int i; |
| 441 | unsigned long flags; |
| 442 | |
| 443 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 444 | |
| 445 | if (is_ap) |
| 446 | index = IWL_AP_ID; |
| 447 | else if (is_broadcast_ether_addr(addr)) |
| 448 | index = priv->hw_setting.bcast_sta_id; |
| 449 | else |
| 450 | for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) |
| 451 | if (priv->stations[i].used && |
| 452 | !compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 453 | addr)) { |
| 454 | index = i; |
| 455 | break; |
| 456 | } |
| 457 | |
| 458 | if (unlikely(index == IWL_INVALID_STATION)) |
| 459 | goto out; |
| 460 | |
| 461 | if (priv->stations[index].used) { |
| 462 | priv->stations[index].used = 0; |
| 463 | priv->num_stations--; |
| 464 | } |
| 465 | |
| 466 | BUG_ON(priv->num_stations < 0); |
| 467 | |
| 468 | out: |
| 469 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 470 | return 0; |
| 471 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 472 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 473 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 474 | /** |
| 475 | * iwl4965_clear_stations_table - Clear the driver's station table |
| 476 | * |
| 477 | * NOTE: This does not clear or otherwise alter the device's station table. |
| 478 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 479 | static void iwl4965_clear_stations_table(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 480 | { |
| 481 | unsigned long flags; |
| 482 | |
| 483 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 484 | |
| 485 | priv->num_stations = 0; |
| 486 | memset(priv->stations, 0, sizeof(priv->stations)); |
| 487 | |
| 488 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 489 | } |
| 490 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 491 | /** |
| 492 | * iwl4965_add_station_flags - Add station to tables in driver and device |
| 493 | */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 494 | u8 iwl4965_add_station_flags(struct iwl4965_priv *priv, const u8 *addr, |
| 495 | int is_ap, u8 flags, void *ht_data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 496 | { |
| 497 | int i; |
| 498 | int index = IWL_INVALID_STATION; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 499 | struct iwl4965_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 500 | unsigned long flags_spin; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 501 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 502 | |
| 503 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 504 | if (is_ap) |
| 505 | index = IWL_AP_ID; |
| 506 | else if (is_broadcast_ether_addr(addr)) |
| 507 | index = priv->hw_setting.bcast_sta_id; |
| 508 | else |
| 509 | for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) { |
| 510 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 511 | addr)) { |
| 512 | index = i; |
| 513 | break; |
| 514 | } |
| 515 | |
| 516 | if (!priv->stations[i].used && |
| 517 | index == IWL_INVALID_STATION) |
| 518 | index = i; |
| 519 | } |
| 520 | |
| 521 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 522 | /* These two conditions have the same outcome, but keep them separate |
| 523 | since they have different meanings */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 524 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 525 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 526 | return index; |
| 527 | } |
| 528 | |
| 529 | if (priv->stations[index].used && |
| 530 | !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) { |
| 531 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 532 | return index; |
| 533 | } |
| 534 | |
| 535 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 536 | 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] | 537 | station = &priv->stations[index]; |
| 538 | station->used = 1; |
| 539 | priv->num_stations++; |
| 540 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 541 | /* Set up the REPLY_ADD_STA command to send to device */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 542 | memset(&station->sta, 0, sizeof(struct iwl4965_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 543 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 544 | station->sta.mode = 0; |
| 545 | station->sta.sta.sta_id = index; |
| 546 | station->sta.station_flags = 0; |
| 547 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 548 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 549 | /* BCAST station and IBSS stations do not work in HT mode */ |
| 550 | if (index != priv->hw_setting.bcast_sta_id && |
| 551 | priv->iw_mode != IEEE80211_IF_TYPE_IBSS) |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 552 | iwl4965_set_ht_add_station(priv, index, |
| 553 | (struct ieee80211_ht_info *) ht_data); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 554 | #endif /*CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 555 | |
| 556 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 557 | |
| 558 | /* Add station to device's station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 559 | iwl4965_send_add_station(priv, &station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 560 | return index; |
| 561 | |
| 562 | } |
| 563 | |
| 564 | /*************** DRIVER STATUS FUNCTIONS *****/ |
| 565 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 566 | static inline int iwl4965_is_ready(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 567 | { |
| 568 | /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are |
| 569 | * set but EXIT_PENDING is not */ |
| 570 | return test_bit(STATUS_READY, &priv->status) && |
| 571 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) && |
| 572 | !test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 573 | } |
| 574 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 575 | static inline int iwl4965_is_alive(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 576 | { |
| 577 | return test_bit(STATUS_ALIVE, &priv->status); |
| 578 | } |
| 579 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 580 | static inline int iwl4965_is_init(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 581 | { |
| 582 | return test_bit(STATUS_INIT, &priv->status); |
| 583 | } |
| 584 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 585 | static inline int iwl4965_is_rfkill(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 586 | { |
| 587 | return test_bit(STATUS_RF_KILL_HW, &priv->status) || |
| 588 | test_bit(STATUS_RF_KILL_SW, &priv->status); |
| 589 | } |
| 590 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 591 | static inline int iwl4965_is_ready_rf(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 592 | { |
| 593 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 594 | if (iwl4965_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 595 | return 0; |
| 596 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 597 | return iwl4965_is_ready(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 601 | |
| 602 | #define IWL_CMD(x) case x : return #x |
| 603 | |
| 604 | static const char *get_cmd_string(u8 cmd) |
| 605 | { |
| 606 | switch (cmd) { |
| 607 | IWL_CMD(REPLY_ALIVE); |
| 608 | IWL_CMD(REPLY_ERROR); |
| 609 | IWL_CMD(REPLY_RXON); |
| 610 | IWL_CMD(REPLY_RXON_ASSOC); |
| 611 | IWL_CMD(REPLY_QOS_PARAM); |
| 612 | IWL_CMD(REPLY_RXON_TIMING); |
| 613 | IWL_CMD(REPLY_ADD_STA); |
| 614 | IWL_CMD(REPLY_REMOVE_STA); |
| 615 | IWL_CMD(REPLY_REMOVE_ALL_STA); |
| 616 | IWL_CMD(REPLY_TX); |
| 617 | IWL_CMD(REPLY_RATE_SCALE); |
| 618 | IWL_CMD(REPLY_LEDS_CMD); |
| 619 | IWL_CMD(REPLY_TX_LINK_QUALITY_CMD); |
| 620 | IWL_CMD(RADAR_NOTIFICATION); |
| 621 | IWL_CMD(REPLY_QUIET_CMD); |
| 622 | IWL_CMD(REPLY_CHANNEL_SWITCH); |
| 623 | IWL_CMD(CHANNEL_SWITCH_NOTIFICATION); |
| 624 | IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD); |
| 625 | IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION); |
| 626 | IWL_CMD(POWER_TABLE_CMD); |
| 627 | IWL_CMD(PM_SLEEP_NOTIFICATION); |
| 628 | IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC); |
| 629 | IWL_CMD(REPLY_SCAN_CMD); |
| 630 | IWL_CMD(REPLY_SCAN_ABORT_CMD); |
| 631 | IWL_CMD(SCAN_START_NOTIFICATION); |
| 632 | IWL_CMD(SCAN_RESULTS_NOTIFICATION); |
| 633 | IWL_CMD(SCAN_COMPLETE_NOTIFICATION); |
| 634 | IWL_CMD(BEACON_NOTIFICATION); |
| 635 | IWL_CMD(REPLY_TX_BEACON); |
| 636 | IWL_CMD(WHO_IS_AWAKE_NOTIFICATION); |
| 637 | IWL_CMD(QUIET_NOTIFICATION); |
| 638 | IWL_CMD(REPLY_TX_PWR_TABLE_CMD); |
| 639 | IWL_CMD(MEASURE_ABORT_NOTIFICATION); |
| 640 | IWL_CMD(REPLY_BT_CONFIG); |
| 641 | IWL_CMD(REPLY_STATISTICS_CMD); |
| 642 | IWL_CMD(STATISTICS_NOTIFICATION); |
| 643 | IWL_CMD(REPLY_CARD_STATE_CMD); |
| 644 | IWL_CMD(CARD_STATE_NOTIFICATION); |
| 645 | IWL_CMD(MISSED_BEACONS_NOTIFICATION); |
| 646 | IWL_CMD(REPLY_CT_KILL_CONFIG_CMD); |
| 647 | IWL_CMD(SENSITIVITY_CMD); |
| 648 | IWL_CMD(REPLY_PHY_CALIBRATION_CMD); |
| 649 | IWL_CMD(REPLY_RX_PHY_CMD); |
| 650 | IWL_CMD(REPLY_RX_MPDU_CMD); |
| 651 | IWL_CMD(REPLY_4965_RX); |
| 652 | IWL_CMD(REPLY_COMPRESSED_BA); |
| 653 | default: |
| 654 | return "UNKNOWN"; |
| 655 | |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | #define HOST_COMPLETE_TIMEOUT (HZ / 2) |
| 660 | |
| 661 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 662 | * iwl4965_enqueue_hcmd - enqueue a uCode command |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 663 | * @priv: device private data point |
| 664 | * @cmd: a point to the ucode command structure |
| 665 | * |
| 666 | * The function returns < 0 values to indicate the operation is |
| 667 | * failed. On success, it turns the index (> 0) of command in the |
| 668 | * command queue. |
| 669 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 670 | 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] | 671 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 672 | struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
| 673 | struct iwl4965_queue *q = &txq->q; |
| 674 | struct iwl4965_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 675 | u32 *control_flags; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 676 | struct iwl4965_cmd *out_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 677 | u32 idx; |
| 678 | u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 679 | dma_addr_t phys_addr; |
| 680 | int ret; |
| 681 | unsigned long flags; |
| 682 | |
| 683 | /* If any of the command structures end up being larger than |
| 684 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
| 685 | * we will need to increase the size of the TFD entries */ |
| 686 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
| 687 | !(cmd->meta.flags & CMD_SIZE_HUGE)); |
| 688 | |
Gregory Greenman | c342a1b | 2008-02-06 11:20:40 -0800 | [diff] [blame] | 689 | if (iwl4965_is_rfkill(priv)) { |
| 690 | IWL_DEBUG_INFO("Not sending command - RF KILL"); |
| 691 | return -EIO; |
| 692 | } |
| 693 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 694 | if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 695 | IWL_ERROR("No space for Tx\n"); |
| 696 | return -ENOSPC; |
| 697 | } |
| 698 | |
| 699 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 700 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 701 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 702 | memset(tfd, 0, sizeof(*tfd)); |
| 703 | |
| 704 | control_flags = (u32 *) tfd; |
| 705 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 706 | 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] | 707 | out_cmd = &txq->cmd[idx]; |
| 708 | |
| 709 | out_cmd->hdr.cmd = cmd->id; |
| 710 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 711 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 712 | |
| 713 | /* At this point, the out_cmd now has all of the incoming cmd |
| 714 | * information */ |
| 715 | |
| 716 | out_cmd->hdr.flags = 0; |
| 717 | 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] | 718 | INDEX_TO_SEQ(q->write_ptr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 719 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
| 720 | out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME); |
| 721 | |
| 722 | phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 723 | offsetof(struct iwl4965_cmd, hdr); |
| 724 | 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] | 725 | |
| 726 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 727 | "%d bytes at %d[%d]:%d\n", |
| 728 | get_cmd_string(out_cmd->hdr.cmd), |
| 729 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 730 | fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 731 | |
| 732 | txq->need_update = 1; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 733 | |
| 734 | /* Set up entry in queue's byte count circular buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 735 | ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 736 | |
| 737 | /* Increment and update queue's write index */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 738 | q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd); |
| 739 | iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 740 | |
| 741 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 742 | return ret ? ret : idx; |
| 743 | } |
| 744 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 745 | 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] | 746 | { |
| 747 | int ret; |
| 748 | |
| 749 | BUG_ON(!(cmd->meta.flags & CMD_ASYNC)); |
| 750 | |
| 751 | /* An asynchronous command can not expect an SKB to be set. */ |
| 752 | BUG_ON(cmd->meta.flags & CMD_WANT_SKB); |
| 753 | |
| 754 | /* An asynchronous command MUST have a callback. */ |
| 755 | BUG_ON(!cmd->meta.u.callback); |
| 756 | |
| 757 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 758 | return -EBUSY; |
| 759 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 760 | ret = iwl4965_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 761 | if (ret < 0) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 762 | IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 763 | get_cmd_string(cmd->id), ret); |
| 764 | return ret; |
| 765 | } |
| 766 | return 0; |
| 767 | } |
| 768 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 769 | 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] | 770 | { |
| 771 | int cmd_idx; |
| 772 | int ret; |
| 773 | static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */ |
| 774 | |
| 775 | BUG_ON(cmd->meta.flags & CMD_ASYNC); |
| 776 | |
| 777 | /* A synchronous command can not have a callback set. */ |
| 778 | BUG_ON(cmd->meta.u.callback != NULL); |
| 779 | |
| 780 | if (atomic_xchg(&entry, 1)) { |
| 781 | IWL_ERROR("Error sending %s: Already sending a host command\n", |
| 782 | get_cmd_string(cmd->id)); |
| 783 | return -EBUSY; |
| 784 | } |
| 785 | |
| 786 | set_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 787 | |
| 788 | if (cmd->meta.flags & CMD_WANT_SKB) |
| 789 | cmd->meta.source = &cmd->meta; |
| 790 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 791 | cmd_idx = iwl4965_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 792 | if (cmd_idx < 0) { |
| 793 | ret = cmd_idx; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 794 | IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 795 | get_cmd_string(cmd->id), ret); |
| 796 | goto out; |
| 797 | } |
| 798 | |
| 799 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 800 | !test_bit(STATUS_HCMD_ACTIVE, &priv->status), |
| 801 | HOST_COMPLETE_TIMEOUT); |
| 802 | if (!ret) { |
| 803 | if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) { |
| 804 | IWL_ERROR("Error sending %s: time out after %dms.\n", |
| 805 | get_cmd_string(cmd->id), |
| 806 | jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); |
| 807 | |
| 808 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 809 | ret = -ETIMEDOUT; |
| 810 | goto cancel; |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 815 | IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n", |
| 816 | get_cmd_string(cmd->id)); |
| 817 | ret = -ECANCELED; |
| 818 | goto fail; |
| 819 | } |
| 820 | if (test_bit(STATUS_FW_ERROR, &priv->status)) { |
| 821 | IWL_DEBUG_INFO("Command %s failed: FW Error\n", |
| 822 | get_cmd_string(cmd->id)); |
| 823 | ret = -EIO; |
| 824 | goto fail; |
| 825 | } |
| 826 | if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) { |
| 827 | IWL_ERROR("Error: Response NULL in '%s'\n", |
| 828 | get_cmd_string(cmd->id)); |
| 829 | ret = -EIO; |
| 830 | goto out; |
| 831 | } |
| 832 | |
| 833 | ret = 0; |
| 834 | goto out; |
| 835 | |
| 836 | cancel: |
| 837 | if (cmd->meta.flags & CMD_WANT_SKB) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 838 | struct iwl4965_cmd *qcmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 839 | |
| 840 | /* Cancel the CMD_WANT_SKB flag for the cmd in the |
| 841 | * TX cmd queue. Otherwise in case the cmd comes |
| 842 | * in later, it will possibly set an invalid |
| 843 | * address (cmd->meta.source). */ |
| 844 | qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx]; |
| 845 | qcmd->meta.flags &= ~CMD_WANT_SKB; |
| 846 | } |
| 847 | fail: |
| 848 | if (cmd->meta.u.skb) { |
| 849 | dev_kfree_skb_any(cmd->meta.u.skb); |
| 850 | cmd->meta.u.skb = NULL; |
| 851 | } |
| 852 | out: |
| 853 | atomic_set(&entry, 0); |
| 854 | return ret; |
| 855 | } |
| 856 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 857 | 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] | 858 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 859 | if (cmd->meta.flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 860 | return iwl4965_send_cmd_async(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 861 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 862 | return iwl4965_send_cmd_sync(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 863 | } |
| 864 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 865 | 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] | 866 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 867 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 868 | .id = id, |
| 869 | .len = len, |
| 870 | .data = data, |
| 871 | }; |
| 872 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 873 | return iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 874 | } |
| 875 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 876 | 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] | 877 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 878 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 879 | .id = id, |
| 880 | .len = sizeof(val), |
| 881 | .data = &val, |
| 882 | }; |
| 883 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 884 | return iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 887 | int iwl4965_send_statistics_request(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 888 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 889 | return iwl4965_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 893 | * iwl4965_rxon_add_station - add station into station table. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 894 | * |
| 895 | * there is only one AP station with id= IWL_AP_ID |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 896 | * NOTE: mutex must be held before calling this fnction |
| 897 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 898 | static int iwl4965_rxon_add_station(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 899 | const u8 *addr, int is_ap) |
| 900 | { |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 901 | u8 sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 902 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 903 | /* Add station to device's station table */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 904 | #ifdef CONFIG_IWL4965_HT |
| 905 | struct ieee80211_conf *conf = &priv->hw->conf; |
| 906 | struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf; |
| 907 | |
| 908 | if ((is_ap) && |
| 909 | (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) && |
| 910 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 911 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, |
| 912 | 0, cur_ht_config); |
| 913 | else |
| 914 | #endif /* CONFIG_IWL4965_HT */ |
| 915 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, |
| 916 | 0, NULL); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 917 | |
| 918 | /* Set up default rate scaling table in device's station table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 919 | iwl4965_add_station(priv, addr, is_ap); |
| 920 | |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 921 | return sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 925 | * 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] | 926 | * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz |
| 927 | * @channel: Any channel valid for the requested phymode |
| 928 | |
| 929 | * In addition to setting the staging RXON, priv->phymode is also set. |
| 930 | * |
| 931 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
| 932 | * in the staging RXON flag structure based on the phymode |
| 933 | */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 934 | static int iwl4965_set_rxon_channel(struct iwl4965_priv *priv, |
| 935 | enum ieee80211_band band, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 936 | u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 937 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 938 | if (!iwl4965_get_channel_info(priv, band, 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", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 940 | channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 941 | return -EINVAL; |
| 942 | } |
| 943 | |
| 944 | if ((le16_to_cpu(priv->staging_rxon.channel) == channel) && |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 945 | (priv->band == band)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 946 | return 0; |
| 947 | |
| 948 | priv->staging_rxon.channel = cpu_to_le16(channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 949 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 950 | priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; |
| 951 | else |
| 952 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 953 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 954 | priv->band = band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 955 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 956 | IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 957 | |
| 958 | return 0; |
| 959 | } |
| 960 | |
| 961 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 962 | * iwl4965_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 963 | * |
| 964 | * NOTE: This is really only useful during development and can eventually |
| 965 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 966 | * making changes |
| 967 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 968 | static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 969 | { |
| 970 | int error = 0; |
| 971 | int counter = 1; |
| 972 | |
| 973 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 974 | error |= le32_to_cpu(rxon->flags & |
| 975 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 976 | RXON_FLG_RADAR_DETECT_MSK)); |
| 977 | if (error) |
| 978 | IWL_WARNING("check 24G fields %d | %d\n", |
| 979 | counter++, error); |
| 980 | } else { |
| 981 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 982 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 983 | if (error) |
| 984 | IWL_WARNING("check 52 fields %d | %d\n", |
| 985 | counter++, error); |
| 986 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 987 | if (error) |
| 988 | IWL_WARNING("check 52 CCK %d | %d\n", |
| 989 | counter++, error); |
| 990 | } |
| 991 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 992 | if (error) |
| 993 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); |
| 994 | |
| 995 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 996 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 997 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 998 | if (error) |
| 999 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); |
| 1000 | |
| 1001 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 1002 | if (error) |
| 1003 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); |
| 1004 | |
| 1005 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 1006 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 1007 | if (error) |
| 1008 | IWL_WARNING("check CCK and short slot %d | %d\n", |
| 1009 | counter++, error); |
| 1010 | |
| 1011 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 1012 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 1013 | if (error) |
| 1014 | IWL_WARNING("check CCK & auto detect %d | %d\n", |
| 1015 | counter++, error); |
| 1016 | |
| 1017 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 1018 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 1019 | if (error) |
| 1020 | IWL_WARNING("check TGG and auto detect %d | %d\n", |
| 1021 | counter++, error); |
| 1022 | |
| 1023 | if (error) |
| 1024 | IWL_WARNING("Tuning to channel %d\n", |
| 1025 | le16_to_cpu(rxon->channel)); |
| 1026 | |
| 1027 | if (error) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1028 | IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1029 | return -1; |
| 1030 | } |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1035 | * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1036 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1037 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1038 | * If the RXON structure is changing enough to require a new tune, |
| 1039 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 1040 | * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1041 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1042 | static int iwl4965_full_rxon_required(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1043 | { |
| 1044 | |
| 1045 | /* These items are only settable from the full RXON command */ |
| 1046 | if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || |
| 1047 | compare_ether_addr(priv->staging_rxon.bssid_addr, |
| 1048 | priv->active_rxon.bssid_addr) || |
| 1049 | compare_ether_addr(priv->staging_rxon.node_addr, |
| 1050 | priv->active_rxon.node_addr) || |
| 1051 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, |
| 1052 | priv->active_rxon.wlap_bssid_addr) || |
| 1053 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || |
| 1054 | (priv->staging_rxon.channel != priv->active_rxon.channel) || |
| 1055 | (priv->staging_rxon.air_propagation != |
| 1056 | priv->active_rxon.air_propagation) || |
| 1057 | (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != |
| 1058 | priv->active_rxon.ofdm_ht_single_stream_basic_rates) || |
| 1059 | (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != |
| 1060 | priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || |
| 1061 | (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) || |
| 1062 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) |
| 1063 | return 1; |
| 1064 | |
| 1065 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 1066 | * be updated with the RXON_ASSOC command -- however only some |
| 1067 | * flag transitions are allowed using RXON_ASSOC */ |
| 1068 | |
| 1069 | /* Check if we are not switching bands */ |
| 1070 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 1071 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
| 1072 | return 1; |
| 1073 | |
| 1074 | /* Check if we are switching association toggle */ |
| 1075 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 1076 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
| 1077 | return 1; |
| 1078 | |
| 1079 | return 0; |
| 1080 | } |
| 1081 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1082 | static int iwl4965_send_rxon_assoc(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1083 | { |
| 1084 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1085 | struct iwl4965_rx_packet *res = NULL; |
| 1086 | struct iwl4965_rxon_assoc_cmd rxon_assoc; |
| 1087 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1088 | .id = REPLY_RXON_ASSOC, |
| 1089 | .len = sizeof(rxon_assoc), |
| 1090 | .meta.flags = CMD_WANT_SKB, |
| 1091 | .data = &rxon_assoc, |
| 1092 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1093 | const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon; |
| 1094 | const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1095 | |
| 1096 | if ((rxon1->flags == rxon2->flags) && |
| 1097 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 1098 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 1099 | (rxon1->ofdm_ht_single_stream_basic_rates == |
| 1100 | rxon2->ofdm_ht_single_stream_basic_rates) && |
| 1101 | (rxon1->ofdm_ht_dual_stream_basic_rates == |
| 1102 | rxon2->ofdm_ht_dual_stream_basic_rates) && |
| 1103 | (rxon1->rx_chain == rxon2->rx_chain) && |
| 1104 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 1105 | IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n"); |
| 1106 | return 0; |
| 1107 | } |
| 1108 | |
| 1109 | rxon_assoc.flags = priv->staging_rxon.flags; |
| 1110 | rxon_assoc.filter_flags = priv->staging_rxon.filter_flags; |
| 1111 | rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates; |
| 1112 | rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates; |
| 1113 | rxon_assoc.reserved = 0; |
| 1114 | rxon_assoc.ofdm_ht_single_stream_basic_rates = |
| 1115 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates; |
| 1116 | rxon_assoc.ofdm_ht_dual_stream_basic_rates = |
| 1117 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates; |
| 1118 | rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain; |
| 1119 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1120 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1121 | if (rc) |
| 1122 | return rc; |
| 1123 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1124 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1125 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1126 | IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n"); |
| 1127 | rc = -EIO; |
| 1128 | } |
| 1129 | |
| 1130 | priv->alloc_rxb_skb--; |
| 1131 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1132 | |
| 1133 | return rc; |
| 1134 | } |
| 1135 | |
| 1136 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1137 | * iwl4965_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1138 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1139 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1140 | * the active_rxon structure is updated with the new data. This |
| 1141 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 1142 | * a HW tune is required based on the RXON structure changes. |
| 1143 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1144 | static int iwl4965_commit_rxon(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1145 | { |
| 1146 | /* cast away the const for active_rxon in this function */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1147 | struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1148 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1149 | int rc = 0; |
| 1150 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1151 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1152 | return -1; |
| 1153 | |
| 1154 | /* always get timestamp with Rx frame */ |
| 1155 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
| 1156 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1157 | rc = iwl4965_check_rxon_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1158 | if (rc) { |
| 1159 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); |
| 1160 | return -EINVAL; |
| 1161 | } |
| 1162 | |
| 1163 | /* If we don't need to send a full RXON, we can use |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1164 | * iwl4965_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1165 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1166 | if (!iwl4965_full_rxon_required(priv)) { |
| 1167 | rc = iwl4965_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1168 | if (rc) { |
| 1169 | IWL_ERROR("Error setting RXON_ASSOC " |
| 1170 | "configuration (%d).\n", rc); |
| 1171 | return rc; |
| 1172 | } |
| 1173 | |
| 1174 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 1175 | |
| 1176 | return 0; |
| 1177 | } |
| 1178 | |
| 1179 | /* station table will be cleared */ |
| 1180 | priv->assoc_station_added = 0; |
| 1181 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1182 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1183 | priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; |
| 1184 | if (!priv->error_recovering) |
| 1185 | priv->start_calib = 0; |
| 1186 | |
| 1187 | iwl4965_init_sensitivity(priv, CMD_ASYNC, 1); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1188 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1189 | |
| 1190 | /* If we are currently associated and the new config requires |
| 1191 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 1192 | * we must clear the associated from the active configuration |
| 1193 | * before we apply the new config */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1194 | if (iwl4965_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1195 | (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
| 1196 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 1197 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 1198 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1199 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON, |
| 1200 | sizeof(struct iwl4965_rxon_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1201 | &priv->active_rxon); |
| 1202 | |
| 1203 | /* If the mask clearing failed then we set |
| 1204 | * active_rxon back to what it was previously */ |
| 1205 | if (rc) { |
| 1206 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 1207 | IWL_ERROR("Error clearing ASSOC_MSK on current " |
| 1208 | "configuration (%d).\n", rc); |
| 1209 | return rc; |
| 1210 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | IWL_DEBUG_INFO("Sending RXON\n" |
| 1214 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 1215 | "* channel = %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1216 | "* bssid = %s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1217 | ((priv->staging_rxon.filter_flags & |
| 1218 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
| 1219 | le16_to_cpu(priv->staging_rxon.channel), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1220 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1221 | |
| 1222 | /* Apply the new configuration */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1223 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON, |
| 1224 | sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1225 | if (rc) { |
| 1226 | IWL_ERROR("Error setting new configuration (%d).\n", rc); |
| 1227 | return rc; |
| 1228 | } |
| 1229 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1230 | iwl4965_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 1231 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1232 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1233 | if (!priv->error_recovering) |
| 1234 | priv->start_calib = 0; |
| 1235 | |
| 1236 | priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; |
| 1237 | iwl4965_init_sensitivity(priv, CMD_ASYNC, 1); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1238 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1239 | |
| 1240 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 1241 | |
| 1242 | /* If we issue a new RXON command which required a tune then we must |
| 1243 | * send a new TXPOWER command or we won't be able to Tx any frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1244 | rc = iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1245 | if (rc) { |
| 1246 | IWL_ERROR("Error setting Tx power (%d).\n", rc); |
| 1247 | return rc; |
| 1248 | } |
| 1249 | |
| 1250 | /* Add the broadcast address so we can send broadcast frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1251 | if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1252 | IWL_INVALID_STATION) { |
| 1253 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); |
| 1254 | return -EIO; |
| 1255 | } |
| 1256 | |
| 1257 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 1258 | * add the IWL_AP_ID to the station rate table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1259 | if (iwl4965_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1260 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1261 | if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1262 | == IWL_INVALID_STATION) { |
| 1263 | IWL_ERROR("Error adding AP address for transmit.\n"); |
| 1264 | return -EIO; |
| 1265 | } |
| 1266 | priv->assoc_station_added = 1; |
| 1267 | } |
| 1268 | |
| 1269 | return 0; |
| 1270 | } |
| 1271 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1272 | static int iwl4965_send_bt_config(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1273 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1274 | struct iwl4965_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1275 | .flags = 3, |
| 1276 | .lead_time = 0xAA, |
| 1277 | .max_kill = 1, |
| 1278 | .kill_ack_mask = 0, |
| 1279 | .kill_cts_mask = 0, |
| 1280 | }; |
| 1281 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1282 | return iwl4965_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
| 1283 | sizeof(struct iwl4965_bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1286 | static int iwl4965_send_scan_abort(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1287 | { |
| 1288 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1289 | struct iwl4965_rx_packet *res; |
| 1290 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1291 | .id = REPLY_SCAN_ABORT_CMD, |
| 1292 | .meta.flags = CMD_WANT_SKB, |
| 1293 | }; |
| 1294 | |
| 1295 | /* If there isn't a scan actively going on in the hardware |
| 1296 | * then we are in between scan bands and not actually |
| 1297 | * actively scanning, so don't send the abort command */ |
| 1298 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1299 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1300 | return 0; |
| 1301 | } |
| 1302 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1303 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1304 | if (rc) { |
| 1305 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1306 | return rc; |
| 1307 | } |
| 1308 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1309 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1310 | if (res->u.status != CAN_ABORT_STATUS) { |
| 1311 | /* The scan abort will return 1 for success or |
| 1312 | * 2 for "failure". A failure condition can be |
| 1313 | * due to simply not being in an active scan which |
| 1314 | * can occur if we send the scan abort before we |
| 1315 | * the microcode has notified us that a scan is |
| 1316 | * completed. */ |
| 1317 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 1318 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1319 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 1320 | } |
| 1321 | |
| 1322 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1323 | |
| 1324 | return rc; |
| 1325 | } |
| 1326 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1327 | static int iwl4965_card_state_sync_callback(struct iwl4965_priv *priv, |
| 1328 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1329 | struct sk_buff *skb) |
| 1330 | { |
| 1331 | return 1; |
| 1332 | } |
| 1333 | |
| 1334 | /* |
| 1335 | * CARD_STATE_CMD |
| 1336 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1337 | * Use: Sets the device's internal card state to enable, disable, or halt |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1338 | * |
| 1339 | * When in the 'enable' state the card operates as normal. |
| 1340 | * When in the 'disable' state, the card enters into a low power mode. |
| 1341 | * When in the 'halt' state, the card is shut down and must be fully |
| 1342 | * restarted to come back on. |
| 1343 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1344 | static int iwl4965_send_card_state(struct iwl4965_priv *priv, u32 flags, u8 meta_flag) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1345 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1346 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1347 | .id = REPLY_CARD_STATE_CMD, |
| 1348 | .len = sizeof(u32), |
| 1349 | .data = &flags, |
| 1350 | .meta.flags = meta_flag, |
| 1351 | }; |
| 1352 | |
| 1353 | if (meta_flag & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1354 | cmd.meta.u.callback = iwl4965_card_state_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1355 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1356 | return iwl4965_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1359 | static int iwl4965_add_sta_sync_callback(struct iwl4965_priv *priv, |
| 1360 | struct iwl4965_cmd *cmd, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1361 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1362 | struct iwl4965_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1363 | |
| 1364 | if (!skb) { |
| 1365 | IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n"); |
| 1366 | return 1; |
| 1367 | } |
| 1368 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1369 | res = (struct iwl4965_rx_packet *)skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1370 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1371 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 1372 | res->hdr.flags); |
| 1373 | return 1; |
| 1374 | } |
| 1375 | |
| 1376 | switch (res->u.add_sta.status) { |
| 1377 | case ADD_STA_SUCCESS_MSK: |
| 1378 | break; |
| 1379 | default: |
| 1380 | break; |
| 1381 | } |
| 1382 | |
| 1383 | /* We didn't cache the SKB; let the caller free it */ |
| 1384 | return 1; |
| 1385 | } |
| 1386 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1387 | int iwl4965_send_add_station(struct iwl4965_priv *priv, |
| 1388 | struct iwl4965_addsta_cmd *sta, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1389 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1390 | struct iwl4965_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1391 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1392 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1393 | .id = REPLY_ADD_STA, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1394 | .len = sizeof(struct iwl4965_addsta_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1395 | .meta.flags = flags, |
| 1396 | .data = sta, |
| 1397 | }; |
| 1398 | |
| 1399 | if (flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1400 | cmd.meta.u.callback = iwl4965_add_sta_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1401 | else |
| 1402 | cmd.meta.flags |= CMD_WANT_SKB; |
| 1403 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1404 | rc = iwl4965_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1405 | |
| 1406 | if (rc || (flags & CMD_ASYNC)) |
| 1407 | return rc; |
| 1408 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1409 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1410 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1411 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 1412 | res->hdr.flags); |
| 1413 | rc = -EIO; |
| 1414 | } |
| 1415 | |
| 1416 | if (rc == 0) { |
| 1417 | switch (res->u.add_sta.status) { |
| 1418 | case ADD_STA_SUCCESS_MSK: |
| 1419 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 1420 | break; |
| 1421 | default: |
| 1422 | rc = -EIO; |
| 1423 | IWL_WARNING("REPLY_ADD_STA failed\n"); |
| 1424 | break; |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | priv->alloc_rxb_skb--; |
| 1429 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1430 | |
| 1431 | return rc; |
| 1432 | } |
| 1433 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1434 | static int iwl4965_update_sta_key_info(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1435 | struct ieee80211_key_conf *keyconf, |
| 1436 | u8 sta_id) |
| 1437 | { |
| 1438 | unsigned long flags; |
| 1439 | __le16 key_flags = 0; |
| 1440 | |
| 1441 | switch (keyconf->alg) { |
| 1442 | case ALG_CCMP: |
| 1443 | key_flags |= STA_KEY_FLG_CCMP; |
| 1444 | key_flags |= cpu_to_le16( |
| 1445 | keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1446 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 1447 | break; |
| 1448 | case ALG_TKIP: |
| 1449 | case ALG_WEP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1450 | default: |
| 1451 | return -EINVAL; |
| 1452 | } |
| 1453 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1454 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 1455 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 1456 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, |
| 1457 | keyconf->keylen); |
| 1458 | |
| 1459 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, |
| 1460 | keyconf->keylen); |
| 1461 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 1462 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1463 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1464 | |
| 1465 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1466 | |
| 1467 | IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1468 | iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1469 | return 0; |
| 1470 | } |
| 1471 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1472 | static int iwl4965_clear_sta_key_info(struct iwl4965_priv *priv, u8 sta_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1473 | { |
| 1474 | unsigned long flags; |
| 1475 | |
| 1476 | spin_lock_irqsave(&priv->sta_lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1477 | memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl4965_hw_key)); |
| 1478 | memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl4965_keyinfo)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1479 | priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; |
| 1480 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1481 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1482 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1483 | |
| 1484 | IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1485 | iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1486 | return 0; |
| 1487 | } |
| 1488 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1489 | static void iwl4965_clear_free_frames(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1490 | { |
| 1491 | struct list_head *element; |
| 1492 | |
| 1493 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 1494 | priv->frames_count); |
| 1495 | |
| 1496 | while (!list_empty(&priv->free_frames)) { |
| 1497 | element = priv->free_frames.next; |
| 1498 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1499 | kfree(list_entry(element, struct iwl4965_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1500 | priv->frames_count--; |
| 1501 | } |
| 1502 | |
| 1503 | if (priv->frames_count) { |
| 1504 | IWL_WARNING("%d frames still in use. Did we lose one?\n", |
| 1505 | priv->frames_count); |
| 1506 | priv->frames_count = 0; |
| 1507 | } |
| 1508 | } |
| 1509 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1510 | static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1511 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1512 | struct iwl4965_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1513 | struct list_head *element; |
| 1514 | if (list_empty(&priv->free_frames)) { |
| 1515 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 1516 | if (!frame) { |
| 1517 | IWL_ERROR("Could not allocate frame!\n"); |
| 1518 | return NULL; |
| 1519 | } |
| 1520 | |
| 1521 | priv->frames_count++; |
| 1522 | return frame; |
| 1523 | } |
| 1524 | |
| 1525 | element = priv->free_frames.next; |
| 1526 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1527 | return list_entry(element, struct iwl4965_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1530 | static void iwl4965_free_frame(struct iwl4965_priv *priv, struct iwl4965_frame *frame) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1531 | { |
| 1532 | memset(frame, 0, sizeof(*frame)); |
| 1533 | list_add(&frame->list, &priv->free_frames); |
| 1534 | } |
| 1535 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1536 | unsigned int iwl4965_fill_beacon_frame(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1537 | struct ieee80211_hdr *hdr, |
| 1538 | const u8 *dest, int left) |
| 1539 | { |
| 1540 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1541 | if (!iwl4965_is_associated(priv) || !priv->ibss_beacon || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1542 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
| 1543 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) |
| 1544 | return 0; |
| 1545 | |
| 1546 | if (priv->ibss_beacon->len > left) |
| 1547 | return 0; |
| 1548 | |
| 1549 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 1550 | |
| 1551 | return priv->ibss_beacon->len; |
| 1552 | } |
| 1553 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1554 | int iwl4965_rate_index_from_plcp(int plcp) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1555 | { |
| 1556 | int i = 0; |
| 1557 | |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1558 | /* 4965 HT rate format */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1559 | if (plcp & RATE_MCS_HT_MSK) { |
| 1560 | i = (plcp & 0xff); |
| 1561 | |
| 1562 | if (i >= IWL_RATE_MIMO_6M_PLCP) |
| 1563 | i = i - IWL_RATE_MIMO_6M_PLCP; |
| 1564 | |
| 1565 | i += IWL_FIRST_OFDM_RATE; |
| 1566 | /* skip 9M not supported in ht*/ |
| 1567 | if (i >= IWL_RATE_9M_INDEX) |
| 1568 | i += 1; |
| 1569 | if ((i >= IWL_FIRST_OFDM_RATE) && |
| 1570 | (i <= IWL_LAST_OFDM_RATE)) |
| 1571 | return i; |
Ben Cahill | 7762635 | 2007-11-29 11:09:44 +0800 | [diff] [blame] | 1572 | |
| 1573 | /* 4965 legacy rate format, search for match in table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1574 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1575 | for (i = 0; i < ARRAY_SIZE(iwl4965_rates); i++) |
| 1576 | if (iwl4965_rates[i].plcp == (plcp &0xFF)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1577 | return i; |
| 1578 | } |
| 1579 | return -1; |
| 1580 | } |
| 1581 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1582 | static u8 iwl4965_rate_get_lowest_plcp(int rate_mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1583 | { |
| 1584 | u8 i; |
| 1585 | |
| 1586 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1587 | i = iwl4965_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1588 | if (rate_mask & (1 << i)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1589 | return iwl4965_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | return IWL_RATE_INVALID; |
| 1593 | } |
| 1594 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1595 | static int iwl4965_send_beacon_cmd(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1596 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1597 | struct iwl4965_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1598 | unsigned int frame_size; |
| 1599 | int rc; |
| 1600 | u8 rate; |
| 1601 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1602 | frame = iwl4965_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1603 | |
| 1604 | if (!frame) { |
| 1605 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 1606 | "command.\n"); |
| 1607 | return -ENOMEM; |
| 1608 | } |
| 1609 | |
| 1610 | if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1611 | rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1612 | 0xFF0); |
| 1613 | if (rate == IWL_INVALID_RATE) |
| 1614 | rate = IWL_RATE_6M_PLCP; |
| 1615 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1616 | rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1617 | if (rate == IWL_INVALID_RATE) |
| 1618 | rate = IWL_RATE_1M_PLCP; |
| 1619 | } |
| 1620 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1621 | frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1622 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1623 | rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1624 | &frame->u.cmd[0]); |
| 1625 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1626 | iwl4965_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1627 | |
| 1628 | return rc; |
| 1629 | } |
| 1630 | |
| 1631 | /****************************************************************************** |
| 1632 | * |
| 1633 | * EEPROM related functions |
| 1634 | * |
| 1635 | ******************************************************************************/ |
| 1636 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1637 | static void get_eeprom_mac(struct iwl4965_priv *priv, u8 *mac) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1638 | { |
| 1639 | memcpy(mac, priv->eeprom.mac_address, 6); |
| 1640 | } |
| 1641 | |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1642 | static inline void iwl4965_eeprom_release_semaphore(struct iwl4965_priv *priv) |
| 1643 | { |
| 1644 | iwl4965_clear_bit(priv, CSR_HW_IF_CONFIG_REG, |
| 1645 | CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM); |
| 1646 | } |
| 1647 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1648 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1649 | * iwl4965_eeprom_init - read EEPROM contents |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1650 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1651 | * Load the EEPROM contents from adapter into priv->eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1652 | * |
| 1653 | * NOTE: This routine uses the non-debug IO access functions. |
| 1654 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1655 | int iwl4965_eeprom_init(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1656 | { |
Tomas Winkler | 58ff6d4 | 2008-02-13 02:47:54 +0200 | [diff] [blame] | 1657 | u16 *e = (u16 *)&priv->eeprom; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1658 | u32 gp = iwl4965_read32(priv, CSR_EEPROM_GP); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1659 | u32 r; |
| 1660 | int sz = sizeof(priv->eeprom); |
| 1661 | int rc; |
| 1662 | int i; |
| 1663 | u16 addr; |
| 1664 | |
| 1665 | /* The EEPROM structure has several padding buffers within it |
| 1666 | * and when adding new EEPROM maps is subject to programmer errors |
| 1667 | * which may be very difficult to identify without explicitly |
| 1668 | * checking the resulting size of the eeprom map. */ |
| 1669 | BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE); |
| 1670 | |
| 1671 | if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { |
| 1672 | IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp); |
| 1673 | return -ENOENT; |
| 1674 | } |
| 1675 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1676 | /* Make sure driver (instead of uCode) is allowed to read EEPROM */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1677 | rc = iwl4965_eeprom_acquire_semaphore(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1678 | if (rc < 0) { |
Ian Schram | 91e1747 | 2007-10-25 17:15:23 +0800 | [diff] [blame] | 1679 | IWL_ERROR("Failed to acquire EEPROM semaphore.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1680 | return -ENOENT; |
| 1681 | } |
| 1682 | |
| 1683 | /* eeprom is an array of 16bit values */ |
| 1684 | for (addr = 0; addr < sz; addr += sizeof(u16)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1685 | _iwl4965_write32(priv, CSR_EEPROM_REG, addr << 1); |
| 1686 | _iwl4965_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1687 | |
| 1688 | for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT; |
| 1689 | i += IWL_EEPROM_ACCESS_DELAY) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1690 | r = _iwl4965_read_direct32(priv, CSR_EEPROM_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1691 | if (r & CSR_EEPROM_REG_READ_VALID_MSK) |
| 1692 | break; |
| 1693 | udelay(IWL_EEPROM_ACCESS_DELAY); |
| 1694 | } |
| 1695 | |
| 1696 | if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) { |
| 1697 | IWL_ERROR("Time out reading EEPROM[%d]", addr); |
| 1698 | rc = -ETIMEDOUT; |
| 1699 | goto done; |
| 1700 | } |
Tomas Winkler | 58ff6d4 | 2008-02-13 02:47:54 +0200 | [diff] [blame] | 1701 | e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1702 | } |
| 1703 | rc = 0; |
| 1704 | |
| 1705 | done: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1706 | iwl4965_eeprom_release_semaphore(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1707 | return rc; |
| 1708 | } |
| 1709 | |
| 1710 | /****************************************************************************** |
| 1711 | * |
| 1712 | * Misc. internal state and helper functions |
| 1713 | * |
| 1714 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1715 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1716 | |
| 1717 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1718 | * iwl4965_report_frame - dump frame to syslog during debug sessions |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1719 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1720 | * You may hack this function to show different aspects of received frames, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1721 | * including selective frame dumps. |
| 1722 | * group100 parameter selects whether to show 1 out of 100 good frames. |
| 1723 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1724 | * TODO: This was originally written for 3945, need to audit for |
| 1725 | * proper operation with 4965. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1726 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1727 | void iwl4965_report_frame(struct iwl4965_priv *priv, |
| 1728 | struct iwl4965_rx_packet *pkt, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1729 | struct ieee80211_hdr *header, int group100) |
| 1730 | { |
| 1731 | u32 to_us; |
| 1732 | u32 print_summary = 0; |
| 1733 | u32 print_dump = 0; /* set to 1 to dump all frames' contents */ |
| 1734 | u32 hundred = 0; |
| 1735 | u32 dataframe = 0; |
| 1736 | u16 fc; |
| 1737 | u16 seq_ctl; |
| 1738 | u16 channel; |
| 1739 | u16 phy_flags; |
| 1740 | int rate_sym; |
| 1741 | u16 length; |
| 1742 | u16 status; |
| 1743 | u16 bcn_tmr; |
| 1744 | u32 tsf_low; |
| 1745 | u64 tsf; |
| 1746 | u8 rssi; |
| 1747 | u8 agc; |
| 1748 | u16 sig_avg; |
| 1749 | u16 noise_diff; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1750 | struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); |
| 1751 | struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); |
| 1752 | struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1753 | u8 *data = IWL_RX_DATA(pkt); |
| 1754 | |
| 1755 | /* MAC header */ |
| 1756 | fc = le16_to_cpu(header->frame_control); |
| 1757 | seq_ctl = le16_to_cpu(header->seq_ctrl); |
| 1758 | |
| 1759 | /* metadata */ |
| 1760 | channel = le16_to_cpu(rx_hdr->channel); |
| 1761 | phy_flags = le16_to_cpu(rx_hdr->phy_flags); |
| 1762 | rate_sym = rx_hdr->rate; |
| 1763 | length = le16_to_cpu(rx_hdr->len); |
| 1764 | |
| 1765 | /* end-of-frame status and timestamp */ |
| 1766 | status = le32_to_cpu(rx_end->status); |
| 1767 | bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp); |
| 1768 | tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff; |
| 1769 | tsf = le64_to_cpu(rx_end->timestamp); |
| 1770 | |
| 1771 | /* signal statistics */ |
| 1772 | rssi = rx_stats->rssi; |
| 1773 | agc = rx_stats->agc; |
| 1774 | sig_avg = le16_to_cpu(rx_stats->sig_avg); |
| 1775 | noise_diff = le16_to_cpu(rx_stats->noise_diff); |
| 1776 | |
| 1777 | to_us = !compare_ether_addr(header->addr1, priv->mac_addr); |
| 1778 | |
| 1779 | /* if data frame is to us and all is good, |
| 1780 | * (optionally) print summary for only 1 out of every 100 */ |
| 1781 | if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) == |
| 1782 | (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) { |
| 1783 | dataframe = 1; |
| 1784 | if (!group100) |
| 1785 | print_summary = 1; /* print each frame */ |
| 1786 | else if (priv->framecnt_to_us < 100) { |
| 1787 | priv->framecnt_to_us++; |
| 1788 | print_summary = 0; |
| 1789 | } else { |
| 1790 | priv->framecnt_to_us = 0; |
| 1791 | print_summary = 1; |
| 1792 | hundred = 1; |
| 1793 | } |
| 1794 | } else { |
| 1795 | /* print summary for all other frames */ |
| 1796 | print_summary = 1; |
| 1797 | } |
| 1798 | |
| 1799 | if (print_summary) { |
| 1800 | char *title; |
| 1801 | u32 rate; |
| 1802 | |
| 1803 | if (hundred) |
| 1804 | title = "100Frames"; |
| 1805 | else if (fc & IEEE80211_FCTL_RETRY) |
| 1806 | title = "Retry"; |
| 1807 | else if (ieee80211_is_assoc_response(fc)) |
| 1808 | title = "AscRsp"; |
| 1809 | else if (ieee80211_is_reassoc_response(fc)) |
| 1810 | title = "RasRsp"; |
| 1811 | else if (ieee80211_is_probe_response(fc)) { |
| 1812 | title = "PrbRsp"; |
| 1813 | print_dump = 1; /* dump frame contents */ |
| 1814 | } else if (ieee80211_is_beacon(fc)) { |
| 1815 | title = "Beacon"; |
| 1816 | print_dump = 1; /* dump frame contents */ |
| 1817 | } else if (ieee80211_is_atim(fc)) |
| 1818 | title = "ATIM"; |
| 1819 | else if (ieee80211_is_auth(fc)) |
| 1820 | title = "Auth"; |
| 1821 | else if (ieee80211_is_deauth(fc)) |
| 1822 | title = "DeAuth"; |
| 1823 | else if (ieee80211_is_disassoc(fc)) |
| 1824 | title = "DisAssoc"; |
| 1825 | else |
| 1826 | title = "Frame"; |
| 1827 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1828 | rate = iwl4965_rate_index_from_plcp(rate_sym); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1829 | if (rate == -1) |
| 1830 | rate = 0; |
| 1831 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1832 | rate = iwl4965_rates[rate].ieee / 2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1833 | |
| 1834 | /* print frame summary. |
| 1835 | * MAC addresses show just the last byte (for brevity), |
| 1836 | * but you can hack it to show more, if you'd like to. */ |
| 1837 | if (dataframe) |
| 1838 | IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, " |
| 1839 | "len=%u, rssi=%d, chnl=%d, rate=%u, \n", |
| 1840 | title, fc, header->addr1[5], |
| 1841 | length, rssi, channel, rate); |
| 1842 | else { |
| 1843 | /* src/dst addresses assume managed mode */ |
| 1844 | IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, " |
| 1845 | "src=0x%02x, rssi=%u, tim=%lu usec, " |
| 1846 | "phy=0x%02x, chnl=%d\n", |
| 1847 | title, fc, header->addr1[5], |
| 1848 | header->addr3[5], rssi, |
| 1849 | tsf_low - priv->scan_start_tsf, |
| 1850 | phy_flags, channel); |
| 1851 | } |
| 1852 | } |
| 1853 | if (print_dump) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1854 | iwl4965_print_hex_dump(IWL_DL_RX, data, length); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1855 | } |
| 1856 | #endif |
| 1857 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1858 | static void iwl4965_unset_hw_setting(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1859 | { |
| 1860 | if (priv->hw_setting.shared_virt) |
| 1861 | pci_free_consistent(priv->pci_dev, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1862 | sizeof(struct iwl4965_shared), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1863 | priv->hw_setting.shared_virt, |
| 1864 | priv->hw_setting.shared_phys); |
| 1865 | } |
| 1866 | |
| 1867 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1868 | * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1869 | * |
| 1870 | * return : set the bit for each supported rate insert in ie |
| 1871 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1872 | static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1873 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1874 | { |
| 1875 | u16 ret_rates = 0, bit; |
| 1876 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1877 | u8 *cnt = ie; |
| 1878 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1879 | |
| 1880 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1881 | if (bit & supported_rate) { |
| 1882 | ret_rates |= bit; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1883 | rates[*cnt] = iwl4965_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1884 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1885 | (*cnt)++; |
| 1886 | (*left)--; |
| 1887 | if ((*left <= 0) || |
| 1888 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1889 | break; |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | return ret_rates; |
| 1894 | } |
| 1895 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 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, |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1900 | enum ieee80211_band band, |
| 1901 | struct ieee80211_mgmt *frame, |
| 1902 | int left, int is_direct) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1903 | { |
| 1904 | int len = 0; |
| 1905 | u8 *pos = NULL; |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1906 | u16 active_rates, ret_rates, cck_rates, active_rate_basic; |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1907 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1908 | const struct ieee80211_supported_band *sband = |
| 1909 | iwl4965_get_hw_mode(priv, band); |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1910 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1911 | |
| 1912 | /* Make sure there is enough space for the probe request, |
| 1913 | * two mandatory IEs and the data */ |
| 1914 | left -= 24; |
| 1915 | if (left < 0) |
| 1916 | return 0; |
| 1917 | len += 24; |
| 1918 | |
| 1919 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1920 | memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1921 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1922 | memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1923 | frame->seq_ctrl = 0; |
| 1924 | |
| 1925 | /* fill in our indirect SSID IE */ |
| 1926 | /* ...next IE... */ |
| 1927 | |
| 1928 | left -= 2; |
| 1929 | if (left < 0) |
| 1930 | return 0; |
| 1931 | len += 2; |
| 1932 | pos = &(frame->u.probe_req.variable[0]); |
| 1933 | *pos++ = WLAN_EID_SSID; |
| 1934 | *pos++ = 0; |
| 1935 | |
| 1936 | /* fill in our direct SSID IE... */ |
| 1937 | if (is_direct) { |
| 1938 | /* ...next IE... */ |
| 1939 | left -= 2 + priv->essid_len; |
| 1940 | if (left < 0) |
| 1941 | return 0; |
| 1942 | /* ... fill it in... */ |
| 1943 | *pos++ = WLAN_EID_SSID; |
| 1944 | *pos++ = priv->essid_len; |
| 1945 | memcpy(pos, priv->essid, priv->essid_len); |
| 1946 | pos += priv->essid_len; |
| 1947 | len += 2 + priv->essid_len; |
| 1948 | } |
| 1949 | |
| 1950 | /* fill in supported rate */ |
| 1951 | /* ...next IE... */ |
| 1952 | left -= 2; |
| 1953 | if (left < 0) |
| 1954 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1955 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1956 | /* ... fill it in... */ |
| 1957 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1958 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1959 | |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1960 | /* exclude 60M rate */ |
| 1961 | active_rates = priv->rates_mask; |
| 1962 | active_rates &= ~IWL_RATE_60M_MASK; |
| 1963 | |
| 1964 | active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1965 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1966 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1967 | ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1968 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1969 | active_rates &= ~ret_rates; |
| 1970 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1971 | ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1972 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1973 | active_rates &= ~ret_rates; |
| 1974 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1975 | len += 2 + *pos; |
| 1976 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1977 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1978 | goto fill_end; |
| 1979 | |
| 1980 | /* fill in supported extended rate */ |
| 1981 | /* ...next IE... */ |
| 1982 | left -= 2; |
| 1983 | if (left < 0) |
| 1984 | return 0; |
| 1985 | /* ... fill it in... */ |
| 1986 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1987 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1988 | iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1989 | active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1990 | if (*pos > 0) |
| 1991 | len += 2 + *pos; |
| 1992 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1993 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1994 | if (sband && sband->ht_info.ht_supported) { |
| 1995 | struct ieee80211_ht_cap *ht_cap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1996 | pos += (*pos) + 1; |
| 1997 | *pos++ = WLAN_EID_HT_CAPABILITY; |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1998 | *pos++ = sizeof(struct ieee80211_ht_cap); |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1999 | ht_cap = (struct ieee80211_ht_cap *)pos; |
| 2000 | ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap); |
| 2001 | memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16); |
| 2002 | ht_cap->ampdu_params_info =(sband->ht_info.ampdu_factor & |
| 2003 | IEEE80211_HT_CAP_AMPDU_FACTOR) | |
| 2004 | ((sband->ht_info.ampdu_density << 2) & |
| 2005 | IEEE80211_HT_CAP_AMPDU_DENSITY); |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 2006 | len += 2 + sizeof(struct ieee80211_ht_cap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2007 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2008 | #endif /*CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2009 | |
| 2010 | fill_end: |
| 2011 | return (u16)len; |
| 2012 | } |
| 2013 | |
| 2014 | /* |
| 2015 | * QoS support |
| 2016 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2017 | static int iwl4965_send_qos_params_command(struct iwl4965_priv *priv, |
| 2018 | struct iwl4965_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2019 | { |
| 2020 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2021 | return iwl4965_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
| 2022 | sizeof(struct iwl4965_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2023 | } |
| 2024 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2025 | static void iwl4965_reset_qos(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2026 | { |
| 2027 | u16 cw_min = 15; |
| 2028 | u16 cw_max = 1023; |
| 2029 | u8 aifs = 2; |
| 2030 | u8 is_legacy = 0; |
| 2031 | unsigned long flags; |
| 2032 | int i; |
| 2033 | |
| 2034 | spin_lock_irqsave(&priv->lock, flags); |
| 2035 | priv->qos_data.qos_active = 0; |
| 2036 | |
| 2037 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) { |
| 2038 | if (priv->qos_data.qos_enable) |
| 2039 | priv->qos_data.qos_active = 1; |
| 2040 | if (!(priv->active_rate & 0xfff0)) { |
| 2041 | cw_min = 31; |
| 2042 | is_legacy = 1; |
| 2043 | } |
| 2044 | } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 2045 | if (priv->qos_data.qos_enable) |
| 2046 | priv->qos_data.qos_active = 1; |
| 2047 | } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) { |
| 2048 | cw_min = 31; |
| 2049 | is_legacy = 1; |
| 2050 | } |
| 2051 | |
| 2052 | if (priv->qos_data.qos_active) |
| 2053 | aifs = 3; |
| 2054 | |
| 2055 | priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min); |
| 2056 | priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max); |
| 2057 | priv->qos_data.def_qos_parm.ac[0].aifsn = aifs; |
| 2058 | priv->qos_data.def_qos_parm.ac[0].edca_txop = 0; |
| 2059 | priv->qos_data.def_qos_parm.ac[0].reserved1 = 0; |
| 2060 | |
| 2061 | if (priv->qos_data.qos_active) { |
| 2062 | i = 1; |
| 2063 | priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min); |
| 2064 | priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max); |
| 2065 | priv->qos_data.def_qos_parm.ac[i].aifsn = 7; |
| 2066 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 2067 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2068 | |
| 2069 | i = 2; |
| 2070 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 2071 | cpu_to_le16((cw_min + 1) / 2 - 1); |
| 2072 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 2073 | cpu_to_le16(cw_max); |
| 2074 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 2075 | if (is_legacy) |
| 2076 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2077 | cpu_to_le16(6016); |
| 2078 | else |
| 2079 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2080 | cpu_to_le16(3008); |
| 2081 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2082 | |
| 2083 | i = 3; |
| 2084 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 2085 | cpu_to_le16((cw_min + 1) / 4 - 1); |
| 2086 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 2087 | cpu_to_le16((cw_max + 1) / 2 - 1); |
| 2088 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 2089 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2090 | if (is_legacy) |
| 2091 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2092 | cpu_to_le16(3264); |
| 2093 | else |
| 2094 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 2095 | cpu_to_le16(1504); |
| 2096 | } else { |
| 2097 | for (i = 1; i < 4; i++) { |
| 2098 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 2099 | cpu_to_le16(cw_min); |
| 2100 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 2101 | cpu_to_le16(cw_max); |
| 2102 | priv->qos_data.def_qos_parm.ac[i].aifsn = aifs; |
| 2103 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 2104 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2105 | } |
| 2106 | } |
| 2107 | IWL_DEBUG_QOS("set QoS to default \n"); |
| 2108 | |
| 2109 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2110 | } |
| 2111 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2112 | static void iwl4965_activate_qos(struct iwl4965_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2113 | { |
| 2114 | unsigned long flags; |
| 2115 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2116 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2117 | return; |
| 2118 | |
| 2119 | if (!priv->qos_data.qos_enable) |
| 2120 | return; |
| 2121 | |
| 2122 | spin_lock_irqsave(&priv->lock, flags); |
| 2123 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 2124 | |
| 2125 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 2126 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 2127 | priv->qos_data.def_qos_parm.qos_flags |= |
| 2128 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2129 | if (priv->qos_data.qos_active) |
| 2130 | priv->qos_data.def_qos_parm.qos_flags |= |
| 2131 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 2132 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2133 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 2134 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 2135 | priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2136 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 2137 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2138 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2139 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2140 | if (force || iwl4965_is_associated(priv)) { |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 2141 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 2142 | priv->qos_data.qos_active, |
| 2143 | priv->qos_data.def_qos_parm.qos_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2144 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2145 | iwl4965_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2146 | &(priv->qos_data.def_qos_parm)); |
| 2147 | } |
| 2148 | } |
| 2149 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2150 | /* |
| 2151 | * Power management (not Tx power!) functions |
| 2152 | */ |
| 2153 | #define MSEC_TO_USEC 1024 |
| 2154 | |
| 2155 | #define NOSLP __constant_cpu_to_le16(0), 0, 0 |
| 2156 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
| 2157 | #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC) |
| 2158 | #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \ |
| 2159 | __constant_cpu_to_le32(X1), \ |
| 2160 | __constant_cpu_to_le32(X2), \ |
| 2161 | __constant_cpu_to_le32(X3), \ |
| 2162 | __constant_cpu_to_le32(X4)} |
| 2163 | |
| 2164 | |
| 2165 | /* default power management (not Tx power) table values */ |
| 2166 | /* for tim 0-10 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2167 | static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2168 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 2169 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 2170 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, |
| 2171 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0}, |
| 2172 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1}, |
| 2173 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1} |
| 2174 | }; |
| 2175 | |
| 2176 | /* for tim > 10 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2177 | static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2178 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 2179 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), |
| 2180 | SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 2181 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), |
| 2182 | SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 2183 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), |
| 2184 | SLP_VEC(2, 6, 9, 9, 0xFF)}, 0}, |
| 2185 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 2186 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), |
| 2187 | SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 2188 | }; |
| 2189 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2190 | int iwl4965_power_init_handle(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2191 | { |
| 2192 | int rc = 0, i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2193 | struct iwl4965_power_mgr *pow_data; |
| 2194 | int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2195 | u16 pci_pm; |
| 2196 | |
| 2197 | IWL_DEBUG_POWER("Initialize power \n"); |
| 2198 | |
| 2199 | pow_data = &(priv->power_data); |
| 2200 | |
| 2201 | memset(pow_data, 0, sizeof(*pow_data)); |
| 2202 | |
| 2203 | pow_data->active_index = IWL_POWER_RANGE_0; |
| 2204 | pow_data->dtim_val = 0xffff; |
| 2205 | |
| 2206 | memcpy(&pow_data->pwr_range_0[0], &range_0[0], size); |
| 2207 | memcpy(&pow_data->pwr_range_1[0], &range_1[0], size); |
| 2208 | |
| 2209 | rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm); |
| 2210 | if (rc != 0) |
| 2211 | return 0; |
| 2212 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2213 | struct iwl4965_powertable_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2214 | |
| 2215 | IWL_DEBUG_POWER("adjust power command flags\n"); |
| 2216 | |
| 2217 | for (i = 0; i < IWL_POWER_AC; i++) { |
| 2218 | cmd = &pow_data->pwr_range_0[i].cmd; |
| 2219 | |
| 2220 | if (pci_pm & 0x1) |
| 2221 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 2222 | else |
| 2223 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 2224 | } |
| 2225 | } |
| 2226 | return rc; |
| 2227 | } |
| 2228 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2229 | static int iwl4965_update_power_cmd(struct iwl4965_priv *priv, |
| 2230 | struct iwl4965_powertable_cmd *cmd, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2231 | { |
| 2232 | int rc = 0, i; |
| 2233 | u8 skip; |
| 2234 | u32 max_sleep = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2235 | struct iwl4965_power_vec_entry *range; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2236 | u8 period = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2237 | struct iwl4965_power_mgr *pow_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2238 | |
| 2239 | if (mode > IWL_POWER_INDEX_5) { |
| 2240 | IWL_DEBUG_POWER("Error invalid power mode \n"); |
| 2241 | return -1; |
| 2242 | } |
| 2243 | pow_data = &(priv->power_data); |
| 2244 | |
| 2245 | if (pow_data->active_index == IWL_POWER_RANGE_0) |
| 2246 | range = &pow_data->pwr_range_0[0]; |
| 2247 | else |
| 2248 | range = &pow_data->pwr_range_1[1]; |
| 2249 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2250 | memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2251 | |
| 2252 | #ifdef IWL_MAC80211_DISABLE |
| 2253 | if (priv->assoc_network != NULL) { |
| 2254 | unsigned long flags; |
| 2255 | |
| 2256 | period = priv->assoc_network->tim.tim_period; |
| 2257 | } |
| 2258 | #endif /*IWL_MAC80211_DISABLE */ |
| 2259 | skip = range[mode].no_dtim; |
| 2260 | |
| 2261 | if (period == 0) { |
| 2262 | period = 1; |
| 2263 | skip = 0; |
| 2264 | } |
| 2265 | |
| 2266 | if (skip == 0) { |
| 2267 | max_sleep = period; |
| 2268 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 2269 | } else { |
| 2270 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 2271 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 2272 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 2273 | } |
| 2274 | |
| 2275 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) { |
| 2276 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 2277 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
| 2278 | } |
| 2279 | |
| 2280 | IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags); |
| 2281 | IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 2282 | IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 2283 | IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
| 2284 | le32_to_cpu(cmd->sleep_interval[0]), |
| 2285 | le32_to_cpu(cmd->sleep_interval[1]), |
| 2286 | le32_to_cpu(cmd->sleep_interval[2]), |
| 2287 | le32_to_cpu(cmd->sleep_interval[3]), |
| 2288 | le32_to_cpu(cmd->sleep_interval[4])); |
| 2289 | |
| 2290 | return rc; |
| 2291 | } |
| 2292 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2293 | static int iwl4965_send_power_mode(struct iwl4965_priv *priv, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2294 | { |
John W. Linville | 9a62f73 | 2007-11-15 16:27:36 -0500 | [diff] [blame] | 2295 | u32 uninitialized_var(final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2296 | int rc; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2297 | struct iwl4965_powertable_cmd cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2298 | |
| 2299 | /* If on battery, set to 3, |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2300 | * if plugged into AC power, set to CAM ("continuously aware mode"), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2301 | * else user level */ |
| 2302 | switch (mode) { |
| 2303 | case IWL_POWER_BATTERY: |
| 2304 | final_mode = IWL_POWER_INDEX_3; |
| 2305 | break; |
| 2306 | case IWL_POWER_AC: |
| 2307 | final_mode = IWL_POWER_MODE_CAM; |
| 2308 | break; |
| 2309 | default: |
| 2310 | final_mode = mode; |
| 2311 | break; |
| 2312 | } |
| 2313 | |
| 2314 | cmd.keep_alive_beacons = 0; |
| 2315 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2316 | iwl4965_update_power_cmd(priv, &cmd, final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2317 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2318 | rc = iwl4965_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2319 | |
| 2320 | if (final_mode == IWL_POWER_MODE_CAM) |
| 2321 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 2322 | else |
| 2323 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 2324 | |
| 2325 | return rc; |
| 2326 | } |
| 2327 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2328 | 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] | 2329 | { |
| 2330 | /* Filter incoming packets to determine if they are targeted toward |
| 2331 | * this network, discarding packets coming from ourselves */ |
| 2332 | switch (priv->iw_mode) { |
| 2333 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 2334 | /* packets from our adapter are dropped (echo) */ |
| 2335 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 2336 | return 0; |
| 2337 | /* {broad,multi}cast packets to our IBSS go through */ |
| 2338 | if (is_multicast_ether_addr(header->addr1)) |
| 2339 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 2340 | /* packets to our adapter go through */ |
| 2341 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2342 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 2343 | /* packets from our adapter are dropped (echo) */ |
| 2344 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 2345 | return 0; |
| 2346 | /* {broad,multi}cast packets to our BSS go through */ |
| 2347 | if (is_multicast_ether_addr(header->addr1)) |
| 2348 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 2349 | /* packets to our adapter go through */ |
| 2350 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2351 | } |
| 2352 | |
| 2353 | return 1; |
| 2354 | } |
| 2355 | |
| 2356 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2357 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2358 | static const char *iwl4965_get_tx_fail_reason(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2359 | { |
| 2360 | switch (status & TX_STATUS_MSK) { |
| 2361 | case TX_STATUS_SUCCESS: |
| 2362 | return "SUCCESS"; |
| 2363 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 2364 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 2365 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 2366 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 2367 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 2368 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 2369 | TX_STATUS_ENTRY(DEST_PS); |
| 2370 | TX_STATUS_ENTRY(ABORTED); |
| 2371 | TX_STATUS_ENTRY(BT_RETRY); |
| 2372 | TX_STATUS_ENTRY(STA_INVALID); |
| 2373 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 2374 | TX_STATUS_ENTRY(TID_DISABLE); |
| 2375 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 2376 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 2377 | TX_STATUS_ENTRY(TX_LOCKED); |
| 2378 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 2379 | } |
| 2380 | |
| 2381 | return "UNKNOWN"; |
| 2382 | } |
| 2383 | |
| 2384 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2385 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2386 | * |
| 2387 | * NOTE: priv->mutex is not required before calling this function |
| 2388 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2389 | static int iwl4965_scan_cancel(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2390 | { |
| 2391 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 2392 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2393 | return 0; |
| 2394 | } |
| 2395 | |
| 2396 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2397 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2398 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 2399 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2400 | queue_work(priv->workqueue, &priv->abort_scan); |
| 2401 | |
| 2402 | } else |
| 2403 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 2404 | |
| 2405 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2406 | } |
| 2407 | |
| 2408 | return 0; |
| 2409 | } |
| 2410 | |
| 2411 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2412 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2413 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 2414 | * |
| 2415 | * NOTE: priv->mutex must be held before calling this function |
| 2416 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2417 | 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] | 2418 | { |
| 2419 | unsigned long now = jiffies; |
| 2420 | int ret; |
| 2421 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2422 | ret = iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2423 | if (ret && ms) { |
| 2424 | mutex_unlock(&priv->mutex); |
| 2425 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 2426 | test_bit(STATUS_SCANNING, &priv->status)) |
| 2427 | msleep(1); |
| 2428 | mutex_lock(&priv->mutex); |
| 2429 | |
| 2430 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2431 | } |
| 2432 | |
| 2433 | return ret; |
| 2434 | } |
| 2435 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2436 | static void iwl4965_sequence_reset(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2437 | { |
| 2438 | /* Reset ieee stats */ |
| 2439 | |
| 2440 | /* We don't reset the net_device_stats (ieee->stats) on |
| 2441 | * re-association */ |
| 2442 | |
| 2443 | priv->last_seq_num = -1; |
| 2444 | priv->last_frag_num = -1; |
| 2445 | priv->last_packet_time = 0; |
| 2446 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2447 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 2451 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 2452 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2453 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2454 | { |
| 2455 | u16 new_val = 0; |
| 2456 | u16 beacon_factor = 0; |
| 2457 | |
| 2458 | beacon_factor = |
| 2459 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 2460 | / MAX_UCODE_BEACON_INTERVAL; |
| 2461 | new_val = beacon_val / beacon_factor; |
| 2462 | |
| 2463 | return cpu_to_le16(new_val); |
| 2464 | } |
| 2465 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2466 | static void iwl4965_setup_rxon_timing(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2467 | { |
| 2468 | u64 interval_tm_unit; |
| 2469 | u64 tsf, result; |
| 2470 | unsigned long flags; |
| 2471 | struct ieee80211_conf *conf = NULL; |
| 2472 | u16 beacon_int = 0; |
| 2473 | |
| 2474 | conf = ieee80211_get_hw_conf(priv->hw); |
| 2475 | |
| 2476 | spin_lock_irqsave(&priv->lock, flags); |
| 2477 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1); |
| 2478 | priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0); |
| 2479 | |
| 2480 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 2481 | |
| 2482 | tsf = priv->timestamp1; |
| 2483 | tsf = ((tsf << 32) | priv->timestamp0); |
| 2484 | |
| 2485 | beacon_int = priv->beacon_int; |
| 2486 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2487 | |
| 2488 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 2489 | if (beacon_int == 0) { |
| 2490 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 2491 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 2492 | } else { |
| 2493 | priv->rxon_timing.beacon_interval = |
| 2494 | cpu_to_le16(beacon_int); |
| 2495 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2496 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2497 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2498 | } |
| 2499 | |
| 2500 | priv->rxon_timing.atim_window = 0; |
| 2501 | } else { |
| 2502 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2503 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2504 | /* TODO: we need to get atim_window from upper stack |
| 2505 | * for now we set to 0 */ |
| 2506 | priv->rxon_timing.atim_window = 0; |
| 2507 | } |
| 2508 | |
| 2509 | interval_tm_unit = |
| 2510 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 2511 | result = do_div(tsf, interval_tm_unit); |
| 2512 | priv->rxon_timing.beacon_init_val = |
| 2513 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 2514 | |
| 2515 | IWL_DEBUG_ASSOC |
| 2516 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 2517 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 2518 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 2519 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 2520 | } |
| 2521 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2522 | static int iwl4965_scan_initiate(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2523 | { |
| 2524 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 2525 | IWL_ERROR("APs don't scan.\n"); |
| 2526 | return 0; |
| 2527 | } |
| 2528 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2529 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2530 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 2531 | return -EIO; |
| 2532 | } |
| 2533 | |
| 2534 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2535 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 2536 | return -EAGAIN; |
| 2537 | } |
| 2538 | |
| 2539 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2540 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 2541 | "Queuing.\n"); |
| 2542 | return -EAGAIN; |
| 2543 | } |
| 2544 | |
| 2545 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 2546 | priv->scan_bands = 2; |
| 2547 | set_bit(STATUS_SCANNING, &priv->status); |
| 2548 | priv->scan_start = jiffies; |
| 2549 | priv->scan_pass_start = priv->scan_start; |
| 2550 | |
| 2551 | queue_work(priv->workqueue, &priv->request_scan); |
| 2552 | |
| 2553 | return 0; |
| 2554 | } |
| 2555 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2556 | 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] | 2557 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2558 | struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2559 | |
| 2560 | if (hw_decrypt) |
| 2561 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 2562 | else |
| 2563 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 2564 | |
| 2565 | return 0; |
| 2566 | } |
| 2567 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2568 | static void iwl4965_set_flags_for_phymode(struct iwl4965_priv *priv, |
| 2569 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2570 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2571 | if (band == IEEE80211_BAND_5GHZ) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2572 | priv->staging_rxon.flags &= |
| 2573 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 2574 | | RXON_FLG_CCK_MSK); |
| 2575 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2576 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2577 | /* Copied from iwl4965_bg_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2578 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 2579 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2580 | else |
| 2581 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2582 | |
| 2583 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 2584 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2585 | |
| 2586 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 2587 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 2588 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 2589 | } |
| 2590 | } |
| 2591 | |
| 2592 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2593 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2594 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2595 | static void iwl4965_connection_init_rx_config(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2596 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2597 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2598 | |
| 2599 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 2600 | |
| 2601 | switch (priv->iw_mode) { |
| 2602 | case IEEE80211_IF_TYPE_AP: |
| 2603 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 2604 | break; |
| 2605 | |
| 2606 | case IEEE80211_IF_TYPE_STA: |
| 2607 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 2608 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 2609 | break; |
| 2610 | |
| 2611 | case IEEE80211_IF_TYPE_IBSS: |
| 2612 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 2613 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2614 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 2615 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2616 | break; |
| 2617 | |
| 2618 | case IEEE80211_IF_TYPE_MNTR: |
| 2619 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 2620 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 2621 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2622 | break; |
| 2623 | } |
| 2624 | |
| 2625 | #if 0 |
| 2626 | /* TODO: Figure out when short_preamble would be set and cache from |
| 2627 | * that */ |
| 2628 | if (!hw_to_local(priv->hw)->short_preamble) |
| 2629 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2630 | else |
| 2631 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2632 | #endif |
| 2633 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2634 | ch_info = iwl4965_get_channel_info(priv, priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2635 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2636 | |
| 2637 | if (!ch_info) |
| 2638 | ch_info = &priv->channel_info[0]; |
| 2639 | |
| 2640 | /* |
| 2641 | * in some case A channels are all non IBSS |
| 2642 | * in this case force B/G channel |
| 2643 | */ |
| 2644 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 2645 | !(is_channel_ibss(ch_info))) |
| 2646 | ch_info = &priv->channel_info[0]; |
| 2647 | |
| 2648 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2649 | priv->band = ch_info->band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2650 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2651 | iwl4965_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2652 | |
| 2653 | priv->staging_rxon.ofdm_basic_rates = |
| 2654 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2655 | priv->staging_rxon.cck_basic_rates = |
| 2656 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2657 | |
| 2658 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 2659 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 2660 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2661 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 2662 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 2663 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
| 2664 | iwl4965_set_rxon_chain(priv); |
| 2665 | } |
| 2666 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2667 | static int iwl4965_set_mode(struct iwl4965_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2668 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2669 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2670 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2671 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2672 | ch_info = iwl4965_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2673 | priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2674 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2675 | |
| 2676 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 2677 | IWL_ERROR("channel %d not IBSS channel\n", |
| 2678 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2679 | return -EINVAL; |
| 2680 | } |
| 2681 | } |
| 2682 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2683 | priv->iw_mode = mode; |
| 2684 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2685 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2686 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2687 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2688 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2689 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2690 | /* dont commit rxon if rf-kill is on*/ |
| 2691 | if (!iwl4965_is_ready_rf(priv)) |
| 2692 | return -EAGAIN; |
| 2693 | |
| 2694 | cancel_delayed_work(&priv->scan_check); |
| 2695 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
| 2696 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 2697 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 2698 | return -EAGAIN; |
| 2699 | } |
| 2700 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2701 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2702 | |
| 2703 | return 0; |
| 2704 | } |
| 2705 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2706 | static void iwl4965_build_tx_cmd_hwcrypto(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2707 | struct ieee80211_tx_control *ctl, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2708 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2709 | struct sk_buff *skb_frag, |
| 2710 | int last_frag) |
| 2711 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2712 | struct iwl4965_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2713 | |
| 2714 | switch (keyinfo->alg) { |
| 2715 | case ALG_CCMP: |
| 2716 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM; |
| 2717 | memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen); |
| 2718 | IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n"); |
| 2719 | break; |
| 2720 | |
| 2721 | case ALG_TKIP: |
| 2722 | #if 0 |
| 2723 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP; |
| 2724 | |
| 2725 | if (last_frag) |
| 2726 | memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8, |
| 2727 | 8); |
| 2728 | else |
| 2729 | memset(cmd->cmd.tx.tkip_mic.byte, 0, 8); |
| 2730 | #endif |
| 2731 | break; |
| 2732 | |
| 2733 | case ALG_WEP: |
| 2734 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP | |
| 2735 | (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT; |
| 2736 | |
| 2737 | if (keyinfo->keylen == 13) |
| 2738 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
| 2739 | |
| 2740 | memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen); |
| 2741 | |
| 2742 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
| 2743 | "with key %d\n", ctl->key_idx); |
| 2744 | break; |
| 2745 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2746 | default: |
| 2747 | printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg); |
| 2748 | break; |
| 2749 | } |
| 2750 | } |
| 2751 | |
| 2752 | /* |
| 2753 | * handle build REPLY_TX command notification. |
| 2754 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2755 | static void iwl4965_build_tx_cmd_basic(struct iwl4965_priv *priv, |
| 2756 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2757 | struct ieee80211_tx_control *ctrl, |
| 2758 | struct ieee80211_hdr *hdr, |
| 2759 | int is_unicast, u8 std_id) |
| 2760 | { |
| 2761 | __le16 *qc; |
| 2762 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2763 | __le32 tx_flags = cmd->cmd.tx.tx_flags; |
| 2764 | |
| 2765 | cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 2766 | if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) { |
| 2767 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
| 2768 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 2769 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2770 | if (ieee80211_is_probe_response(fc) && |
| 2771 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 2772 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 2773 | } else { |
| 2774 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 2775 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2776 | } |
| 2777 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2778 | if (ieee80211_is_back_request(fc)) |
| 2779 | tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK; |
| 2780 | |
| 2781 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2782 | cmd->cmd.tx.sta_id = std_id; |
| 2783 | if (ieee80211_get_morefrag(hdr)) |
| 2784 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 2785 | |
| 2786 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2787 | if (qc) { |
| 2788 | cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf); |
| 2789 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
| 2790 | } else |
| 2791 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2792 | |
| 2793 | if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) { |
| 2794 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 2795 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
| 2796 | } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { |
| 2797 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 2798 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 2799 | } |
| 2800 | |
| 2801 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 2802 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 2803 | |
| 2804 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
| 2805 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { |
| 2806 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || |
| 2807 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2808 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2809 | else |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2810 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2811 | } else |
| 2812 | cmd->cmd.tx.timeout.pm_frame_timeout = 0; |
| 2813 | |
| 2814 | cmd->cmd.tx.driver_txop = 0; |
| 2815 | cmd->cmd.tx.tx_flags = tx_flags; |
| 2816 | cmd->cmd.tx.next_frame_len = 0; |
| 2817 | } |
| 2818 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2819 | /** |
| 2820 | * iwl4965_get_sta_id - Find station's index within station table |
| 2821 | * |
| 2822 | * If new IBSS station, create new entry in station table |
| 2823 | */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2824 | static int iwl4965_get_sta_id(struct iwl4965_priv *priv, |
| 2825 | struct ieee80211_hdr *hdr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2826 | { |
| 2827 | int sta_id; |
| 2828 | u16 fc = le16_to_cpu(hdr->frame_control); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2829 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2830 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2831 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2832 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 2833 | is_multicast_ether_addr(hdr->addr1)) |
| 2834 | return priv->hw_setting.bcast_sta_id; |
| 2835 | |
| 2836 | switch (priv->iw_mode) { |
| 2837 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2838 | /* If we are a client station in a BSS network, use the special |
| 2839 | * AP station entry (that's the only station we communicate with) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2840 | case IEEE80211_IF_TYPE_STA: |
| 2841 | return IWL_AP_ID; |
| 2842 | |
| 2843 | /* If we are an AP, then find the station, or use BCAST */ |
| 2844 | case IEEE80211_IF_TYPE_AP: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2845 | sta_id = iwl4965_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2846 | if (sta_id != IWL_INVALID_STATION) |
| 2847 | return sta_id; |
| 2848 | return priv->hw_setting.bcast_sta_id; |
| 2849 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2850 | /* If this frame is going out to an IBSS network, find the station, |
| 2851 | * or create a new station table entry */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2852 | case IEEE80211_IF_TYPE_IBSS: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2853 | sta_id = iwl4965_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2854 | if (sta_id != IWL_INVALID_STATION) |
| 2855 | return sta_id; |
| 2856 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2857 | /* Create new station table entry */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 2858 | sta_id = iwl4965_add_station_flags(priv, hdr->addr1, |
| 2859 | 0, CMD_ASYNC, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2860 | |
| 2861 | if (sta_id != IWL_INVALID_STATION) |
| 2862 | return sta_id; |
| 2863 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2864 | IWL_DEBUG_DROP("Station %s not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2865 | "Defaulting to broadcast...\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2866 | print_mac(mac, hdr->addr1)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2867 | iwl4965_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2868 | return priv->hw_setting.bcast_sta_id; |
| 2869 | |
| 2870 | default: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2871 | IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2872 | return priv->hw_setting.bcast_sta_id; |
| 2873 | } |
| 2874 | } |
| 2875 | |
| 2876 | /* |
| 2877 | * start REPLY_TX command process |
| 2878 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2879 | static int iwl4965_tx_skb(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2880 | struct sk_buff *skb, struct ieee80211_tx_control *ctl) |
| 2881 | { |
| 2882 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2883 | struct iwl4965_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2884 | u32 *control_flags; |
| 2885 | int txq_id = ctl->queue; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2886 | struct iwl4965_tx_queue *txq = NULL; |
| 2887 | struct iwl4965_queue *q = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2888 | dma_addr_t phys_addr; |
| 2889 | dma_addr_t txcmd_phys; |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2890 | dma_addr_t scratch_phys; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2891 | struct iwl4965_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2892 | u16 len, idx, len_org; |
| 2893 | u8 id, hdr_len, unicast; |
| 2894 | u8 sta_id; |
| 2895 | u16 seq_number = 0; |
| 2896 | u16 fc; |
| 2897 | __le16 *qc; |
| 2898 | u8 wait_write_ptr = 0; |
| 2899 | unsigned long flags; |
| 2900 | int rc; |
| 2901 | |
| 2902 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2903 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2904 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 2905 | goto drop_unlock; |
| 2906 | } |
| 2907 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 2908 | if (!priv->vif) { |
| 2909 | IWL_DEBUG_DROP("Dropping - !priv->vif\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2910 | goto drop_unlock; |
| 2911 | } |
| 2912 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2913 | if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2914 | IWL_ERROR("ERROR: No TX rate available.\n"); |
| 2915 | goto drop_unlock; |
| 2916 | } |
| 2917 | |
| 2918 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 2919 | id = 0; |
| 2920 | |
| 2921 | fc = le16_to_cpu(hdr->frame_control); |
| 2922 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2923 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2924 | if (ieee80211_is_auth(fc)) |
| 2925 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
| 2926 | else if (ieee80211_is_assoc_request(fc)) |
| 2927 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
| 2928 | else if (ieee80211_is_reassoc_request(fc)) |
| 2929 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 2930 | #endif |
| 2931 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2932 | /* drop all data frame if we are not associated */ |
Gregory Greenman | 76f3915 | 2008-01-23 10:15:21 -0800 | [diff] [blame] | 2933 | if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) && |
| 2934 | (!iwl4965_is_associated(priv) || |
Reinette Chatre | a647724 | 2008-02-14 10:40:28 -0800 | [diff] [blame] | 2935 | ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id) || |
Gregory Greenman | 76f3915 | 2008-01-23 10:15:21 -0800 | [diff] [blame] | 2936 | !priv->assoc_station_added)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2937 | IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2938 | goto drop_unlock; |
| 2939 | } |
| 2940 | |
| 2941 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2942 | |
| 2943 | hdr_len = ieee80211_get_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2944 | |
| 2945 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2946 | sta_id = iwl4965_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2947 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2948 | DECLARE_MAC_BUF(mac); |
| 2949 | |
| 2950 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n", |
| 2951 | print_mac(mac, hdr->addr1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2952 | goto drop; |
| 2953 | } |
| 2954 | |
| 2955 | IWL_DEBUG_RATE("station Id %d\n", sta_id); |
| 2956 | |
| 2957 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2958 | if (qc) { |
| 2959 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2960 | seq_number = priv->stations[sta_id].tid[tid].seq_number & |
| 2961 | IEEE80211_SCTL_SEQ; |
| 2962 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 2963 | (hdr->seq_ctrl & |
| 2964 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 2965 | seq_number += 0x10; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2966 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2967 | /* aggregation is on for this <sta,tid> */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2968 | if (ctl->flags & IEEE80211_TXCTL_AMPDU) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2969 | txq_id = priv->stations[sta_id].tid[tid].agg.txq_id; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2970 | priv->stations[sta_id].tid[tid].tfds_in_queue++; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2971 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2972 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2973 | |
| 2974 | /* Descriptor for chosen Tx queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2975 | txq = &priv->txq[txq_id]; |
| 2976 | q = &txq->q; |
| 2977 | |
| 2978 | spin_lock_irqsave(&priv->lock, flags); |
| 2979 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2980 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2981 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2982 | memset(tfd, 0, sizeof(*tfd)); |
| 2983 | control_flags = (u32 *) tfd; |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2984 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2985 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2986 | /* Set up driver data for this TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2987 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2988 | txq->txb[q->write_ptr].skb[0] = skb; |
| 2989 | memcpy(&(txq->txb[q->write_ptr].status.control), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2990 | ctl, sizeof(struct ieee80211_tx_control)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2991 | |
| 2992 | /* 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] | 2993 | out_cmd = &txq->cmd[idx]; |
| 2994 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 2995 | memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2996 | |
| 2997 | /* |
| 2998 | * Set up the Tx-command (not MAC!) header. |
| 2999 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 3000 | * after Tx, uCode's Tx response will return this value so driver can |
| 3001 | * locate the frame within the tx queue and do post-tx processing. |
| 3002 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3003 | out_cmd->hdr.cmd = REPLY_TX; |
| 3004 | 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] | 3005 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3006 | |
| 3007 | /* Copy MAC header from skb into command buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3008 | memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); |
| 3009 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3010 | /* |
| 3011 | * Use the first empty entry in this queue's command buffer array |
| 3012 | * to contain the Tx command and MAC header concatenated together |
| 3013 | * (payload data will be in another buffer). |
| 3014 | * Size of this varies, due to varying MAC header length. |
| 3015 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 3016 | * of the MAC header (device reads on dword boundaries). |
| 3017 | * We'll tell device about this padding later. |
| 3018 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3019 | len = priv->hw_setting.tx_cmd_len + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3020 | sizeof(struct iwl4965_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3021 | |
| 3022 | len_org = len; |
| 3023 | len = (len + 3) & ~3; |
| 3024 | |
| 3025 | if (len_org != len) |
| 3026 | len_org = 1; |
| 3027 | else |
| 3028 | len_org = 0; |
| 3029 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3030 | /* Physical address of this Tx command's header (not MAC header!), |
| 3031 | * within command buffer array. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3032 | txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl4965_cmd) * idx + |
| 3033 | offsetof(struct iwl4965_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3034 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3035 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 3036 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3037 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3038 | |
| 3039 | if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3040 | iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3041 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3042 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 3043 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3044 | len = skb->len - hdr_len; |
| 3045 | if (len) { |
| 3046 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 3047 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3048 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3049 | } |
| 3050 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3051 | /* Tell 4965 about any 2-byte padding after MAC header */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3052 | if (len_org) |
| 3053 | out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK; |
| 3054 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3055 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3056 | len = (u16)skb->len; |
| 3057 | out_cmd->cmd.tx.len = cpu_to_le16(len); |
| 3058 | |
| 3059 | /* TODO need this for burst mode later on */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3060 | 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] | 3061 | |
| 3062 | /* set is_hcca to 0; it probably will never be implemented */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3063 | 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] | 3064 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 3065 | scratch_phys = txcmd_phys + sizeof(struct iwl4965_cmd_header) + |
| 3066 | offsetof(struct iwl4965_tx_cmd, scratch); |
| 3067 | out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys); |
| 3068 | out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys); |
| 3069 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3070 | if (!ieee80211_get_morefrag(hdr)) { |
| 3071 | txq->need_update = 1; |
| 3072 | if (qc) { |
| 3073 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 3074 | priv->stations[sta_id].tid[tid].seq_number = seq_number; |
| 3075 | } |
| 3076 | } else { |
| 3077 | wait_write_ptr = 1; |
| 3078 | txq->need_update = 0; |
| 3079 | } |
| 3080 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3081 | iwl4965_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3082 | sizeof(out_cmd->cmd.tx)); |
| 3083 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3084 | 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] | 3085 | ieee80211_get_hdrlen(fc)); |
| 3086 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3087 | /* Set up entry for this TFD in Tx byte-count array */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3088 | iwl4965_tx_queue_update_wr_ptr(priv, txq, len); |
| 3089 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3090 | /* Tell device the write index *just past* this latest filled TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3091 | q->write_ptr = iwl4965_queue_inc_wrap(q->write_ptr, q->n_bd); |
| 3092 | rc = 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 | if (rc) |
| 3096 | return rc; |
| 3097 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3098 | if ((iwl4965_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3099 | && priv->mac80211_registered) { |
| 3100 | if (wait_write_ptr) { |
| 3101 | spin_lock_irqsave(&priv->lock, flags); |
| 3102 | txq->need_update = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3103 | iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3104 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3105 | } |
| 3106 | |
| 3107 | ieee80211_stop_queue(priv->hw, ctl->queue); |
| 3108 | } |
| 3109 | |
| 3110 | return 0; |
| 3111 | |
| 3112 | drop_unlock: |
| 3113 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3114 | drop: |
| 3115 | return -1; |
| 3116 | } |
| 3117 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3118 | static void iwl4965_set_rate(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3119 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3120 | const struct ieee80211_supported_band *hw = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3121 | struct ieee80211_rate *rate; |
| 3122 | int i; |
| 3123 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3124 | hw = iwl4965_get_hw_mode(priv, priv->band); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 3125 | if (!hw) { |
| 3126 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 3127 | return; |
| 3128 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3129 | |
| 3130 | priv->active_rate = 0; |
| 3131 | priv->active_rate_basic = 0; |
| 3132 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3133 | for (i = 0; i < hw->n_bitrates; i++) { |
| 3134 | rate = &(hw->bitrates[i]); |
| 3135 | if (rate->hw_value < IWL_RATE_COUNT) |
| 3136 | priv->active_rate |= (1 << rate->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3137 | } |
| 3138 | |
| 3139 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 3140 | priv->active_rate, priv->active_rate_basic); |
| 3141 | |
| 3142 | /* |
| 3143 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 3144 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 3145 | * OFDM |
| 3146 | */ |
| 3147 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 3148 | priv->staging_rxon.cck_basic_rates = |
| 3149 | ((priv->active_rate_basic & |
| 3150 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 3151 | else |
| 3152 | priv->staging_rxon.cck_basic_rates = |
| 3153 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 3154 | |
| 3155 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 3156 | priv->staging_rxon.ofdm_basic_rates = |
| 3157 | ((priv->active_rate_basic & |
| 3158 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 3159 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 3160 | else |
| 3161 | priv->staging_rxon.ofdm_basic_rates = |
| 3162 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 3163 | } |
| 3164 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3165 | 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] | 3166 | { |
| 3167 | unsigned long flags; |
| 3168 | |
| 3169 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 3170 | return; |
| 3171 | |
| 3172 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 3173 | disable_radio ? "OFF" : "ON"); |
| 3174 | |
| 3175 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3176 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3177 | /* FIXME: This is a workaround for AP */ |
| 3178 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 3179 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3180 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3181 | CSR_UCODE_SW_BIT_RFKILL); |
| 3182 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3183 | iwl4965_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3184 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3185 | } |
| 3186 | return; |
| 3187 | } |
| 3188 | |
| 3189 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3190 | 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] | 3191 | |
| 3192 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3193 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3194 | |
| 3195 | /* wake up ucode */ |
| 3196 | msleep(10); |
| 3197 | |
| 3198 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3199 | iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
| 3200 | if (!iwl4965_grab_nic_access(priv)) |
| 3201 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3202 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3203 | |
| 3204 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 3205 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 3206 | "disabled by HW switch\n"); |
| 3207 | return; |
| 3208 | } |
| 3209 | |
| 3210 | queue_work(priv->workqueue, &priv->restart); |
| 3211 | return; |
| 3212 | } |
| 3213 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3214 | 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] | 3215 | u32 decrypt_res, struct ieee80211_rx_status *stats) |
| 3216 | { |
| 3217 | u16 fc = |
| 3218 | le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control); |
| 3219 | |
| 3220 | if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
| 3221 | return; |
| 3222 | |
| 3223 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 3224 | return; |
| 3225 | |
| 3226 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 3227 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 3228 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 3229 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 3230 | RX_RES_STATUS_BAD_ICV_MIC) |
| 3231 | stats->flag |= RX_FLAG_MMIC_ERROR; |
| 3232 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 3233 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 3234 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 3235 | RX_RES_STATUS_DECRYPT_OK) { |
| 3236 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 3237 | stats->flag |= RX_FLAG_DECRYPTED; |
| 3238 | } |
| 3239 | break; |
| 3240 | |
| 3241 | default: |
| 3242 | break; |
| 3243 | } |
| 3244 | } |
| 3245 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3246 | |
| 3247 | #define IWL_PACKET_RETRY_TIME HZ |
| 3248 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3249 | 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] | 3250 | { |
| 3251 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 3252 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 3253 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 3254 | u16 *last_seq, *last_frag; |
| 3255 | unsigned long *last_time; |
| 3256 | |
| 3257 | switch (priv->iw_mode) { |
| 3258 | case IEEE80211_IF_TYPE_IBSS:{ |
| 3259 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3260 | struct iwl4965_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3261 | u8 *mac = header->addr2; |
| 3262 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 3263 | |
| 3264 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3265 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3266 | if (!compare_ether_addr(entry->mac, mac)) |
| 3267 | break; |
| 3268 | } |
| 3269 | if (p == &priv->ibss_mac_hash[index]) { |
| 3270 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 3271 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 3272 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3273 | return 0; |
| 3274 | } |
| 3275 | memcpy(entry->mac, mac, ETH_ALEN); |
| 3276 | entry->seq_num = seq; |
| 3277 | entry->frag_num = frag; |
| 3278 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 3279 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3280 | return 0; |
| 3281 | } |
| 3282 | last_seq = &entry->seq_num; |
| 3283 | last_frag = &entry->frag_num; |
| 3284 | last_time = &entry->packet_time; |
| 3285 | break; |
| 3286 | } |
| 3287 | case IEEE80211_IF_TYPE_STA: |
| 3288 | last_seq = &priv->last_seq_num; |
| 3289 | last_frag = &priv->last_frag_num; |
| 3290 | last_time = &priv->last_packet_time; |
| 3291 | break; |
| 3292 | default: |
| 3293 | return 0; |
| 3294 | } |
| 3295 | if ((*last_seq == seq) && |
| 3296 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 3297 | if (*last_frag == frag) |
| 3298 | goto drop; |
| 3299 | if (*last_frag + 1 != frag) |
| 3300 | /* out-of-order fragment */ |
| 3301 | goto drop; |
| 3302 | } else |
| 3303 | *last_seq = seq; |
| 3304 | |
| 3305 | *last_frag = frag; |
| 3306 | *last_time = jiffies; |
| 3307 | return 0; |
| 3308 | |
| 3309 | drop: |
| 3310 | return 1; |
| 3311 | } |
| 3312 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3313 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3314 | |
| 3315 | #include "iwl-spectrum.h" |
| 3316 | |
| 3317 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 3318 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 3319 | #define TIME_UNIT 1024 |
| 3320 | |
| 3321 | /* |
| 3322 | * extended beacon time format |
| 3323 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 3324 | * the high 1 byte is the beacon counts |
| 3325 | * the lower 3 bytes is the time in usec within one beacon interval |
| 3326 | */ |
| 3327 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3328 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3329 | { |
| 3330 | u32 quot; |
| 3331 | u32 rem; |
| 3332 | u32 interval = beacon_interval * 1024; |
| 3333 | |
| 3334 | if (!interval || !usec) |
| 3335 | return 0; |
| 3336 | |
| 3337 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 3338 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 3339 | |
| 3340 | return (quot << 24) + rem; |
| 3341 | } |
| 3342 | |
| 3343 | /* base is usually what we get from ucode with each received frame, |
| 3344 | * the same as HW timer counter counting down |
| 3345 | */ |
| 3346 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3347 | 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] | 3348 | { |
| 3349 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 3350 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 3351 | u32 interval = beacon_interval * TIME_UNIT; |
| 3352 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 3353 | (addon & BEACON_TIME_MASK_HIGH); |
| 3354 | |
| 3355 | if (base_low > addon_low) |
| 3356 | res += base_low - addon_low; |
| 3357 | else if (base_low < addon_low) { |
| 3358 | res += interval + base_low - addon_low; |
| 3359 | res += (1 << 24); |
| 3360 | } else |
| 3361 | res += (1 << 24); |
| 3362 | |
| 3363 | return cpu_to_le32(res); |
| 3364 | } |
| 3365 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3366 | static int iwl4965_get_measurement(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3367 | struct ieee80211_measurement_params *params, |
| 3368 | u8 type) |
| 3369 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3370 | struct iwl4965_spectrum_cmd spectrum; |
| 3371 | struct iwl4965_rx_packet *res; |
| 3372 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3373 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 3374 | .data = (void *)&spectrum, |
| 3375 | .meta.flags = CMD_WANT_SKB, |
| 3376 | }; |
| 3377 | u32 add_time = le64_to_cpu(params->start_time); |
| 3378 | int rc; |
| 3379 | int spectrum_resp_status; |
| 3380 | int duration = le16_to_cpu(params->duration); |
| 3381 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3382 | if (iwl4965_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3383 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3384 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3385 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 3386 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3387 | |
| 3388 | memset(&spectrum, 0, sizeof(spectrum)); |
| 3389 | |
| 3390 | spectrum.channel_count = cpu_to_le16(1); |
| 3391 | spectrum.flags = |
| 3392 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 3393 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 3394 | cmd.len = sizeof(spectrum); |
| 3395 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 3396 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3397 | if (iwl4965_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3398 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3399 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3400 | add_time, |
| 3401 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3402 | else |
| 3403 | spectrum.start_time = 0; |
| 3404 | |
| 3405 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 3406 | spectrum.channels[0].channel = params->channel; |
| 3407 | spectrum.channels[0].type = type; |
| 3408 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 3409 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 3410 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 3411 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3412 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3413 | if (rc) |
| 3414 | return rc; |
| 3415 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3416 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3417 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 3418 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 3419 | rc = -EIO; |
| 3420 | } |
| 3421 | |
| 3422 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 3423 | switch (spectrum_resp_status) { |
| 3424 | case 0: /* Command will be handled */ |
| 3425 | if (res->u.spectrum.id != 0xff) { |
| 3426 | IWL_DEBUG_INFO |
| 3427 | ("Replaced existing measurement: %d\n", |
| 3428 | res->u.spectrum.id); |
| 3429 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 3430 | } |
| 3431 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 3432 | rc = 0; |
| 3433 | break; |
| 3434 | |
| 3435 | case 1: /* Command will not be handled */ |
| 3436 | rc = -EAGAIN; |
| 3437 | break; |
| 3438 | } |
| 3439 | |
| 3440 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 3441 | |
| 3442 | return rc; |
| 3443 | } |
| 3444 | #endif |
| 3445 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3446 | static void iwl4965_txstatus_to_ieee(struct iwl4965_priv *priv, |
| 3447 | struct iwl4965_tx_info *tx_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3448 | { |
| 3449 | |
| 3450 | tx_sta->status.ack_signal = 0; |
| 3451 | tx_sta->status.excessive_retries = 0; |
| 3452 | tx_sta->status.queue_length = 0; |
| 3453 | tx_sta->status.queue_number = 0; |
| 3454 | |
| 3455 | if (in_interrupt()) |
| 3456 | ieee80211_tx_status_irqsafe(priv->hw, |
| 3457 | tx_sta->skb[0], &(tx_sta->status)); |
| 3458 | else |
| 3459 | ieee80211_tx_status(priv->hw, |
| 3460 | tx_sta->skb[0], &(tx_sta->status)); |
| 3461 | |
| 3462 | tx_sta->skb[0] = NULL; |
| 3463 | } |
| 3464 | |
| 3465 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3466 | * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3467 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3468 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 3469 | * need to be reclaimed. As result, some free space forms. If there is |
| 3470 | * enough free space (> low mark), wake the stack that feeds us. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3471 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3472 | 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] | 3473 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3474 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
| 3475 | struct iwl4965_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3476 | int nfreed = 0; |
| 3477 | |
| 3478 | if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) { |
| 3479 | IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " |
| 3480 | "is out of range [0-%d] %d %d.\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3481 | index, q->n_bd, q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3482 | return 0; |
| 3483 | } |
| 3484 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3485 | for (index = iwl4965_queue_inc_wrap(index, q->n_bd); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3486 | q->read_ptr != index; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3487 | 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] | 3488 | if (txq_id != IWL_CMD_QUEUE_NUM) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3489 | iwl4965_txstatus_to_ieee(priv, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3490 | &(txq->txb[txq->q.read_ptr])); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3491 | iwl4965_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3492 | } else if (nfreed > 1) { |
| 3493 | IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3494 | q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3495 | queue_work(priv->workqueue, &priv->restart); |
| 3496 | } |
| 3497 | nfreed++; |
| 3498 | } |
| 3499 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3500 | /* if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3501 | (txq_id != IWL_CMD_QUEUE_NUM) && |
| 3502 | priv->mac80211_registered) |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3503 | ieee80211_wake_queue(priv->hw, txq_id); */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3504 | |
| 3505 | |
| 3506 | return nfreed; |
| 3507 | } |
| 3508 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3509 | static int iwl4965_is_tx_success(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3510 | { |
| 3511 | status &= TX_STATUS_MSK; |
| 3512 | return (status == TX_STATUS_SUCCESS) |
| 3513 | || (status == TX_STATUS_DIRECT_DONE); |
| 3514 | } |
| 3515 | |
| 3516 | /****************************************************************************** |
| 3517 | * |
| 3518 | * Generic RX handler implementations |
| 3519 | * |
| 3520 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3521 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3522 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3523 | static inline int iwl4965_get_ra_sta_id(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3524 | struct ieee80211_hdr *hdr) |
| 3525 | { |
| 3526 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) |
| 3527 | return IWL_AP_ID; |
| 3528 | else { |
| 3529 | u8 *da = ieee80211_get_DA(hdr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3530 | return iwl4965_hw_find_station(priv, da); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3531 | } |
| 3532 | } |
| 3533 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3534 | static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr( |
| 3535 | struct iwl4965_priv *priv, int txq_id, int idx) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3536 | { |
| 3537 | if (priv->txq[txq_id].txb[idx].skb[0]) |
| 3538 | return (struct ieee80211_hdr *)priv->txq[txq_id]. |
| 3539 | txb[idx].skb[0]->data; |
| 3540 | return NULL; |
| 3541 | } |
| 3542 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3543 | 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] | 3544 | { |
| 3545 | __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + |
| 3546 | tx_resp->frame_count); |
| 3547 | return le32_to_cpu(*scd_ssn) & MAX_SN; |
| 3548 | |
| 3549 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3550 | |
| 3551 | /** |
| 3552 | * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue |
| 3553 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3554 | static int iwl4965_tx_status_reply_tx(struct iwl4965_priv *priv, |
| 3555 | struct iwl4965_ht_agg *agg, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3556 | struct iwl4965_tx_resp_agg *tx_resp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3557 | u16 start_idx) |
| 3558 | { |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3559 | u16 status; |
| 3560 | struct agg_tx_status *frame_status = &tx_resp->status; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3561 | struct ieee80211_tx_status *tx_status = NULL; |
| 3562 | struct ieee80211_hdr *hdr = NULL; |
| 3563 | int i, sh; |
| 3564 | int txq_id, idx; |
| 3565 | u16 seq; |
| 3566 | |
| 3567 | if (agg->wait_for_ba) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3568 | IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3569 | |
| 3570 | agg->frame_count = tx_resp->frame_count; |
| 3571 | agg->start_idx = start_idx; |
| 3572 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3573 | agg->bitmap = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3574 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3575 | /* # frames attempted by Tx command */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3576 | if (agg->frame_count == 1) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3577 | /* Only one frame was attempted; no block-ack will arrive */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3578 | status = le16_to_cpu(frame_status[0].status); |
| 3579 | seq = le16_to_cpu(frame_status[0].sequence); |
| 3580 | idx = SEQ_TO_INDEX(seq); |
| 3581 | txq_id = SEQ_TO_QUEUE(seq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3582 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3583 | /* FIXME: code repetition */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3584 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n", |
| 3585 | agg->frame_count, agg->start_idx, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3586 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3587 | tx_status = &(priv->txq[txq_id].txb[idx].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3588 | tx_status->retry_count = tx_resp->failure_frame; |
| 3589 | tx_status->queue_number = status & 0xff; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3590 | tx_status->queue_length = tx_resp->failure_rts; |
| 3591 | tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3592 | tx_status->flags = iwl4965_is_tx_success(status)? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3593 | IEEE80211_TX_STATUS_ACK : 0; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3594 | /* FIXME Wrong Rate |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3595 | tx_status->control.tx_rate = |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3596 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags); */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3597 | /* FIXME: code repetition end */ |
| 3598 | |
| 3599 | IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", |
| 3600 | status & 0xff, tx_resp->failure_frame); |
| 3601 | IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3602 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3603 | |
| 3604 | agg->wait_for_ba = 0; |
| 3605 | } else { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3606 | /* Two or more frames were attempted; expect block-ack */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3607 | u64 bitmap = 0; |
| 3608 | int start = agg->start_idx; |
| 3609 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3610 | /* Construct bit-map of pending frames within Tx window */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3611 | for (i = 0; i < agg->frame_count; i++) { |
| 3612 | u16 sc; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3613 | status = le16_to_cpu(frame_status[i].status); |
| 3614 | seq = le16_to_cpu(frame_status[i].sequence); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3615 | idx = SEQ_TO_INDEX(seq); |
| 3616 | txq_id = SEQ_TO_QUEUE(seq); |
| 3617 | |
| 3618 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 3619 | AGG_TX_STATE_ABORT_MSK)) |
| 3620 | continue; |
| 3621 | |
| 3622 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
| 3623 | agg->frame_count, txq_id, idx); |
| 3624 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3625 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3626 | |
| 3627 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 3628 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
| 3629 | IWL_ERROR("BUG_ON idx doesn't match seq control" |
| 3630 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 3631 | idx, SEQ_TO_SN(sc), |
| 3632 | hdr->seq_ctrl); |
| 3633 | return -1; |
| 3634 | } |
| 3635 | |
| 3636 | IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
| 3637 | i, idx, SEQ_TO_SN(sc)); |
| 3638 | |
| 3639 | sh = idx - start; |
| 3640 | if (sh > 64) { |
| 3641 | sh = (start - idx) + 0xff; |
| 3642 | bitmap = bitmap << sh; |
| 3643 | sh = 0; |
| 3644 | start = idx; |
| 3645 | } else if (sh < -64) |
| 3646 | sh = 0xff - (start - idx); |
| 3647 | else if (sh < 0) { |
| 3648 | sh = start - idx; |
| 3649 | start = idx; |
| 3650 | bitmap = bitmap << sh; |
| 3651 | sh = 0; |
| 3652 | } |
| 3653 | bitmap |= (1 << sh); |
| 3654 | IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n", |
| 3655 | start, (u32)(bitmap & 0xFFFFFFFF)); |
| 3656 | } |
| 3657 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3658 | agg->bitmap = bitmap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3659 | agg->start_idx = start; |
| 3660 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3661 | IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3662 | agg->frame_count, agg->start_idx, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3663 | agg->bitmap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3664 | |
| 3665 | if (bitmap) |
| 3666 | agg->wait_for_ba = 1; |
| 3667 | } |
| 3668 | return 0; |
| 3669 | } |
| 3670 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3671 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3672 | /** |
| 3673 | * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response |
| 3674 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3675 | static void iwl4965_rx_reply_tx(struct iwl4965_priv *priv, |
| 3676 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3677 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3678 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3679 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3680 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3681 | int index = SEQ_TO_INDEX(sequence); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3682 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3683 | struct ieee80211_tx_status *tx_status; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3684 | struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3685 | u32 status = le32_to_cpu(tx_resp->status); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3686 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3687 | int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION; |
| 3688 | struct ieee80211_hdr *hdr; |
| 3689 | __le16 *qc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3690 | #endif |
| 3691 | |
| 3692 | if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) { |
| 3693 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 3694 | "is out of range [0-%d] %d %d\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3695 | index, txq->q.n_bd, txq->q.write_ptr, |
| 3696 | txq->q.read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3697 | return; |
| 3698 | } |
| 3699 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3700 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3701 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index); |
| 3702 | qc = ieee80211_get_qos_ctrl(hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3703 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3704 | if (qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3705 | tid = le16_to_cpu(*qc) & 0xf; |
| 3706 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3707 | sta_id = iwl4965_get_ra_sta_id(priv, hdr); |
| 3708 | if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) { |
| 3709 | IWL_ERROR("Station not known\n"); |
| 3710 | return; |
| 3711 | } |
| 3712 | |
| 3713 | if (txq->sched_retry) { |
| 3714 | const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp); |
| 3715 | struct iwl4965_ht_agg *agg = NULL; |
| 3716 | |
| 3717 | if (!qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3718 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3719 | |
| 3720 | agg = &priv->stations[sta_id].tid[tid].agg; |
| 3721 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3722 | iwl4965_tx_status_reply_tx(priv, agg, |
| 3723 | (struct iwl4965_tx_resp_agg *)tx_resp, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3724 | |
| 3725 | if ((tx_resp->frame_count == 1) && |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3726 | !iwl4965_is_tx_success(status)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3727 | /* TODO: send BAR */ |
| 3728 | } |
| 3729 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3730 | if (txq->q.read_ptr != (scd_ssn & 0xff)) { |
| 3731 | int freed; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3732 | index = iwl4965_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3733 | IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " |
| 3734 | "%d index %d\n", scd_ssn , index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3735 | freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
| 3736 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 3737 | |
| 3738 | if (iwl4965_queue_space(&txq->q) > txq->q.low_mark && |
| 3739 | txq_id >= 0 && priv->mac80211_registered && |
| 3740 | agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) |
| 3741 | ieee80211_wake_queue(priv->hw, txq_id); |
| 3742 | |
| 3743 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3744 | } |
| 3745 | } else { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3746 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3747 | tx_status = &(txq->txb[txq->q.read_ptr].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3748 | |
| 3749 | tx_status->retry_count = tx_resp->failure_frame; |
| 3750 | tx_status->queue_number = status; |
| 3751 | tx_status->queue_length = tx_resp->bt_kill_count; |
| 3752 | tx_status->queue_length |= tx_resp->failure_rts; |
| 3753 | |
| 3754 | tx_status->flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3755 | iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3756 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3757 | 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] | 3758 | "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3759 | status, le32_to_cpu(tx_resp->rate_n_flags), |
| 3760 | tx_resp->failure_frame); |
| 3761 | |
| 3762 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3763 | if (index != -1) { |
| 3764 | int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3765 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3766 | if (tid != MAX_TID_COUNT) |
| 3767 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 3768 | if (iwl4965_queue_space(&txq->q) > txq->q.low_mark && |
| 3769 | (txq_id >= 0) && |
| 3770 | priv->mac80211_registered) |
| 3771 | ieee80211_wake_queue(priv->hw, txq_id); |
| 3772 | if (tid != MAX_TID_COUNT) |
| 3773 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
| 3774 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3775 | } |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3776 | #ifdef CONFIG_IWL4965_HT |
| 3777 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3778 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3779 | |
| 3780 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 3781 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 3782 | } |
| 3783 | |
| 3784 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3785 | static void iwl4965_rx_reply_alive(struct iwl4965_priv *priv, |
| 3786 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3787 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3788 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3789 | struct iwl4965_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3790 | struct delayed_work *pwork; |
| 3791 | |
| 3792 | palive = &pkt->u.alive_frame; |
| 3793 | |
| 3794 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 3795 | "0x%01X 0x%01X\n", |
| 3796 | palive->is_valid, palive->ver_type, |
| 3797 | palive->ver_subtype); |
| 3798 | |
| 3799 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 3800 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 3801 | memcpy(&priv->card_alive_init, |
| 3802 | &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3803 | sizeof(struct iwl4965_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3804 | pwork = &priv->init_alive_start; |
| 3805 | } else { |
| 3806 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 3807 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3808 | sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3809 | pwork = &priv->alive_start; |
| 3810 | } |
| 3811 | |
| 3812 | /* We delay the ALIVE response by 5ms to |
| 3813 | * give the HW RF Kill time to activate... */ |
| 3814 | if (palive->is_valid == UCODE_VALID_OK) |
| 3815 | queue_delayed_work(priv->workqueue, pwork, |
| 3816 | msecs_to_jiffies(5)); |
| 3817 | else |
| 3818 | IWL_WARNING("uCode did not respond OK.\n"); |
| 3819 | } |
| 3820 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3821 | static void iwl4965_rx_reply_add_sta(struct iwl4965_priv *priv, |
| 3822 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3823 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3824 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3825 | |
| 3826 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 3827 | return; |
| 3828 | } |
| 3829 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3830 | static void iwl4965_rx_reply_error(struct iwl4965_priv *priv, |
| 3831 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3832 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3833 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3834 | |
| 3835 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 3836 | "seq 0x%04X ser 0x%08X\n", |
| 3837 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 3838 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 3839 | pkt->u.err_resp.cmd_id, |
| 3840 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 3841 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 3842 | } |
| 3843 | |
| 3844 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 3845 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3846 | 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] | 3847 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3848 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3849 | struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon; |
| 3850 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3851 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 3852 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 3853 | rxon->channel = csa->channel; |
| 3854 | priv->staging_rxon.channel = csa->channel; |
| 3855 | } |
| 3856 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3857 | static void iwl4965_rx_spectrum_measure_notif(struct iwl4965_priv *priv, |
| 3858 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3859 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3860 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3861 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3862 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3863 | |
| 3864 | if (!report->state) { |
| 3865 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 3866 | "Spectrum Measure Notification: Start\n"); |
| 3867 | return; |
| 3868 | } |
| 3869 | |
| 3870 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 3871 | priv->measurement_status |= MEASUREMENT_READY; |
| 3872 | #endif |
| 3873 | } |
| 3874 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3875 | static void iwl4965_rx_pm_sleep_notif(struct iwl4965_priv *priv, |
| 3876 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3877 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3878 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3879 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3880 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3881 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 3882 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 3883 | #endif |
| 3884 | } |
| 3885 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3886 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl4965_priv *priv, |
| 3887 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3888 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3889 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3890 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 3891 | "notification for %s:\n", |
| 3892 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3893 | 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] | 3894 | } |
| 3895 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3896 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3897 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3898 | struct iwl4965_priv *priv = |
| 3899 | container_of(work, struct iwl4965_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3900 | struct sk_buff *beacon; |
| 3901 | |
| 3902 | /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3903 | beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3904 | |
| 3905 | if (!beacon) { |
| 3906 | IWL_ERROR("update beacon failed\n"); |
| 3907 | return; |
| 3908 | } |
| 3909 | |
| 3910 | mutex_lock(&priv->mutex); |
| 3911 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 3912 | if (priv->ibss_beacon) |
| 3913 | dev_kfree_skb(priv->ibss_beacon); |
| 3914 | |
| 3915 | priv->ibss_beacon = beacon; |
| 3916 | mutex_unlock(&priv->mutex); |
| 3917 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3918 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3919 | } |
| 3920 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3921 | static void iwl4965_rx_beacon_notif(struct iwl4965_priv *priv, |
| 3922 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3923 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3924 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3925 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3926 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 3927 | 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] | 3928 | |
| 3929 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 3930 | "tsf %d %d rate %d\n", |
| 3931 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 3932 | beacon->beacon_notify_hdr.failure_frame, |
| 3933 | le32_to_cpu(beacon->ibss_mgr_status), |
| 3934 | le32_to_cpu(beacon->high_tsf), |
| 3935 | le32_to_cpu(beacon->low_tsf), rate); |
| 3936 | #endif |
| 3937 | |
| 3938 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 3939 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 3940 | queue_work(priv->workqueue, &priv->beacon_update); |
| 3941 | } |
| 3942 | |
| 3943 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3944 | static void iwl4965_rx_reply_scan(struct iwl4965_priv *priv, |
| 3945 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3946 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3947 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3948 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3949 | struct iwl4965_scanreq_notification *notif = |
| 3950 | (struct iwl4965_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3951 | |
| 3952 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 3953 | #endif |
| 3954 | } |
| 3955 | |
| 3956 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3957 | static void iwl4965_rx_scan_start_notif(struct iwl4965_priv *priv, |
| 3958 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3959 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3960 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3961 | struct iwl4965_scanstart_notification *notif = |
| 3962 | (struct iwl4965_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3963 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 3964 | IWL_DEBUG_SCAN("Scan start: " |
| 3965 | "%d [802.11%s] " |
| 3966 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 3967 | notif->channel, |
| 3968 | notif->band ? "bg" : "a", |
| 3969 | notif->tsf_high, |
| 3970 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 3971 | } |
| 3972 | |
| 3973 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3974 | static void iwl4965_rx_scan_results_notif(struct iwl4965_priv *priv, |
| 3975 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3976 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3977 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3978 | struct iwl4965_scanresults_notification *notif = |
| 3979 | (struct iwl4965_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3980 | |
| 3981 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 3982 | "%d [802.11%s] " |
| 3983 | "(TSF: 0x%08X:%08X) - %d " |
| 3984 | "elapsed=%lu usec (%dms since last)\n", |
| 3985 | notif->channel, |
| 3986 | notif->band ? "bg" : "a", |
| 3987 | le32_to_cpu(notif->tsf_high), |
| 3988 | le32_to_cpu(notif->tsf_low), |
| 3989 | le32_to_cpu(notif->statistics[0]), |
| 3990 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 3991 | jiffies_to_msecs(elapsed_jiffies |
| 3992 | (priv->last_scan_jiffies, jiffies))); |
| 3993 | |
| 3994 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3995 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
| 3998 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3999 | static void iwl4965_rx_scan_complete_notif(struct iwl4965_priv *priv, |
| 4000 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4001 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4002 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 4003 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4004 | |
| 4005 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 4006 | scan_notif->scanned_channels, |
| 4007 | scan_notif->tsf_low, |
| 4008 | scan_notif->tsf_high, scan_notif->status); |
| 4009 | |
| 4010 | /* The HW is no longer scanning */ |
| 4011 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 4012 | |
| 4013 | /* The scan completion notification came in, so kill that timer... */ |
| 4014 | cancel_delayed_work(&priv->scan_check); |
| 4015 | |
| 4016 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 4017 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 4018 | jiffies_to_msecs(elapsed_jiffies |
| 4019 | (priv->scan_pass_start, jiffies))); |
| 4020 | |
| 4021 | /* Remove this scanned band from the list |
| 4022 | * of pending bands to scan */ |
| 4023 | priv->scan_bands--; |
| 4024 | |
| 4025 | /* If a request to abort was given, or the scan did not succeed |
| 4026 | * then we reset the scan state machine and terminate, |
| 4027 | * re-queuing another scan if one has been requested */ |
| 4028 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 4029 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 4030 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 4031 | } else { |
| 4032 | /* If there are more bands on this scan pass reschedule */ |
| 4033 | if (priv->scan_bands > 0) |
| 4034 | goto reschedule; |
| 4035 | } |
| 4036 | |
| 4037 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4038 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4039 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 4040 | |
| 4041 | clear_bit(STATUS_SCANNING, &priv->status); |
| 4042 | |
| 4043 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 4044 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 4045 | |
| 4046 | queue_work(priv->workqueue, &priv->scan_completed); |
| 4047 | |
| 4048 | return; |
| 4049 | |
| 4050 | reschedule: |
| 4051 | priv->scan_pass_start = jiffies; |
| 4052 | queue_work(priv->workqueue, &priv->request_scan); |
| 4053 | } |
| 4054 | |
| 4055 | /* Handle notification from uCode that card's power state is changing |
| 4056 | * due to software, hardware, or critical temperature RFKILL */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4057 | static void iwl4965_rx_card_state_notif(struct iwl4965_priv *priv, |
| 4058 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4059 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4060 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4061 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 4062 | unsigned long status = priv->status; |
| 4063 | |
| 4064 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 4065 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 4066 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 4067 | |
| 4068 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 4069 | RF_CARD_DISABLED)) { |
| 4070 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4071 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4072 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 4073 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4074 | if (!iwl4965_grab_nic_access(priv)) { |
| 4075 | iwl4965_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4076 | priv, HBUS_TARG_MBX_C, |
| 4077 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 4078 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4079 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4080 | } |
| 4081 | |
| 4082 | if (!(flags & RXON_CARD_DISABLED)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4083 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4084 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4085 | if (!iwl4965_grab_nic_access(priv)) { |
| 4086 | iwl4965_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4087 | priv, HBUS_TARG_MBX_C, |
| 4088 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 4089 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4090 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4091 | } |
| 4092 | } |
| 4093 | |
| 4094 | if (flags & RF_CARD_DISABLED) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4095 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4096 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4097 | iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
| 4098 | if (!iwl4965_grab_nic_access(priv)) |
| 4099 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4100 | } |
| 4101 | } |
| 4102 | |
| 4103 | if (flags & HW_CARD_DISABLED) |
| 4104 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4105 | else |
| 4106 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4107 | |
| 4108 | |
| 4109 | if (flags & SW_CARD_DISABLED) |
| 4110 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 4111 | else |
| 4112 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 4113 | |
| 4114 | if (!(flags & RXON_CARD_DISABLED)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4115 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4116 | |
| 4117 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 4118 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 4119 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 4120 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 4121 | queue_work(priv->workqueue, &priv->rf_kill); |
| 4122 | else |
| 4123 | wake_up_interruptible(&priv->wait_command_queue); |
| 4124 | } |
| 4125 | |
| 4126 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4127 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4128 | * |
| 4129 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 4130 | * to the host. |
| 4131 | * |
| 4132 | * This function chains into the hardware specific files for them to setup |
| 4133 | * any hardware specific handlers as well. |
| 4134 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4135 | static void iwl4965_setup_rx_handlers(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4136 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4137 | priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive; |
| 4138 | priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta; |
| 4139 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 4140 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4141 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4142 | iwl4965_rx_spectrum_measure_notif; |
| 4143 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4144 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4145 | iwl4965_rx_pm_debug_statistics_notif; |
| 4146 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4147 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4148 | /* |
| 4149 | * The same handler is used for both the REPLY to a discrete |
| 4150 | * statistics request from the host as well as for the periodic |
| 4151 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4152 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4153 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
| 4154 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4155 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4156 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
| 4157 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4158 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4159 | iwl4965_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4160 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4161 | iwl4965_rx_scan_complete_notif; |
| 4162 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
| 4163 | priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4164 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4165 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4166 | iwl4965_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4170 | * 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] | 4171 | * @rxb: Rx buffer to reclaim |
| 4172 | * |
| 4173 | * If an Rx buffer has an async callback associated with it the callback |
| 4174 | * will be executed. The attached skb (if present) will only be freed |
| 4175 | * if the callback returns 1 |
| 4176 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4177 | static void iwl4965_tx_cmd_complete(struct iwl4965_priv *priv, |
| 4178 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4179 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4180 | struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4181 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 4182 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 4183 | int index = SEQ_TO_INDEX(sequence); |
| 4184 | int huge = sequence & SEQ_HUGE_FRAME; |
| 4185 | int cmd_index; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4186 | struct iwl4965_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4187 | |
| 4188 | /* If a Tx command is being handled and it isn't in the actual |
| 4189 | * command queue then there a command routing bug has been introduced |
| 4190 | * in the queue management code. */ |
| 4191 | if (txq_id != IWL_CMD_QUEUE_NUM) |
| 4192 | IWL_ERROR("Error wrong command queue %d command id 0x%X\n", |
| 4193 | txq_id, pkt->hdr.cmd); |
| 4194 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 4195 | |
| 4196 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 4197 | cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
| 4198 | |
| 4199 | /* Input error checking is done when commands are added to queue. */ |
| 4200 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 4201 | cmd->meta.source->u.skb = rxb->skb; |
| 4202 | rxb->skb = NULL; |
| 4203 | } else if (cmd->meta.u.callback && |
| 4204 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 4205 | rxb->skb = NULL; |
| 4206 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4207 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4208 | |
| 4209 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 4210 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 4211 | wake_up_interruptible(&priv->wait_command_queue); |
| 4212 | } |
| 4213 | } |
| 4214 | |
| 4215 | /************************** RX-FUNCTIONS ****************************/ |
| 4216 | /* |
| 4217 | * Rx theory of operation |
| 4218 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4219 | * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs), |
| 4220 | * each of which point to Receive Buffers to be filled by 4965. These get |
| 4221 | * used not only for Rx frames, but for any command response or notification |
| 4222 | * from the 4965. The driver and 4965 manage the Rx buffers by means |
| 4223 | * of indexes into the circular buffer. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4224 | * |
| 4225 | * Rx Queue Indexes |
| 4226 | * The host/firmware share two index registers for managing the Rx buffers. |
| 4227 | * |
| 4228 | * The READ index maps to the first position that the firmware may be writing |
| 4229 | * to -- the driver can read up to (but not including) this position and get |
| 4230 | * good data. |
| 4231 | * The READ index is managed by the firmware once the card is enabled. |
| 4232 | * |
| 4233 | * The WRITE index maps to the last position the driver has read from -- the |
| 4234 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 4235 | * |
| 4236 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 4237 | * WRITE = READ. |
| 4238 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4239 | * 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] | 4240 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 4241 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4242 | * 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] | 4243 | * and fire the RX interrupt. The driver can then query the READ index and |
| 4244 | * process as many packets as possible, moving the WRITE index forward as it |
| 4245 | * resets the Rx queue buffers with new memory. |
| 4246 | * |
| 4247 | * The management in the driver is as follows: |
| 4248 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 4249 | * 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] | 4250 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4251 | * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4252 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 4253 | * 'processed' and 'read' driver indexes as well) |
| 4254 | * + A received packet is processed and handed to the kernel network stack, |
| 4255 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 4256 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 4257 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 4258 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 4259 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 4260 | * |
| 4261 | * |
| 4262 | * Driver sequence: |
| 4263 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4264 | * iwl4965_rx_queue_alloc() Allocates rx_free |
| 4265 | * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4266 | * iwl4965_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4267 | * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4268 | * queue, updates firmware pointers, and updates |
| 4269 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4270 | * are available, schedules iwl4965_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4271 | * |
| 4272 | * -- enable interrupts -- |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4273 | * 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] | 4274 | * READ INDEX, detaching the SKB from the pool. |
| 4275 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4276 | * Calls iwl4965_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4277 | * slots. |
| 4278 | * ... |
| 4279 | * |
| 4280 | */ |
| 4281 | |
| 4282 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4283 | * iwl4965_rx_queue_space - Return number of free slots available in queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4284 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4285 | static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4286 | { |
| 4287 | int s = q->read - q->write; |
| 4288 | if (s <= 0) |
| 4289 | s += RX_QUEUE_SIZE; |
| 4290 | /* keep some buffer to not confuse full and empty queue */ |
| 4291 | s -= 2; |
| 4292 | if (s < 0) |
| 4293 | s = 0; |
| 4294 | return s; |
| 4295 | } |
| 4296 | |
| 4297 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4298 | * 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] | 4299 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4300 | 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] | 4301 | { |
| 4302 | u32 reg = 0; |
| 4303 | int rc = 0; |
| 4304 | unsigned long flags; |
| 4305 | |
| 4306 | spin_lock_irqsave(&q->lock, flags); |
| 4307 | |
| 4308 | if (q->need_update == 0) |
| 4309 | goto exit_unlock; |
| 4310 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4311 | /* If power-saving is in use, make sure device is awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4312 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4313 | reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4314 | |
| 4315 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4316 | iwl4965_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4317 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4318 | goto exit_unlock; |
| 4319 | } |
| 4320 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4321 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4322 | if (rc) |
| 4323 | goto exit_unlock; |
| 4324 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4325 | /* Device expects a multiple of 8 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4326 | iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_WPTR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4327 | q->write & ~0x7); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4328 | iwl4965_release_nic_access(priv); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4329 | |
| 4330 | /* Else device is assumed to be awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4331 | } else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4332 | /* Device expects a multiple of 8 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4333 | iwl4965_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4334 | |
| 4335 | |
| 4336 | q->need_update = 0; |
| 4337 | |
| 4338 | exit_unlock: |
| 4339 | spin_unlock_irqrestore(&q->lock, flags); |
| 4340 | return rc; |
| 4341 | } |
| 4342 | |
| 4343 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4344 | * 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] | 4345 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4346 | static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4347 | dma_addr_t dma_addr) |
| 4348 | { |
| 4349 | return cpu_to_le32((u32)(dma_addr >> 8)); |
| 4350 | } |
| 4351 | |
| 4352 | |
| 4353 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4354 | * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4355 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4356 | * 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] | 4357 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4358 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4359 | * |
| 4360 | * This moves the 'write' index forward to catch up with 'processed', and |
| 4361 | * also updates the memory address in the firmware to reference the new |
| 4362 | * target buffer. |
| 4363 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4364 | static int iwl4965_rx_queue_restock(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4365 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4366 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4367 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4368 | struct iwl4965_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4369 | unsigned long flags; |
| 4370 | int write, rc; |
| 4371 | |
| 4372 | spin_lock_irqsave(&rxq->lock, flags); |
| 4373 | write = rxq->write & ~0x7; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4374 | while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4375 | /* Get next free Rx buffer, remove from free list */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4376 | element = rxq->rx_free.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4377 | rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4378 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4379 | |
| 4380 | /* Point to Rx buffer via next RBD in circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4381 | rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4382 | rxq->queue[rxq->write] = rxb; |
| 4383 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 4384 | rxq->free_count--; |
| 4385 | } |
| 4386 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4387 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 4388 | * refill it */ |
| 4389 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 4390 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 4391 | |
| 4392 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4393 | /* If we've added more space for the firmware to place data, tell it. |
| 4394 | * Increment device's write pointer in multiples of 8. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4395 | if ((write != (rxq->write & ~0x7)) |
| 4396 | || (abs(rxq->write - rxq->read) > 7)) { |
| 4397 | spin_lock_irqsave(&rxq->lock, flags); |
| 4398 | rxq->need_update = 1; |
| 4399 | spin_unlock_irqrestore(&rxq->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4400 | rc = iwl4965_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4401 | if (rc) |
| 4402 | return rc; |
| 4403 | } |
| 4404 | |
| 4405 | return 0; |
| 4406 | } |
| 4407 | |
| 4408 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4409 | * 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] | 4410 | * |
| 4411 | * When moving to rx_free an SKB is allocated for the slot. |
| 4412 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4413 | * Also restock the Rx queue via iwl4965_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 4414 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4415 | */ |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4416 | static void iwl4965_rx_allocate(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4417 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4418 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4419 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4420 | struct iwl4965_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4421 | unsigned long flags; |
| 4422 | spin_lock_irqsave(&rxq->lock, flags); |
| 4423 | while (!list_empty(&rxq->rx_used)) { |
| 4424 | element = rxq->rx_used.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4425 | rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4426 | |
| 4427 | /* Alloc a new receive buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4428 | rxb->skb = |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4429 | alloc_skb(priv->hw_setting.rx_buf_size, |
| 4430 | __GFP_NOWARN | GFP_ATOMIC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4431 | if (!rxb->skb) { |
| 4432 | if (net_ratelimit()) |
| 4433 | printk(KERN_CRIT DRV_NAME |
| 4434 | ": Can not allocate SKB buffers\n"); |
| 4435 | /* We don't reschedule replenish work here -- we will |
| 4436 | * call the restock method and if it still needs |
| 4437 | * more buffers it will schedule replenish */ |
| 4438 | break; |
| 4439 | } |
| 4440 | priv->alloc_rxb_skb++; |
| 4441 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4442 | |
| 4443 | /* Get physical address of RB/SKB */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4444 | rxb->dma_addr = |
| 4445 | pci_map_single(priv->pci_dev, rxb->skb->data, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4446 | priv->hw_setting.rx_buf_size, PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4447 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 4448 | rxq->free_count++; |
| 4449 | } |
| 4450 | spin_unlock_irqrestore(&rxq->lock, flags); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4451 | } |
| 4452 | |
| 4453 | /* |
| 4454 | * this should be called while priv->lock is locked |
| 4455 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 4456 | static void __iwl4965_rx_replenish(void *data) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4457 | { |
| 4458 | struct iwl4965_priv *priv = data; |
| 4459 | |
| 4460 | iwl4965_rx_allocate(priv); |
| 4461 | iwl4965_rx_queue_restock(priv); |
| 4462 | } |
| 4463 | |
| 4464 | |
| 4465 | void iwl4965_rx_replenish(void *data) |
| 4466 | { |
| 4467 | struct iwl4965_priv *priv = data; |
| 4468 | unsigned long flags; |
| 4469 | |
| 4470 | iwl4965_rx_allocate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4471 | |
| 4472 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4473 | iwl4965_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4474 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4475 | } |
| 4476 | |
| 4477 | /* 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] | 4478 | * 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] | 4479 | * This free routine walks the list of POOL entries and if SKB is set to |
| 4480 | * non NULL it is unmapped and freed |
| 4481 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4482 | 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] | 4483 | { |
| 4484 | int i; |
| 4485 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 4486 | if (rxq->pool[i].skb != NULL) { |
| 4487 | pci_unmap_single(priv->pci_dev, |
| 4488 | rxq->pool[i].dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4489 | priv->hw_setting.rx_buf_size, |
| 4490 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4491 | dev_kfree_skb(rxq->pool[i].skb); |
| 4492 | } |
| 4493 | } |
| 4494 | |
| 4495 | pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd, |
| 4496 | rxq->dma_addr); |
| 4497 | rxq->bd = NULL; |
| 4498 | } |
| 4499 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4500 | int iwl4965_rx_queue_alloc(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4501 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4502 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4503 | struct pci_dev *dev = priv->pci_dev; |
| 4504 | int i; |
| 4505 | |
| 4506 | spin_lock_init(&rxq->lock); |
| 4507 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4508 | INIT_LIST_HEAD(&rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4509 | |
| 4510 | /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4511 | rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr); |
| 4512 | if (!rxq->bd) |
| 4513 | return -ENOMEM; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4514 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4515 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4516 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
| 4517 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4518 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4519 | /* Set us so that we have processed and used all buffers, but have |
| 4520 | * not restocked the Rx queue with fresh buffers */ |
| 4521 | rxq->read = rxq->write = 0; |
| 4522 | rxq->free_count = 0; |
| 4523 | rxq->need_update = 0; |
| 4524 | return 0; |
| 4525 | } |
| 4526 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4527 | 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] | 4528 | { |
| 4529 | unsigned long flags; |
| 4530 | int i; |
| 4531 | spin_lock_irqsave(&rxq->lock, flags); |
| 4532 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4533 | INIT_LIST_HEAD(&rxq->rx_used); |
| 4534 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4535 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 4536 | /* In the reset function, these buffers may have been allocated |
| 4537 | * to an SKB, so we need to unmap and free potential storage */ |
| 4538 | if (rxq->pool[i].skb != NULL) { |
| 4539 | pci_unmap_single(priv->pci_dev, |
| 4540 | rxq->pool[i].dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4541 | priv->hw_setting.rx_buf_size, |
| 4542 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4543 | priv->alloc_rxb_skb--; |
| 4544 | dev_kfree_skb(rxq->pool[i].skb); |
| 4545 | rxq->pool[i].skb = NULL; |
| 4546 | } |
| 4547 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 4548 | } |
| 4549 | |
| 4550 | /* Set us so that we have processed and used all buffers, but have |
| 4551 | * not restocked the Rx queue with fresh buffers */ |
| 4552 | rxq->read = rxq->write = 0; |
| 4553 | rxq->free_count = 0; |
| 4554 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4555 | } |
| 4556 | |
| 4557 | /* Convert linear signal-to-noise ratio into dB */ |
| 4558 | static u8 ratio2dB[100] = { |
| 4559 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 4560 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 4561 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 4562 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 4563 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 4564 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 4565 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 4566 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 4567 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 4568 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 4569 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 4570 | }; |
| 4571 | |
| 4572 | /* Calculates a relative dB value from a ratio of linear |
| 4573 | * (i.e. not dB) signal levels. |
| 4574 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4575 | int iwl4965_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4576 | { |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4577 | /* 1000:1 or higher just report as 60 dB */ |
| 4578 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4579 | return 60; |
| 4580 | |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4581 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4582 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4583 | if (sig_ratio >= 100) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4584 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 4585 | |
| 4586 | /* We shouldn't see this */ |
| 4587 | if (sig_ratio < 1) |
| 4588 | return 0; |
| 4589 | |
| 4590 | /* Use table for ratios 1:1 - 99:1 */ |
| 4591 | return (int)ratio2dB[sig_ratio]; |
| 4592 | } |
| 4593 | |
| 4594 | #define PERFECT_RSSI (-20) /* dBm */ |
| 4595 | #define WORST_RSSI (-95) /* dBm */ |
| 4596 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 4597 | |
| 4598 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 4599 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 4600 | * about formulas used below. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4601 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4602 | { |
| 4603 | int sig_qual; |
| 4604 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 4605 | |
| 4606 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 4607 | * as indicator; formula is (signal dbm - noise dbm). |
| 4608 | * SNR at or above 40 is a great signal (100%). |
| 4609 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 4610 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 4611 | if (noise_dbm) { |
| 4612 | if (rssi_dbm - noise_dbm >= 40) |
| 4613 | return 100; |
| 4614 | else if (rssi_dbm < noise_dbm) |
| 4615 | return 0; |
| 4616 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 4617 | |
| 4618 | /* Else use just the signal level. |
| 4619 | * This formula is a least squares fit of data points collected and |
| 4620 | * compared with a reference system that had a percentage (%) display |
| 4621 | * for signal quality. */ |
| 4622 | } else |
| 4623 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 4624 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 4625 | (RSSI_RANGE * RSSI_RANGE); |
| 4626 | |
| 4627 | if (sig_qual > 100) |
| 4628 | sig_qual = 100; |
| 4629 | else if (sig_qual < 1) |
| 4630 | sig_qual = 0; |
| 4631 | |
| 4632 | return sig_qual; |
| 4633 | } |
| 4634 | |
| 4635 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4636 | * iwl4965_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4637 | * |
| 4638 | * Uses the priv->rx_handlers callback function array to invoke |
| 4639 | * the appropriate handlers, including command responses, |
| 4640 | * frame-received notifications, and other notifications. |
| 4641 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4642 | static void iwl4965_rx_handle(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4643 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4644 | struct iwl4965_rx_mem_buffer *rxb; |
| 4645 | struct iwl4965_rx_packet *pkt; |
| 4646 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4647 | u32 r, i; |
| 4648 | int reclaim; |
| 4649 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4650 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 4651 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4652 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4653 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 4654 | * buffer that the driver may process (last buffer filled by ucode). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4655 | r = iwl4965_hw_get_rx_read(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4656 | i = rxq->read; |
| 4657 | |
| 4658 | /* Rx interrupt, but nothing sent from uCode */ |
| 4659 | if (i == r) |
| 4660 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 4661 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4662 | if (iwl4965_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
| 4663 | fill_rx = 1; |
| 4664 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4665 | while (i != r) { |
| 4666 | rxb = rxq->queue[i]; |
| 4667 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4668 | /* 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] | 4669 | * then a bug has been introduced in the queue refilling |
| 4670 | * routines -- catch it here */ |
| 4671 | BUG_ON(rxb == NULL); |
| 4672 | |
| 4673 | rxq->queue[i] = NULL; |
| 4674 | |
| 4675 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4676 | priv->hw_setting.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4677 | PCI_DMA_FROMDEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4678 | pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4679 | |
| 4680 | /* Reclaim a command buffer only if this packet is a response |
| 4681 | * to a (driver-originated) command. |
| 4682 | * If the packet (e.g. Rx frame) originated from uCode, |
| 4683 | * there is no command buffer to reclaim. |
| 4684 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 4685 | * but apparently a few don't get set; catch them here. */ |
| 4686 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 4687 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
| 4688 | (pkt->hdr.cmd != REPLY_4965_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 4689 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4690 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 4691 | (pkt->hdr.cmd != REPLY_TX); |
| 4692 | |
| 4693 | /* Based on type of command response or notification, |
| 4694 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4695 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4696 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
| 4697 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4698 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 4699 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 4700 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 4701 | } else { |
| 4702 | /* No handling needed */ |
| 4703 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4704 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 4705 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 4706 | pkt->hdr.cmd); |
| 4707 | } |
| 4708 | |
| 4709 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4710 | /* Invoke any callbacks, transfer the skb to caller, and |
| 4711 | * fire off the (possibly) blocking iwl4965_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4712 | * as we reclaim the driver command queue */ |
| 4713 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4714 | iwl4965_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4715 | else |
| 4716 | IWL_WARNING("Claim null rxb?\n"); |
| 4717 | } |
| 4718 | |
| 4719 | /* For now we just don't re-use anything. We can tweak this |
| 4720 | * later to try and re-use notification packets and SKBs that |
| 4721 | * fail to Rx correctly */ |
| 4722 | if (rxb->skb != NULL) { |
| 4723 | priv->alloc_rxb_skb--; |
| 4724 | dev_kfree_skb_any(rxb->skb); |
| 4725 | rxb->skb = NULL; |
| 4726 | } |
| 4727 | |
| 4728 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4729 | priv->hw_setting.rx_buf_size, |
| 4730 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4731 | spin_lock_irqsave(&rxq->lock, flags); |
| 4732 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 4733 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4734 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4735 | /* If there are a lot of unused frames, |
| 4736 | * restock the Rx queue so ucode wont assert. */ |
| 4737 | if (fill_rx) { |
| 4738 | count++; |
| 4739 | if (count >= 8) { |
| 4740 | priv->rxq.read = i; |
| 4741 | __iwl4965_rx_replenish(priv); |
| 4742 | count = 0; |
| 4743 | } |
| 4744 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4745 | } |
| 4746 | |
| 4747 | /* Backtrack one entry */ |
| 4748 | priv->rxq.read = i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4749 | iwl4965_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4750 | } |
| 4751 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4752 | /** |
| 4753 | * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware |
| 4754 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4755 | static int iwl4965_tx_queue_update_write_ptr(struct iwl4965_priv *priv, |
| 4756 | struct iwl4965_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4757 | { |
| 4758 | u32 reg = 0; |
| 4759 | int rc = 0; |
| 4760 | int txq_id = txq->q.id; |
| 4761 | |
| 4762 | if (txq->need_update == 0) |
| 4763 | return rc; |
| 4764 | |
| 4765 | /* if we're trying to save power */ |
| 4766 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 4767 | /* wake up nic if it's powered down ... |
| 4768 | * uCode will wake up, and interrupt us again, so next |
| 4769 | * time we'll skip this part. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4770 | reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4771 | |
| 4772 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 4773 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4774 | iwl4965_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4775 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4776 | return rc; |
| 4777 | } |
| 4778 | |
| 4779 | /* restore this queue's parameters in nic hardware. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4780 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4781 | if (rc) |
| 4782 | return rc; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4783 | iwl4965_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 4784 | txq->q.write_ptr | (txq_id << 8)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4785 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4786 | |
| 4787 | /* else not in power-save mode, uCode will never sleep when we're |
| 4788 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 4789 | } else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4790 | iwl4965_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 4791 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4792 | |
| 4793 | txq->need_update = 0; |
| 4794 | |
| 4795 | return rc; |
| 4796 | } |
| 4797 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4798 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4799 | static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4800 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4801 | DECLARE_MAC_BUF(mac); |
| 4802 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4803 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4804 | iwl4965_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4805 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 4806 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 4807 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 4808 | le32_to_cpu(rxon->filter_flags)); |
| 4809 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 4810 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 4811 | rxon->ofdm_basic_rates); |
| 4812 | 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] | 4813 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 4814 | print_mac(mac, rxon->node_addr)); |
| 4815 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 4816 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4817 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 4818 | } |
| 4819 | #endif |
| 4820 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4821 | static void iwl4965_enable_interrupts(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4822 | { |
| 4823 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 4824 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4825 | iwl4965_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4826 | } |
| 4827 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4828 | static inline void iwl4965_disable_interrupts(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4829 | { |
| 4830 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 4831 | |
| 4832 | /* disable interrupts from uCode/NIC to host */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4833 | iwl4965_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4834 | |
| 4835 | /* acknowledge/clear/reset any interrupts still pending |
| 4836 | * from uCode or flow handler (Rx/Tx DMA) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4837 | iwl4965_write32(priv, CSR_INT, 0xffffffff); |
| 4838 | iwl4965_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4839 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 4840 | } |
| 4841 | |
| 4842 | static const char *desc_lookup(int i) |
| 4843 | { |
| 4844 | switch (i) { |
| 4845 | case 1: |
| 4846 | return "FAIL"; |
| 4847 | case 2: |
| 4848 | return "BAD_PARAM"; |
| 4849 | case 3: |
| 4850 | return "BAD_CHECKSUM"; |
| 4851 | case 4: |
| 4852 | return "NMI_INTERRUPT"; |
| 4853 | case 5: |
| 4854 | return "SYSASSERT"; |
| 4855 | case 6: |
| 4856 | return "FATAL_ERROR"; |
| 4857 | } |
| 4858 | |
| 4859 | return "UNKNOWN"; |
| 4860 | } |
| 4861 | |
| 4862 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 4863 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 4864 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4865 | static void iwl4965_dump_nic_error_log(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4866 | { |
| 4867 | u32 data2, line; |
| 4868 | u32 desc, time, count, base, data1; |
| 4869 | u32 blink1, blink2, ilink1, ilink2; |
| 4870 | int rc; |
| 4871 | |
| 4872 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 4873 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4874 | if (!iwl4965_hw_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4875 | IWL_ERROR("Not valid error log pointer 0x%08X\n", base); |
| 4876 | return; |
| 4877 | } |
| 4878 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4879 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4880 | if (rc) { |
| 4881 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4882 | return; |
| 4883 | } |
| 4884 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4885 | count = iwl4965_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4886 | |
| 4887 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
| 4888 | IWL_ERROR("Start IWL Error Log Dump:\n"); |
Tomas Winkler | 2acae16 | 2008-03-02 01:25:59 +0200 | [diff] [blame] | 4889 | IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4890 | } |
| 4891 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4892 | desc = iwl4965_read_targ_mem(priv, base + 1 * sizeof(u32)); |
| 4893 | blink1 = iwl4965_read_targ_mem(priv, base + 3 * sizeof(u32)); |
| 4894 | blink2 = iwl4965_read_targ_mem(priv, base + 4 * sizeof(u32)); |
| 4895 | ilink1 = iwl4965_read_targ_mem(priv, base + 5 * sizeof(u32)); |
| 4896 | ilink2 = iwl4965_read_targ_mem(priv, base + 6 * sizeof(u32)); |
| 4897 | data1 = iwl4965_read_targ_mem(priv, base + 7 * sizeof(u32)); |
| 4898 | data2 = iwl4965_read_targ_mem(priv, base + 8 * sizeof(u32)); |
| 4899 | line = iwl4965_read_targ_mem(priv, base + 9 * sizeof(u32)); |
| 4900 | time = iwl4965_read_targ_mem(priv, base + 11 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4901 | |
| 4902 | IWL_ERROR("Desc Time " |
| 4903 | "data1 data2 line\n"); |
| 4904 | IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n", |
| 4905 | desc_lookup(desc), desc, time, data1, data2, line); |
| 4906 | IWL_ERROR("blink1 blink2 ilink1 ilink2\n"); |
| 4907 | IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2, |
| 4908 | ilink1, ilink2); |
| 4909 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4910 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4911 | } |
| 4912 | |
| 4913 | #define EVENT_START_OFFSET (4 * sizeof(u32)) |
| 4914 | |
| 4915 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4916 | * iwl4965_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4917 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4918 | * NOTE: Must be called with iwl4965_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4919 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4920 | 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] | 4921 | u32 num_events, u32 mode) |
| 4922 | { |
| 4923 | u32 i; |
| 4924 | u32 base; /* SRAM byte address of event log header */ |
| 4925 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 4926 | u32 ptr; /* SRAM byte address of log data */ |
| 4927 | u32 ev, time, data; /* event log data */ |
| 4928 | |
| 4929 | if (num_events == 0) |
| 4930 | return; |
| 4931 | |
| 4932 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 4933 | |
| 4934 | if (mode == 0) |
| 4935 | event_size = 2 * sizeof(u32); |
| 4936 | else |
| 4937 | event_size = 3 * sizeof(u32); |
| 4938 | |
| 4939 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 4940 | |
| 4941 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 4942 | * place event id # at far right for easier visual parsing. */ |
| 4943 | for (i = 0; i < num_events; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4944 | ev = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4945 | ptr += sizeof(u32); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4946 | time = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4947 | ptr += sizeof(u32); |
| 4948 | if (mode == 0) |
| 4949 | IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */ |
| 4950 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4951 | data = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4952 | ptr += sizeof(u32); |
| 4953 | IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev); |
| 4954 | } |
| 4955 | } |
| 4956 | } |
| 4957 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4958 | static void iwl4965_dump_nic_event_log(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4959 | { |
| 4960 | int rc; |
| 4961 | u32 base; /* SRAM byte address of event log header */ |
| 4962 | u32 capacity; /* event log capacity in # entries */ |
| 4963 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 4964 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 4965 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 4966 | u32 size; /* # entries that we'll print */ |
| 4967 | |
| 4968 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4969 | if (!iwl4965_hw_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4970 | IWL_ERROR("Invalid event log pointer 0x%08X\n", base); |
| 4971 | return; |
| 4972 | } |
| 4973 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4974 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4975 | if (rc) { |
| 4976 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4977 | return; |
| 4978 | } |
| 4979 | |
| 4980 | /* event log header */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4981 | capacity = iwl4965_read_targ_mem(priv, base); |
| 4982 | mode = iwl4965_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 4983 | num_wraps = iwl4965_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 4984 | next_entry = iwl4965_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4985 | |
| 4986 | size = num_wraps ? capacity : next_entry; |
| 4987 | |
| 4988 | /* bail out if nothing in log */ |
| 4989 | if (size == 0) { |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 4990 | IWL_ERROR("Start IWL Event Log Dump: nothing in log\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4991 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4992 | return; |
| 4993 | } |
| 4994 | |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 4995 | 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] | 4996 | size, num_wraps); |
| 4997 | |
| 4998 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 4999 | * i.e the next one that uCode would fill. */ |
| 5000 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5001 | iwl4965_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5002 | capacity - next_entry, mode); |
| 5003 | |
| 5004 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5005 | iwl4965_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5006 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5007 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5008 | } |
| 5009 | |
| 5010 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5011 | * 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] | 5012 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5013 | static void iwl4965_irq_handle_error(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5014 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5015 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5016 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 5017 | |
| 5018 | /* Cancel currently queued command. */ |
| 5019 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 5020 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5021 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5022 | if (iwl4965_debug_level & IWL_DL_FW_ERRORS) { |
| 5023 | iwl4965_dump_nic_error_log(priv); |
| 5024 | iwl4965_dump_nic_event_log(priv); |
| 5025 | iwl4965_print_rx_config_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5026 | } |
| 5027 | #endif |
| 5028 | |
| 5029 | wake_up_interruptible(&priv->wait_command_queue); |
| 5030 | |
| 5031 | /* Keep the restart process from trying to send host |
| 5032 | * commands by clearing the INIT status bit */ |
| 5033 | clear_bit(STATUS_READY, &priv->status); |
| 5034 | |
| 5035 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 5036 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 5037 | "Restarting adapter due to uCode error.\n"); |
| 5038 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5039 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5040 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 5041 | sizeof(priv->recovery_rxon)); |
| 5042 | priv->error_recovering = 1; |
| 5043 | } |
| 5044 | queue_work(priv->workqueue, &priv->restart); |
| 5045 | } |
| 5046 | } |
| 5047 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5048 | static void iwl4965_error_recovery(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5049 | { |
| 5050 | unsigned long flags; |
| 5051 | |
| 5052 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 5053 | sizeof(priv->staging_rxon)); |
| 5054 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5055 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5056 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5057 | iwl4965_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5058 | |
| 5059 | spin_lock_irqsave(&priv->lock, flags); |
| 5060 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 5061 | priv->error_recovering = 0; |
| 5062 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5063 | } |
| 5064 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5065 | static void iwl4965_irq_tasklet(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5066 | { |
| 5067 | u32 inta, handled = 0; |
| 5068 | u32 inta_fh; |
| 5069 | unsigned long flags; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5070 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5071 | u32 inta_mask; |
| 5072 | #endif |
| 5073 | |
| 5074 | spin_lock_irqsave(&priv->lock, flags); |
| 5075 | |
| 5076 | /* Ack/clear/reset pending uCode interrupts. |
| 5077 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 5078 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5079 | inta = iwl4965_read32(priv, CSR_INT); |
| 5080 | iwl4965_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5081 | |
| 5082 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 5083 | * Any new interrupts that happen after this, either while we're |
| 5084 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5085 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
| 5086 | iwl4965_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5087 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5088 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5089 | if (iwl4965_debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5090 | /* just for debug */ |
| 5091 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5092 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 5093 | inta, inta_mask, inta_fh); |
| 5094 | } |
| 5095 | #endif |
| 5096 | |
| 5097 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 5098 | * atomic, make sure that inta covers all the interrupts that |
| 5099 | * we've discovered, even if FH interrupt came in just after |
| 5100 | * reading CSR_INT. */ |
| 5101 | if (inta_fh & CSR_FH_INT_RX_MASK) |
| 5102 | inta |= CSR_INT_BIT_FH_RX; |
| 5103 | if (inta_fh & CSR_FH_INT_TX_MASK) |
| 5104 | inta |= CSR_INT_BIT_FH_TX; |
| 5105 | |
| 5106 | /* Now service all interrupt bits discovered above. */ |
| 5107 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 5108 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 5109 | |
| 5110 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5111 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5112 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5113 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5114 | |
| 5115 | handled |= CSR_INT_BIT_HW_ERR; |
| 5116 | |
| 5117 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5118 | |
| 5119 | return; |
| 5120 | } |
| 5121 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5122 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5123 | if (iwl4965_debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5124 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 5125 | if (inta & CSR_INT_BIT_SCD) |
| 5126 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 5127 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5128 | |
| 5129 | /* Alive notification via Rx interrupt will do the real work */ |
| 5130 | if (inta & CSR_INT_BIT_ALIVE) |
| 5131 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 5132 | } |
| 5133 | #endif |
| 5134 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 5135 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5136 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5137 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5138 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 5139 | int hw_rf_kill = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5140 | if (!(iwl4965_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5141 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 5142 | hw_rf_kill = 1; |
| 5143 | |
| 5144 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR, |
| 5145 | "RF_KILL bit toggled to %s.\n", |
| 5146 | hw_rf_kill ? "disable radio":"enable radio"); |
| 5147 | |
| 5148 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 5149 | * when we loaded driver, and is now set to "enable". |
| 5150 | * After we're Alive, RF_KILL gets handled by |
Reinette Chatre | 3230455 | 2008-02-15 14:34:37 -0800 | [diff] [blame] | 5151 | * iwl4965_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 5152 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 5153 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5154 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 5155 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5156 | |
| 5157 | handled |= CSR_INT_BIT_RF_KILL; |
| 5158 | } |
| 5159 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5160 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5161 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 5162 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 5163 | handled |= CSR_INT_BIT_CT_KILL; |
| 5164 | } |
| 5165 | |
| 5166 | /* Error detected by uCode */ |
| 5167 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 5168 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 5169 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5170 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5171 | handled |= CSR_INT_BIT_SW_ERR; |
| 5172 | } |
| 5173 | |
| 5174 | /* uCode wakes up after power-down sleep */ |
| 5175 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 5176 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5177 | iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq); |
| 5178 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]); |
| 5179 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]); |
| 5180 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]); |
| 5181 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]); |
| 5182 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]); |
| 5183 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5184 | |
| 5185 | handled |= CSR_INT_BIT_WAKEUP; |
| 5186 | } |
| 5187 | |
| 5188 | /* All uCode command responses, including Tx command responses, |
| 5189 | * Rx "responses" (frame-received notification), and other |
| 5190 | * notifications from uCode come through here*/ |
| 5191 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5192 | iwl4965_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5193 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 5194 | } |
| 5195 | |
| 5196 | if (inta & CSR_INT_BIT_FH_TX) { |
| 5197 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 5198 | handled |= CSR_INT_BIT_FH_TX; |
| 5199 | } |
| 5200 | |
| 5201 | if (inta & ~handled) |
| 5202 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 5203 | |
| 5204 | if (inta & ~CSR_INI_SET_MASK) { |
| 5205 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 5206 | inta & ~CSR_INI_SET_MASK); |
| 5207 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 5208 | } |
| 5209 | |
| 5210 | /* Re-enable all interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5211 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5212 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5213 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5214 | if (iwl4965_debug_level & (IWL_DL_ISR)) { |
| 5215 | inta = iwl4965_read32(priv, CSR_INT); |
| 5216 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); |
| 5217 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5218 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 5219 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 5220 | } |
| 5221 | #endif |
| 5222 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5223 | } |
| 5224 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5225 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5226 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5227 | struct iwl4965_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5228 | u32 inta, inta_mask; |
| 5229 | u32 inta_fh; |
| 5230 | if (!priv) |
| 5231 | return IRQ_NONE; |
| 5232 | |
| 5233 | spin_lock(&priv->lock); |
| 5234 | |
| 5235 | /* Disable (but don't clear!) interrupts here to avoid |
| 5236 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 5237 | * If we have something to service, the tasklet will re-enable ints. |
| 5238 | * 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] | 5239 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 5240 | iwl4965_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5241 | |
| 5242 | /* Discover which interrupts are active/pending */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5243 | inta = iwl4965_read32(priv, CSR_INT); |
| 5244 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5245 | |
| 5246 | /* Ignore interrupt if there's nothing in NIC to service. |
| 5247 | * This may be due to IRQ shared with another device, |
| 5248 | * or due to sporadic interrupts thrown from our NIC. */ |
| 5249 | if (!inta && !inta_fh) { |
| 5250 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 5251 | goto none; |
| 5252 | } |
| 5253 | |
| 5254 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5255 | /* Hardware disappeared. It might have already raised |
| 5256 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5257 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5258 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5259 | } |
| 5260 | |
| 5261 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 5262 | inta, inta_mask, inta_fh); |
| 5263 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 5264 | inta &= ~CSR_INT_BIT_SCD; |
| 5265 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5266 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 5267 | if (likely(inta || inta_fh)) |
| 5268 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5269 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 5270 | unplugged: |
| 5271 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5272 | return IRQ_HANDLED; |
| 5273 | |
| 5274 | none: |
| 5275 | /* re-enable interrupts here since we don't have anything to service. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5276 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5277 | spin_unlock(&priv->lock); |
| 5278 | return IRQ_NONE; |
| 5279 | } |
| 5280 | |
| 5281 | /************************** EEPROM BANDS **************************** |
| 5282 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5283 | * The iwl4965_eeprom_band definitions below provide the mapping from the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5284 | * EEPROM contents to the specific channel number supported for each |
| 5285 | * band. |
| 5286 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5287 | * 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] | 5288 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. |
| 5289 | * The specific geography and calibration information for that channel |
| 5290 | * is contained in the eeprom map itself. |
| 5291 | * |
| 5292 | * During init, we copy the eeprom information and channel map |
| 5293 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 |
| 5294 | * |
| 5295 | * channel_map_24/52 provides the index in the channel_info array for a |
| 5296 | * given channel. We have to have two separate maps as there is channel |
| 5297 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and |
| 5298 | * band_2 |
| 5299 | * |
| 5300 | * A value of 0xff stored in the channel_map indicates that the channel |
| 5301 | * is not supported by the hardware at all. |
| 5302 | * |
| 5303 | * A value of 0xfe in the channel_map indicates that the channel is not |
| 5304 | * valid for Tx with the current hardware. This means that |
| 5305 | * while the system can tune and receive on a given channel, it may not |
| 5306 | * be able to associate or transmit any frames on that |
| 5307 | * channel. There is no corresponding channel information for that |
| 5308 | * entry. |
| 5309 | * |
| 5310 | *********************************************************************/ |
| 5311 | |
| 5312 | /* 2.4 GHz */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5313 | static const u8 iwl4965_eeprom_band_1[14] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5314 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
| 5315 | }; |
| 5316 | |
| 5317 | /* 5.2 GHz bands */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5318 | static const u8 iwl4965_eeprom_band_2[] = { /* 4915-5080MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5319 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
| 5320 | }; |
| 5321 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5322 | static const u8 iwl4965_eeprom_band_3[] = { /* 5170-5320MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5323 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
| 5324 | }; |
| 5325 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5326 | static const u8 iwl4965_eeprom_band_4[] = { /* 5500-5700MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5327 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
| 5328 | }; |
| 5329 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5330 | static const u8 iwl4965_eeprom_band_5[] = { /* 5725-5825MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5331 | 145, 149, 153, 157, 161, 165 |
| 5332 | }; |
| 5333 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5334 | static u8 iwl4965_eeprom_band_6[] = { /* 2.4 FAT channel */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5335 | 1, 2, 3, 4, 5, 6, 7 |
| 5336 | }; |
| 5337 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5338 | static u8 iwl4965_eeprom_band_7[] = { /* 5.2 FAT channel */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5339 | 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157 |
| 5340 | }; |
| 5341 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5342 | static void iwl4965_init_band_reference(const struct iwl4965_priv *priv, |
| 5343 | int band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5344 | int *eeprom_ch_count, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5345 | const struct iwl4965_eeprom_channel |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5346 | **eeprom_ch_info, |
| 5347 | const u8 **eeprom_ch_index) |
| 5348 | { |
| 5349 | switch (band) { |
| 5350 | case 1: /* 2.4GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5351 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5352 | *eeprom_ch_info = priv->eeprom.band_1_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5353 | *eeprom_ch_index = iwl4965_eeprom_band_1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5354 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5355 | case 2: /* 4.9GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5356 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5357 | *eeprom_ch_info = priv->eeprom.band_2_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5358 | *eeprom_ch_index = iwl4965_eeprom_band_2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5359 | break; |
| 5360 | case 3: /* 5.2GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5361 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5362 | *eeprom_ch_info = priv->eeprom.band_3_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5363 | *eeprom_ch_index = iwl4965_eeprom_band_3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5364 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5365 | case 4: /* 5.5GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5366 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_4); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5367 | *eeprom_ch_info = priv->eeprom.band_4_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5368 | *eeprom_ch_index = iwl4965_eeprom_band_4; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5369 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5370 | case 5: /* 5.7GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5371 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5372 | *eeprom_ch_info = priv->eeprom.band_5_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5373 | *eeprom_ch_index = iwl4965_eeprom_band_5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5374 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5375 | case 6: /* 2.4GHz FAT channels */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5376 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_6); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5377 | *eeprom_ch_info = priv->eeprom.band_24_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5378 | *eeprom_ch_index = iwl4965_eeprom_band_6; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5379 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5380 | case 7: /* 5 GHz FAT channels */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5381 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5382 | *eeprom_ch_info = priv->eeprom.band_52_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5383 | *eeprom_ch_index = iwl4965_eeprom_band_7; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5384 | break; |
| 5385 | default: |
| 5386 | BUG(); |
| 5387 | return; |
| 5388 | } |
| 5389 | } |
| 5390 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5391 | /** |
| 5392 | * iwl4965_get_channel_info - Find driver's private channel info |
| 5393 | * |
| 5394 | * Based on band and channel number. |
| 5395 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5396 | const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl4965_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5397 | enum ieee80211_band band, u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5398 | { |
| 5399 | int i; |
| 5400 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5401 | switch (band) { |
| 5402 | case IEEE80211_BAND_5GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5403 | for (i = 14; i < priv->channel_count; i++) { |
| 5404 | if (priv->channel_info[i].channel == channel) |
| 5405 | return &priv->channel_info[i]; |
| 5406 | } |
| 5407 | break; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5408 | case IEEE80211_BAND_2GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5409 | if (channel >= 1 && channel <= 14) |
| 5410 | return &priv->channel_info[channel - 1]; |
| 5411 | break; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5412 | default: |
| 5413 | BUG(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | return NULL; |
| 5417 | } |
| 5418 | |
| 5419 | #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ |
| 5420 | ? # x " " : "") |
| 5421 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5422 | /** |
| 5423 | * iwl4965_init_channel_map - Set up driver's info for all possible channels |
| 5424 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5425 | static int iwl4965_init_channel_map(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5426 | { |
| 5427 | int eeprom_ch_count = 0; |
| 5428 | const u8 *eeprom_ch_index = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5429 | const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5430 | int band, ch; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5431 | struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5432 | |
| 5433 | if (priv->channel_count) { |
| 5434 | IWL_DEBUG_INFO("Channel map already initialized.\n"); |
| 5435 | return 0; |
| 5436 | } |
| 5437 | |
| 5438 | if (priv->eeprom.version < 0x2f) { |
| 5439 | IWL_WARNING("Unsupported EEPROM version: 0x%04X\n", |
| 5440 | priv->eeprom.version); |
| 5441 | return -EINVAL; |
| 5442 | } |
| 5443 | |
| 5444 | IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); |
| 5445 | |
| 5446 | priv->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5447 | ARRAY_SIZE(iwl4965_eeprom_band_1) + |
| 5448 | ARRAY_SIZE(iwl4965_eeprom_band_2) + |
| 5449 | ARRAY_SIZE(iwl4965_eeprom_band_3) + |
| 5450 | ARRAY_SIZE(iwl4965_eeprom_band_4) + |
| 5451 | ARRAY_SIZE(iwl4965_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5452 | |
| 5453 | IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); |
| 5454 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5455 | priv->channel_info = kzalloc(sizeof(struct iwl4965_channel_info) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5456 | priv->channel_count, GFP_KERNEL); |
| 5457 | if (!priv->channel_info) { |
| 5458 | IWL_ERROR("Could not allocate channel_info\n"); |
| 5459 | priv->channel_count = 0; |
| 5460 | return -ENOMEM; |
| 5461 | } |
| 5462 | |
| 5463 | ch_info = priv->channel_info; |
| 5464 | |
| 5465 | /* Loop through the 5 EEPROM bands adding them in order to the |
| 5466 | * channel map we maintain (that contains additional information than |
| 5467 | * what just in the EEPROM) */ |
| 5468 | for (band = 1; band <= 5; band++) { |
| 5469 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5470 | iwl4965_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5471 | &eeprom_ch_info, &eeprom_ch_index); |
| 5472 | |
| 5473 | /* Loop through each band adding each of the channels */ |
| 5474 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5475 | ch_info->channel = eeprom_ch_index[ch]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5476 | ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ : |
| 5477 | IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5478 | |
| 5479 | /* permanently store EEPROM's channel regulatory flags |
| 5480 | * and max power in channel info database. */ |
| 5481 | ch_info->eeprom = eeprom_ch_info[ch]; |
| 5482 | |
| 5483 | /* Copy the run-time flags so they are there even on |
| 5484 | * invalid channels */ |
| 5485 | ch_info->flags = eeprom_ch_info[ch].flags; |
| 5486 | |
| 5487 | if (!(is_channel_valid(ch_info))) { |
| 5488 | IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - " |
| 5489 | "No traffic\n", |
| 5490 | ch_info->channel, |
| 5491 | ch_info->flags, |
| 5492 | is_channel_a_band(ch_info) ? |
| 5493 | "5.2" : "2.4"); |
| 5494 | ch_info++; |
| 5495 | continue; |
| 5496 | } |
| 5497 | |
| 5498 | /* Initialize regulatory-based run-time data */ |
| 5499 | ch_info->max_power_avg = ch_info->curr_txpow = |
| 5500 | eeprom_ch_info[ch].max_power_avg; |
| 5501 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; |
| 5502 | ch_info->min_power = 0; |
| 5503 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame^] | 5504 | IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s%s(0x%02x" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5505 | " %ddBm): Ad-Hoc %ssupported\n", |
| 5506 | ch_info->channel, |
| 5507 | is_channel_a_band(ch_info) ? |
| 5508 | "5.2" : "2.4", |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame^] | 5509 | CHECK_AND_PRINT(VALID), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5510 | CHECK_AND_PRINT(IBSS), |
| 5511 | CHECK_AND_PRINT(ACTIVE), |
| 5512 | CHECK_AND_PRINT(RADAR), |
| 5513 | CHECK_AND_PRINT(WIDE), |
| 5514 | CHECK_AND_PRINT(NARROW), |
| 5515 | CHECK_AND_PRINT(DFS), |
| 5516 | eeprom_ch_info[ch].flags, |
| 5517 | eeprom_ch_info[ch].max_power_avg, |
| 5518 | ((eeprom_ch_info[ch]. |
| 5519 | flags & EEPROM_CHANNEL_IBSS) |
| 5520 | && !(eeprom_ch_info[ch]. |
| 5521 | flags & EEPROM_CHANNEL_RADAR)) |
| 5522 | ? "" : "not "); |
| 5523 | |
| 5524 | /* Set the user_txpower_limit to the highest power |
| 5525 | * supported by any channel */ |
| 5526 | if (eeprom_ch_info[ch].max_power_avg > |
| 5527 | priv->user_txpower_limit) |
| 5528 | priv->user_txpower_limit = |
| 5529 | eeprom_ch_info[ch].max_power_avg; |
| 5530 | |
| 5531 | ch_info++; |
| 5532 | } |
| 5533 | } |
| 5534 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5535 | /* Two additional EEPROM bands for 2.4 and 5 GHz FAT channels */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5536 | for (band = 6; band <= 7; band++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5537 | enum ieee80211_band ieeeband; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5538 | u8 fat_extension_chan; |
| 5539 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5540 | iwl4965_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5541 | &eeprom_ch_info, &eeprom_ch_index); |
| 5542 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5543 | /* EEPROM band 6 is 2.4, band 7 is 5 GHz */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5544 | ieeeband = (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5545 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5546 | /* Loop through each band adding each of the channels */ |
| 5547 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5548 | |
| 5549 | if ((band == 6) && |
| 5550 | ((eeprom_ch_index[ch] == 5) || |
| 5551 | (eeprom_ch_index[ch] == 6) || |
| 5552 | (eeprom_ch_index[ch] == 7))) |
| 5553 | fat_extension_chan = HT_IE_EXT_CHANNEL_MAX; |
| 5554 | else |
| 5555 | fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE; |
| 5556 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5557 | /* Set up driver's info for lower half */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5558 | iwl4965_set_fat_chan_info(priv, ieeeband, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5559 | eeprom_ch_index[ch], |
| 5560 | &(eeprom_ch_info[ch]), |
| 5561 | fat_extension_chan); |
| 5562 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5563 | /* Set up driver's info for upper half */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5564 | iwl4965_set_fat_chan_info(priv, ieeeband, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5565 | (eeprom_ch_index[ch] + 4), |
| 5566 | &(eeprom_ch_info[ch]), |
| 5567 | HT_IE_EXT_CHANNEL_BELOW); |
| 5568 | } |
| 5569 | } |
| 5570 | |
| 5571 | return 0; |
| 5572 | } |
| 5573 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5574 | /* |
| 5575 | * iwl4965_free_channel_map - undo allocations in iwl4965_init_channel_map |
| 5576 | */ |
| 5577 | static void iwl4965_free_channel_map(struct iwl4965_priv *priv) |
| 5578 | { |
| 5579 | kfree(priv->channel_info); |
| 5580 | priv->channel_count = 0; |
| 5581 | } |
| 5582 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5583 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 5584 | * sending probe req. This should be set long enough to hear probe responses |
| 5585 | * from more than one AP. */ |
| 5586 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5587 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 5588 | |
| 5589 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 5590 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 5591 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 5592 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 5593 | * no other traffic). |
| 5594 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 5595 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 5596 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 5597 | |
| 5598 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 5599 | * Must be set longer than active dwell time. |
| 5600 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 5601 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5602 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 5603 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 5604 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 5605 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5606 | static inline u16 iwl4965_get_active_dwell_time(struct iwl4965_priv *priv, |
| 5607 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5608 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5609 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5610 | return IWL_ACTIVE_DWELL_TIME_52; |
| 5611 | else |
| 5612 | return IWL_ACTIVE_DWELL_TIME_24; |
| 5613 | } |
| 5614 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5615 | static u16 iwl4965_get_passive_dwell_time(struct iwl4965_priv *priv, |
| 5616 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5617 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5618 | u16 active = iwl4965_get_active_dwell_time(priv, band); |
| 5619 | u16 passive = (band != IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5620 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 5621 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 5622 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5623 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5624 | /* If we're associated, we clamp the maximum passive |
| 5625 | * dwell time to be 98% of the beacon interval (minus |
| 5626 | * 2 * channel tune time) */ |
| 5627 | passive = priv->beacon_int; |
| 5628 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 5629 | passive = IWL_PASSIVE_DWELL_BASE; |
| 5630 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 5631 | } |
| 5632 | |
| 5633 | if (passive <= active) |
| 5634 | passive = active + 1; |
| 5635 | |
| 5636 | return passive; |
| 5637 | } |
| 5638 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5639 | static int iwl4965_get_channels_for_scan(struct iwl4965_priv *priv, |
| 5640 | enum ieee80211_band band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5641 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5642 | struct iwl4965_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5643 | { |
| 5644 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5645 | const struct ieee80211_supported_band *sband; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5646 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5647 | u16 passive_dwell = 0; |
| 5648 | u16 active_dwell = 0; |
| 5649 | int added, i; |
| 5650 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5651 | sband = iwl4965_get_hw_mode(priv, band); |
| 5652 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5653 | return 0; |
| 5654 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5655 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5656 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5657 | active_dwell = iwl4965_get_active_dwell_time(priv, band); |
| 5658 | passive_dwell = iwl4965_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5659 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5660 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
| 5661 | if (ieee80211_frequency_to_channel(channels[i].center_freq) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5662 | le16_to_cpu(priv->active_rxon.channel)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5663 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5664 | IWL_DEBUG_SCAN |
| 5665 | ("Skipping current channel %d\n", |
| 5666 | le16_to_cpu(priv->active_rxon.channel)); |
| 5667 | continue; |
| 5668 | } |
| 5669 | } else if (priv->only_active_channel) |
| 5670 | continue; |
| 5671 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5672 | scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5673 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5674 | ch_info = iwl4965_get_channel_info(priv, band, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5675 | scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5676 | if (!is_channel_valid(ch_info)) { |
| 5677 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 5678 | scan_ch->channel); |
| 5679 | continue; |
| 5680 | } |
| 5681 | |
| 5682 | if (!is_active || is_channel_passive(ch_info) || |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5683 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5684 | scan_ch->type = 0; /* passive */ |
| 5685 | else |
| 5686 | scan_ch->type = 1; /* active */ |
| 5687 | |
| 5688 | if (scan_ch->type & 1) |
| 5689 | scan_ch->type |= (direct_mask << 1); |
| 5690 | |
| 5691 | if (is_channel_narrow(ch_info)) |
| 5692 | scan_ch->type |= (1 << 7); |
| 5693 | |
| 5694 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 5695 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 5696 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5697 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5698 | scan_ch->tpc.dsp_atten = 110; |
| 5699 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 5700 | |
| 5701 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5702 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5703 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 5704 | else { |
| 5705 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 5706 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5707 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 5708 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5709 | */ |
| 5710 | } |
| 5711 | |
| 5712 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 5713 | scan_ch->channel, |
| 5714 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 5715 | (scan_ch->type & 1) ? |
| 5716 | active_dwell : passive_dwell); |
| 5717 | |
| 5718 | scan_ch++; |
| 5719 | added++; |
| 5720 | } |
| 5721 | |
| 5722 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 5723 | return added; |
| 5724 | } |
| 5725 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5726 | static void iwl4965_init_hw_rates(struct iwl4965_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5727 | struct ieee80211_rate *rates) |
| 5728 | { |
| 5729 | int i; |
| 5730 | |
| 5731 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5732 | rates[i].bitrate = iwl4965_rates[i].ieee * 5; |
| 5733 | rates[i].hw_value = i; /* Rate scaling will work on indexes */ |
| 5734 | rates[i].hw_value_short = i; |
| 5735 | rates[i].flags = 0; |
| 5736 | if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5737 | /* |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5738 | * If CCK != 1M then set short preamble rate flag. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5739 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5740 | rates[i].flags |= (iwl4965_rates[i].plcp == 10) ? |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5741 | 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5742 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5743 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5744 | } |
| 5745 | |
| 5746 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5747 | * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5748 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5749 | static int iwl4965_init_geos(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5750 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5751 | struct iwl4965_channel_info *ch; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame^] | 5752 | struct ieee80211_supported_band *sband; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5753 | struct ieee80211_channel *channels; |
| 5754 | struct ieee80211_channel *geo_ch; |
| 5755 | struct ieee80211_rate *rates; |
| 5756 | int i = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5757 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5758 | if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates || |
| 5759 | priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5760 | IWL_DEBUG_INFO("Geography modes already initialized.\n"); |
| 5761 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5762 | return 0; |
| 5763 | } |
| 5764 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5765 | channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 5766 | priv->channel_count, GFP_KERNEL); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5767 | if (!channels) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5768 | return -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5769 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame^] | 5770 | rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5771 | GFP_KERNEL); |
| 5772 | if (!rates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5773 | kfree(channels); |
| 5774 | return -ENOMEM; |
| 5775 | } |
| 5776 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5777 | /* 5.2GHz channels start after the 2.4GHz channels */ |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame^] | 5778 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
| 5779 | sband->channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)]; |
| 5780 | /* just OFDM */ |
| 5781 | sband->bitrates = &rates[IWL_FIRST_OFDM_RATE]; |
| 5782 | sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5783 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame^] | 5784 | iwl4965_init_ht_hw_capab(&sband->ht_info, IEEE80211_BAND_5GHZ); |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5785 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame^] | 5786 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 5787 | sband->channels = channels; |
| 5788 | /* OFDM & CCK */ |
| 5789 | sband->bitrates = rates; |
| 5790 | sband->n_bitrates = IWL_RATE_COUNT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5791 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame^] | 5792 | iwl4965_init_ht_hw_capab(&sband->ht_info, IEEE80211_BAND_2GHZ); |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5793 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5794 | priv->ieee_channels = channels; |
| 5795 | priv->ieee_rates = rates; |
| 5796 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5797 | iwl4965_init_hw_rates(priv, rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5798 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame^] | 5799 | for (i = 0; i < priv->channel_count; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5800 | ch = &priv->channel_info[i]; |
| 5801 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame^] | 5802 | /* FIXME: might be removed if scan is OK */ |
| 5803 | if (!is_channel_valid(ch)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5804 | continue; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5805 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame^] | 5806 | if (is_channel_a_band(ch)) |
| 5807 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
| 5808 | else |
| 5809 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5810 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame^] | 5811 | geo_ch = &sband->channels[sband->n_channels++]; |
| 5812 | |
| 5813 | geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5814 | geo_ch->max_power = ch->max_power_avg; |
| 5815 | geo_ch->max_antenna_gain = 0xff; |
Mohamed Abbas | 7b72304 | 2008-01-31 21:46:40 -0800 | [diff] [blame] | 5816 | geo_ch->hw_value = ch->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5817 | |
| 5818 | if (is_channel_valid(ch)) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5819 | if (!(ch->flags & EEPROM_CHANNEL_IBSS)) |
| 5820 | geo_ch->flags |= IEEE80211_CHAN_NO_IBSS; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5821 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5822 | if (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) |
| 5823 | geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5824 | |
| 5825 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5826 | geo_ch->flags |= IEEE80211_CHAN_RADAR; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5827 | |
| 5828 | if (ch->max_power_avg > priv->max_channel_txpower_limit) |
| 5829 | priv->max_channel_txpower_limit = |
| 5830 | ch->max_power_avg; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame^] | 5831 | } else { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5832 | geo_ch->flags |= IEEE80211_CHAN_DISABLED; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame^] | 5833 | } |
| 5834 | |
| 5835 | /* Save flags for reg domain usage */ |
| 5836 | geo_ch->orig_flags = geo_ch->flags; |
| 5837 | |
| 5838 | IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n", |
| 5839 | ch->channel, geo_ch->center_freq, |
| 5840 | is_channel_a_band(ch) ? "5.2" : "2.4", |
| 5841 | geo_ch->flags & IEEE80211_CHAN_DISABLED ? |
| 5842 | "restricted" : "valid", |
| 5843 | geo_ch->flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5844 | } |
| 5845 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5846 | if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && priv->is_abg) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5847 | printk(KERN_INFO DRV_NAME |
| 5848 | ": Incorrectly detected BG card as ABG. Please send " |
| 5849 | "your PCI ID 0x%04X:0x%04X to maintainer.\n", |
| 5850 | priv->pci_dev->device, priv->pci_dev->subsystem_device); |
| 5851 | priv->is_abg = 0; |
| 5852 | } |
| 5853 | |
| 5854 | printk(KERN_INFO DRV_NAME |
| 5855 | ": Tunable channels: %d 802.11bg, %d 802.11a channels\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5856 | priv->bands[IEEE80211_BAND_2GHZ].n_channels, |
| 5857 | priv->bands[IEEE80211_BAND_5GHZ].n_channels); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5858 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5859 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 5860 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->bands[IEEE80211_BAND_5GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5861 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5862 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5863 | |
| 5864 | return 0; |
| 5865 | } |
| 5866 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5867 | /* |
| 5868 | * iwl4965_free_geos - undo allocations in iwl4965_init_geos |
| 5869 | */ |
| 5870 | static void iwl4965_free_geos(struct iwl4965_priv *priv) |
| 5871 | { |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5872 | kfree(priv->ieee_channels); |
| 5873 | kfree(priv->ieee_rates); |
| 5874 | clear_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5875 | } |
| 5876 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5877 | /****************************************************************************** |
| 5878 | * |
| 5879 | * uCode download functions |
| 5880 | * |
| 5881 | ******************************************************************************/ |
| 5882 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5883 | static void iwl4965_dealloc_ucode_pci(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5884 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5885 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 5886 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 5887 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 5888 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 5889 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 5890 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5894 | * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5895 | * looking at all data. |
| 5896 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 5897 | static int iwl4965_verify_inst_full(struct iwl4965_priv *priv, __le32 *image, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5898 | u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5899 | { |
| 5900 | u32 val; |
| 5901 | u32 save_len = len; |
| 5902 | int rc = 0; |
| 5903 | u32 errcnt; |
| 5904 | |
| 5905 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 5906 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5907 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5908 | if (rc) |
| 5909 | return rc; |
| 5910 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5911 | iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5912 | |
| 5913 | errcnt = 0; |
| 5914 | for (; len > 0; len -= sizeof(u32), image++) { |
| 5915 | /* read data comes through single port, auto-incr addr */ |
| 5916 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 5917 | * if IWL_DL_IO is set */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5918 | val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5919 | if (val != le32_to_cpu(*image)) { |
| 5920 | IWL_ERROR("uCode INST section is invalid at " |
| 5921 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 5922 | save_len - len, val, le32_to_cpu(*image)); |
| 5923 | rc = -EIO; |
| 5924 | errcnt++; |
| 5925 | if (errcnt >= 20) |
| 5926 | break; |
| 5927 | } |
| 5928 | } |
| 5929 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5930 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5931 | |
| 5932 | if (!errcnt) |
| 5933 | IWL_DEBUG_INFO |
| 5934 | ("ucode image in INSTRUCTION memory is good\n"); |
| 5935 | |
| 5936 | return rc; |
| 5937 | } |
| 5938 | |
| 5939 | |
| 5940 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5941 | * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5942 | * using sample data 100 bytes apart. If these sample points are good, |
| 5943 | * it's a pretty good bet that everything between them is good, too. |
| 5944 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5945 | 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] | 5946 | { |
| 5947 | u32 val; |
| 5948 | int rc = 0; |
| 5949 | u32 errcnt = 0; |
| 5950 | u32 i; |
| 5951 | |
| 5952 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 5953 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5954 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5955 | if (rc) |
| 5956 | return rc; |
| 5957 | |
| 5958 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 5959 | /* read data comes through single port, auto-incr addr */ |
| 5960 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 5961 | * if IWL_DL_IO is set */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5962 | iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5963 | i + RTC_INST_LOWER_BOUND); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5964 | val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5965 | if (val != le32_to_cpu(*image)) { |
| 5966 | #if 0 /* Enable this if you want to see details */ |
| 5967 | IWL_ERROR("uCode INST section is invalid at " |
| 5968 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 5969 | i, val, *image); |
| 5970 | #endif |
| 5971 | rc = -EIO; |
| 5972 | errcnt++; |
| 5973 | if (errcnt >= 3) |
| 5974 | break; |
| 5975 | } |
| 5976 | } |
| 5977 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5978 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5979 | |
| 5980 | return rc; |
| 5981 | } |
| 5982 | |
| 5983 | |
| 5984 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5985 | * iwl4965_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5986 | * and verify its contents |
| 5987 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5988 | static int iwl4965_verify_ucode(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5989 | { |
| 5990 | __le32 *image; |
| 5991 | u32 len; |
| 5992 | int rc = 0; |
| 5993 | |
| 5994 | /* Try bootstrap */ |
| 5995 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 5996 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5997 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5998 | if (rc == 0) { |
| 5999 | IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); |
| 6000 | return 0; |
| 6001 | } |
| 6002 | |
| 6003 | /* Try initialize */ |
| 6004 | image = (__le32 *)priv->ucode_init.v_addr; |
| 6005 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6006 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6007 | if (rc == 0) { |
| 6008 | IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); |
| 6009 | return 0; |
| 6010 | } |
| 6011 | |
| 6012 | /* Try runtime/protocol */ |
| 6013 | image = (__le32 *)priv->ucode_code.v_addr; |
| 6014 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6015 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6016 | if (rc == 0) { |
| 6017 | IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); |
| 6018 | return 0; |
| 6019 | } |
| 6020 | |
| 6021 | IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
| 6022 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6023 | /* Since nothing seems to match, show first several data entries in |
| 6024 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 6025 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6026 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 6027 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6028 | rc = iwl4965_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6029 | |
| 6030 | return rc; |
| 6031 | } |
| 6032 | |
| 6033 | |
| 6034 | /* check contents of special bootstrap uCode SRAM */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6035 | static int iwl4965_verify_bsm(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6036 | { |
| 6037 | __le32 *image = priv->ucode_boot.v_addr; |
| 6038 | u32 len = priv->ucode_boot.len; |
| 6039 | u32 reg; |
| 6040 | u32 val; |
| 6041 | |
| 6042 | IWL_DEBUG_INFO("Begin verify bsm\n"); |
| 6043 | |
| 6044 | /* verify BSM SRAM contents */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6045 | val = iwl4965_read_prph(priv, BSM_WR_DWCOUNT_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6046 | for (reg = BSM_SRAM_LOWER_BOUND; |
| 6047 | reg < BSM_SRAM_LOWER_BOUND + len; |
| 6048 | reg += sizeof(u32), image ++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6049 | val = iwl4965_read_prph(priv, reg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6050 | if (val != le32_to_cpu(*image)) { |
| 6051 | IWL_ERROR("BSM uCode verification failed at " |
| 6052 | "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", |
| 6053 | BSM_SRAM_LOWER_BOUND, |
| 6054 | reg - BSM_SRAM_LOWER_BOUND, len, |
| 6055 | val, le32_to_cpu(*image)); |
| 6056 | return -EIO; |
| 6057 | } |
| 6058 | } |
| 6059 | |
| 6060 | IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n"); |
| 6061 | |
| 6062 | return 0; |
| 6063 | } |
| 6064 | |
| 6065 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6066 | * iwl4965_load_bsm - Load bootstrap instructions |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6067 | * |
| 6068 | * BSM operation: |
| 6069 | * |
| 6070 | * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program |
| 6071 | * in special SRAM that does not power down during RFKILL. When powering back |
| 6072 | * up after power-saving sleeps (or during initial uCode load), the BSM loads |
| 6073 | * the bootstrap program into the on-board processor, and starts it. |
| 6074 | * |
| 6075 | * The bootstrap program loads (via DMA) instructions and data for a new |
| 6076 | * program from host DRAM locations indicated by the host driver in the |
| 6077 | * BSM_DRAM_* registers. Once the new program is loaded, it starts |
| 6078 | * automatically. |
| 6079 | * |
| 6080 | * When initializing the NIC, the host driver points the BSM to the |
| 6081 | * "initialize" uCode image. This uCode sets up some internal data, then |
| 6082 | * notifies host via "initialize alive" that it is complete. |
| 6083 | * |
| 6084 | * The host then replaces the BSM_DRAM_* pointer values to point to the |
| 6085 | * normal runtime uCode instructions and a backup uCode data cache buffer |
| 6086 | * (filled initially with starting data values for the on-board processor), |
| 6087 | * then triggers the "initialize" uCode to load and launch the runtime uCode, |
| 6088 | * which begins normal operation. |
| 6089 | * |
| 6090 | * When doing a power-save shutdown, runtime uCode saves data SRAM into |
| 6091 | * the backup data cache in DRAM before SRAM is powered down. |
| 6092 | * |
| 6093 | * When powering back up, the BSM loads the bootstrap program. This reloads |
| 6094 | * the runtime uCode instructions and the backup data cache into SRAM, |
| 6095 | * and re-launches the runtime uCode from where it left off. |
| 6096 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6097 | static int iwl4965_load_bsm(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6098 | { |
| 6099 | __le32 *image = priv->ucode_boot.v_addr; |
| 6100 | u32 len = priv->ucode_boot.len; |
| 6101 | dma_addr_t pinst; |
| 6102 | dma_addr_t pdata; |
| 6103 | u32 inst_len; |
| 6104 | u32 data_len; |
| 6105 | int rc; |
| 6106 | int i; |
| 6107 | u32 done; |
| 6108 | u32 reg_offset; |
| 6109 | |
| 6110 | IWL_DEBUG_INFO("Begin load bsm\n"); |
| 6111 | |
| 6112 | /* make sure bootstrap program is no larger than BSM's SRAM size */ |
| 6113 | if (len > IWL_MAX_BSM_SIZE) |
| 6114 | return -EINVAL; |
| 6115 | |
| 6116 | /* Tell bootstrap uCode where to find the "Initialize" uCode |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6117 | * in host DRAM ... host DRAM physical address bits 35:4 for 4965. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6118 | * NOTE: iwl4965_initialize_alive_start() will replace these values, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6119 | * after the "initialize" uCode has run, to point to |
| 6120 | * runtime/protocol instructions and backup data cache. */ |
| 6121 | pinst = priv->ucode_init.p_addr >> 4; |
| 6122 | pdata = priv->ucode_init_data.p_addr >> 4; |
| 6123 | inst_len = priv->ucode_init.len; |
| 6124 | data_len = priv->ucode_init_data.len; |
| 6125 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6126 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6127 | if (rc) |
| 6128 | return rc; |
| 6129 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6130 | iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 6131 | iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 6132 | iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); |
| 6133 | iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6134 | |
| 6135 | /* Fill BSM memory with bootstrap instructions */ |
| 6136 | for (reg_offset = BSM_SRAM_LOWER_BOUND; |
| 6137 | reg_offset < BSM_SRAM_LOWER_BOUND + len; |
| 6138 | reg_offset += sizeof(u32), image++) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6139 | _iwl4965_write_prph(priv, reg_offset, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6140 | le32_to_cpu(*image)); |
| 6141 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6142 | rc = iwl4965_verify_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6143 | if (rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6144 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6145 | return rc; |
| 6146 | } |
| 6147 | |
| 6148 | /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6149 | iwl4965_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0); |
| 6150 | iwl4965_write_prph(priv, BSM_WR_MEM_DST_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6151 | RTC_INST_LOWER_BOUND); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6152 | iwl4965_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6153 | |
| 6154 | /* Load bootstrap code into instruction SRAM now, |
| 6155 | * to prepare to load "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6156 | iwl4965_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6157 | BSM_WR_CTRL_REG_BIT_START); |
| 6158 | |
| 6159 | /* Wait for load of bootstrap uCode to finish */ |
| 6160 | for (i = 0; i < 100; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6161 | done = iwl4965_read_prph(priv, BSM_WR_CTRL_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6162 | if (!(done & BSM_WR_CTRL_REG_BIT_START)) |
| 6163 | break; |
| 6164 | udelay(10); |
| 6165 | } |
| 6166 | if (i < 100) |
| 6167 | IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i); |
| 6168 | else { |
| 6169 | IWL_ERROR("BSM write did not complete!\n"); |
| 6170 | return -EIO; |
| 6171 | } |
| 6172 | |
| 6173 | /* Enable future boot loads whenever power management unit triggers it |
| 6174 | * (e.g. when powering back up after power-save shutdown) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6175 | iwl4965_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6176 | BSM_WR_CTRL_REG_BIT_START_EN); |
| 6177 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6178 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6179 | |
| 6180 | return 0; |
| 6181 | } |
| 6182 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6183 | static void iwl4965_nic_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6184 | { |
| 6185 | /* Remove all resets to allow NIC to operate */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6186 | iwl4965_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6187 | } |
| 6188 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6189 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6190 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6191 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6192 | * |
| 6193 | * Copy into buffers for card to fetch via bus-mastering |
| 6194 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6195 | static int iwl4965_read_ucode(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6196 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6197 | struct iwl4965_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6198 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6199 | const struct firmware *ucode_raw; |
| 6200 | const char *name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode"; |
| 6201 | u8 *src; |
| 6202 | size_t len; |
| 6203 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 6204 | |
| 6205 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 6206 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6207 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 6208 | if (ret < 0) { |
| 6209 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 6210 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6211 | goto error; |
| 6212 | } |
| 6213 | |
| 6214 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 6215 | name, ucode_raw->size); |
| 6216 | |
| 6217 | /* Make sure that we got at least our header! */ |
| 6218 | if (ucode_raw->size < sizeof(*ucode)) { |
| 6219 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6220 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6221 | goto err_release; |
| 6222 | } |
| 6223 | |
| 6224 | /* Data from ucode file: header followed by uCode images */ |
| 6225 | ucode = (void *)ucode_raw->data; |
| 6226 | |
| 6227 | ver = le32_to_cpu(ucode->ver); |
| 6228 | inst_size = le32_to_cpu(ucode->inst_size); |
| 6229 | data_size = le32_to_cpu(ucode->data_size); |
| 6230 | init_size = le32_to_cpu(ucode->init_size); |
| 6231 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 6232 | boot_size = le32_to_cpu(ucode->boot_size); |
| 6233 | |
| 6234 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 6235 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 6236 | inst_size); |
| 6237 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 6238 | data_size); |
| 6239 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 6240 | init_size); |
| 6241 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 6242 | init_data_size); |
| 6243 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 6244 | boot_size); |
| 6245 | |
| 6246 | /* Verify size of file vs. image size info in file's header */ |
| 6247 | if (ucode_raw->size < sizeof(*ucode) + |
| 6248 | inst_size + data_size + init_size + |
| 6249 | init_data_size + boot_size) { |
| 6250 | |
| 6251 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 6252 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6253 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6254 | goto err_release; |
| 6255 | } |
| 6256 | |
| 6257 | /* Verify that uCode images will fit in card's SRAM */ |
| 6258 | if (inst_size > IWL_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6259 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 6260 | inst_size); |
| 6261 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6262 | goto err_release; |
| 6263 | } |
| 6264 | |
| 6265 | if (data_size > IWL_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6266 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 6267 | data_size); |
| 6268 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6269 | goto err_release; |
| 6270 | } |
| 6271 | if (init_size > IWL_MAX_INST_SIZE) { |
| 6272 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6273 | ("uCode init instr len %d too large to fit in\n", |
| 6274 | init_size); |
| 6275 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6276 | goto err_release; |
| 6277 | } |
| 6278 | if (init_data_size > IWL_MAX_DATA_SIZE) { |
| 6279 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6280 | ("uCode init data len %d too large to fit in\n", |
| 6281 | init_data_size); |
| 6282 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6283 | goto err_release; |
| 6284 | } |
| 6285 | if (boot_size > IWL_MAX_BSM_SIZE) { |
| 6286 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6287 | ("uCode boot instr len %d too large to fit in\n", |
| 6288 | boot_size); |
| 6289 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6290 | goto err_release; |
| 6291 | } |
| 6292 | |
| 6293 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 6294 | |
| 6295 | /* Runtime instructions and 2 copies of data: |
| 6296 | * 1) unmodified from disk |
| 6297 | * 2) backup cache for save/restore during power-downs */ |
| 6298 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6299 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6300 | |
| 6301 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6302 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6303 | |
| 6304 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6305 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6306 | |
| 6307 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6308 | if (init_size && init_data_size) { |
| 6309 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6310 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6311 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6312 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6313 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6314 | |
| 6315 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 6316 | goto err_pci_alloc; |
| 6317 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6318 | |
| 6319 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6320 | if (boot_size) { |
| 6321 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6322 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6323 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6324 | if (!priv->ucode_boot.v_addr) |
| 6325 | goto err_pci_alloc; |
| 6326 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6327 | |
| 6328 | /* Copy images into buffers for card's bus-master reads ... */ |
| 6329 | |
| 6330 | /* Runtime instructions (first block of data in file) */ |
| 6331 | src = &ucode->data[0]; |
| 6332 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6333 | 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] | 6334 | memcpy(priv->ucode_code.v_addr, src, len); |
| 6335 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 6336 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 6337 | |
| 6338 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6339 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6340 | src = &ucode->data[inst_size]; |
| 6341 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6342 | 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] | 6343 | memcpy(priv->ucode_data.v_addr, src, len); |
| 6344 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 6345 | |
| 6346 | /* Initialization instructions (3rd block) */ |
| 6347 | if (init_size) { |
| 6348 | src = &ucode->data[inst_size + data_size]; |
| 6349 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6350 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 6351 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6352 | memcpy(priv->ucode_init.v_addr, src, len); |
| 6353 | } |
| 6354 | |
| 6355 | /* Initialization data (4th block) */ |
| 6356 | if (init_data_size) { |
| 6357 | src = &ucode->data[inst_size + data_size + init_size]; |
| 6358 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6359 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 6360 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6361 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 6362 | } |
| 6363 | |
| 6364 | /* Bootstrap instructions (5th block) */ |
| 6365 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 6366 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6367 | 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] | 6368 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 6369 | |
| 6370 | /* We have our copies now, allow OS release its copies */ |
| 6371 | release_firmware(ucode_raw); |
| 6372 | return 0; |
| 6373 | |
| 6374 | err_pci_alloc: |
| 6375 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6376 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6377 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6378 | |
| 6379 | err_release: |
| 6380 | release_firmware(ucode_raw); |
| 6381 | |
| 6382 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6383 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6384 | } |
| 6385 | |
| 6386 | |
| 6387 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6388 | * iwl4965_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6389 | * |
| 6390 | * Tell initialization uCode where to find runtime uCode. |
| 6391 | * |
| 6392 | * BSM registers initially contain pointers to initialization uCode. |
| 6393 | * We need to replace them to load runtime uCode inst and data, |
| 6394 | * and to save runtime data when powering down. |
| 6395 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6396 | static int iwl4965_set_ucode_ptrs(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6397 | { |
| 6398 | dma_addr_t pinst; |
| 6399 | dma_addr_t pdata; |
| 6400 | int rc = 0; |
| 6401 | unsigned long flags; |
| 6402 | |
| 6403 | /* bits 35:4 for 4965 */ |
| 6404 | pinst = priv->ucode_code.p_addr >> 4; |
| 6405 | pdata = priv->ucode_data_backup.p_addr >> 4; |
| 6406 | |
| 6407 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6408 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6409 | if (rc) { |
| 6410 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6411 | return rc; |
| 6412 | } |
| 6413 | |
| 6414 | /* Tell bootstrap uCode where to find image to load */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6415 | iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 6416 | iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 6417 | iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6418 | priv->ucode_data.len); |
| 6419 | |
| 6420 | /* Inst bytecount must be last to set up, bit 31 signals uCode |
| 6421 | * that all new ptr/size info is in place */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6422 | iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6423 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 6424 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6425 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6426 | |
| 6427 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6428 | |
| 6429 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 6430 | |
| 6431 | return rc; |
| 6432 | } |
| 6433 | |
| 6434 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6435 | * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6436 | * |
| 6437 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 6438 | * |
| 6439 | * The 4965 "initialize" ALIVE reply contains calibration data for: |
| 6440 | * Voltage, temperature, and MIMO tx gain correction, now stored in priv |
| 6441 | * (3945 does not contain this data). |
| 6442 | * |
| 6443 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
| 6444 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6445 | static void iwl4965_init_alive_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6446 | { |
| 6447 | /* Check alive response for "valid" sign from uCode */ |
| 6448 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 6449 | /* We had an error bringing up the hardware, so take it |
| 6450 | * all the way back down so we can try again */ |
| 6451 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 6452 | goto restart; |
| 6453 | } |
| 6454 | |
| 6455 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 6456 | * This is a paranoid check, because we would not have gotten the |
| 6457 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6458 | if (iwl4965_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6459 | /* Runtime instruction load was bad; |
| 6460 | * take it all the way back down so we can try again */ |
| 6461 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 6462 | goto restart; |
| 6463 | } |
| 6464 | |
| 6465 | /* Calculate temperature */ |
| 6466 | priv->temperature = iwl4965_get_temperature(priv); |
| 6467 | |
| 6468 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 6469 | * load and launch runtime uCode, which will send us another "Alive" |
| 6470 | * notification. */ |
| 6471 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6472 | if (iwl4965_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6473 | /* Runtime instruction load won't happen; |
| 6474 | * take it all the way back down so we can try again */ |
| 6475 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 6476 | goto restart; |
| 6477 | } |
| 6478 | return; |
| 6479 | |
| 6480 | restart: |
| 6481 | queue_work(priv->workqueue, &priv->restart); |
| 6482 | } |
| 6483 | |
| 6484 | |
| 6485 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6486 | * iwl4965_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6487 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6488 | * Alive gets handled by iwl4965_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6489 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6490 | static void iwl4965_alive_start(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6491 | { |
| 6492 | int rc = 0; |
| 6493 | |
| 6494 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 6495 | |
| 6496 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 6497 | /* We had an error bringing up the hardware, so take it |
| 6498 | * all the way back down so we can try again */ |
| 6499 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 6500 | goto restart; |
| 6501 | } |
| 6502 | |
| 6503 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 6504 | * This is a paranoid check, because we would not have gotten the |
| 6505 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6506 | if (iwl4965_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6507 | /* Runtime instruction load was bad; |
| 6508 | * take it all the way back down so we can try again */ |
| 6509 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 6510 | goto restart; |
| 6511 | } |
| 6512 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6513 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6514 | |
| 6515 | rc = iwl4965_alive_notify(priv); |
| 6516 | if (rc) { |
| 6517 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
| 6518 | rc); |
| 6519 | goto restart; |
| 6520 | } |
| 6521 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6522 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6523 | set_bit(STATUS_ALIVE, &priv->status); |
| 6524 | |
| 6525 | /* Clear out the uCode error bit if it is set */ |
| 6526 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 6527 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6528 | if (iwl4965_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6529 | return; |
| 6530 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6531 | ieee80211_start_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6532 | |
| 6533 | priv->active_rate = priv->rates_mask; |
| 6534 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 6535 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6536 | iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6537 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6538 | if (iwl4965_is_associated(priv)) { |
| 6539 | struct iwl4965_rxon_cmd *active_rxon = |
| 6540 | (struct iwl4965_rxon_cmd *)(&priv->active_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6541 | |
| 6542 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 6543 | sizeof(priv->staging_rxon)); |
| 6544 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 6545 | } else { |
| 6546 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6547 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6548 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 6549 | } |
| 6550 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6551 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6552 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6553 | |
| 6554 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6555 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6556 | |
| 6557 | /* At this point, the NIC is initialized and operational */ |
| 6558 | priv->notif_missed_beacons = 0; |
| 6559 | set_bit(STATUS_READY, &priv->status); |
| 6560 | |
| 6561 | iwl4965_rf_kill_ct_config(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6562 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6563 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6564 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6565 | |
| 6566 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6567 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6568 | |
| 6569 | return; |
| 6570 | |
| 6571 | restart: |
| 6572 | queue_work(priv->workqueue, &priv->restart); |
| 6573 | } |
| 6574 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6575 | static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6576 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6577 | static void __iwl4965_down(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6578 | { |
| 6579 | unsigned long flags; |
| 6580 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6581 | struct ieee80211_conf *conf = NULL; |
| 6582 | |
| 6583 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 6584 | |
| 6585 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6586 | |
| 6587 | if (!exit_pending) |
| 6588 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6589 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6590 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6591 | |
| 6592 | /* Unblock any waiting calls */ |
| 6593 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 6594 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6595 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 6596 | * exiting the module */ |
| 6597 | if (!exit_pending) |
| 6598 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6599 | |
| 6600 | /* stop and reset the on-board processor */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6601 | iwl4965_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6602 | |
| 6603 | /* tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6604 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6605 | |
| 6606 | if (priv->mac80211_registered) |
| 6607 | ieee80211_stop_queues(priv->hw); |
| 6608 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6609 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6610 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6611 | if (!iwl4965_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6612 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6613 | STATUS_RF_KILL_HW | |
| 6614 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6615 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 6616 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 6617 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6618 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6619 | STATUS_IN_SUSPEND; |
| 6620 | goto exit; |
| 6621 | } |
| 6622 | |
| 6623 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 6624 | * SUSPEND bits and continue taking the NIC down. */ |
| 6625 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6626 | STATUS_RF_KILL_HW | |
| 6627 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6628 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 6629 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 6630 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6631 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6632 | STATUS_IN_SUSPEND | |
| 6633 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 6634 | STATUS_FW_ERROR; |
| 6635 | |
| 6636 | spin_lock_irqsave(&priv->lock, flags); |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6637 | iwl4965_clear_bit(priv, CSR_GP_CNTRL, |
| 6638 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6639 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6640 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6641 | iwl4965_hw_txq_ctx_stop(priv); |
| 6642 | iwl4965_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6643 | |
| 6644 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6645 | if (!iwl4965_grab_nic_access(priv)) { |
| 6646 | iwl4965_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6647 | APMG_CLK_VAL_DMA_CLK_RQT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6648 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6649 | } |
| 6650 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6651 | |
| 6652 | udelay(5); |
| 6653 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6654 | iwl4965_hw_nic_stop_master(priv); |
| 6655 | iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
| 6656 | iwl4965_hw_nic_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6657 | |
| 6658 | exit: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6659 | memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6660 | |
| 6661 | if (priv->ibss_beacon) |
| 6662 | dev_kfree_skb(priv->ibss_beacon); |
| 6663 | priv->ibss_beacon = NULL; |
| 6664 | |
| 6665 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6666 | iwl4965_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6667 | } |
| 6668 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6669 | static void iwl4965_down(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6670 | { |
| 6671 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6672 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6673 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 6674 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6675 | iwl4965_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6676 | } |
| 6677 | |
| 6678 | #define MAX_HW_RESTARTS 5 |
| 6679 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6680 | static int __iwl4965_up(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6681 | { |
| 6682 | int rc, i; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6683 | |
| 6684 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6685 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 6686 | return -EIO; |
| 6687 | } |
| 6688 | |
| 6689 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 6690 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 6691 | "parameter)\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6692 | return -ENODEV; |
| 6693 | } |
| 6694 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 6695 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 6696 | IWL_ERROR("ucode not available for device bringup\n"); |
| 6697 | return -EIO; |
| 6698 | } |
| 6699 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6700 | /* If platform's RF_KILL switch is NOT set to KILL */ |
| 6701 | if (iwl4965_read32(priv, CSR_GP_CNTRL) & |
| 6702 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 6703 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 6704 | else { |
| 6705 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 6706 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
| 6707 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 6708 | return -ENODEV; |
| 6709 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6710 | } |
| 6711 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6712 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6713 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6714 | rc = iwl4965_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6715 | if (rc) { |
| 6716 | IWL_ERROR("Unable to int nic\n"); |
| 6717 | return rc; |
| 6718 | } |
| 6719 | |
| 6720 | /* make sure rfkill handshake bits are cleared */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6721 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6722 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6723 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 6724 | |
| 6725 | /* clear (again), then enable host interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6726 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
| 6727 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6728 | |
| 6729 | /* really make sure rfkill handshake bits are cleared */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6730 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6731 | 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] | 6732 | |
| 6733 | /* Copy original ucode data image from disk into backup cache. |
| 6734 | * This will be used to initialize the on-board processor's |
| 6735 | * data SRAM for a clean start when the runtime program first loads. */ |
| 6736 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6737 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6738 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6739 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 6740 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6741 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6742 | |
| 6743 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 6744 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6745 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6746 | |
| 6747 | /* load bootstrap state machine, |
| 6748 | * load bootstrap program into processor's memory, |
| 6749 | * prepare to load the "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6750 | rc = iwl4965_load_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6751 | |
| 6752 | if (rc) { |
| 6753 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc); |
| 6754 | continue; |
| 6755 | } |
| 6756 | |
| 6757 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6758 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6759 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6760 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 6761 | |
| 6762 | return 0; |
| 6763 | } |
| 6764 | |
| 6765 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6766 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6767 | |
| 6768 | /* tried to restart and config the device for as long as our |
| 6769 | * patience could withstand */ |
| 6770 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 6771 | return -EIO; |
| 6772 | } |
| 6773 | |
| 6774 | |
| 6775 | /***************************************************************************** |
| 6776 | * |
| 6777 | * Workqueue callbacks |
| 6778 | * |
| 6779 | *****************************************************************************/ |
| 6780 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6781 | static void iwl4965_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6782 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6783 | struct iwl4965_priv *priv = |
| 6784 | container_of(data, struct iwl4965_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6785 | |
| 6786 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6787 | return; |
| 6788 | |
| 6789 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6790 | iwl4965_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6791 | mutex_unlock(&priv->mutex); |
| 6792 | } |
| 6793 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6794 | static void iwl4965_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6795 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6796 | struct iwl4965_priv *priv = |
| 6797 | container_of(data, struct iwl4965_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6798 | |
| 6799 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6800 | return; |
| 6801 | |
| 6802 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6803 | iwl4965_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6804 | mutex_unlock(&priv->mutex); |
| 6805 | } |
| 6806 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6807 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6808 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6809 | struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6810 | |
| 6811 | wake_up_interruptible(&priv->wait_command_queue); |
| 6812 | |
| 6813 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6814 | return; |
| 6815 | |
| 6816 | mutex_lock(&priv->mutex); |
| 6817 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6818 | if (!iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6819 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 6820 | "HW and/or SW RF Kill no longer active, restarting " |
| 6821 | "device\n"); |
| 6822 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6823 | queue_work(priv->workqueue, &priv->restart); |
| 6824 | } else { |
| 6825 | |
| 6826 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 6827 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 6828 | "disabled by SW switch\n"); |
| 6829 | else |
| 6830 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 6831 | "Kill switch must be turned off for " |
| 6832 | "wireless networking to work.\n"); |
| 6833 | } |
| 6834 | mutex_unlock(&priv->mutex); |
| 6835 | } |
| 6836 | |
| 6837 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 6838 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6839 | static void iwl4965_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6840 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6841 | struct iwl4965_priv *priv = |
| 6842 | container_of(data, struct iwl4965_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6843 | |
| 6844 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6845 | return; |
| 6846 | |
| 6847 | mutex_lock(&priv->mutex); |
| 6848 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 6849 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6850 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 6851 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 6852 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6853 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6854 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6855 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6856 | } |
| 6857 | mutex_unlock(&priv->mutex); |
| 6858 | } |
| 6859 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6860 | static void iwl4965_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6861 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6862 | struct iwl4965_priv *priv = |
| 6863 | container_of(data, struct iwl4965_priv, request_scan); |
| 6864 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6865 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6866 | .len = sizeof(struct iwl4965_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6867 | .meta.flags = CMD_SIZE_HUGE, |
| 6868 | }; |
| 6869 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6870 | struct iwl4965_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6871 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 6872 | u16 cmd_len; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6873 | enum ieee80211_band band; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 6874 | u8 direct_mask; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6875 | |
| 6876 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6877 | |
| 6878 | mutex_lock(&priv->mutex); |
| 6879 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6880 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6881 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 6882 | goto done; |
| 6883 | } |
| 6884 | |
| 6885 | /* Make sure the scan wasn't cancelled before this queued work |
| 6886 | * was given the chance to run... */ |
| 6887 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 6888 | goto done; |
| 6889 | |
| 6890 | /* This should never be called or scheduled if there is currently |
| 6891 | * a scan active in the hardware. */ |
| 6892 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 6893 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 6894 | "Ignoring second request.\n"); |
| 6895 | rc = -EIO; |
| 6896 | goto done; |
| 6897 | } |
| 6898 | |
| 6899 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6900 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 6901 | goto done; |
| 6902 | } |
| 6903 | |
| 6904 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6905 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 6906 | goto done; |
| 6907 | } |
| 6908 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6909 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6910 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 6911 | goto done; |
| 6912 | } |
| 6913 | |
| 6914 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 6915 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 6916 | goto done; |
| 6917 | } |
| 6918 | |
| 6919 | if (!priv->scan_bands) { |
| 6920 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 6921 | goto done; |
| 6922 | } |
| 6923 | |
| 6924 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6925 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6926 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 6927 | if (!priv->scan) { |
| 6928 | rc = -ENOMEM; |
| 6929 | goto done; |
| 6930 | } |
| 6931 | } |
| 6932 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6933 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6934 | |
| 6935 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 6936 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 6937 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6938 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6939 | u16 interval = 0; |
| 6940 | u32 extra; |
| 6941 | u32 suspend_time = 100; |
| 6942 | u32 scan_suspend_time = 100; |
| 6943 | unsigned long flags; |
| 6944 | |
| 6945 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 6946 | |
| 6947 | spin_lock_irqsave(&priv->lock, flags); |
| 6948 | interval = priv->beacon_int; |
| 6949 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6950 | |
| 6951 | scan->suspend_time = 0; |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6952 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6953 | if (!interval) |
| 6954 | interval = suspend_time; |
| 6955 | |
| 6956 | extra = (suspend_time / interval) << 22; |
| 6957 | scan_suspend_time = (extra | |
| 6958 | ((suspend_time % interval) * 1024)); |
| 6959 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 6960 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 6961 | scan_suspend_time, interval); |
| 6962 | } |
| 6963 | |
| 6964 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 6965 | if (priv->one_direct_scan) { |
| 6966 | IWL_DEBUG_SCAN |
| 6967 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6968 | iwl4965_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6969 | priv->direct_ssid_len)); |
| 6970 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 6971 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 6972 | memcpy(scan->direct_scan[0].ssid, |
| 6973 | priv->direct_ssid, priv->direct_ssid_len); |
| 6974 | direct_mask = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6975 | } else if (!iwl4965_is_associated(priv) && priv->essid_len) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6976 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 6977 | scan->direct_scan[0].len = priv->essid_len; |
| 6978 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 6979 | direct_mask = 1; |
| 6980 | } else |
| 6981 | direct_mask = 0; |
| 6982 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6983 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
| 6984 | scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id; |
| 6985 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 6986 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6987 | |
| 6988 | switch (priv->scan_bands) { |
| 6989 | case 2: |
| 6990 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 6991 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6992 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6993 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 6994 | |
| 6995 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6996 | band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6997 | break; |
| 6998 | |
| 6999 | case 1: |
| 7000 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7001 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7002 | RATE_MCS_ANT_B_MSK); |
| 7003 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7004 | band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7005 | break; |
| 7006 | |
| 7007 | default: |
| 7008 | IWL_WARNING("Invalid scan band count\n"); |
| 7009 | goto done; |
| 7010 | } |
| 7011 | |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 7012 | /* We don't build a direct scan probe request; the uCode will do |
| 7013 | * that based on the direct_mask added to each channel entry */ |
| 7014 | cmd_len = iwl4965_fill_probe_req(priv, band, |
| 7015 | (struct ieee80211_mgmt *)scan->data, |
| 7016 | IWL_MAX_SCAN_SIZE - sizeof(*scan), 0); |
| 7017 | |
| 7018 | scan->tx_cmd.len = cpu_to_le16(cmd_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7019 | /* select Rx chains */ |
| 7020 | |
| 7021 | /* Force use of chains B and C (0x6) for scan Rx. |
| 7022 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 7023 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 7024 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 7025 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 7026 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 7027 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 7028 | |
| 7029 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 7030 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 7031 | |
| 7032 | if (direct_mask) |
| 7033 | IWL_DEBUG_SCAN |
| 7034 | ("Initiating direct scan for %s.\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7035 | iwl4965_escape_essid(priv->essid, priv->essid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7036 | else |
| 7037 | IWL_DEBUG_SCAN("Initiating indirect scan.\n"); |
| 7038 | |
| 7039 | scan->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7040 | iwl4965_get_channels_for_scan( |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7041 | priv, band, 1, /* active */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7042 | direct_mask, |
| 7043 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
| 7044 | |
| 7045 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7046 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7047 | cmd.data = scan; |
| 7048 | scan->len = cpu_to_le16(cmd.len); |
| 7049 | |
| 7050 | set_bit(STATUS_SCAN_HW, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7051 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7052 | if (rc) |
| 7053 | goto done; |
| 7054 | |
| 7055 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 7056 | IWL_SCAN_CHECK_WATCHDOG); |
| 7057 | |
| 7058 | mutex_unlock(&priv->mutex); |
| 7059 | return; |
| 7060 | |
| 7061 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 7062 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7063 | queue_work(priv->workqueue, &priv->scan_completed); |
| 7064 | mutex_unlock(&priv->mutex); |
| 7065 | } |
| 7066 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7067 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7068 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7069 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7070 | |
| 7071 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7072 | return; |
| 7073 | |
| 7074 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7075 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7076 | mutex_unlock(&priv->mutex); |
| 7077 | } |
| 7078 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7079 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7080 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7081 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7082 | |
| 7083 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7084 | return; |
| 7085 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7086 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7087 | queue_work(priv->workqueue, &priv->up); |
| 7088 | } |
| 7089 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7090 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7091 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7092 | struct iwl4965_priv *priv = |
| 7093 | container_of(data, struct iwl4965_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7094 | |
| 7095 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7096 | return; |
| 7097 | |
| 7098 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7099 | iwl4965_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7100 | mutex_unlock(&priv->mutex); |
| 7101 | } |
| 7102 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7103 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 7104 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7105 | static void iwl4965_bg_post_associate(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7106 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7107 | struct iwl4965_priv *priv = container_of(data, struct iwl4965_priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7108 | post_associate.work); |
| 7109 | |
| 7110 | int rc = 0; |
| 7111 | struct ieee80211_conf *conf = NULL; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7112 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7113 | |
| 7114 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 7115 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 7116 | return; |
| 7117 | } |
| 7118 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7119 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 7120 | priv->assoc_id, |
| 7121 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7122 | |
| 7123 | |
| 7124 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7125 | return; |
| 7126 | |
| 7127 | mutex_lock(&priv->mutex); |
| 7128 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7129 | if (!priv->vif || !priv->is_open) { |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7130 | mutex_unlock(&priv->mutex); |
| 7131 | return; |
| 7132 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7133 | iwl4965_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7134 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7135 | conf = ieee80211_get_hw_conf(priv->hw); |
| 7136 | |
| 7137 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7138 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7139 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7140 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 7141 | iwl4965_setup_rxon_timing(priv); |
| 7142 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7143 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 7144 | if (rc) |
| 7145 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 7146 | "Attempting to continue.\n"); |
| 7147 | |
| 7148 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 7149 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7150 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7151 | if (priv->current_ht_config.is_ht) |
| 7152 | iwl4965_set_rxon_ht(priv, &priv->current_ht_config); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7153 | #endif /* CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7154 | iwl4965_set_rxon_chain(priv); |
| 7155 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 7156 | |
| 7157 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 7158 | priv->assoc_id, priv->beacon_int); |
| 7159 | |
| 7160 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7161 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7162 | else |
| 7163 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7164 | |
| 7165 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 7166 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 7167 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 7168 | else |
| 7169 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 7170 | |
| 7171 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7172 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 7173 | |
| 7174 | } |
| 7175 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7176 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7177 | |
| 7178 | switch (priv->iw_mode) { |
| 7179 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7180 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7181 | break; |
| 7182 | |
| 7183 | case IEEE80211_IF_TYPE_IBSS: |
| 7184 | |
| 7185 | /* clear out the station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7186 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7187 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7188 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
| 7189 | iwl4965_rxon_add_station(priv, priv->bssid, 0); |
| 7190 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
| 7191 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7192 | |
| 7193 | break; |
| 7194 | |
| 7195 | default: |
| 7196 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 7197 | __FUNCTION__, priv->iw_mode); |
| 7198 | break; |
| 7199 | } |
| 7200 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7201 | iwl4965_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7202 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7203 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7204 | /* Enable Rx differential gain and sensitivity calibrations */ |
| 7205 | iwl4965_chain_noise_reset(priv); |
| 7206 | priv->start_calib = 1; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7207 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7208 | |
| 7209 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7210 | priv->assoc_station_added = 1; |
| 7211 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7212 | iwl4965_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 7213 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7214 | /* we have just associated, don't start scan too early */ |
| 7215 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7216 | mutex_unlock(&priv->mutex); |
| 7217 | } |
| 7218 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7219 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7220 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7221 | struct iwl4965_priv *priv = container_of(work, struct iwl4965_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7222 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7223 | if (!iwl4965_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7224 | return; |
| 7225 | |
| 7226 | mutex_lock(&priv->mutex); |
| 7227 | |
| 7228 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7229 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7230 | |
| 7231 | mutex_unlock(&priv->mutex); |
| 7232 | } |
| 7233 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7234 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 7235 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7236 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7237 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7238 | struct iwl4965_priv *priv = |
| 7239 | container_of(work, struct iwl4965_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7240 | |
| 7241 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 7242 | |
| 7243 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 7244 | return; |
| 7245 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7246 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
| 7247 | iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7248 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7249 | ieee80211_scan_completed(priv->hw); |
| 7250 | |
| 7251 | /* Since setting the TXPOWER may have been deferred while |
| 7252 | * performing the scan, fire one off */ |
| 7253 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7254 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7255 | mutex_unlock(&priv->mutex); |
| 7256 | } |
| 7257 | |
| 7258 | /***************************************************************************** |
| 7259 | * |
| 7260 | * mac80211 entry point functions |
| 7261 | * |
| 7262 | *****************************************************************************/ |
| 7263 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7264 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 7265 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7266 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7267 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7268 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7269 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7270 | |
| 7271 | IWL_DEBUG_MAC80211("enter\n"); |
| 7272 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7273 | if (pci_enable_device(priv->pci_dev)) { |
| 7274 | IWL_ERROR("Fail to pci_enable_device\n"); |
| 7275 | return -ENODEV; |
| 7276 | } |
| 7277 | pci_restore_state(priv->pci_dev); |
| 7278 | pci_enable_msi(priv->pci_dev); |
| 7279 | |
| 7280 | ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, |
| 7281 | DRV_NAME, priv); |
| 7282 | if (ret) { |
| 7283 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 7284 | goto out_disable_msi; |
| 7285 | } |
| 7286 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7287 | /* we should be verifying the device is ready to be opened */ |
| 7288 | mutex_lock(&priv->mutex); |
| 7289 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7290 | memset(&priv->staging_rxon, 0, sizeof(struct iwl4965_rxon_cmd)); |
| 7291 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 7292 | * ucode filename and max sizes are card-specific. */ |
| 7293 | |
| 7294 | if (!priv->ucode_code.len) { |
| 7295 | ret = iwl4965_read_ucode(priv); |
| 7296 | if (ret) { |
| 7297 | IWL_ERROR("Could not read microcode: %d\n", ret); |
| 7298 | mutex_unlock(&priv->mutex); |
| 7299 | goto out_release_irq; |
| 7300 | } |
| 7301 | } |
| 7302 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7303 | ret = __iwl4965_up(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7304 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7305 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7306 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7307 | if (ret) |
| 7308 | goto out_release_irq; |
| 7309 | |
| 7310 | IWL_DEBUG_INFO("Start UP work done.\n"); |
| 7311 | |
| 7312 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 7313 | return 0; |
| 7314 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7315 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 7316 | * mac80211 will not be run successfully. */ |
| 7317 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 7318 | test_bit(STATUS_READY, &priv->status), |
| 7319 | UCODE_READY_TIMEOUT); |
| 7320 | if (!ret) { |
| 7321 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 7322 | IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n", |
| 7323 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 7324 | ret = -ETIMEDOUT; |
| 7325 | goto out_release_irq; |
| 7326 | } |
| 7327 | } |
| 7328 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7329 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7330 | IWL_DEBUG_MAC80211("leave\n"); |
| 7331 | return 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7332 | |
| 7333 | out_release_irq: |
| 7334 | free_irq(priv->pci_dev->irq, priv); |
| 7335 | out_disable_msi: |
| 7336 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7337 | pci_disable_device(priv->pci_dev); |
| 7338 | priv->is_open = 0; |
| 7339 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7340 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7341 | } |
| 7342 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7343 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7344 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7345 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7346 | |
| 7347 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7348 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7349 | if (!priv->is_open) { |
| 7350 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 7351 | return; |
| 7352 | } |
| 7353 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7354 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7355 | |
| 7356 | if (iwl4965_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7357 | /* stop mac, cancel any scan request and clear |
| 7358 | * RXON_FILTER_ASSOC_MSK BIT |
| 7359 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7360 | mutex_lock(&priv->mutex); |
| 7361 | iwl4965_scan_cancel_timeout(priv, 100); |
| 7362 | cancel_delayed_work(&priv->post_associate); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7363 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7364 | } |
| 7365 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7366 | iwl4965_down(priv); |
| 7367 | |
| 7368 | flush_workqueue(priv->workqueue); |
| 7369 | free_irq(priv->pci_dev->irq, priv); |
| 7370 | pci_disable_msi(priv->pci_dev); |
| 7371 | pci_save_state(priv->pci_dev); |
| 7372 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7373 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7374 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7375 | } |
| 7376 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7377 | 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] | 7378 | struct ieee80211_tx_control *ctl) |
| 7379 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7380 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7381 | |
| 7382 | IWL_DEBUG_MAC80211("enter\n"); |
| 7383 | |
| 7384 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 7385 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 7386 | return -1; |
| 7387 | } |
| 7388 | |
| 7389 | IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7390 | ctl->tx_rate->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7391 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7392 | if (iwl4965_tx_skb(priv, skb, ctl)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7393 | dev_kfree_skb_any(skb); |
| 7394 | |
| 7395 | IWL_DEBUG_MAC80211("leave\n"); |
| 7396 | return 0; |
| 7397 | } |
| 7398 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7399 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7400 | struct ieee80211_if_init_conf *conf) |
| 7401 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7402 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7403 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7404 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7405 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7406 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7407 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7408 | if (priv->vif) { |
| 7409 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Reinette Chatre | 75849d2 | 2008-01-23 10:15:17 -0800 | [diff] [blame] | 7410 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7411 | } |
| 7412 | |
| 7413 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7414 | priv->vif = conf->vif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7415 | |
| 7416 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7417 | |
| 7418 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 7419 | |
| 7420 | if (conf->mac_addr) { |
| 7421 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 7422 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 7423 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7424 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7425 | if (iwl4965_is_ready(priv)) |
| 7426 | iwl4965_set_mode(priv, conf->type); |
| 7427 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7428 | mutex_unlock(&priv->mutex); |
| 7429 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7430 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7431 | return 0; |
| 7432 | } |
| 7433 | |
| 7434 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7435 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7436 | * |
| 7437 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 7438 | * be set inappropriately and the driver currently sets the hardware up to |
| 7439 | * use it whenever needed. |
| 7440 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7441 | 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] | 7442 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7443 | struct iwl4965_priv *priv = hw->priv; |
| 7444 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7445 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7446 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7447 | |
| 7448 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7449 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7450 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 7451 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
| 7452 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7453 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7454 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7455 | ret = -EIO; |
| 7456 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7457 | } |
| 7458 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7459 | if (unlikely(!iwl4965_param_disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7460 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7461 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 7462 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7463 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7464 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7465 | } |
| 7466 | |
| 7467 | spin_lock_irqsave(&priv->lock, flags); |
| 7468 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7469 | ch_info = iwl4965_get_channel_info(priv, conf->channel->band, |
| 7470 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7471 | if (!is_channel_valid(ch_info)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7472 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 7473 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7474 | ret = -EINVAL; |
| 7475 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7476 | } |
| 7477 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7478 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 7479 | /* if we are switching from ht to 2.4 clear flags |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7480 | * from any ht related info since 2.4 does not |
| 7481 | * support ht */ |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 7482 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7483 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7484 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 7485 | #endif |
| 7486 | ) |
| 7487 | priv->staging_rxon.flags = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7488 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7489 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7490 | iwl4965_set_rxon_channel(priv, conf->channel->band, |
| 7491 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7492 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7493 | iwl4965_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7494 | |
| 7495 | /* The list of supported rates and rate mask can be different |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7496 | * for each band; since the band may have changed, reset |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7497 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7498 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7499 | |
| 7500 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7501 | |
| 7502 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7503 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7504 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7505 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7506 | } |
| 7507 | #endif |
| 7508 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7509 | iwl4965_radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7510 | |
| 7511 | if (!conf->radio_enabled) { |
| 7512 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7513 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7514 | } |
| 7515 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7516 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7517 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7518 | ret = -EIO; |
| 7519 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7520 | } |
| 7521 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7522 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7523 | |
| 7524 | if (memcmp(&priv->active_rxon, |
| 7525 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7526 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7527 | else |
| 7528 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 7529 | |
| 7530 | IWL_DEBUG_MAC80211("leave\n"); |
| 7531 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7532 | out: |
| 7533 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7534 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7535 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7536 | } |
| 7537 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7538 | static void iwl4965_config_ap(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7539 | { |
| 7540 | int rc = 0; |
| 7541 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 7542 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7543 | return; |
| 7544 | |
| 7545 | /* The following should be done only at AP bring up */ |
| 7546 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 7547 | |
| 7548 | /* RXON - unassoc (to set timing command) */ |
| 7549 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7550 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7551 | |
| 7552 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7553 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 7554 | iwl4965_setup_rxon_timing(priv); |
| 7555 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7556 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 7557 | if (rc) |
| 7558 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 7559 | "Attempting to continue.\n"); |
| 7560 | |
| 7561 | iwl4965_set_rxon_chain(priv); |
| 7562 | |
| 7563 | /* FIXME: what should be the assoc_id for AP? */ |
| 7564 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 7565 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7566 | priv->staging_rxon.flags |= |
| 7567 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7568 | else |
| 7569 | priv->staging_rxon.flags &= |
| 7570 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7571 | |
| 7572 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 7573 | if (priv->assoc_capability & |
| 7574 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 7575 | priv->staging_rxon.flags |= |
| 7576 | RXON_FLG_SHORT_SLOT_MSK; |
| 7577 | else |
| 7578 | priv->staging_rxon.flags &= |
| 7579 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7580 | |
| 7581 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7582 | priv->staging_rxon.flags &= |
| 7583 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7584 | } |
| 7585 | /* restore RXON assoc */ |
| 7586 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7587 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7588 | iwl4965_activate_qos(priv, 1); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7589 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 7590 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7591 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7592 | |
| 7593 | /* FIXME - we need to add code here to detect a totally new |
| 7594 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 7595 | * clear sta table, add BCAST sta... */ |
| 7596 | } |
| 7597 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7598 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, |
| 7599 | struct ieee80211_vif *vif, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7600 | struct ieee80211_if_conf *conf) |
| 7601 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7602 | struct iwl4965_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7603 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7604 | unsigned long flags; |
| 7605 | int rc; |
| 7606 | |
| 7607 | if (conf == NULL) |
| 7608 | return -EIO; |
| 7609 | |
| 7610 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 7611 | (!conf->beacon || !conf->ssid_len)) { |
| 7612 | IWL_DEBUG_MAC80211 |
| 7613 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 7614 | return 0; |
| 7615 | } |
| 7616 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7617 | if (!iwl4965_is_alive(priv)) |
| 7618 | return -EAGAIN; |
| 7619 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7620 | mutex_lock(&priv->mutex); |
| 7621 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7622 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7623 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 7624 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7625 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7626 | /* |
| 7627 | * very dubious code was here; the probe filtering flag is never set: |
| 7628 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7629 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 7630 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7631 | */ |
| 7632 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7633 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 7634 | mutex_unlock(&priv->mutex); |
| 7635 | return 0; |
| 7636 | } |
| 7637 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7638 | if (priv->vif != vif) { |
| 7639 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7640 | mutex_unlock(&priv->mutex); |
| 7641 | return 0; |
| 7642 | } |
| 7643 | |
| 7644 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 7645 | if (!conf->bssid) { |
| 7646 | conf->bssid = priv->mac_addr; |
| 7647 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7648 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 7649 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7650 | } |
| 7651 | if (priv->ibss_beacon) |
| 7652 | dev_kfree_skb(priv->ibss_beacon); |
| 7653 | |
| 7654 | priv->ibss_beacon = conf->beacon; |
| 7655 | } |
| 7656 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7657 | if (iwl4965_is_rfkill(priv)) |
| 7658 | goto done; |
| 7659 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7660 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 7661 | !is_multicast_ether_addr(conf->bssid)) { |
| 7662 | /* If there is currently a HW scan going on in the background |
| 7663 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7664 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7665 | IWL_WARNING("Aborted scan still in progress " |
| 7666 | "after 100ms\n"); |
| 7667 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 7668 | mutex_unlock(&priv->mutex); |
| 7669 | return -EAGAIN; |
| 7670 | } |
| 7671 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 7672 | |
| 7673 | /* TODO: Audit driver for usage of these members and see |
| 7674 | * if mac80211 deprecates them (priv->bssid looks like it |
| 7675 | * shouldn't be there, but I haven't scanned the IBSS code |
| 7676 | * to verify) - jpk */ |
| 7677 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 7678 | |
| 7679 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7680 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7681 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7682 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7683 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7684 | iwl4965_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7685 | priv, priv->active_rxon.bssid_addr, 1); |
| 7686 | } |
| 7687 | |
| 7688 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7689 | iwl4965_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7690 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7691 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7692 | } |
| 7693 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7694 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7695 | spin_lock_irqsave(&priv->lock, flags); |
| 7696 | if (!conf->ssid_len) |
| 7697 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7698 | else |
| 7699 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 7700 | |
| 7701 | priv->essid_len = conf->ssid_len; |
| 7702 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7703 | |
| 7704 | IWL_DEBUG_MAC80211("leave\n"); |
| 7705 | mutex_unlock(&priv->mutex); |
| 7706 | |
| 7707 | return 0; |
| 7708 | } |
| 7709 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7710 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7711 | unsigned int changed_flags, |
| 7712 | unsigned int *total_flags, |
| 7713 | int mc_count, struct dev_addr_list *mc_list) |
| 7714 | { |
| 7715 | /* |
| 7716 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7717 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7718 | */ |
| 7719 | *total_flags = 0; |
| 7720 | } |
| 7721 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7722 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7723 | struct ieee80211_if_init_conf *conf) |
| 7724 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7725 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7726 | |
| 7727 | IWL_DEBUG_MAC80211("enter\n"); |
| 7728 | |
| 7729 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7730 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7731 | if (iwl4965_is_ready_rf(priv)) { |
| 7732 | iwl4965_scan_cancel_timeout(priv, 100); |
| 7733 | cancel_delayed_work(&priv->post_associate); |
| 7734 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 7735 | iwl4965_commit_rxon(priv); |
| 7736 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7737 | if (priv->vif == conf->vif) { |
| 7738 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7739 | memset(priv->bssid, 0, ETH_ALEN); |
| 7740 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7741 | priv->essid_len = 0; |
| 7742 | } |
| 7743 | mutex_unlock(&priv->mutex); |
| 7744 | |
| 7745 | IWL_DEBUG_MAC80211("leave\n"); |
| 7746 | |
| 7747 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7748 | |
| 7749 | static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, |
| 7750 | struct ieee80211_vif *vif, |
| 7751 | struct ieee80211_bss_conf *bss_conf, |
| 7752 | u32 changes) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7753 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7754 | struct iwl4965_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7755 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7756 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
| 7757 | if (bss_conf->use_short_preamble) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7758 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7759 | else |
| 7760 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7761 | } |
| 7762 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7763 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7764 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7765 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 7766 | else |
| 7767 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 7768 | } |
| 7769 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7770 | if (changes & BSS_CHANGED_ASSOC) { |
| 7771 | /* |
| 7772 | * TODO: |
| 7773 | * do stuff instead of sniffing assoc resp |
| 7774 | */ |
| 7775 | } |
| 7776 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7777 | if (iwl4965_is_associated(priv)) |
| 7778 | iwl4965_send_rxon_assoc(priv); |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7779 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7780 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7781 | 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] | 7782 | { |
| 7783 | int rc = 0; |
| 7784 | unsigned long flags; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7785 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7786 | |
| 7787 | IWL_DEBUG_MAC80211("enter\n"); |
| 7788 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7789 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7790 | spin_lock_irqsave(&priv->lock, flags); |
| 7791 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7792 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7793 | rc = -EIO; |
| 7794 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 7795 | goto out_unlock; |
| 7796 | } |
| 7797 | |
| 7798 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 7799 | rc = -EIO; |
| 7800 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 7801 | goto out_unlock; |
| 7802 | } |
| 7803 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7804 | /* we don't schedule scan within next_scan_jiffies period */ |
| 7805 | if (priv->next_scan_jiffies && |
| 7806 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 7807 | rc = -EAGAIN; |
| 7808 | goto out_unlock; |
| 7809 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7810 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7811 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 7812 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7813 | rc = -EAGAIN; |
| 7814 | goto out_unlock; |
| 7815 | } |
| 7816 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7817 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7818 | iwl4965_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7819 | |
| 7820 | priv->one_direct_scan = 1; |
| 7821 | priv->direct_ssid_len = (u8) |
| 7822 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 7823 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7824 | } else |
| 7825 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7826 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7827 | rc = iwl4965_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7828 | |
| 7829 | IWL_DEBUG_MAC80211("leave\n"); |
| 7830 | |
| 7831 | out_unlock: |
| 7832 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7833 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7834 | |
| 7835 | return rc; |
| 7836 | } |
| 7837 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7838 | 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] | 7839 | const u8 *local_addr, const u8 *addr, |
| 7840 | struct ieee80211_key_conf *key) |
| 7841 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7842 | struct iwl4965_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7843 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7844 | int rc = 0; |
| 7845 | u8 sta_id; |
| 7846 | |
| 7847 | IWL_DEBUG_MAC80211("enter\n"); |
| 7848 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7849 | if (!iwl4965_param_hwcrypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7850 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 7851 | return -EOPNOTSUPP; |
| 7852 | } |
| 7853 | |
| 7854 | if (is_zero_ether_addr(addr)) |
| 7855 | /* only support pairwise keys */ |
| 7856 | return -EOPNOTSUPP; |
| 7857 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7858 | sta_id = iwl4965_hw_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7859 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7860 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 7861 | print_mac(mac, addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7862 | return -EINVAL; |
| 7863 | } |
| 7864 | |
| 7865 | mutex_lock(&priv->mutex); |
| 7866 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7867 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7868 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7869 | switch (cmd) { |
| 7870 | case SET_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7871 | rc = iwl4965_update_sta_key_info(priv, key, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7872 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7873 | iwl4965_set_rxon_hwcrypto(priv, 1); |
| 7874 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7875 | key->hw_key_idx = sta_id; |
| 7876 | IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); |
| 7877 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 7878 | } |
| 7879 | break; |
| 7880 | case DISABLE_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7881 | rc = iwl4965_clear_sta_key_info(priv, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7882 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7883 | iwl4965_set_rxon_hwcrypto(priv, 0); |
| 7884 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7885 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
| 7886 | } |
| 7887 | break; |
| 7888 | default: |
| 7889 | rc = -EINVAL; |
| 7890 | } |
| 7891 | |
| 7892 | IWL_DEBUG_MAC80211("leave\n"); |
| 7893 | mutex_unlock(&priv->mutex); |
| 7894 | |
| 7895 | return rc; |
| 7896 | } |
| 7897 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7898 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7899 | const struct ieee80211_tx_queue_params *params) |
| 7900 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7901 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7902 | unsigned long flags; |
| 7903 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7904 | |
| 7905 | IWL_DEBUG_MAC80211("enter\n"); |
| 7906 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7907 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7908 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7909 | return -EIO; |
| 7910 | } |
| 7911 | |
| 7912 | if (queue >= AC_NUM) { |
| 7913 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 7914 | return 0; |
| 7915 | } |
| 7916 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7917 | if (!priv->qos_data.qos_enable) { |
| 7918 | priv->qos_data.qos_active = 0; |
| 7919 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 7920 | return 0; |
| 7921 | } |
| 7922 | q = AC_NUM - 1 - queue; |
| 7923 | |
| 7924 | spin_lock_irqsave(&priv->lock, flags); |
| 7925 | |
| 7926 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 7927 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 7928 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 7929 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 7930 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7931 | |
| 7932 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 7933 | priv->qos_data.qos_active = 1; |
| 7934 | |
| 7935 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7936 | |
| 7937 | mutex_lock(&priv->mutex); |
| 7938 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7939 | iwl4965_activate_qos(priv, 1); |
| 7940 | else if (priv->assoc_id && iwl4965_is_associated(priv)) |
| 7941 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7942 | |
| 7943 | mutex_unlock(&priv->mutex); |
| 7944 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7945 | IWL_DEBUG_MAC80211("leave\n"); |
| 7946 | return 0; |
| 7947 | } |
| 7948 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7949 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7950 | struct ieee80211_tx_queue_stats *stats) |
| 7951 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7952 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7953 | int i, avail; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7954 | struct iwl4965_tx_queue *txq; |
| 7955 | struct iwl4965_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7956 | unsigned long flags; |
| 7957 | |
| 7958 | IWL_DEBUG_MAC80211("enter\n"); |
| 7959 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7960 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7961 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7962 | return -EIO; |
| 7963 | } |
| 7964 | |
| 7965 | spin_lock_irqsave(&priv->lock, flags); |
| 7966 | |
| 7967 | for (i = 0; i < AC_NUM; i++) { |
| 7968 | txq = &priv->txq[i]; |
| 7969 | q = &txq->q; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7970 | avail = iwl4965_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7971 | |
| 7972 | stats->data[i].len = q->n_window - avail; |
| 7973 | stats->data[i].limit = q->n_window - q->high_mark; |
| 7974 | stats->data[i].count = q->n_window; |
| 7975 | |
| 7976 | } |
| 7977 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7978 | |
| 7979 | IWL_DEBUG_MAC80211("leave\n"); |
| 7980 | |
| 7981 | return 0; |
| 7982 | } |
| 7983 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7984 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7985 | struct ieee80211_low_level_stats *stats) |
| 7986 | { |
| 7987 | IWL_DEBUG_MAC80211("enter\n"); |
| 7988 | IWL_DEBUG_MAC80211("leave\n"); |
| 7989 | |
| 7990 | return 0; |
| 7991 | } |
| 7992 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7993 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7994 | { |
| 7995 | IWL_DEBUG_MAC80211("enter\n"); |
| 7996 | IWL_DEBUG_MAC80211("leave\n"); |
| 7997 | |
| 7998 | return 0; |
| 7999 | } |
| 8000 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8001 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8002 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8003 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8004 | unsigned long flags; |
| 8005 | |
| 8006 | mutex_lock(&priv->mutex); |
| 8007 | IWL_DEBUG_MAC80211("enter\n"); |
| 8008 | |
| 8009 | priv->lq_mngr.lq_ready = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8010 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8011 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8012 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8013 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8014 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8015 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8016 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8017 | |
| 8018 | cancel_delayed_work(&priv->post_associate); |
| 8019 | |
| 8020 | spin_lock_irqsave(&priv->lock, flags); |
| 8021 | priv->assoc_id = 0; |
| 8022 | priv->assoc_capability = 0; |
| 8023 | priv->call_post_assoc_from_beacon = 0; |
| 8024 | priv->assoc_station_added = 0; |
| 8025 | |
| 8026 | /* new association get rid of ibss beacon skb */ |
| 8027 | if (priv->ibss_beacon) |
| 8028 | dev_kfree_skb(priv->ibss_beacon); |
| 8029 | |
| 8030 | priv->ibss_beacon = NULL; |
| 8031 | |
| 8032 | priv->beacon_int = priv->hw->conf.beacon_int; |
| 8033 | priv->timestamp1 = 0; |
| 8034 | priv->timestamp0 = 0; |
| 8035 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 8036 | priv->beacon_int = 0; |
| 8037 | |
| 8038 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8039 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 8040 | if (!iwl4965_is_ready_rf(priv)) { |
| 8041 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 8042 | mutex_unlock(&priv->mutex); |
| 8043 | return; |
| 8044 | } |
| 8045 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 8046 | /* we are restarting association process |
| 8047 | * clear RXON_FILTER_ASSOC_MSK bit |
| 8048 | */ |
| 8049 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8050 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 8051 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8052 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 8053 | } |
| 8054 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8055 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 8056 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 8057 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8058 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 8059 | mutex_unlock(&priv->mutex); |
| 8060 | return; |
| 8061 | } |
| 8062 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8063 | priv->only_active_channel = 0; |
| 8064 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8065 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8066 | |
| 8067 | mutex_unlock(&priv->mutex); |
| 8068 | |
| 8069 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8070 | } |
| 8071 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8072 | 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] | 8073 | struct ieee80211_tx_control *control) |
| 8074 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8075 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8076 | unsigned long flags; |
| 8077 | |
| 8078 | mutex_lock(&priv->mutex); |
| 8079 | IWL_DEBUG_MAC80211("enter\n"); |
| 8080 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8081 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8082 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 8083 | mutex_unlock(&priv->mutex); |
| 8084 | return -EIO; |
| 8085 | } |
| 8086 | |
| 8087 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 8088 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 8089 | mutex_unlock(&priv->mutex); |
| 8090 | return -EIO; |
| 8091 | } |
| 8092 | |
| 8093 | spin_lock_irqsave(&priv->lock, flags); |
| 8094 | |
| 8095 | if (priv->ibss_beacon) |
| 8096 | dev_kfree_skb(priv->ibss_beacon); |
| 8097 | |
| 8098 | priv->ibss_beacon = skb; |
| 8099 | |
| 8100 | priv->assoc_id = 0; |
| 8101 | |
| 8102 | IWL_DEBUG_MAC80211("leave\n"); |
| 8103 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8104 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8105 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8106 | |
| 8107 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 8108 | |
| 8109 | mutex_unlock(&priv->mutex); |
| 8110 | |
| 8111 | return 0; |
| 8112 | } |
| 8113 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8114 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8115 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8116 | static void iwl4965_ht_info_fill(struct ieee80211_conf *conf, |
| 8117 | struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8118 | { |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8119 | struct iwl_ht_info *iwl_conf = &priv->current_ht_config; |
| 8120 | struct ieee80211_ht_info *ht_conf = &conf->ht_conf; |
| 8121 | struct ieee80211_ht_bss_info *ht_bss_conf = &conf->ht_bss_conf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8122 | |
| 8123 | IWL_DEBUG_MAC80211("enter: \n"); |
| 8124 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8125 | if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) { |
| 8126 | iwl_conf->is_ht = 0; |
| 8127 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8128 | } |
| 8129 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8130 | iwl_conf->is_ht = 1; |
| 8131 | 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] | 8132 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8133 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) |
| 8134 | iwl_conf->sgf |= 0x1; |
| 8135 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) |
| 8136 | iwl_conf->sgf |= 0x2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8137 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8138 | iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); |
| 8139 | iwl_conf->max_amsdu_size = |
| 8140 | !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); |
| 8141 | iwl_conf->supported_chan_width = |
| 8142 | !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); |
| 8143 | iwl_conf->tx_mimo_ps_mode = |
| 8144 | (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 8145 | memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8146 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8147 | iwl_conf->control_channel = ht_bss_conf->primary_channel; |
| 8148 | iwl_conf->extension_chan_offset = |
| 8149 | ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; |
| 8150 | iwl_conf->tx_chan_width = |
| 8151 | !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); |
| 8152 | iwl_conf->ht_protection = |
| 8153 | ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; |
| 8154 | iwl_conf->non_GF_STA_present = |
| 8155 | !!(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] | 8156 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8157 | IWL_DEBUG_MAC80211("control channel %d\n", |
| 8158 | iwl_conf->control_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8159 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8160 | } |
| 8161 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8162 | static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw, |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8163 | struct ieee80211_conf *conf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8164 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8165 | struct iwl4965_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8166 | |
| 8167 | IWL_DEBUG_MAC80211("enter: \n"); |
| 8168 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8169 | iwl4965_ht_info_fill(conf, priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8170 | iwl4965_set_rxon_chain(priv); |
| 8171 | |
| 8172 | if (priv && priv->assoc_id && |
| 8173 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
| 8174 | unsigned long flags; |
| 8175 | |
| 8176 | spin_lock_irqsave(&priv->lock, flags); |
| 8177 | if (priv->beacon_int) |
| 8178 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 8179 | else |
| 8180 | priv->call_post_assoc_from_beacon = 1; |
| 8181 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8182 | } |
| 8183 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 8184 | IWL_DEBUG_MAC80211("leave:\n"); |
| 8185 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8186 | } |
| 8187 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8188 | #endif /*CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8189 | |
| 8190 | /***************************************************************************** |
| 8191 | * |
| 8192 | * sysfs attributes |
| 8193 | * |
| 8194 | *****************************************************************************/ |
| 8195 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8196 | #ifdef CONFIG_IWL4965_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8197 | |
| 8198 | /* |
| 8199 | * The following adds a new attribute to the sysfs representation |
| 8200 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 8201 | * used for controlling the debug level. |
| 8202 | * |
| 8203 | * See the level definitions in iwl for details. |
| 8204 | */ |
| 8205 | |
| 8206 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 8207 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8208 | return sprintf(buf, "0x%08X\n", iwl4965_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8209 | } |
| 8210 | static ssize_t store_debug_level(struct device_driver *d, |
| 8211 | const char *buf, size_t count) |
| 8212 | { |
| 8213 | char *p = (char *)buf; |
| 8214 | u32 val; |
| 8215 | |
| 8216 | val = simple_strtoul(p, &p, 0); |
| 8217 | if (p == buf) |
| 8218 | printk(KERN_INFO DRV_NAME |
| 8219 | ": %s is not in hex or decimal form.\n", buf); |
| 8220 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8221 | iwl4965_debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8222 | |
| 8223 | return strnlen(buf, count); |
| 8224 | } |
| 8225 | |
| 8226 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 8227 | show_debug_level, store_debug_level); |
| 8228 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8229 | #endif /* CONFIG_IWL4965_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8230 | |
| 8231 | static ssize_t show_rf_kill(struct device *d, |
| 8232 | struct device_attribute *attr, char *buf) |
| 8233 | { |
| 8234 | /* |
| 8235 | * 0 - RF kill not enabled |
| 8236 | * 1 - SW based RF kill active (sysfs) |
| 8237 | * 2 - HW based RF kill active |
| 8238 | * 3 - Both HW and SW based RF kill active |
| 8239 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8240 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8241 | int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) | |
| 8242 | (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0); |
| 8243 | |
| 8244 | return sprintf(buf, "%i\n", val); |
| 8245 | } |
| 8246 | |
| 8247 | static ssize_t store_rf_kill(struct device *d, |
| 8248 | struct device_attribute *attr, |
| 8249 | const char *buf, size_t count) |
| 8250 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8251 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8252 | |
| 8253 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8254 | iwl4965_radio_kill_sw(priv, buf[0] == '1'); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8255 | mutex_unlock(&priv->mutex); |
| 8256 | |
| 8257 | return count; |
| 8258 | } |
| 8259 | |
| 8260 | static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); |
| 8261 | |
| 8262 | static ssize_t show_temperature(struct device *d, |
| 8263 | struct device_attribute *attr, char *buf) |
| 8264 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8265 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8266 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8267 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8268 | return -EAGAIN; |
| 8269 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8270 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8271 | } |
| 8272 | |
| 8273 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 8274 | |
| 8275 | static ssize_t show_rs_window(struct device *d, |
| 8276 | struct device_attribute *attr, |
| 8277 | char *buf) |
| 8278 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8279 | struct iwl4965_priv *priv = d->driver_data; |
| 8280 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8281 | } |
| 8282 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 8283 | |
| 8284 | static ssize_t show_tx_power(struct device *d, |
| 8285 | struct device_attribute *attr, char *buf) |
| 8286 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8287 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8288 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 8289 | } |
| 8290 | |
| 8291 | static ssize_t store_tx_power(struct device *d, |
| 8292 | struct device_attribute *attr, |
| 8293 | const char *buf, size_t count) |
| 8294 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8295 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8296 | char *p = (char *)buf; |
| 8297 | u32 val; |
| 8298 | |
| 8299 | val = simple_strtoul(p, &p, 10); |
| 8300 | if (p == buf) |
| 8301 | printk(KERN_INFO DRV_NAME |
| 8302 | ": %s is not in decimal form.\n", buf); |
| 8303 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8304 | iwl4965_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8305 | |
| 8306 | return count; |
| 8307 | } |
| 8308 | |
| 8309 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 8310 | |
| 8311 | static ssize_t show_flags(struct device *d, |
| 8312 | struct device_attribute *attr, char *buf) |
| 8313 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8314 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8315 | |
| 8316 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 8317 | } |
| 8318 | |
| 8319 | static ssize_t store_flags(struct device *d, |
| 8320 | struct device_attribute *attr, |
| 8321 | const char *buf, size_t count) |
| 8322 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8323 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8324 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 8325 | |
| 8326 | mutex_lock(&priv->mutex); |
| 8327 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 8328 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8329 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8330 | IWL_WARNING("Could not cancel scan.\n"); |
| 8331 | else { |
| 8332 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 8333 | flags); |
| 8334 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8335 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8336 | } |
| 8337 | } |
| 8338 | mutex_unlock(&priv->mutex); |
| 8339 | |
| 8340 | return count; |
| 8341 | } |
| 8342 | |
| 8343 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 8344 | |
| 8345 | static ssize_t show_filter_flags(struct device *d, |
| 8346 | struct device_attribute *attr, char *buf) |
| 8347 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8348 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8349 | |
| 8350 | return sprintf(buf, "0x%04X\n", |
| 8351 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 8352 | } |
| 8353 | |
| 8354 | static ssize_t store_filter_flags(struct device *d, |
| 8355 | struct device_attribute *attr, |
| 8356 | const char *buf, size_t count) |
| 8357 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8358 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8359 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 8360 | |
| 8361 | mutex_lock(&priv->mutex); |
| 8362 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 8363 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8364 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8365 | IWL_WARNING("Could not cancel scan.\n"); |
| 8366 | else { |
| 8367 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 8368 | "0x%04X\n", filter_flags); |
| 8369 | priv->staging_rxon.filter_flags = |
| 8370 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8371 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8372 | } |
| 8373 | } |
| 8374 | mutex_unlock(&priv->mutex); |
| 8375 | |
| 8376 | return count; |
| 8377 | } |
| 8378 | |
| 8379 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 8380 | store_filter_flags); |
| 8381 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8382 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8383 | |
| 8384 | static ssize_t show_measurement(struct device *d, |
| 8385 | struct device_attribute *attr, char *buf) |
| 8386 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8387 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
| 8388 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8389 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 8390 | u8 *data = (u8 *) & measure_report; |
| 8391 | unsigned long flags; |
| 8392 | |
| 8393 | spin_lock_irqsave(&priv->lock, flags); |
| 8394 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 8395 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8396 | return 0; |
| 8397 | } |
| 8398 | memcpy(&measure_report, &priv->measure_report, size); |
| 8399 | priv->measurement_status = 0; |
| 8400 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8401 | |
| 8402 | while (size && (PAGE_SIZE - len)) { |
| 8403 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8404 | PAGE_SIZE - len, 1); |
| 8405 | len = strlen(buf); |
| 8406 | if (PAGE_SIZE - len) |
| 8407 | buf[len++] = '\n'; |
| 8408 | |
| 8409 | ofs += 16; |
| 8410 | size -= min(size, 16U); |
| 8411 | } |
| 8412 | |
| 8413 | return len; |
| 8414 | } |
| 8415 | |
| 8416 | static ssize_t store_measurement(struct device *d, |
| 8417 | struct device_attribute *attr, |
| 8418 | const char *buf, size_t count) |
| 8419 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8420 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8421 | struct ieee80211_measurement_params params = { |
| 8422 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 8423 | .start_time = cpu_to_le64(priv->last_tsf), |
| 8424 | .duration = cpu_to_le16(1), |
| 8425 | }; |
| 8426 | u8 type = IWL_MEASURE_BASIC; |
| 8427 | u8 buffer[32]; |
| 8428 | u8 channel; |
| 8429 | |
| 8430 | if (count) { |
| 8431 | char *p = buffer; |
| 8432 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 8433 | channel = simple_strtoul(p, NULL, 0); |
| 8434 | if (channel) |
| 8435 | params.channel = channel; |
| 8436 | |
| 8437 | p = buffer; |
| 8438 | while (*p && *p != ' ') |
| 8439 | p++; |
| 8440 | if (*p) |
| 8441 | type = simple_strtoul(p + 1, NULL, 0); |
| 8442 | } |
| 8443 | |
| 8444 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 8445 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8446 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8447 | |
| 8448 | return count; |
| 8449 | } |
| 8450 | |
| 8451 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 8452 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8453 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8454 | |
| 8455 | static ssize_t store_retry_rate(struct device *d, |
| 8456 | struct device_attribute *attr, |
| 8457 | const char *buf, size_t count) |
| 8458 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8459 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8460 | |
| 8461 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 8462 | if (priv->retry_rate <= 0) |
| 8463 | priv->retry_rate = 1; |
| 8464 | |
| 8465 | return count; |
| 8466 | } |
| 8467 | |
| 8468 | static ssize_t show_retry_rate(struct device *d, |
| 8469 | struct device_attribute *attr, char *buf) |
| 8470 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8471 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8472 | return sprintf(buf, "%d", priv->retry_rate); |
| 8473 | } |
| 8474 | |
| 8475 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 8476 | store_retry_rate); |
| 8477 | |
| 8478 | static ssize_t store_power_level(struct device *d, |
| 8479 | struct device_attribute *attr, |
| 8480 | const char *buf, size_t count) |
| 8481 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8482 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8483 | int rc; |
| 8484 | int mode; |
| 8485 | |
| 8486 | mode = simple_strtoul(buf, NULL, 0); |
| 8487 | mutex_lock(&priv->mutex); |
| 8488 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8489 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8490 | rc = -EAGAIN; |
| 8491 | goto out; |
| 8492 | } |
| 8493 | |
| 8494 | if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC)) |
| 8495 | mode = IWL_POWER_AC; |
| 8496 | else |
| 8497 | mode |= IWL_POWER_ENABLED; |
| 8498 | |
| 8499 | if (mode != priv->power_mode) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8500 | rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8501 | if (rc) { |
| 8502 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 8503 | goto out; |
| 8504 | } |
| 8505 | priv->power_mode = mode; |
| 8506 | } |
| 8507 | |
| 8508 | rc = count; |
| 8509 | |
| 8510 | out: |
| 8511 | mutex_unlock(&priv->mutex); |
| 8512 | return rc; |
| 8513 | } |
| 8514 | |
| 8515 | #define MAX_WX_STRING 80 |
| 8516 | |
| 8517 | /* Values are in microsecond */ |
| 8518 | static const s32 timeout_duration[] = { |
| 8519 | 350000, |
| 8520 | 250000, |
| 8521 | 75000, |
| 8522 | 37000, |
| 8523 | 25000, |
| 8524 | }; |
| 8525 | static const s32 period_duration[] = { |
| 8526 | 400000, |
| 8527 | 700000, |
| 8528 | 1000000, |
| 8529 | 1000000, |
| 8530 | 1000000 |
| 8531 | }; |
| 8532 | |
| 8533 | static ssize_t show_power_level(struct device *d, |
| 8534 | struct device_attribute *attr, char *buf) |
| 8535 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8536 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8537 | int level = IWL_POWER_LEVEL(priv->power_mode); |
| 8538 | char *p = buf; |
| 8539 | |
| 8540 | p += sprintf(p, "%d ", level); |
| 8541 | switch (level) { |
| 8542 | case IWL_POWER_MODE_CAM: |
| 8543 | case IWL_POWER_AC: |
| 8544 | p += sprintf(p, "(AC)"); |
| 8545 | break; |
| 8546 | case IWL_POWER_BATTERY: |
| 8547 | p += sprintf(p, "(BATTERY)"); |
| 8548 | break; |
| 8549 | default: |
| 8550 | p += sprintf(p, |
| 8551 | "(Timeout %dms, Period %dms)", |
| 8552 | timeout_duration[level - 1] / 1000, |
| 8553 | period_duration[level - 1] / 1000); |
| 8554 | } |
| 8555 | |
| 8556 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 8557 | p += sprintf(p, " OFF\n"); |
| 8558 | else |
| 8559 | p += sprintf(p, " \n"); |
| 8560 | |
| 8561 | return (p - buf + 1); |
| 8562 | |
| 8563 | } |
| 8564 | |
| 8565 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 8566 | store_power_level); |
| 8567 | |
| 8568 | static ssize_t show_channels(struct device *d, |
| 8569 | struct device_attribute *attr, char *buf) |
| 8570 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 8571 | /* all this shit doesn't belong into sysfs anyway */ |
| 8572 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8573 | } |
| 8574 | |
| 8575 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 8576 | |
| 8577 | static ssize_t show_statistics(struct device *d, |
| 8578 | struct device_attribute *attr, char *buf) |
| 8579 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8580 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
| 8581 | u32 size = sizeof(struct iwl4965_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8582 | u32 len = 0, ofs = 0; |
| 8583 | u8 *data = (u8 *) & priv->statistics; |
| 8584 | int rc = 0; |
| 8585 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8586 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8587 | return -EAGAIN; |
| 8588 | |
| 8589 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8590 | rc = iwl4965_send_statistics_request(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8591 | mutex_unlock(&priv->mutex); |
| 8592 | |
| 8593 | if (rc) { |
| 8594 | len = sprintf(buf, |
| 8595 | "Error sending statistics request: 0x%08X\n", rc); |
| 8596 | return len; |
| 8597 | } |
| 8598 | |
| 8599 | while (size && (PAGE_SIZE - len)) { |
| 8600 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8601 | PAGE_SIZE - len, 1); |
| 8602 | len = strlen(buf); |
| 8603 | if (PAGE_SIZE - len) |
| 8604 | buf[len++] = '\n'; |
| 8605 | |
| 8606 | ofs += 16; |
| 8607 | size -= min(size, 16U); |
| 8608 | } |
| 8609 | |
| 8610 | return len; |
| 8611 | } |
| 8612 | |
| 8613 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 8614 | |
| 8615 | static ssize_t show_antenna(struct device *d, |
| 8616 | struct device_attribute *attr, char *buf) |
| 8617 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8618 | struct iwl4965_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8619 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8620 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8621 | return -EAGAIN; |
| 8622 | |
| 8623 | return sprintf(buf, "%d\n", priv->antenna); |
| 8624 | } |
| 8625 | |
| 8626 | static ssize_t store_antenna(struct device *d, |
| 8627 | struct device_attribute *attr, |
| 8628 | const char *buf, size_t count) |
| 8629 | { |
| 8630 | int ant; |
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 | |
| 8633 | if (count == 0) |
| 8634 | return 0; |
| 8635 | |
| 8636 | if (sscanf(buf, "%1i", &ant) != 1) { |
| 8637 | IWL_DEBUG_INFO("not in hex or decimal form.\n"); |
| 8638 | return count; |
| 8639 | } |
| 8640 | |
| 8641 | if ((ant >= 0) && (ant <= 2)) { |
| 8642 | IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8643 | priv->antenna = (enum iwl4965_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8644 | } else |
| 8645 | IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); |
| 8646 | |
| 8647 | |
| 8648 | return count; |
| 8649 | } |
| 8650 | |
| 8651 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 8652 | |
| 8653 | static ssize_t show_status(struct device *d, |
| 8654 | struct device_attribute *attr, char *buf) |
| 8655 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8656 | struct iwl4965_priv *priv = (struct iwl4965_priv *)d->driver_data; |
| 8657 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8658 | return -EAGAIN; |
| 8659 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 8660 | } |
| 8661 | |
| 8662 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 8663 | |
| 8664 | static ssize_t dump_error_log(struct device *d, |
| 8665 | struct device_attribute *attr, |
| 8666 | const char *buf, size_t count) |
| 8667 | { |
| 8668 | char *p = (char *)buf; |
| 8669 | |
| 8670 | if (p[0] == '1') |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8671 | iwl4965_dump_nic_error_log((struct iwl4965_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8672 | |
| 8673 | return strnlen(buf, count); |
| 8674 | } |
| 8675 | |
| 8676 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 8677 | |
| 8678 | static ssize_t dump_event_log(struct device *d, |
| 8679 | struct device_attribute *attr, |
| 8680 | const char *buf, size_t count) |
| 8681 | { |
| 8682 | char *p = (char *)buf; |
| 8683 | |
| 8684 | if (p[0] == '1') |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8685 | iwl4965_dump_nic_event_log((struct iwl4965_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8686 | |
| 8687 | return strnlen(buf, count); |
| 8688 | } |
| 8689 | |
| 8690 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 8691 | |
| 8692 | /***************************************************************************** |
| 8693 | * |
| 8694 | * driver setup and teardown |
| 8695 | * |
| 8696 | *****************************************************************************/ |
| 8697 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8698 | static void iwl4965_setup_deferred_work(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8699 | { |
| 8700 | priv->workqueue = create_workqueue(DRV_NAME); |
| 8701 | |
| 8702 | init_waitqueue_head(&priv->wait_command_queue); |
| 8703 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8704 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 8705 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 8706 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
| 8707 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); |
| 8708 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); |
| 8709 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); |
| 8710 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 8711 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
| 8712 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
| 8713 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start); |
| 8714 | INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start); |
| 8715 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8716 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8717 | iwl4965_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8718 | |
| 8719 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8720 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8721 | } |
| 8722 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8723 | static void iwl4965_cancel_deferred_work(struct iwl4965_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8724 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8725 | iwl4965_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8726 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 8727 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8728 | cancel_delayed_work(&priv->scan_check); |
| 8729 | cancel_delayed_work(&priv->alive_start); |
| 8730 | cancel_delayed_work(&priv->post_associate); |
| 8731 | cancel_work_sync(&priv->beacon_update); |
| 8732 | } |
| 8733 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8734 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8735 | &dev_attr_antenna.attr, |
| 8736 | &dev_attr_channels.attr, |
| 8737 | &dev_attr_dump_errors.attr, |
| 8738 | &dev_attr_dump_events.attr, |
| 8739 | &dev_attr_flags.attr, |
| 8740 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8741 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8742 | &dev_attr_measurement.attr, |
| 8743 | #endif |
| 8744 | &dev_attr_power_level.attr, |
| 8745 | &dev_attr_retry_rate.attr, |
| 8746 | &dev_attr_rf_kill.attr, |
| 8747 | &dev_attr_rs_window.attr, |
| 8748 | &dev_attr_statistics.attr, |
| 8749 | &dev_attr_status.attr, |
| 8750 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8751 | &dev_attr_tx_power.attr, |
| 8752 | |
| 8753 | NULL |
| 8754 | }; |
| 8755 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8756 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8757 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8758 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8759 | }; |
| 8760 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8761 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 8762 | .tx = iwl4965_mac_tx, |
| 8763 | .start = iwl4965_mac_start, |
| 8764 | .stop = iwl4965_mac_stop, |
| 8765 | .add_interface = iwl4965_mac_add_interface, |
| 8766 | .remove_interface = iwl4965_mac_remove_interface, |
| 8767 | .config = iwl4965_mac_config, |
| 8768 | .config_interface = iwl4965_mac_config_interface, |
| 8769 | .configure_filter = iwl4965_configure_filter, |
| 8770 | .set_key = iwl4965_mac_set_key, |
| 8771 | .get_stats = iwl4965_mac_get_stats, |
| 8772 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 8773 | .conf_tx = iwl4965_mac_conf_tx, |
| 8774 | .get_tsf = iwl4965_mac_get_tsf, |
| 8775 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 8776 | .beacon_update = iwl4965_mac_beacon_update, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 8777 | .bss_info_changed = iwl4965_bss_info_changed, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8778 | #ifdef CONFIG_IWL4965_HT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8779 | .conf_ht = iwl4965_mac_conf_ht, |
Ron Rindjunsky | 9ab4617 | 2007-12-25 17:00:38 +0200 | [diff] [blame] | 8780 | .ampdu_action = iwl4965_mac_ampdu_action, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8781 | #endif /* CONFIG_IWL4965_HT */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8782 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8783 | }; |
| 8784 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8785 | 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] | 8786 | { |
| 8787 | int err = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8788 | struct iwl4965_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8789 | struct ieee80211_hw *hw; |
| 8790 | int i; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8791 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8792 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8793 | /* Disabling hardware scan means that mac80211 will perform scans |
| 8794 | * "the hard way", rather than using device's scan. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8795 | if (iwl4965_param_disable_hw_scan) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8796 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8797 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8798 | } |
| 8799 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8800 | if ((iwl4965_param_queues_num > IWL_MAX_NUM_QUEUES) || |
| 8801 | (iwl4965_param_queues_num < IWL_MIN_NUM_QUEUES)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8802 | IWL_ERROR("invalid queues_num, should be between %d and %d\n", |
| 8803 | IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES); |
| 8804 | err = -EINVAL; |
| 8805 | goto out; |
| 8806 | } |
| 8807 | |
| 8808 | /* mac80211 allocates memory for this device instance, including |
| 8809 | * space for this driver's private structure */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8810 | hw = ieee80211_alloc_hw(sizeof(struct iwl4965_priv), &iwl4965_hw_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8811 | if (hw == NULL) { |
| 8812 | IWL_ERROR("Can not allocate network device\n"); |
| 8813 | err = -ENOMEM; |
| 8814 | goto out; |
| 8815 | } |
| 8816 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 8817 | |
Johannes Berg | f51359a | 2007-10-28 14:53:36 +0100 | [diff] [blame] | 8818 | hw->rate_control_algorithm = "iwl-4965-rs"; |
| 8819 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8820 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
| 8821 | priv = hw->priv; |
| 8822 | priv->hw = hw; |
| 8823 | |
| 8824 | priv->pci_dev = pdev; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8825 | priv->antenna = (enum iwl4965_antenna)iwl4965_param_antenna; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8826 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8827 | iwl4965_debug_level = iwl4965_param_debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8828 | atomic_set(&priv->restrict_refcnt, 0); |
| 8829 | #endif |
| 8830 | priv->retry_rate = 1; |
| 8831 | |
| 8832 | priv->ibss_beacon = NULL; |
| 8833 | |
| 8834 | /* Tell mac80211 and its clients (e.g. Wireless Extensions) |
| 8835 | * the range of signal quality values that we'll provide. |
| 8836 | * Negative values for level/noise indicate that we'll provide dBm. |
| 8837 | * For WE, at least, non-0 values here *enable* display of values |
| 8838 | * in app (iwconfig). */ |
| 8839 | hw->max_rssi = -20; /* signal level, negative indicates dBm */ |
| 8840 | hw->max_noise = -20; /* noise level, negative indicates dBm */ |
| 8841 | hw->max_signal = 100; /* link quality indication (%) */ |
| 8842 | |
| 8843 | /* Tell mac80211 our Tx characteristics */ |
| 8844 | hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE; |
| 8845 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8846 | /* Default value; 4 EDCA QOS priorities */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8847 | hw->queues = 4; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8848 | #ifdef CONFIG_IWL4965_HT |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8849 | /* Enhanced value; more queues, to support 11n aggregation */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8850 | hw->queues = 16; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8851 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8852 | |
| 8853 | spin_lock_init(&priv->lock); |
| 8854 | spin_lock_init(&priv->power_data.lock); |
| 8855 | spin_lock_init(&priv->sta_lock); |
| 8856 | spin_lock_init(&priv->hcmd_lock); |
| 8857 | spin_lock_init(&priv->lq_mngr.lock); |
| 8858 | |
| 8859 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) |
| 8860 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
| 8861 | |
| 8862 | INIT_LIST_HEAD(&priv->free_frames); |
| 8863 | |
| 8864 | mutex_init(&priv->mutex); |
| 8865 | if (pci_enable_device(pdev)) { |
| 8866 | err = -ENODEV; |
| 8867 | goto out_ieee80211_free_hw; |
| 8868 | } |
| 8869 | |
| 8870 | pci_set_master(pdev); |
| 8871 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8872 | /* Clear the driver's (not device's) station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8873 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8874 | |
| 8875 | priv->data_retry_limit = -1; |
| 8876 | priv->ieee_channels = NULL; |
| 8877 | priv->ieee_rates = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 8878 | priv->band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8879 | |
| 8880 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 8881 | if (!err) |
| 8882 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 8883 | if (err) { |
| 8884 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 8885 | goto out_pci_disable_device; |
| 8886 | } |
| 8887 | |
| 8888 | pci_set_drvdata(pdev, priv); |
| 8889 | err = pci_request_regions(pdev, DRV_NAME); |
| 8890 | if (err) |
| 8891 | goto out_pci_disable_device; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8892 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8893 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 8894 | * PCI Tx retries from interfering with C3 CPU state */ |
| 8895 | pci_write_config_byte(pdev, 0x41, 0x00); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8896 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8897 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 8898 | if (!priv->hw_base) { |
| 8899 | err = -ENODEV; |
| 8900 | goto out_pci_release_regions; |
| 8901 | } |
| 8902 | |
| 8903 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 8904 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 8905 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 8906 | |
| 8907 | /* Initialize module parameter values here */ |
| 8908 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8909 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8910 | if (iwl4965_param_disable) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8911 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 8912 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 8913 | } |
| 8914 | |
| 8915 | priv->iw_mode = IEEE80211_IF_TYPE_STA; |
| 8916 | |
| 8917 | priv->ps_mode = 0; |
| 8918 | priv->use_ant_b_for_management_frame = 1; /* start with ant B */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8919 | priv->valid_antenna = 0x7; /* assume all 3 connected */ |
| 8920 | priv->ps_mode = IWL_MIMO_PS_NONE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8921 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8922 | /* Choose which receivers/antennas to use */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8923 | iwl4965_set_rxon_chain(priv); |
| 8924 | |
| 8925 | printk(KERN_INFO DRV_NAME |
| 8926 | ": Detected Intel Wireless WiFi Link 4965AGN\n"); |
| 8927 | |
| 8928 | /* Device-specific setup */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8929 | if (iwl4965_hw_set_hw_setting(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8930 | IWL_ERROR("failed to set hw settings\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8931 | goto out_iounmap; |
| 8932 | } |
| 8933 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8934 | if (iwl4965_param_qos_enable) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8935 | priv->qos_data.qos_enable = 1; |
| 8936 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8937 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8938 | |
| 8939 | priv->qos_data.qos_active = 0; |
| 8940 | priv->qos_data.qos_cap.val = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8941 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 8942 | iwl4965_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8943 | iwl4965_setup_deferred_work(priv); |
| 8944 | iwl4965_setup_rx_handlers(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8945 | |
| 8946 | priv->rates_mask = IWL_RATES_MASK; |
| 8947 | /* If power management is turned on, default to AC mode */ |
| 8948 | priv->power_mode = IWL_POWER_AC; |
| 8949 | priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; |
| 8950 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8951 | iwl4965_disable_interrupts(priv); |
Jes Sorensen | 49df2b3 | 2007-10-26 16:10:39 +0200 | [diff] [blame] | 8952 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8953 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8954 | if (err) { |
| 8955 | IWL_ERROR("failed to create sysfs device attributes\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8956 | goto out_release_irq; |
| 8957 | } |
| 8958 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8959 | /* nic init */ |
| 8960 | iwl4965_set_bit(priv, CSR_GIO_CHICKEN_BITS, |
| 8961 | CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); |
| 8962 | |
| 8963 | iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); |
| 8964 | err = iwl4965_poll_bit(priv, CSR_GP_CNTRL, |
| 8965 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, |
| 8966 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); |
| 8967 | if (err < 0) { |
| 8968 | IWL_DEBUG_INFO("Failed to init the card\n"); |
| 8969 | goto out_remove_sysfs; |
| 8970 | } |
| 8971 | /* Read the EEPROM */ |
| 8972 | err = iwl4965_eeprom_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8973 | if (err) { |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8974 | IWL_ERROR("Unable to init EEPROM\n"); |
| 8975 | goto out_remove_sysfs; |
| 8976 | } |
| 8977 | /* MAC Address location in EEPROM same for 3945/4965 */ |
| 8978 | get_eeprom_mac(priv, priv->mac_addr); |
| 8979 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); |
| 8980 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 8981 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8982 | err = iwl4965_init_channel_map(priv); |
| 8983 | if (err) { |
| 8984 | IWL_ERROR("initializing regulatory failed: %d\n", err); |
| 8985 | goto out_remove_sysfs; |
| 8986 | } |
| 8987 | |
| 8988 | err = iwl4965_init_geos(priv); |
| 8989 | if (err) { |
| 8990 | IWL_ERROR("initializing geos failed: %d\n", err); |
| 8991 | goto out_free_channel_map; |
| 8992 | } |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8993 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8994 | iwl4965_rate_control_register(priv->hw); |
| 8995 | err = ieee80211_register_hw(priv->hw); |
| 8996 | if (err) { |
| 8997 | IWL_ERROR("Failed to register network device (error %d)\n", err); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8998 | goto out_free_geos; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8999 | } |
| 9000 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 9001 | priv->hw->conf.beacon_int = 100; |
| 9002 | priv->mac80211_registered = 1; |
| 9003 | pci_save_state(pdev); |
| 9004 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9005 | |
| 9006 | return 0; |
| 9007 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 9008 | out_free_geos: |
| 9009 | iwl4965_free_geos(priv); |
| 9010 | out_free_channel_map: |
| 9011 | iwl4965_free_channel_map(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 9012 | out_remove_sysfs: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9013 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9014 | |
| 9015 | out_release_irq: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9016 | destroy_workqueue(priv->workqueue); |
| 9017 | priv->workqueue = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9018 | iwl4965_unset_hw_setting(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9019 | |
| 9020 | out_iounmap: |
| 9021 | pci_iounmap(pdev, priv->hw_base); |
| 9022 | out_pci_release_regions: |
| 9023 | pci_release_regions(pdev); |
| 9024 | out_pci_disable_device: |
| 9025 | pci_disable_device(pdev); |
| 9026 | pci_set_drvdata(pdev, NULL); |
| 9027 | out_ieee80211_free_hw: |
| 9028 | ieee80211_free_hw(priv->hw); |
| 9029 | out: |
| 9030 | return err; |
| 9031 | } |
| 9032 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9033 | static void iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9034 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9035 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9036 | struct list_head *p, *q; |
| 9037 | int i; |
| 9038 | |
| 9039 | if (!priv) |
| 9040 | return; |
| 9041 | |
| 9042 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 9043 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9044 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 9045 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9046 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9047 | |
| 9048 | /* Free MAC hash list for ADHOC */ |
| 9049 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 9050 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 9051 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9052 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9053 | } |
| 9054 | } |
| 9055 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9056 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9057 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9058 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9059 | |
| 9060 | if (priv->rxq.bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9061 | iwl4965_rx_queue_free(priv, &priv->rxq); |
| 9062 | iwl4965_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9063 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9064 | iwl4965_unset_hw_setting(priv); |
| 9065 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9066 | |
| 9067 | if (priv->mac80211_registered) { |
| 9068 | ieee80211_unregister_hw(priv->hw); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9069 | iwl4965_rate_control_unregister(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9070 | } |
| 9071 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 9072 | /*netif_stop_queue(dev); */ |
| 9073 | flush_workqueue(priv->workqueue); |
| 9074 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9075 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9076 | * priv->workqueue... so we can't take down the workqueue |
| 9077 | * until now... */ |
| 9078 | destroy_workqueue(priv->workqueue); |
| 9079 | priv->workqueue = NULL; |
| 9080 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9081 | pci_iounmap(pdev, priv->hw_base); |
| 9082 | pci_release_regions(pdev); |
| 9083 | pci_disable_device(pdev); |
| 9084 | pci_set_drvdata(pdev, NULL); |
| 9085 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 9086 | iwl4965_free_channel_map(priv); |
| 9087 | iwl4965_free_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9088 | |
| 9089 | if (priv->ibss_beacon) |
| 9090 | dev_kfree_skb(priv->ibss_beacon); |
| 9091 | |
| 9092 | ieee80211_free_hw(priv->hw); |
| 9093 | } |
| 9094 | |
| 9095 | #ifdef CONFIG_PM |
| 9096 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9097 | 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] | 9098 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9099 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9100 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 9101 | if (priv->is_open) { |
| 9102 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 9103 | iwl4965_mac_stop(priv->hw); |
| 9104 | priv->is_open = 1; |
| 9105 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9106 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9107 | pci_set_power_state(pdev, PCI_D3hot); |
| 9108 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9109 | return 0; |
| 9110 | } |
| 9111 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9112 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9113 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9114 | struct iwl4965_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9115 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9116 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9117 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 9118 | if (priv->is_open) |
| 9119 | iwl4965_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9120 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 9121 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9122 | return 0; |
| 9123 | } |
| 9124 | |
| 9125 | #endif /* CONFIG_PM */ |
| 9126 | |
| 9127 | /***************************************************************************** |
| 9128 | * |
| 9129 | * driver and module entry point |
| 9130 | * |
| 9131 | *****************************************************************************/ |
| 9132 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9133 | static struct pci_driver iwl4965_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9134 | .name = DRV_NAME, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9135 | .id_table = iwl4965_hw_card_ids, |
| 9136 | .probe = iwl4965_pci_probe, |
| 9137 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9138 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9139 | .suspend = iwl4965_pci_suspend, |
| 9140 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9141 | #endif |
| 9142 | }; |
| 9143 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9144 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9145 | { |
| 9146 | |
| 9147 | int ret; |
| 9148 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 9149 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9150 | ret = pci_register_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9151 | if (ret) { |
| 9152 | IWL_ERROR("Unable to initialize PCI module\n"); |
| 9153 | return ret; |
| 9154 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9155 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9156 | ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9157 | if (ret) { |
| 9158 | IWL_ERROR("Unable to create driver sysfs file\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9159 | pci_unregister_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9160 | return ret; |
| 9161 | } |
| 9162 | #endif |
| 9163 | |
| 9164 | return ret; |
| 9165 | } |
| 9166 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9167 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9168 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 9169 | #ifdef CONFIG_IWL4965_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9170 | driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9171 | #endif |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9172 | pci_unregister_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9173 | } |
| 9174 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9175 | module_param_named(antenna, iwl4965_param_antenna, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9176 | 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] | 9177 | module_param_named(disable, iwl4965_param_disable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9178 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9179 | module_param_named(hwcrypto, iwl4965_param_hwcrypto, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9180 | MODULE_PARM_DESC(hwcrypto, |
| 9181 | "using hardware crypto engine (default 0 [software])\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9182 | module_param_named(debug, iwl4965_param_debug, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9183 | MODULE_PARM_DESC(debug, "debug output mask"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9184 | 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] | 9185 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 9186 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9187 | module_param_named(queues_num, iwl4965_param_queues_num, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9188 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 9189 | |
| 9190 | /* QoS */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9191 | module_param_named(qos_enable, iwl4965_param_qos_enable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9192 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionality"); |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 9193 | module_param_named(amsdu_size_8K, iwl4965_param_amsdu_size_8K, int, 0444); |
| 9194 | MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 9195 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 9196 | module_exit(iwl4965_exit); |
| 9197 | module_init(iwl4965_init); |