Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | eb7ae89 | 2008-03-11 16:17:17 -0700 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 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 | |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 48 | #include "iwl-eeprom.h" |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 49 | #include "iwl-core.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 50 | #include "iwl-4965.h" |
| 51 | #include "iwl-helpers.h" |
| 52 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 53 | static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 54 | struct iwl4965_tx_queue *txq); |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 55 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 56 | /****************************************************************************** |
| 57 | * |
| 58 | * module boiler plate |
| 59 | * |
| 60 | ******************************************************************************/ |
| 61 | |
| 62 | /* module parameters */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 63 | static int iwl4965_param_disable_hw_scan; /* def: 0 = use 4965's h/w scan */ |
| 64 | static int iwl4965_param_debug; /* def: 0 = minimal debug log messages */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 65 | static int iwl4965_param_disable; /* def: enable radio */ |
| 66 | static int iwl4965_param_antenna; /* def: 0 = both antennas (use diversity) */ |
| 67 | int iwl4965_param_hwcrypto; /* def: using software encryption */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 68 | static int iwl4965_param_qos_enable = 1; /* def: 1 = use quality of service */ |
| 69 | 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] | 70 | int iwl4965_param_amsdu_size_8K; /* def: enable 8K amsdu size */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * module name, copyright, version, etc. |
| 74 | * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk |
| 75 | */ |
| 76 | |
| 77 | #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux" |
| 78 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 79 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 80 | #define VD "d" |
| 81 | #else |
| 82 | #define VD |
| 83 | #endif |
| 84 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 85 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 86 | #define VS "s" |
| 87 | #else |
| 88 | #define VS |
| 89 | #endif |
| 90 | |
Tomas Winkler | df48c32 | 2008-03-06 10:40:19 -0800 | [diff] [blame] | 91 | #define DRV_VERSION IWLWIFI_VERSION VD VS |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 92 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 93 | |
| 94 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 95 | MODULE_VERSION(DRV_VERSION); |
| 96 | MODULE_AUTHOR(DRV_COPYRIGHT); |
| 97 | MODULE_LICENSE("GPL"); |
| 98 | |
| 99 | __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr) |
| 100 | { |
| 101 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 102 | int hdr_len = ieee80211_get_hdrlen(fc); |
| 103 | |
| 104 | if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA)) |
| 105 | return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN); |
| 106 | return NULL; |
| 107 | } |
| 108 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 109 | static const struct ieee80211_supported_band *iwl4965_get_hw_mode( |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 110 | struct iwl_priv *priv, enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 111 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 112 | return priv->hw->wiphy->bands[band]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 115 | static int iwl4965_is_empty_essid(const char *essid, int essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 116 | { |
| 117 | /* Single white space is for Linksys APs */ |
| 118 | if (essid_len == 1 && essid[0] == ' ') |
| 119 | return 1; |
| 120 | |
| 121 | /* Otherwise, if the entire essid is 0, we assume it is hidden */ |
| 122 | while (essid_len) { |
| 123 | essid_len--; |
| 124 | if (essid[essid_len] != '\0') |
| 125 | return 0; |
| 126 | } |
| 127 | |
| 128 | return 1; |
| 129 | } |
| 130 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 131 | static const char *iwl4965_escape_essid(const char *essid, u8 essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 132 | { |
| 133 | static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
| 134 | const char *s = essid; |
| 135 | char *d = escaped; |
| 136 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 137 | if (iwl4965_is_empty_essid(essid, essid_len)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 138 | memcpy(escaped, "<hidden>", sizeof("<hidden>")); |
| 139 | return escaped; |
| 140 | } |
| 141 | |
| 142 | essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE); |
| 143 | while (essid_len--) { |
| 144 | if (*s == '\0') { |
| 145 | *d++ = '\\'; |
| 146 | *d++ = '0'; |
| 147 | s++; |
| 148 | } else |
| 149 | *d++ = *s++; |
| 150 | } |
| 151 | *d = '\0'; |
| 152 | return escaped; |
| 153 | } |
| 154 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 155 | /*************** DMA-QUEUE-GENERAL-FUNCTIONS ***** |
| 156 | * DMA services |
| 157 | * |
| 158 | * Theory of operation |
| 159 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 160 | * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer |
| 161 | * of buffer descriptors, each of which points to one or more data buffers for |
| 162 | * the device to read from or fill. Driver and device exchange status of each |
| 163 | * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty |
| 164 | * entries in each circular buffer, to protect against confusing empty and full |
| 165 | * queue states. |
| 166 | * |
| 167 | * The device reads or writes the data in the queues via the device's several |
| 168 | * DMA/FIFO channels. Each queue is mapped to a single DMA channel. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 169 | * |
| 170 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 171 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 172 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 173 | * Tx queue resumed. |
| 174 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 175 | * The 4965 operates with up to 17 queues: One receive queue, one transmit |
| 176 | * queue (#4) for sending commands to the device firmware, and 15 other |
| 177 | * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels. |
Ben Cahill | e385144 | 2007-11-29 11:10:07 +0800 | [diff] [blame] | 178 | * |
| 179 | * See more detailed info in iwl-4965-hw.h. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 180 | ***************************************************/ |
| 181 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 182 | int iwl4965_queue_space(const struct iwl4965_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 183 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 184 | int s = q->read_ptr - q->write_ptr; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 185 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 186 | if (q->read_ptr > q->write_ptr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 187 | s -= q->n_bd; |
| 188 | |
| 189 | if (s <= 0) |
| 190 | s += q->n_window; |
| 191 | /* keep some reserve to not confuse empty and full situations */ |
| 192 | s -= 2; |
| 193 | if (s < 0) |
| 194 | s = 0; |
| 195 | return s; |
| 196 | } |
| 197 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 198 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 199 | 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] | 200 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 201 | return q->write_ptr > q->read_ptr ? |
| 202 | (i >= q->read_ptr && i < q->write_ptr) : |
| 203 | !(i < q->read_ptr && i >= q->write_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 206 | 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] | 207 | { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 208 | /* 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] | 209 | if (is_huge) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 210 | return q->n_window; /* must be power of 2 */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 211 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 212 | /* Otherwise, use normal size buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 213 | return index & (q->n_window - 1); |
| 214 | } |
| 215 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 216 | /** |
| 217 | * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes |
| 218 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 219 | static int iwl4965_queue_init(struct iwl_priv *priv, struct iwl4965_queue *q, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 220 | int count, int slots_num, u32 id) |
| 221 | { |
| 222 | q->n_bd = count; |
| 223 | q->n_window = slots_num; |
| 224 | q->id = id; |
| 225 | |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 226 | /* count must be power-of-two size, otherwise iwl_queue_inc_wrap |
| 227 | * and iwl_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 228 | BUG_ON(!is_power_of_2(count)); |
| 229 | |
| 230 | /* slots_num must be power-of-two size, otherwise |
| 231 | * get_cmd_index is broken. */ |
| 232 | BUG_ON(!is_power_of_2(slots_num)); |
| 233 | |
| 234 | q->low_mark = q->n_window / 4; |
| 235 | if (q->low_mark < 4) |
| 236 | q->low_mark = 4; |
| 237 | |
| 238 | q->high_mark = q->n_window / 8; |
| 239 | if (q->high_mark < 2) |
| 240 | q->high_mark = 2; |
| 241 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 242 | q->write_ptr = q->read_ptr = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 247 | /** |
| 248 | * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue |
| 249 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 250 | static int iwl4965_tx_queue_alloc(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 251 | struct iwl4965_tx_queue *txq, u32 id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 252 | { |
| 253 | struct pci_dev *dev = priv->pci_dev; |
| 254 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 255 | /* Driver private data, only for Tx (not command) queues, |
| 256 | * not shared with device. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 257 | if (id != IWL_CMD_QUEUE_NUM) { |
| 258 | txq->txb = kmalloc(sizeof(txq->txb[0]) * |
| 259 | TFD_QUEUE_SIZE_MAX, GFP_KERNEL); |
| 260 | if (!txq->txb) { |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 261 | IWL_ERROR("kmalloc for auxiliary BD " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 262 | "structures failed\n"); |
| 263 | goto error; |
| 264 | } |
| 265 | } else |
| 266 | txq->txb = NULL; |
| 267 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 268 | /* Circular buffer of transmit frame descriptors (TFDs), |
| 269 | * shared with device */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 270 | txq->bd = pci_alloc_consistent(dev, |
| 271 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX, |
| 272 | &txq->q.dma_addr); |
| 273 | |
| 274 | if (!txq->bd) { |
| 275 | IWL_ERROR("pci_alloc_consistent(%zd) failed\n", |
| 276 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX); |
| 277 | goto error; |
| 278 | } |
| 279 | txq->q.id = id; |
| 280 | |
| 281 | return 0; |
| 282 | |
| 283 | error: |
| 284 | if (txq->txb) { |
| 285 | kfree(txq->txb); |
| 286 | txq->txb = NULL; |
| 287 | } |
| 288 | |
| 289 | return -ENOMEM; |
| 290 | } |
| 291 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 292 | /** |
| 293 | * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue |
| 294 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 295 | int iwl4965_tx_queue_init(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 296 | struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 297 | { |
| 298 | struct pci_dev *dev = priv->pci_dev; |
| 299 | int len; |
| 300 | int rc = 0; |
| 301 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 302 | /* |
| 303 | * Alloc buffer array for commands (Tx or other types of commands). |
| 304 | * For the command queue (#4), allocate command space + one big |
| 305 | * command for scan, since scan command is very huge; the system will |
| 306 | * 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] | 307 | * For normal Tx queues (all other queues), no super-size command |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 308 | * space is needed. |
| 309 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 310 | len = sizeof(struct iwl4965_cmd) * slots_num; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 311 | if (txq_id == IWL_CMD_QUEUE_NUM) |
| 312 | len += IWL_MAX_SCAN_SIZE; |
| 313 | txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd); |
| 314 | if (!txq->cmd) |
| 315 | return -ENOMEM; |
| 316 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 317 | /* Alloc driver data array and TFD circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 318 | rc = iwl4965_tx_queue_alloc(priv, txq, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 319 | if (rc) { |
| 320 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 321 | |
| 322 | return -ENOMEM; |
| 323 | } |
| 324 | txq->need_update = 0; |
| 325 | |
| 326 | /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 327 | * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 328 | 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] | 329 | |
| 330 | /* Initialize queue's high/low-water marks, and head/tail indexes */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 331 | 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] | 332 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 333 | /* Tell device where to find queue */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 334 | iwl4965_hw_tx_queue_init(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 340 | * iwl4965_tx_queue_free - Deallocate DMA queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 341 | * @txq: Transmit queue to deallocate. |
| 342 | * |
| 343 | * Empty queue by removing and destroying all BD's. |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 344 | * Free all buffers. |
| 345 | * 0-fill, but do not free "txq" descriptor structure. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 346 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 347 | void iwl4965_tx_queue_free(struct iwl_priv *priv, struct iwl4965_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 348 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 349 | struct iwl4965_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 350 | struct pci_dev *dev = priv->pci_dev; |
| 351 | int len; |
| 352 | |
| 353 | if (q->n_bd == 0) |
| 354 | return; |
| 355 | |
| 356 | /* first, empty all BD's */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 357 | for (; q->write_ptr != q->read_ptr; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 358 | q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 359 | iwl4965_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 360 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 361 | len = sizeof(struct iwl4965_cmd) * q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 362 | if (q->id == IWL_CMD_QUEUE_NUM) |
| 363 | len += IWL_MAX_SCAN_SIZE; |
| 364 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 365 | /* De-alloc array of command/tx buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 366 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 367 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 368 | /* De-alloc circular buffer of TFDs */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 369 | if (txq->q.n_bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 370 | pci_free_consistent(dev, sizeof(struct iwl4965_tfd_frame) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 371 | txq->q.n_bd, txq->bd, txq->q.dma_addr); |
| 372 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 373 | /* De-alloc array of per-TFD driver data */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 374 | if (txq->txb) { |
| 375 | kfree(txq->txb); |
| 376 | txq->txb = NULL; |
| 377 | } |
| 378 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 379 | /* 0-fill queue descriptor structure */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 380 | memset(txq, 0, sizeof(*txq)); |
| 381 | } |
| 382 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 383 | 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] | 384 | |
| 385 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 386 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 387 | * the functionality provided here |
| 388 | */ |
| 389 | |
| 390 | /**************************************************************/ |
| 391 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 392 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 393 | /** |
| 394 | * iwl4965_remove_station - Remove driver's knowledge of station. |
| 395 | * |
| 396 | * NOTE: This does not remove station from device's station table. |
| 397 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 398 | static u8 iwl4965_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 399 | { |
| 400 | int index = IWL_INVALID_STATION; |
| 401 | int i; |
| 402 | unsigned long flags; |
| 403 | |
| 404 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 405 | |
| 406 | if (is_ap) |
| 407 | index = IWL_AP_ID; |
| 408 | else if (is_broadcast_ether_addr(addr)) |
| 409 | index = priv->hw_setting.bcast_sta_id; |
| 410 | else |
| 411 | for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) |
| 412 | if (priv->stations[i].used && |
| 413 | !compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 414 | addr)) { |
| 415 | index = i; |
| 416 | break; |
| 417 | } |
| 418 | |
| 419 | if (unlikely(index == IWL_INVALID_STATION)) |
| 420 | goto out; |
| 421 | |
| 422 | if (priv->stations[index].used) { |
| 423 | priv->stations[index].used = 0; |
| 424 | priv->num_stations--; |
| 425 | } |
| 426 | |
| 427 | BUG_ON(priv->num_stations < 0); |
| 428 | |
| 429 | out: |
| 430 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 431 | return 0; |
| 432 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 433 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 434 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 435 | /** |
| 436 | * iwl4965_clear_stations_table - Clear the driver's station table |
| 437 | * |
| 438 | * NOTE: This does not clear or otherwise alter the device's station table. |
| 439 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 440 | static void iwl4965_clear_stations_table(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 441 | { |
| 442 | unsigned long flags; |
| 443 | |
| 444 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 445 | |
| 446 | priv->num_stations = 0; |
| 447 | memset(priv->stations, 0, sizeof(priv->stations)); |
| 448 | |
| 449 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 450 | } |
| 451 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 452 | /** |
| 453 | * iwl4965_add_station_flags - Add station to tables in driver and device |
| 454 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 455 | u8 iwl4965_add_station_flags(struct iwl_priv *priv, const u8 *addr, |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 456 | int is_ap, u8 flags, void *ht_data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 457 | { |
| 458 | int i; |
| 459 | int index = IWL_INVALID_STATION; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 460 | struct iwl4965_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 461 | unsigned long flags_spin; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 462 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 463 | |
| 464 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 465 | if (is_ap) |
| 466 | index = IWL_AP_ID; |
| 467 | else if (is_broadcast_ether_addr(addr)) |
| 468 | index = priv->hw_setting.bcast_sta_id; |
| 469 | else |
| 470 | for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) { |
| 471 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 472 | addr)) { |
| 473 | index = i; |
| 474 | break; |
| 475 | } |
| 476 | |
| 477 | if (!priv->stations[i].used && |
| 478 | index == IWL_INVALID_STATION) |
| 479 | index = i; |
| 480 | } |
| 481 | |
| 482 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 483 | /* These two conditions have the same outcome, but keep them separate |
| 484 | since they have different meanings */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 485 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 486 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 487 | return index; |
| 488 | } |
| 489 | |
| 490 | if (priv->stations[index].used && |
| 491 | !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) { |
| 492 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 493 | return index; |
| 494 | } |
| 495 | |
| 496 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 497 | 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] | 498 | station = &priv->stations[index]; |
| 499 | station->used = 1; |
| 500 | priv->num_stations++; |
| 501 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 502 | /* Set up the REPLY_ADD_STA command to send to device */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 503 | memset(&station->sta, 0, sizeof(struct iwl4965_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 504 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 505 | station->sta.mode = 0; |
| 506 | station->sta.sta.sta_id = index; |
| 507 | station->sta.station_flags = 0; |
| 508 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 509 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 510 | /* BCAST station and IBSS stations do not work in HT mode */ |
| 511 | if (index != priv->hw_setting.bcast_sta_id && |
| 512 | priv->iw_mode != IEEE80211_IF_TYPE_IBSS) |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 513 | iwl4965_set_ht_add_station(priv, index, |
| 514 | (struct ieee80211_ht_info *) ht_data); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 515 | #endif /*CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 516 | |
| 517 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 518 | |
| 519 | /* Add station to device's station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 520 | iwl4965_send_add_station(priv, &station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 521 | return index; |
| 522 | |
| 523 | } |
| 524 | |
| 525 | /*************** DRIVER STATUS FUNCTIONS *****/ |
| 526 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 527 | static inline int iwl4965_is_ready(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 528 | { |
| 529 | /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are |
| 530 | * set but EXIT_PENDING is not */ |
| 531 | return test_bit(STATUS_READY, &priv->status) && |
| 532 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) && |
| 533 | !test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 534 | } |
| 535 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 536 | static inline int iwl4965_is_alive(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 537 | { |
| 538 | return test_bit(STATUS_ALIVE, &priv->status); |
| 539 | } |
| 540 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 541 | static inline int iwl4965_is_init(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 542 | { |
| 543 | return test_bit(STATUS_INIT, &priv->status); |
| 544 | } |
| 545 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 546 | static inline int iwl4965_is_rfkill(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 547 | { |
| 548 | return test_bit(STATUS_RF_KILL_HW, &priv->status) || |
| 549 | test_bit(STATUS_RF_KILL_SW, &priv->status); |
| 550 | } |
| 551 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 552 | static inline int iwl4965_is_ready_rf(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 553 | { |
| 554 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 555 | if (iwl4965_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 556 | return 0; |
| 557 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 558 | return iwl4965_is_ready(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 562 | |
| 563 | #define IWL_CMD(x) case x : return #x |
| 564 | |
| 565 | static const char *get_cmd_string(u8 cmd) |
| 566 | { |
| 567 | switch (cmd) { |
| 568 | IWL_CMD(REPLY_ALIVE); |
| 569 | IWL_CMD(REPLY_ERROR); |
| 570 | IWL_CMD(REPLY_RXON); |
| 571 | IWL_CMD(REPLY_RXON_ASSOC); |
| 572 | IWL_CMD(REPLY_QOS_PARAM); |
| 573 | IWL_CMD(REPLY_RXON_TIMING); |
| 574 | IWL_CMD(REPLY_ADD_STA); |
| 575 | IWL_CMD(REPLY_REMOVE_STA); |
| 576 | IWL_CMD(REPLY_REMOVE_ALL_STA); |
| 577 | IWL_CMD(REPLY_TX); |
| 578 | IWL_CMD(REPLY_RATE_SCALE); |
| 579 | IWL_CMD(REPLY_LEDS_CMD); |
| 580 | IWL_CMD(REPLY_TX_LINK_QUALITY_CMD); |
| 581 | IWL_CMD(RADAR_NOTIFICATION); |
| 582 | IWL_CMD(REPLY_QUIET_CMD); |
| 583 | IWL_CMD(REPLY_CHANNEL_SWITCH); |
| 584 | IWL_CMD(CHANNEL_SWITCH_NOTIFICATION); |
| 585 | IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD); |
| 586 | IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION); |
| 587 | IWL_CMD(POWER_TABLE_CMD); |
| 588 | IWL_CMD(PM_SLEEP_NOTIFICATION); |
| 589 | IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC); |
| 590 | IWL_CMD(REPLY_SCAN_CMD); |
| 591 | IWL_CMD(REPLY_SCAN_ABORT_CMD); |
| 592 | IWL_CMD(SCAN_START_NOTIFICATION); |
| 593 | IWL_CMD(SCAN_RESULTS_NOTIFICATION); |
| 594 | IWL_CMD(SCAN_COMPLETE_NOTIFICATION); |
| 595 | IWL_CMD(BEACON_NOTIFICATION); |
| 596 | IWL_CMD(REPLY_TX_BEACON); |
| 597 | IWL_CMD(WHO_IS_AWAKE_NOTIFICATION); |
| 598 | IWL_CMD(QUIET_NOTIFICATION); |
| 599 | IWL_CMD(REPLY_TX_PWR_TABLE_CMD); |
| 600 | IWL_CMD(MEASURE_ABORT_NOTIFICATION); |
| 601 | IWL_CMD(REPLY_BT_CONFIG); |
| 602 | IWL_CMD(REPLY_STATISTICS_CMD); |
| 603 | IWL_CMD(STATISTICS_NOTIFICATION); |
| 604 | IWL_CMD(REPLY_CARD_STATE_CMD); |
| 605 | IWL_CMD(CARD_STATE_NOTIFICATION); |
| 606 | IWL_CMD(MISSED_BEACONS_NOTIFICATION); |
| 607 | IWL_CMD(REPLY_CT_KILL_CONFIG_CMD); |
| 608 | IWL_CMD(SENSITIVITY_CMD); |
| 609 | IWL_CMD(REPLY_PHY_CALIBRATION_CMD); |
| 610 | IWL_CMD(REPLY_RX_PHY_CMD); |
| 611 | IWL_CMD(REPLY_RX_MPDU_CMD); |
| 612 | IWL_CMD(REPLY_4965_RX); |
| 613 | IWL_CMD(REPLY_COMPRESSED_BA); |
| 614 | default: |
| 615 | return "UNKNOWN"; |
| 616 | |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | #define HOST_COMPLETE_TIMEOUT (HZ / 2) |
| 621 | |
| 622 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 623 | * iwl4965_enqueue_hcmd - enqueue a uCode command |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 624 | * @priv: device private data point |
| 625 | * @cmd: a point to the ucode command structure |
| 626 | * |
| 627 | * The function returns < 0 values to indicate the operation is |
| 628 | * failed. On success, it turns the index (> 0) of command in the |
| 629 | * command queue. |
| 630 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 631 | static int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 632 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 633 | struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
| 634 | struct iwl4965_queue *q = &txq->q; |
| 635 | struct iwl4965_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 636 | u32 *control_flags; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 637 | struct iwl4965_cmd *out_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 638 | u32 idx; |
| 639 | u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 640 | dma_addr_t phys_addr; |
| 641 | int ret; |
| 642 | unsigned long flags; |
| 643 | |
| 644 | /* If any of the command structures end up being larger than |
| 645 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
| 646 | * we will need to increase the size of the TFD entries */ |
| 647 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
| 648 | !(cmd->meta.flags & CMD_SIZE_HUGE)); |
| 649 | |
Gregory Greenman | c342a1b | 2008-02-06 11:20:40 -0800 | [diff] [blame] | 650 | if (iwl4965_is_rfkill(priv)) { |
| 651 | IWL_DEBUG_INFO("Not sending command - RF KILL"); |
| 652 | return -EIO; |
| 653 | } |
| 654 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 655 | if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 656 | IWL_ERROR("No space for Tx\n"); |
| 657 | return -ENOSPC; |
| 658 | } |
| 659 | |
| 660 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 661 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 662 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 663 | memset(tfd, 0, sizeof(*tfd)); |
| 664 | |
| 665 | control_flags = (u32 *) tfd; |
| 666 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 667 | 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] | 668 | out_cmd = &txq->cmd[idx]; |
| 669 | |
| 670 | out_cmd->hdr.cmd = cmd->id; |
| 671 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 672 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 673 | |
| 674 | /* At this point, the out_cmd now has all of the incoming cmd |
| 675 | * information */ |
| 676 | |
| 677 | out_cmd->hdr.flags = 0; |
| 678 | 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] | 679 | INDEX_TO_SEQ(q->write_ptr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 680 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
| 681 | out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME); |
| 682 | |
| 683 | phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 684 | offsetof(struct iwl4965_cmd, hdr); |
| 685 | 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] | 686 | |
| 687 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 688 | "%d bytes at %d[%d]:%d\n", |
| 689 | get_cmd_string(out_cmd->hdr.cmd), |
| 690 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 691 | fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 692 | |
| 693 | txq->need_update = 1; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 694 | |
| 695 | /* Set up entry in queue's byte count circular buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 696 | ret = iwl4965_tx_queue_update_wr_ptr(priv, txq, 0); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 697 | |
| 698 | /* Increment and update queue's write index */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 699 | q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 700 | iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 701 | |
| 702 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 703 | return ret ? ret : idx; |
| 704 | } |
| 705 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 706 | static int iwl4965_send_cmd_async(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 707 | { |
| 708 | int ret; |
| 709 | |
| 710 | BUG_ON(!(cmd->meta.flags & CMD_ASYNC)); |
| 711 | |
| 712 | /* An asynchronous command can not expect an SKB to be set. */ |
| 713 | BUG_ON(cmd->meta.flags & CMD_WANT_SKB); |
| 714 | |
| 715 | /* An asynchronous command MUST have a callback. */ |
| 716 | BUG_ON(!cmd->meta.u.callback); |
| 717 | |
| 718 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 719 | return -EBUSY; |
| 720 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 721 | ret = iwl4965_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 722 | if (ret < 0) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 723 | IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 724 | get_cmd_string(cmd->id), ret); |
| 725 | return ret; |
| 726 | } |
| 727 | return 0; |
| 728 | } |
| 729 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 730 | static int iwl4965_send_cmd_sync(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 731 | { |
| 732 | int cmd_idx; |
| 733 | int ret; |
| 734 | static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */ |
| 735 | |
| 736 | BUG_ON(cmd->meta.flags & CMD_ASYNC); |
| 737 | |
| 738 | /* A synchronous command can not have a callback set. */ |
| 739 | BUG_ON(cmd->meta.u.callback != NULL); |
| 740 | |
| 741 | if (atomic_xchg(&entry, 1)) { |
| 742 | IWL_ERROR("Error sending %s: Already sending a host command\n", |
| 743 | get_cmd_string(cmd->id)); |
| 744 | return -EBUSY; |
| 745 | } |
| 746 | |
| 747 | set_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 748 | |
| 749 | if (cmd->meta.flags & CMD_WANT_SKB) |
| 750 | cmd->meta.source = &cmd->meta; |
| 751 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 752 | cmd_idx = iwl4965_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 753 | if (cmd_idx < 0) { |
| 754 | ret = cmd_idx; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 755 | IWL_ERROR("Error sending %s: iwl4965_enqueue_hcmd failed: %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 756 | get_cmd_string(cmd->id), ret); |
| 757 | goto out; |
| 758 | } |
| 759 | |
| 760 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 761 | !test_bit(STATUS_HCMD_ACTIVE, &priv->status), |
| 762 | HOST_COMPLETE_TIMEOUT); |
| 763 | if (!ret) { |
| 764 | if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) { |
| 765 | IWL_ERROR("Error sending %s: time out after %dms.\n", |
| 766 | get_cmd_string(cmd->id), |
| 767 | jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); |
| 768 | |
| 769 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 770 | ret = -ETIMEDOUT; |
| 771 | goto cancel; |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 776 | IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n", |
| 777 | get_cmd_string(cmd->id)); |
| 778 | ret = -ECANCELED; |
| 779 | goto fail; |
| 780 | } |
| 781 | if (test_bit(STATUS_FW_ERROR, &priv->status)) { |
| 782 | IWL_DEBUG_INFO("Command %s failed: FW Error\n", |
| 783 | get_cmd_string(cmd->id)); |
| 784 | ret = -EIO; |
| 785 | goto fail; |
| 786 | } |
| 787 | if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) { |
| 788 | IWL_ERROR("Error: Response NULL in '%s'\n", |
| 789 | get_cmd_string(cmd->id)); |
| 790 | ret = -EIO; |
| 791 | goto out; |
| 792 | } |
| 793 | |
| 794 | ret = 0; |
| 795 | goto out; |
| 796 | |
| 797 | cancel: |
| 798 | if (cmd->meta.flags & CMD_WANT_SKB) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 799 | struct iwl4965_cmd *qcmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 800 | |
| 801 | /* Cancel the CMD_WANT_SKB flag for the cmd in the |
| 802 | * TX cmd queue. Otherwise in case the cmd comes |
| 803 | * in later, it will possibly set an invalid |
| 804 | * address (cmd->meta.source). */ |
| 805 | qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx]; |
| 806 | qcmd->meta.flags &= ~CMD_WANT_SKB; |
| 807 | } |
| 808 | fail: |
| 809 | if (cmd->meta.u.skb) { |
| 810 | dev_kfree_skb_any(cmd->meta.u.skb); |
| 811 | cmd->meta.u.skb = NULL; |
| 812 | } |
| 813 | out: |
| 814 | atomic_set(&entry, 0); |
| 815 | return ret; |
| 816 | } |
| 817 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 818 | int iwl4965_send_cmd(struct iwl_priv *priv, struct iwl4965_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 819 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 820 | if (cmd->meta.flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 821 | return iwl4965_send_cmd_async(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 822 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 823 | return iwl4965_send_cmd_sync(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 824 | } |
| 825 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 826 | int iwl4965_send_cmd_pdu(struct iwl_priv *priv, u8 id, u16 len, const void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 827 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 828 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 829 | .id = id, |
| 830 | .len = len, |
| 831 | .data = data, |
| 832 | }; |
| 833 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 834 | return iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 837 | static int __must_check iwl4965_send_cmd_u32(struct iwl_priv *priv, u8 id, u32 val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 838 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 839 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 840 | .id = id, |
| 841 | .len = sizeof(val), |
| 842 | .data = &val, |
| 843 | }; |
| 844 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 845 | return iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 848 | int iwl4965_send_statistics_request(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 849 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 850 | return iwl4965_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 854 | * iwl4965_rxon_add_station - add station into station table. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 855 | * |
| 856 | * there is only one AP station with id= IWL_AP_ID |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 857 | * NOTE: mutex must be held before calling this fnction |
| 858 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 859 | static int iwl4965_rxon_add_station(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 860 | const u8 *addr, int is_ap) |
| 861 | { |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 862 | u8 sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 863 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 864 | /* Add station to device's station table */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 865 | #ifdef CONFIG_IWL4965_HT |
| 866 | struct ieee80211_conf *conf = &priv->hw->conf; |
| 867 | struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf; |
| 868 | |
| 869 | if ((is_ap) && |
| 870 | (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) && |
| 871 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 872 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, |
| 873 | 0, cur_ht_config); |
| 874 | else |
| 875 | #endif /* CONFIG_IWL4965_HT */ |
| 876 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, |
| 877 | 0, NULL); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 878 | |
| 879 | /* Set up default rate scaling table in device's station table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 880 | iwl4965_add_station(priv, addr, is_ap); |
| 881 | |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 882 | return sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 886 | * 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] | 887 | * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz |
| 888 | * @channel: Any channel valid for the requested phymode |
| 889 | |
| 890 | * In addition to setting the staging RXON, priv->phymode is also set. |
| 891 | * |
| 892 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
| 893 | * in the staging RXON flag structure based on the phymode |
| 894 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 895 | static int iwl4965_set_rxon_channel(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 896 | enum ieee80211_band band, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 897 | u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 898 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 899 | if (!iwl4965_get_channel_info(priv, band, channel)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 900 | IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 901 | channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 902 | return -EINVAL; |
| 903 | } |
| 904 | |
| 905 | if ((le16_to_cpu(priv->staging_rxon.channel) == channel) && |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 906 | (priv->band == band)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 907 | return 0; |
| 908 | |
| 909 | priv->staging_rxon.channel = cpu_to_le16(channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 910 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 911 | priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; |
| 912 | else |
| 913 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 914 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 915 | priv->band = band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 916 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 917 | IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 918 | |
| 919 | return 0; |
| 920 | } |
| 921 | |
| 922 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 923 | * iwl4965_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 924 | * |
| 925 | * NOTE: This is really only useful during development and can eventually |
| 926 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 927 | * making changes |
| 928 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 929 | static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 930 | { |
| 931 | int error = 0; |
| 932 | int counter = 1; |
| 933 | |
| 934 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 935 | error |= le32_to_cpu(rxon->flags & |
| 936 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 937 | RXON_FLG_RADAR_DETECT_MSK)); |
| 938 | if (error) |
| 939 | IWL_WARNING("check 24G fields %d | %d\n", |
| 940 | counter++, error); |
| 941 | } else { |
| 942 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 943 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 944 | if (error) |
| 945 | IWL_WARNING("check 52 fields %d | %d\n", |
| 946 | counter++, error); |
| 947 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 948 | if (error) |
| 949 | IWL_WARNING("check 52 CCK %d | %d\n", |
| 950 | counter++, error); |
| 951 | } |
| 952 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 953 | if (error) |
| 954 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); |
| 955 | |
| 956 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 957 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 958 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 959 | if (error) |
| 960 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); |
| 961 | |
| 962 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 963 | if (error) |
| 964 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); |
| 965 | |
| 966 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 967 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 968 | if (error) |
| 969 | IWL_WARNING("check CCK and short slot %d | %d\n", |
| 970 | counter++, error); |
| 971 | |
| 972 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 973 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 974 | if (error) |
| 975 | IWL_WARNING("check CCK & auto detect %d | %d\n", |
| 976 | counter++, error); |
| 977 | |
| 978 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 979 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 980 | if (error) |
| 981 | IWL_WARNING("check TGG and auto detect %d | %d\n", |
| 982 | counter++, error); |
| 983 | |
| 984 | if (error) |
| 985 | IWL_WARNING("Tuning to channel %d\n", |
| 986 | le16_to_cpu(rxon->channel)); |
| 987 | |
| 988 | if (error) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 989 | IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 990 | return -1; |
| 991 | } |
| 992 | return 0; |
| 993 | } |
| 994 | |
| 995 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 996 | * 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] | 997 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 998 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 999 | * If the RXON structure is changing enough to require a new tune, |
| 1000 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 1001 | * 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] | 1002 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1003 | static int iwl4965_full_rxon_required(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1004 | { |
| 1005 | |
| 1006 | /* These items are only settable from the full RXON command */ |
| 1007 | if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || |
| 1008 | compare_ether_addr(priv->staging_rxon.bssid_addr, |
| 1009 | priv->active_rxon.bssid_addr) || |
| 1010 | compare_ether_addr(priv->staging_rxon.node_addr, |
| 1011 | priv->active_rxon.node_addr) || |
| 1012 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, |
| 1013 | priv->active_rxon.wlap_bssid_addr) || |
| 1014 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || |
| 1015 | (priv->staging_rxon.channel != priv->active_rxon.channel) || |
| 1016 | (priv->staging_rxon.air_propagation != |
| 1017 | priv->active_rxon.air_propagation) || |
| 1018 | (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != |
| 1019 | priv->active_rxon.ofdm_ht_single_stream_basic_rates) || |
| 1020 | (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != |
| 1021 | priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || |
| 1022 | (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) || |
| 1023 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) |
| 1024 | return 1; |
| 1025 | |
| 1026 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 1027 | * be updated with the RXON_ASSOC command -- however only some |
| 1028 | * flag transitions are allowed using RXON_ASSOC */ |
| 1029 | |
| 1030 | /* Check if we are not switching bands */ |
| 1031 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 1032 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
| 1033 | return 1; |
| 1034 | |
| 1035 | /* Check if we are switching association toggle */ |
| 1036 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 1037 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
| 1038 | return 1; |
| 1039 | |
| 1040 | return 0; |
| 1041 | } |
| 1042 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1043 | static int iwl4965_send_rxon_assoc(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1044 | { |
| 1045 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1046 | struct iwl4965_rx_packet *res = NULL; |
| 1047 | struct iwl4965_rxon_assoc_cmd rxon_assoc; |
| 1048 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1049 | .id = REPLY_RXON_ASSOC, |
| 1050 | .len = sizeof(rxon_assoc), |
| 1051 | .meta.flags = CMD_WANT_SKB, |
| 1052 | .data = &rxon_assoc, |
| 1053 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1054 | const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon; |
| 1055 | const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1056 | |
| 1057 | if ((rxon1->flags == rxon2->flags) && |
| 1058 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 1059 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 1060 | (rxon1->ofdm_ht_single_stream_basic_rates == |
| 1061 | rxon2->ofdm_ht_single_stream_basic_rates) && |
| 1062 | (rxon1->ofdm_ht_dual_stream_basic_rates == |
| 1063 | rxon2->ofdm_ht_dual_stream_basic_rates) && |
| 1064 | (rxon1->rx_chain == rxon2->rx_chain) && |
| 1065 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 1066 | IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n"); |
| 1067 | return 0; |
| 1068 | } |
| 1069 | |
| 1070 | rxon_assoc.flags = priv->staging_rxon.flags; |
| 1071 | rxon_assoc.filter_flags = priv->staging_rxon.filter_flags; |
| 1072 | rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates; |
| 1073 | rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates; |
| 1074 | rxon_assoc.reserved = 0; |
| 1075 | rxon_assoc.ofdm_ht_single_stream_basic_rates = |
| 1076 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates; |
| 1077 | rxon_assoc.ofdm_ht_dual_stream_basic_rates = |
| 1078 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates; |
| 1079 | rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain; |
| 1080 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1081 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1082 | if (rc) |
| 1083 | return rc; |
| 1084 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1085 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1086 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1087 | IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n"); |
| 1088 | rc = -EIO; |
| 1089 | } |
| 1090 | |
| 1091 | priv->alloc_rxb_skb--; |
| 1092 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1093 | |
| 1094 | return rc; |
| 1095 | } |
| 1096 | |
| 1097 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1098 | * iwl4965_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1099 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1100 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1101 | * the active_rxon structure is updated with the new data. This |
| 1102 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 1103 | * a HW tune is required based on the RXON structure changes. |
| 1104 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1105 | static int iwl4965_commit_rxon(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1106 | { |
| 1107 | /* cast away the const for active_rxon in this function */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1108 | struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1109 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1110 | int rc = 0; |
| 1111 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1112 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1113 | return -1; |
| 1114 | |
| 1115 | /* always get timestamp with Rx frame */ |
| 1116 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
| 1117 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1118 | rc = iwl4965_check_rxon_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1119 | if (rc) { |
| 1120 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); |
| 1121 | return -EINVAL; |
| 1122 | } |
| 1123 | |
| 1124 | /* 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] | 1125 | * iwl4965_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1126 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1127 | if (!iwl4965_full_rxon_required(priv)) { |
| 1128 | rc = iwl4965_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1129 | if (rc) { |
| 1130 | IWL_ERROR("Error setting RXON_ASSOC " |
| 1131 | "configuration (%d).\n", rc); |
| 1132 | return rc; |
| 1133 | } |
| 1134 | |
| 1135 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 1136 | |
| 1137 | return 0; |
| 1138 | } |
| 1139 | |
| 1140 | /* station table will be cleared */ |
| 1141 | priv->assoc_station_added = 0; |
| 1142 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1143 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1144 | priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; |
| 1145 | if (!priv->error_recovering) |
| 1146 | priv->start_calib = 0; |
| 1147 | |
| 1148 | iwl4965_init_sensitivity(priv, CMD_ASYNC, 1); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1149 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1150 | |
| 1151 | /* If we are currently associated and the new config requires |
| 1152 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 1153 | * we must clear the associated from the active configuration |
| 1154 | * before we apply the new config */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1155 | if (iwl4965_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1156 | (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
| 1157 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 1158 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 1159 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1160 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON, |
| 1161 | sizeof(struct iwl4965_rxon_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1162 | &priv->active_rxon); |
| 1163 | |
| 1164 | /* If the mask clearing failed then we set |
| 1165 | * active_rxon back to what it was previously */ |
| 1166 | if (rc) { |
| 1167 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 1168 | IWL_ERROR("Error clearing ASSOC_MSK on current " |
| 1169 | "configuration (%d).\n", rc); |
| 1170 | return rc; |
| 1171 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | IWL_DEBUG_INFO("Sending RXON\n" |
| 1175 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 1176 | "* channel = %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1177 | "* bssid = %s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1178 | ((priv->staging_rxon.filter_flags & |
| 1179 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
| 1180 | le16_to_cpu(priv->staging_rxon.channel), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1181 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1182 | |
| 1183 | /* Apply the new configuration */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1184 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON, |
| 1185 | sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1186 | if (rc) { |
| 1187 | IWL_ERROR("Error setting new configuration (%d).\n", rc); |
| 1188 | return rc; |
| 1189 | } |
| 1190 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1191 | iwl4965_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 1192 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1193 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1194 | if (!priv->error_recovering) |
| 1195 | priv->start_calib = 0; |
| 1196 | |
| 1197 | priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT; |
| 1198 | iwl4965_init_sensitivity(priv, CMD_ASYNC, 1); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1199 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1200 | |
| 1201 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 1202 | |
| 1203 | /* If we issue a new RXON command which required a tune then we must |
| 1204 | * 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] | 1205 | rc = iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1206 | if (rc) { |
| 1207 | IWL_ERROR("Error setting Tx power (%d).\n", rc); |
| 1208 | return rc; |
| 1209 | } |
| 1210 | |
| 1211 | /* Add the broadcast address so we can send broadcast frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1212 | if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1213 | IWL_INVALID_STATION) { |
| 1214 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); |
| 1215 | return -EIO; |
| 1216 | } |
| 1217 | |
| 1218 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 1219 | * add the IWL_AP_ID to the station rate table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1220 | if (iwl4965_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1221 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1222 | if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1223 | == IWL_INVALID_STATION) { |
| 1224 | IWL_ERROR("Error adding AP address for transmit.\n"); |
| 1225 | return -EIO; |
| 1226 | } |
| 1227 | priv->assoc_station_added = 1; |
| 1228 | } |
| 1229 | |
| 1230 | return 0; |
| 1231 | } |
| 1232 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1233 | static int iwl4965_send_bt_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1234 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1235 | struct iwl4965_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1236 | .flags = 3, |
| 1237 | .lead_time = 0xAA, |
| 1238 | .max_kill = 1, |
| 1239 | .kill_ack_mask = 0, |
| 1240 | .kill_cts_mask = 0, |
| 1241 | }; |
| 1242 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1243 | return iwl4965_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
| 1244 | sizeof(struct iwl4965_bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1247 | static int iwl4965_send_scan_abort(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1248 | { |
| 1249 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1250 | struct iwl4965_rx_packet *res; |
| 1251 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1252 | .id = REPLY_SCAN_ABORT_CMD, |
| 1253 | .meta.flags = CMD_WANT_SKB, |
| 1254 | }; |
| 1255 | |
| 1256 | /* If there isn't a scan actively going on in the hardware |
| 1257 | * then we are in between scan bands and not actually |
| 1258 | * actively scanning, so don't send the abort command */ |
| 1259 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1260 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1261 | return 0; |
| 1262 | } |
| 1263 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1264 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1265 | if (rc) { |
| 1266 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1267 | return rc; |
| 1268 | } |
| 1269 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1270 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1271 | if (res->u.status != CAN_ABORT_STATUS) { |
| 1272 | /* The scan abort will return 1 for success or |
| 1273 | * 2 for "failure". A failure condition can be |
| 1274 | * due to simply not being in an active scan which |
| 1275 | * can occur if we send the scan abort before we |
| 1276 | * the microcode has notified us that a scan is |
| 1277 | * completed. */ |
| 1278 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 1279 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1280 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 1281 | } |
| 1282 | |
| 1283 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1284 | |
| 1285 | return rc; |
| 1286 | } |
| 1287 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1288 | static int iwl4965_card_state_sync_callback(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1289 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1290 | struct sk_buff *skb) |
| 1291 | { |
| 1292 | return 1; |
| 1293 | } |
| 1294 | |
| 1295 | /* |
| 1296 | * CARD_STATE_CMD |
| 1297 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1298 | * 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] | 1299 | * |
| 1300 | * When in the 'enable' state the card operates as normal. |
| 1301 | * When in the 'disable' state, the card enters into a low power mode. |
| 1302 | * When in the 'halt' state, the card is shut down and must be fully |
| 1303 | * restarted to come back on. |
| 1304 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1305 | static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1306 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1307 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1308 | .id = REPLY_CARD_STATE_CMD, |
| 1309 | .len = sizeof(u32), |
| 1310 | .data = &flags, |
| 1311 | .meta.flags = meta_flag, |
| 1312 | }; |
| 1313 | |
| 1314 | if (meta_flag & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1315 | cmd.meta.u.callback = iwl4965_card_state_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1316 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1317 | return iwl4965_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1318 | } |
| 1319 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1320 | static int iwl4965_add_sta_sync_callback(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1321 | struct iwl4965_cmd *cmd, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1322 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1323 | struct iwl4965_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1324 | |
| 1325 | if (!skb) { |
| 1326 | IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n"); |
| 1327 | return 1; |
| 1328 | } |
| 1329 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1330 | res = (struct iwl4965_rx_packet *)skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1331 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1332 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 1333 | res->hdr.flags); |
| 1334 | return 1; |
| 1335 | } |
| 1336 | |
| 1337 | switch (res->u.add_sta.status) { |
| 1338 | case ADD_STA_SUCCESS_MSK: |
| 1339 | break; |
| 1340 | default: |
| 1341 | break; |
| 1342 | } |
| 1343 | |
| 1344 | /* We didn't cache the SKB; let the caller free it */ |
| 1345 | return 1; |
| 1346 | } |
| 1347 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1348 | int iwl4965_send_add_station(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1349 | struct iwl4965_addsta_cmd *sta, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1350 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1351 | struct iwl4965_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1352 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1353 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1354 | .id = REPLY_ADD_STA, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1355 | .len = sizeof(struct iwl4965_addsta_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1356 | .meta.flags = flags, |
| 1357 | .data = sta, |
| 1358 | }; |
| 1359 | |
| 1360 | if (flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1361 | cmd.meta.u.callback = iwl4965_add_sta_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1362 | else |
| 1363 | cmd.meta.flags |= CMD_WANT_SKB; |
| 1364 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1365 | rc = iwl4965_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1366 | |
| 1367 | if (rc || (flags & CMD_ASYNC)) |
| 1368 | return rc; |
| 1369 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1370 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1371 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1372 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 1373 | res->hdr.flags); |
| 1374 | rc = -EIO; |
| 1375 | } |
| 1376 | |
| 1377 | if (rc == 0) { |
| 1378 | switch (res->u.add_sta.status) { |
| 1379 | case ADD_STA_SUCCESS_MSK: |
| 1380 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 1381 | break; |
| 1382 | default: |
| 1383 | rc = -EIO; |
| 1384 | IWL_WARNING("REPLY_ADD_STA failed\n"); |
| 1385 | break; |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | priv->alloc_rxb_skb--; |
| 1390 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1391 | |
| 1392 | return rc; |
| 1393 | } |
| 1394 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1395 | static int iwl4965_update_sta_key_info(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1396 | struct ieee80211_key_conf *keyconf, |
| 1397 | u8 sta_id) |
| 1398 | { |
| 1399 | unsigned long flags; |
| 1400 | __le16 key_flags = 0; |
| 1401 | |
| 1402 | switch (keyconf->alg) { |
| 1403 | case ALG_CCMP: |
| 1404 | key_flags |= STA_KEY_FLG_CCMP; |
| 1405 | key_flags |= cpu_to_le16( |
| 1406 | keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1407 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 1408 | break; |
| 1409 | case ALG_TKIP: |
| 1410 | case ALG_WEP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1411 | default: |
| 1412 | return -EINVAL; |
| 1413 | } |
| 1414 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1415 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 1416 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 1417 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, |
| 1418 | keyconf->keylen); |
| 1419 | |
| 1420 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, |
| 1421 | keyconf->keylen); |
| 1422 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 1423 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1424 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1425 | |
| 1426 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1427 | |
| 1428 | IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1429 | iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1430 | return 0; |
| 1431 | } |
| 1432 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1433 | static int iwl4965_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1434 | { |
| 1435 | unsigned long flags; |
| 1436 | |
| 1437 | spin_lock_irqsave(&priv->sta_lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1438 | memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl4965_hw_key)); |
| 1439 | memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl4965_keyinfo)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1440 | priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; |
| 1441 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1442 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1443 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1444 | |
| 1445 | IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1446 | iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1447 | return 0; |
| 1448 | } |
| 1449 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1450 | static void iwl4965_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1451 | { |
| 1452 | struct list_head *element; |
| 1453 | |
| 1454 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 1455 | priv->frames_count); |
| 1456 | |
| 1457 | while (!list_empty(&priv->free_frames)) { |
| 1458 | element = priv->free_frames.next; |
| 1459 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1460 | kfree(list_entry(element, struct iwl4965_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1461 | priv->frames_count--; |
| 1462 | } |
| 1463 | |
| 1464 | if (priv->frames_count) { |
| 1465 | IWL_WARNING("%d frames still in use. Did we lose one?\n", |
| 1466 | priv->frames_count); |
| 1467 | priv->frames_count = 0; |
| 1468 | } |
| 1469 | } |
| 1470 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1471 | static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1472 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1473 | struct iwl4965_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1474 | struct list_head *element; |
| 1475 | if (list_empty(&priv->free_frames)) { |
| 1476 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 1477 | if (!frame) { |
| 1478 | IWL_ERROR("Could not allocate frame!\n"); |
| 1479 | return NULL; |
| 1480 | } |
| 1481 | |
| 1482 | priv->frames_count++; |
| 1483 | return frame; |
| 1484 | } |
| 1485 | |
| 1486 | element = priv->free_frames.next; |
| 1487 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1488 | return list_entry(element, struct iwl4965_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1489 | } |
| 1490 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1491 | static void iwl4965_free_frame(struct iwl_priv *priv, struct iwl4965_frame *frame) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1492 | { |
| 1493 | memset(frame, 0, sizeof(*frame)); |
| 1494 | list_add(&frame->list, &priv->free_frames); |
| 1495 | } |
| 1496 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1497 | unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1498 | struct ieee80211_hdr *hdr, |
| 1499 | const u8 *dest, int left) |
| 1500 | { |
| 1501 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1502 | if (!iwl4965_is_associated(priv) || !priv->ibss_beacon || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1503 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
| 1504 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) |
| 1505 | return 0; |
| 1506 | |
| 1507 | if (priv->ibss_beacon->len > left) |
| 1508 | return 0; |
| 1509 | |
| 1510 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 1511 | |
| 1512 | return priv->ibss_beacon->len; |
| 1513 | } |
| 1514 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1515 | static u8 iwl4965_rate_get_lowest_plcp(int rate_mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1516 | { |
| 1517 | u8 i; |
| 1518 | |
| 1519 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1520 | i = iwl4965_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1521 | if (rate_mask & (1 << i)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1522 | return iwl4965_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | return IWL_RATE_INVALID; |
| 1526 | } |
| 1527 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1528 | static int iwl4965_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1529 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1530 | struct iwl4965_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1531 | unsigned int frame_size; |
| 1532 | int rc; |
| 1533 | u8 rate; |
| 1534 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1535 | frame = iwl4965_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1536 | |
| 1537 | if (!frame) { |
| 1538 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 1539 | "command.\n"); |
| 1540 | return -ENOMEM; |
| 1541 | } |
| 1542 | |
| 1543 | if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1544 | rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1545 | 0xFF0); |
| 1546 | if (rate == IWL_INVALID_RATE) |
| 1547 | rate = IWL_RATE_6M_PLCP; |
| 1548 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1549 | rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1550 | if (rate == IWL_INVALID_RATE) |
| 1551 | rate = IWL_RATE_1M_PLCP; |
| 1552 | } |
| 1553 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1554 | frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1555 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1556 | rc = iwl4965_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1557 | &frame->u.cmd[0]); |
| 1558 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1559 | iwl4965_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1560 | |
| 1561 | return rc; |
| 1562 | } |
| 1563 | |
| 1564 | /****************************************************************************** |
| 1565 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1566 | * Misc. internal state and helper functions |
| 1567 | * |
| 1568 | ******************************************************************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1569 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1570 | static void iwl4965_unset_hw_setting(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1571 | { |
| 1572 | if (priv->hw_setting.shared_virt) |
| 1573 | pci_free_consistent(priv->pci_dev, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1574 | sizeof(struct iwl4965_shared), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1575 | priv->hw_setting.shared_virt, |
| 1576 | priv->hw_setting.shared_phys); |
| 1577 | } |
| 1578 | |
| 1579 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1580 | * 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] | 1581 | * |
| 1582 | * return : set the bit for each supported rate insert in ie |
| 1583 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1584 | static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1585 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1586 | { |
| 1587 | u16 ret_rates = 0, bit; |
| 1588 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1589 | u8 *cnt = ie; |
| 1590 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1591 | |
| 1592 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1593 | if (bit & supported_rate) { |
| 1594 | ret_rates |= bit; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1595 | rates[*cnt] = iwl4965_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1596 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1597 | (*cnt)++; |
| 1598 | (*left)--; |
| 1599 | if ((*left <= 0) || |
| 1600 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1601 | break; |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | return ret_rates; |
| 1606 | } |
| 1607 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1608 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1609 | * 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] | 1610 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1611 | static u16 iwl4965_fill_probe_req(struct iwl_priv *priv, |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1612 | enum ieee80211_band band, |
| 1613 | struct ieee80211_mgmt *frame, |
| 1614 | int left, int is_direct) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1615 | { |
| 1616 | int len = 0; |
| 1617 | u8 *pos = NULL; |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1618 | u16 active_rates, ret_rates, cck_rates, active_rate_basic; |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1619 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1620 | const struct ieee80211_supported_band *sband = |
| 1621 | iwl4965_get_hw_mode(priv, band); |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1622 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1623 | |
| 1624 | /* Make sure there is enough space for the probe request, |
| 1625 | * two mandatory IEs and the data */ |
| 1626 | left -= 24; |
| 1627 | if (left < 0) |
| 1628 | return 0; |
| 1629 | len += 24; |
| 1630 | |
| 1631 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1632 | memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1633 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1634 | memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1635 | frame->seq_ctrl = 0; |
| 1636 | |
| 1637 | /* fill in our indirect SSID IE */ |
| 1638 | /* ...next IE... */ |
| 1639 | |
| 1640 | left -= 2; |
| 1641 | if (left < 0) |
| 1642 | return 0; |
| 1643 | len += 2; |
| 1644 | pos = &(frame->u.probe_req.variable[0]); |
| 1645 | *pos++ = WLAN_EID_SSID; |
| 1646 | *pos++ = 0; |
| 1647 | |
| 1648 | /* fill in our direct SSID IE... */ |
| 1649 | if (is_direct) { |
| 1650 | /* ...next IE... */ |
| 1651 | left -= 2 + priv->essid_len; |
| 1652 | if (left < 0) |
| 1653 | return 0; |
| 1654 | /* ... fill it in... */ |
| 1655 | *pos++ = WLAN_EID_SSID; |
| 1656 | *pos++ = priv->essid_len; |
| 1657 | memcpy(pos, priv->essid, priv->essid_len); |
| 1658 | pos += priv->essid_len; |
| 1659 | len += 2 + priv->essid_len; |
| 1660 | } |
| 1661 | |
| 1662 | /* fill in supported rate */ |
| 1663 | /* ...next IE... */ |
| 1664 | left -= 2; |
| 1665 | if (left < 0) |
| 1666 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1667 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1668 | /* ... fill it in... */ |
| 1669 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1670 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1671 | |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1672 | /* exclude 60M rate */ |
| 1673 | active_rates = priv->rates_mask; |
| 1674 | active_rates &= ~IWL_RATE_60M_MASK; |
| 1675 | |
| 1676 | active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1677 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1678 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1679 | ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1680 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1681 | active_rates &= ~ret_rates; |
| 1682 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1683 | ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1684 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1685 | active_rates &= ~ret_rates; |
| 1686 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1687 | len += 2 + *pos; |
| 1688 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1689 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1690 | goto fill_end; |
| 1691 | |
| 1692 | /* fill in supported extended rate */ |
| 1693 | /* ...next IE... */ |
| 1694 | left -= 2; |
| 1695 | if (left < 0) |
| 1696 | return 0; |
| 1697 | /* ... fill it in... */ |
| 1698 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1699 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1700 | iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1701 | active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1702 | if (*pos > 0) |
| 1703 | len += 2 + *pos; |
| 1704 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1705 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1706 | if (sband && sband->ht_info.ht_supported) { |
| 1707 | struct ieee80211_ht_cap *ht_cap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1708 | pos += (*pos) + 1; |
| 1709 | *pos++ = WLAN_EID_HT_CAPABILITY; |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1710 | *pos++ = sizeof(struct ieee80211_ht_cap); |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1711 | ht_cap = (struct ieee80211_ht_cap *)pos; |
| 1712 | ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap); |
| 1713 | memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16); |
| 1714 | ht_cap->ampdu_params_info =(sband->ht_info.ampdu_factor & |
| 1715 | IEEE80211_HT_CAP_AMPDU_FACTOR) | |
| 1716 | ((sband->ht_info.ampdu_density << 2) & |
| 1717 | IEEE80211_HT_CAP_AMPDU_DENSITY); |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1718 | len += 2 + sizeof(struct ieee80211_ht_cap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1719 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1720 | #endif /*CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1721 | |
| 1722 | fill_end: |
| 1723 | return (u16)len; |
| 1724 | } |
| 1725 | |
| 1726 | /* |
| 1727 | * QoS support |
| 1728 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1729 | static int iwl4965_send_qos_params_command(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1730 | struct iwl4965_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1731 | { |
| 1732 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1733 | return iwl4965_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
| 1734 | sizeof(struct iwl4965_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1735 | } |
| 1736 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1737 | static void iwl4965_reset_qos(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1738 | { |
| 1739 | u16 cw_min = 15; |
| 1740 | u16 cw_max = 1023; |
| 1741 | u8 aifs = 2; |
| 1742 | u8 is_legacy = 0; |
| 1743 | unsigned long flags; |
| 1744 | int i; |
| 1745 | |
| 1746 | spin_lock_irqsave(&priv->lock, flags); |
| 1747 | priv->qos_data.qos_active = 0; |
| 1748 | |
| 1749 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) { |
| 1750 | if (priv->qos_data.qos_enable) |
| 1751 | priv->qos_data.qos_active = 1; |
| 1752 | if (!(priv->active_rate & 0xfff0)) { |
| 1753 | cw_min = 31; |
| 1754 | is_legacy = 1; |
| 1755 | } |
| 1756 | } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 1757 | if (priv->qos_data.qos_enable) |
| 1758 | priv->qos_data.qos_active = 1; |
| 1759 | } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) { |
| 1760 | cw_min = 31; |
| 1761 | is_legacy = 1; |
| 1762 | } |
| 1763 | |
| 1764 | if (priv->qos_data.qos_active) |
| 1765 | aifs = 3; |
| 1766 | |
| 1767 | priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min); |
| 1768 | priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max); |
| 1769 | priv->qos_data.def_qos_parm.ac[0].aifsn = aifs; |
| 1770 | priv->qos_data.def_qos_parm.ac[0].edca_txop = 0; |
| 1771 | priv->qos_data.def_qos_parm.ac[0].reserved1 = 0; |
| 1772 | |
| 1773 | if (priv->qos_data.qos_active) { |
| 1774 | i = 1; |
| 1775 | priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min); |
| 1776 | priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max); |
| 1777 | priv->qos_data.def_qos_parm.ac[i].aifsn = 7; |
| 1778 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 1779 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1780 | |
| 1781 | i = 2; |
| 1782 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 1783 | cpu_to_le16((cw_min + 1) / 2 - 1); |
| 1784 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 1785 | cpu_to_le16(cw_max); |
| 1786 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 1787 | if (is_legacy) |
| 1788 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1789 | cpu_to_le16(6016); |
| 1790 | else |
| 1791 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1792 | cpu_to_le16(3008); |
| 1793 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1794 | |
| 1795 | i = 3; |
| 1796 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 1797 | cpu_to_le16((cw_min + 1) / 4 - 1); |
| 1798 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 1799 | cpu_to_le16((cw_max + 1) / 2 - 1); |
| 1800 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 1801 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1802 | if (is_legacy) |
| 1803 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1804 | cpu_to_le16(3264); |
| 1805 | else |
| 1806 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1807 | cpu_to_le16(1504); |
| 1808 | } else { |
| 1809 | for (i = 1; i < 4; i++) { |
| 1810 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 1811 | cpu_to_le16(cw_min); |
| 1812 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 1813 | cpu_to_le16(cw_max); |
| 1814 | priv->qos_data.def_qos_parm.ac[i].aifsn = aifs; |
| 1815 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 1816 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1817 | } |
| 1818 | } |
| 1819 | IWL_DEBUG_QOS("set QoS to default \n"); |
| 1820 | |
| 1821 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1822 | } |
| 1823 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1824 | static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1825 | { |
| 1826 | unsigned long flags; |
| 1827 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1828 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 1829 | return; |
| 1830 | |
| 1831 | if (!priv->qos_data.qos_enable) |
| 1832 | return; |
| 1833 | |
| 1834 | spin_lock_irqsave(&priv->lock, flags); |
| 1835 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 1836 | |
| 1837 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 1838 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 1839 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1840 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1841 | if (priv->qos_data.qos_active) |
| 1842 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1843 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 1844 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1845 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 1846 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1847 | 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] | 1848 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1849 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1850 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1851 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1852 | if (force || iwl4965_is_associated(priv)) { |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1853 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 1854 | priv->qos_data.qos_active, |
| 1855 | priv->qos_data.def_qos_parm.qos_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1856 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1857 | iwl4965_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1858 | &(priv->qos_data.def_qos_parm)); |
| 1859 | } |
| 1860 | } |
| 1861 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1862 | /* |
| 1863 | * Power management (not Tx power!) functions |
| 1864 | */ |
| 1865 | #define MSEC_TO_USEC 1024 |
| 1866 | |
| 1867 | #define NOSLP __constant_cpu_to_le16(0), 0, 0 |
| 1868 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0 |
| 1869 | #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC) |
| 1870 | #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \ |
| 1871 | __constant_cpu_to_le32(X1), \ |
| 1872 | __constant_cpu_to_le32(X2), \ |
| 1873 | __constant_cpu_to_le32(X3), \ |
| 1874 | __constant_cpu_to_le32(X4)} |
| 1875 | |
| 1876 | |
| 1877 | /* default power management (not Tx power) table values */ |
| 1878 | /* for tim 0-10 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1879 | static struct iwl4965_power_vec_entry range_0[IWL_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1880 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 1881 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 1882 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, |
| 1883 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0}, |
| 1884 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1}, |
| 1885 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1} |
| 1886 | }; |
| 1887 | |
| 1888 | /* for tim > 10 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1889 | static struct iwl4965_power_vec_entry range_1[IWL_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1890 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 1891 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), |
| 1892 | SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 1893 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), |
| 1894 | SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 1895 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), |
| 1896 | SLP_VEC(2, 6, 9, 9, 0xFF)}, 0}, |
| 1897 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 1898 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), |
| 1899 | SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 1900 | }; |
| 1901 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1902 | int iwl4965_power_init_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1903 | { |
| 1904 | int rc = 0, i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1905 | struct iwl4965_power_mgr *pow_data; |
| 1906 | int size = sizeof(struct iwl4965_power_vec_entry) * IWL_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1907 | u16 pci_pm; |
| 1908 | |
| 1909 | IWL_DEBUG_POWER("Initialize power \n"); |
| 1910 | |
| 1911 | pow_data = &(priv->power_data); |
| 1912 | |
| 1913 | memset(pow_data, 0, sizeof(*pow_data)); |
| 1914 | |
| 1915 | pow_data->active_index = IWL_POWER_RANGE_0; |
| 1916 | pow_data->dtim_val = 0xffff; |
| 1917 | |
| 1918 | memcpy(&pow_data->pwr_range_0[0], &range_0[0], size); |
| 1919 | memcpy(&pow_data->pwr_range_1[0], &range_1[0], size); |
| 1920 | |
| 1921 | rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm); |
| 1922 | if (rc != 0) |
| 1923 | return 0; |
| 1924 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1925 | struct iwl4965_powertable_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1926 | |
| 1927 | IWL_DEBUG_POWER("adjust power command flags\n"); |
| 1928 | |
| 1929 | for (i = 0; i < IWL_POWER_AC; i++) { |
| 1930 | cmd = &pow_data->pwr_range_0[i].cmd; |
| 1931 | |
| 1932 | if (pci_pm & 0x1) |
| 1933 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 1934 | else |
| 1935 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 1936 | } |
| 1937 | } |
| 1938 | return rc; |
| 1939 | } |
| 1940 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 1941 | static int iwl4965_update_power_cmd(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1942 | struct iwl4965_powertable_cmd *cmd, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1943 | { |
| 1944 | int rc = 0, i; |
| 1945 | u8 skip; |
| 1946 | u32 max_sleep = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1947 | struct iwl4965_power_vec_entry *range; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1948 | u8 period = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1949 | struct iwl4965_power_mgr *pow_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1950 | |
| 1951 | if (mode > IWL_POWER_INDEX_5) { |
| 1952 | IWL_DEBUG_POWER("Error invalid power mode \n"); |
| 1953 | return -1; |
| 1954 | } |
| 1955 | pow_data = &(priv->power_data); |
| 1956 | |
| 1957 | if (pow_data->active_index == IWL_POWER_RANGE_0) |
| 1958 | range = &pow_data->pwr_range_0[0]; |
| 1959 | else |
| 1960 | range = &pow_data->pwr_range_1[1]; |
| 1961 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1962 | memcpy(cmd, &range[mode].cmd, sizeof(struct iwl4965_powertable_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1963 | |
| 1964 | #ifdef IWL_MAC80211_DISABLE |
| 1965 | if (priv->assoc_network != NULL) { |
| 1966 | unsigned long flags; |
| 1967 | |
| 1968 | period = priv->assoc_network->tim.tim_period; |
| 1969 | } |
| 1970 | #endif /*IWL_MAC80211_DISABLE */ |
| 1971 | skip = range[mode].no_dtim; |
| 1972 | |
| 1973 | if (period == 0) { |
| 1974 | period = 1; |
| 1975 | skip = 0; |
| 1976 | } |
| 1977 | |
| 1978 | if (skip == 0) { |
| 1979 | max_sleep = period; |
| 1980 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 1981 | } else { |
| 1982 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 1983 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 1984 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 1985 | } |
| 1986 | |
| 1987 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) { |
| 1988 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 1989 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
| 1990 | } |
| 1991 | |
| 1992 | IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags); |
| 1993 | IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 1994 | IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 1995 | IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
| 1996 | le32_to_cpu(cmd->sleep_interval[0]), |
| 1997 | le32_to_cpu(cmd->sleep_interval[1]), |
| 1998 | le32_to_cpu(cmd->sleep_interval[2]), |
| 1999 | le32_to_cpu(cmd->sleep_interval[3]), |
| 2000 | le32_to_cpu(cmd->sleep_interval[4])); |
| 2001 | |
| 2002 | return rc; |
| 2003 | } |
| 2004 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2005 | static int iwl4965_send_power_mode(struct iwl_priv *priv, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2006 | { |
John W. Linville | 9a62f73 | 2007-11-15 16:27:36 -0500 | [diff] [blame] | 2007 | u32 uninitialized_var(final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2008 | int rc; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2009 | struct iwl4965_powertable_cmd cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2010 | |
| 2011 | /* If on battery, set to 3, |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2012 | * if plugged into AC power, set to CAM ("continuously aware mode"), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2013 | * else user level */ |
| 2014 | switch (mode) { |
| 2015 | case IWL_POWER_BATTERY: |
| 2016 | final_mode = IWL_POWER_INDEX_3; |
| 2017 | break; |
| 2018 | case IWL_POWER_AC: |
| 2019 | final_mode = IWL_POWER_MODE_CAM; |
| 2020 | break; |
| 2021 | default: |
| 2022 | final_mode = mode; |
| 2023 | break; |
| 2024 | } |
| 2025 | |
| 2026 | cmd.keep_alive_beacons = 0; |
| 2027 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2028 | iwl4965_update_power_cmd(priv, &cmd, final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2029 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2030 | rc = iwl4965_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2031 | |
| 2032 | if (final_mode == IWL_POWER_MODE_CAM) |
| 2033 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 2034 | else |
| 2035 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 2036 | |
| 2037 | return rc; |
| 2038 | } |
| 2039 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2040 | int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2041 | { |
| 2042 | /* Filter incoming packets to determine if they are targeted toward |
| 2043 | * this network, discarding packets coming from ourselves */ |
| 2044 | switch (priv->iw_mode) { |
| 2045 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 2046 | /* packets from our adapter are dropped (echo) */ |
| 2047 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 2048 | return 0; |
| 2049 | /* {broad,multi}cast packets to our IBSS go through */ |
| 2050 | if (is_multicast_ether_addr(header->addr1)) |
| 2051 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 2052 | /* packets to our adapter go through */ |
| 2053 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2054 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 2055 | /* packets from our adapter are dropped (echo) */ |
| 2056 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 2057 | return 0; |
| 2058 | /* {broad,multi}cast packets to our BSS go through */ |
| 2059 | if (is_multicast_ether_addr(header->addr1)) |
| 2060 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 2061 | /* packets to our adapter go through */ |
| 2062 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2063 | } |
| 2064 | |
| 2065 | return 1; |
| 2066 | } |
| 2067 | |
| 2068 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2069 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2070 | static const char *iwl4965_get_tx_fail_reason(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2071 | { |
| 2072 | switch (status & TX_STATUS_MSK) { |
| 2073 | case TX_STATUS_SUCCESS: |
| 2074 | return "SUCCESS"; |
| 2075 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 2076 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 2077 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 2078 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 2079 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 2080 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 2081 | TX_STATUS_ENTRY(DEST_PS); |
| 2082 | TX_STATUS_ENTRY(ABORTED); |
| 2083 | TX_STATUS_ENTRY(BT_RETRY); |
| 2084 | TX_STATUS_ENTRY(STA_INVALID); |
| 2085 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 2086 | TX_STATUS_ENTRY(TID_DISABLE); |
| 2087 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 2088 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 2089 | TX_STATUS_ENTRY(TX_LOCKED); |
| 2090 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 2091 | } |
| 2092 | |
| 2093 | return "UNKNOWN"; |
| 2094 | } |
| 2095 | |
| 2096 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2097 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2098 | * |
| 2099 | * NOTE: priv->mutex is not required before calling this function |
| 2100 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2101 | static int iwl4965_scan_cancel(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2102 | { |
| 2103 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 2104 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2105 | return 0; |
| 2106 | } |
| 2107 | |
| 2108 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2109 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2110 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 2111 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2112 | queue_work(priv->workqueue, &priv->abort_scan); |
| 2113 | |
| 2114 | } else |
| 2115 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 2116 | |
| 2117 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2118 | } |
| 2119 | |
| 2120 | return 0; |
| 2121 | } |
| 2122 | |
| 2123 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2124 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2125 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 2126 | * |
| 2127 | * NOTE: priv->mutex must be held before calling this function |
| 2128 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2129 | static int iwl4965_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2130 | { |
| 2131 | unsigned long now = jiffies; |
| 2132 | int ret; |
| 2133 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2134 | ret = iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2135 | if (ret && ms) { |
| 2136 | mutex_unlock(&priv->mutex); |
| 2137 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 2138 | test_bit(STATUS_SCANNING, &priv->status)) |
| 2139 | msleep(1); |
| 2140 | mutex_lock(&priv->mutex); |
| 2141 | |
| 2142 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2143 | } |
| 2144 | |
| 2145 | return ret; |
| 2146 | } |
| 2147 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2148 | static void iwl4965_sequence_reset(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2149 | { |
| 2150 | /* Reset ieee stats */ |
| 2151 | |
| 2152 | /* We don't reset the net_device_stats (ieee->stats) on |
| 2153 | * re-association */ |
| 2154 | |
| 2155 | priv->last_seq_num = -1; |
| 2156 | priv->last_frag_num = -1; |
| 2157 | priv->last_packet_time = 0; |
| 2158 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2159 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 2163 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 2164 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2165 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2166 | { |
| 2167 | u16 new_val = 0; |
| 2168 | u16 beacon_factor = 0; |
| 2169 | |
| 2170 | beacon_factor = |
| 2171 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 2172 | / MAX_UCODE_BEACON_INTERVAL; |
| 2173 | new_val = beacon_val / beacon_factor; |
| 2174 | |
| 2175 | return cpu_to_le16(new_val); |
| 2176 | } |
| 2177 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2178 | static void iwl4965_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2179 | { |
| 2180 | u64 interval_tm_unit; |
| 2181 | u64 tsf, result; |
| 2182 | unsigned long flags; |
| 2183 | struct ieee80211_conf *conf = NULL; |
| 2184 | u16 beacon_int = 0; |
| 2185 | |
| 2186 | conf = ieee80211_get_hw_conf(priv->hw); |
| 2187 | |
| 2188 | spin_lock_irqsave(&priv->lock, flags); |
| 2189 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1); |
| 2190 | priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0); |
| 2191 | |
| 2192 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 2193 | |
| 2194 | tsf = priv->timestamp1; |
| 2195 | tsf = ((tsf << 32) | priv->timestamp0); |
| 2196 | |
| 2197 | beacon_int = priv->beacon_int; |
| 2198 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2199 | |
| 2200 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 2201 | if (beacon_int == 0) { |
| 2202 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 2203 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 2204 | } else { |
| 2205 | priv->rxon_timing.beacon_interval = |
| 2206 | cpu_to_le16(beacon_int); |
| 2207 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2208 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2209 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2210 | } |
| 2211 | |
| 2212 | priv->rxon_timing.atim_window = 0; |
| 2213 | } else { |
| 2214 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2215 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2216 | /* TODO: we need to get atim_window from upper stack |
| 2217 | * for now we set to 0 */ |
| 2218 | priv->rxon_timing.atim_window = 0; |
| 2219 | } |
| 2220 | |
| 2221 | interval_tm_unit = |
| 2222 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 2223 | result = do_div(tsf, interval_tm_unit); |
| 2224 | priv->rxon_timing.beacon_init_val = |
| 2225 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 2226 | |
| 2227 | IWL_DEBUG_ASSOC |
| 2228 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 2229 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 2230 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 2231 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 2232 | } |
| 2233 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2234 | static int iwl4965_scan_initiate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2235 | { |
| 2236 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 2237 | IWL_ERROR("APs don't scan.\n"); |
| 2238 | return 0; |
| 2239 | } |
| 2240 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2241 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2242 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 2243 | return -EIO; |
| 2244 | } |
| 2245 | |
| 2246 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2247 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 2248 | return -EAGAIN; |
| 2249 | } |
| 2250 | |
| 2251 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2252 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 2253 | "Queuing.\n"); |
| 2254 | return -EAGAIN; |
| 2255 | } |
| 2256 | |
| 2257 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 2258 | priv->scan_bands = 2; |
| 2259 | set_bit(STATUS_SCANNING, &priv->status); |
| 2260 | priv->scan_start = jiffies; |
| 2261 | priv->scan_pass_start = priv->scan_start; |
| 2262 | |
| 2263 | queue_work(priv->workqueue, &priv->request_scan); |
| 2264 | |
| 2265 | return 0; |
| 2266 | } |
| 2267 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2268 | static int iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2269 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2270 | struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2271 | |
| 2272 | if (hw_decrypt) |
| 2273 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 2274 | else |
| 2275 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 2276 | |
| 2277 | return 0; |
| 2278 | } |
| 2279 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2280 | static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2281 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2282 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2283 | if (band == IEEE80211_BAND_5GHZ) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2284 | priv->staging_rxon.flags &= |
| 2285 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 2286 | | RXON_FLG_CCK_MSK); |
| 2287 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2288 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2289 | /* Copied from iwl4965_bg_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2290 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 2291 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2292 | else |
| 2293 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2294 | |
| 2295 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 2296 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2297 | |
| 2298 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 2299 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 2300 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 2301 | } |
| 2302 | } |
| 2303 | |
| 2304 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2305 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2306 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2307 | static void iwl4965_connection_init_rx_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2308 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2309 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2310 | |
| 2311 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 2312 | |
| 2313 | switch (priv->iw_mode) { |
| 2314 | case IEEE80211_IF_TYPE_AP: |
| 2315 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 2316 | break; |
| 2317 | |
| 2318 | case IEEE80211_IF_TYPE_STA: |
| 2319 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 2320 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 2321 | break; |
| 2322 | |
| 2323 | case IEEE80211_IF_TYPE_IBSS: |
| 2324 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 2325 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2326 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 2327 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2328 | break; |
| 2329 | |
| 2330 | case IEEE80211_IF_TYPE_MNTR: |
| 2331 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 2332 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 2333 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2334 | break; |
| 2335 | } |
| 2336 | |
| 2337 | #if 0 |
| 2338 | /* TODO: Figure out when short_preamble would be set and cache from |
| 2339 | * that */ |
| 2340 | if (!hw_to_local(priv->hw)->short_preamble) |
| 2341 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2342 | else |
| 2343 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2344 | #endif |
| 2345 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2346 | ch_info = iwl4965_get_channel_info(priv, priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2347 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2348 | |
| 2349 | if (!ch_info) |
| 2350 | ch_info = &priv->channel_info[0]; |
| 2351 | |
| 2352 | /* |
| 2353 | * in some case A channels are all non IBSS |
| 2354 | * in this case force B/G channel |
| 2355 | */ |
| 2356 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 2357 | !(is_channel_ibss(ch_info))) |
| 2358 | ch_info = &priv->channel_info[0]; |
| 2359 | |
| 2360 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2361 | priv->band = ch_info->band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2362 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2363 | iwl4965_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2364 | |
| 2365 | priv->staging_rxon.ofdm_basic_rates = |
| 2366 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2367 | priv->staging_rxon.cck_basic_rates = |
| 2368 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2369 | |
| 2370 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 2371 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 2372 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2373 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 2374 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 2375 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
| 2376 | iwl4965_set_rxon_chain(priv); |
| 2377 | } |
| 2378 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2379 | static int iwl4965_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2380 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2381 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2382 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2383 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2384 | ch_info = iwl4965_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2385 | priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2386 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2387 | |
| 2388 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 2389 | IWL_ERROR("channel %d not IBSS channel\n", |
| 2390 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2391 | return -EINVAL; |
| 2392 | } |
| 2393 | } |
| 2394 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2395 | priv->iw_mode = mode; |
| 2396 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2397 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2398 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2399 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2400 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2401 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2402 | /* dont commit rxon if rf-kill is on*/ |
| 2403 | if (!iwl4965_is_ready_rf(priv)) |
| 2404 | return -EAGAIN; |
| 2405 | |
| 2406 | cancel_delayed_work(&priv->scan_check); |
| 2407 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
| 2408 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 2409 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 2410 | return -EAGAIN; |
| 2411 | } |
| 2412 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2413 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2414 | |
| 2415 | return 0; |
| 2416 | } |
| 2417 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2418 | static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2419 | struct ieee80211_tx_control *ctl, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2420 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2421 | struct sk_buff *skb_frag, |
| 2422 | int last_frag) |
| 2423 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2424 | struct iwl4965_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2425 | |
| 2426 | switch (keyinfo->alg) { |
| 2427 | case ALG_CCMP: |
| 2428 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM; |
| 2429 | memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen); |
Max Stepanov | 8236e18 | 2008-03-12 16:58:48 -0700 | [diff] [blame] | 2430 | if (ctl->flags & IEEE80211_TXCTL_AMPDU) |
| 2431 | cmd->cmd.tx.tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2432 | IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n"); |
| 2433 | break; |
| 2434 | |
| 2435 | case ALG_TKIP: |
| 2436 | #if 0 |
| 2437 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP; |
| 2438 | |
| 2439 | if (last_frag) |
| 2440 | memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8, |
| 2441 | 8); |
| 2442 | else |
| 2443 | memset(cmd->cmd.tx.tkip_mic.byte, 0, 8); |
| 2444 | #endif |
| 2445 | break; |
| 2446 | |
| 2447 | case ALG_WEP: |
| 2448 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP | |
| 2449 | (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT; |
| 2450 | |
| 2451 | if (keyinfo->keylen == 13) |
| 2452 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
| 2453 | |
| 2454 | memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen); |
| 2455 | |
| 2456 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
| 2457 | "with key %d\n", ctl->key_idx); |
| 2458 | break; |
| 2459 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2460 | default: |
| 2461 | printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg); |
| 2462 | break; |
| 2463 | } |
| 2464 | } |
| 2465 | |
| 2466 | /* |
| 2467 | * handle build REPLY_TX command notification. |
| 2468 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2469 | static void iwl4965_build_tx_cmd_basic(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2470 | struct iwl4965_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2471 | struct ieee80211_tx_control *ctrl, |
| 2472 | struct ieee80211_hdr *hdr, |
| 2473 | int is_unicast, u8 std_id) |
| 2474 | { |
| 2475 | __le16 *qc; |
| 2476 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2477 | __le32 tx_flags = cmd->cmd.tx.tx_flags; |
| 2478 | |
| 2479 | cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 2480 | if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) { |
| 2481 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
| 2482 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 2483 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2484 | if (ieee80211_is_probe_response(fc) && |
| 2485 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 2486 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 2487 | } else { |
| 2488 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 2489 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2490 | } |
| 2491 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2492 | if (ieee80211_is_back_request(fc)) |
| 2493 | tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK; |
| 2494 | |
| 2495 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2496 | cmd->cmd.tx.sta_id = std_id; |
| 2497 | if (ieee80211_get_morefrag(hdr)) |
| 2498 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 2499 | |
| 2500 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2501 | if (qc) { |
| 2502 | cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf); |
| 2503 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
| 2504 | } else |
| 2505 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2506 | |
| 2507 | if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) { |
| 2508 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 2509 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
| 2510 | } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { |
| 2511 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 2512 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 2513 | } |
| 2514 | |
| 2515 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 2516 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 2517 | |
| 2518 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
| 2519 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { |
| 2520 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || |
| 2521 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2522 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2523 | else |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2524 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2525 | } else |
| 2526 | cmd->cmd.tx.timeout.pm_frame_timeout = 0; |
| 2527 | |
| 2528 | cmd->cmd.tx.driver_txop = 0; |
| 2529 | cmd->cmd.tx.tx_flags = tx_flags; |
| 2530 | cmd->cmd.tx.next_frame_len = 0; |
| 2531 | } |
| 2532 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2533 | /** |
| 2534 | * iwl4965_get_sta_id - Find station's index within station table |
| 2535 | * |
| 2536 | * If new IBSS station, create new entry in station table |
| 2537 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2538 | static int iwl4965_get_sta_id(struct iwl_priv *priv, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2539 | struct ieee80211_hdr *hdr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2540 | { |
| 2541 | int sta_id; |
| 2542 | u16 fc = le16_to_cpu(hdr->frame_control); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2543 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2544 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2545 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2546 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 2547 | is_multicast_ether_addr(hdr->addr1)) |
| 2548 | return priv->hw_setting.bcast_sta_id; |
| 2549 | |
| 2550 | switch (priv->iw_mode) { |
| 2551 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2552 | /* If we are a client station in a BSS network, use the special |
| 2553 | * AP station entry (that's the only station we communicate with) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2554 | case IEEE80211_IF_TYPE_STA: |
| 2555 | return IWL_AP_ID; |
| 2556 | |
| 2557 | /* If we are an AP, then find the station, or use BCAST */ |
| 2558 | case IEEE80211_IF_TYPE_AP: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2559 | sta_id = iwl4965_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2560 | if (sta_id != IWL_INVALID_STATION) |
| 2561 | return sta_id; |
| 2562 | return priv->hw_setting.bcast_sta_id; |
| 2563 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2564 | /* If this frame is going out to an IBSS network, find the station, |
| 2565 | * or create a new station table entry */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2566 | case IEEE80211_IF_TYPE_IBSS: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2567 | sta_id = iwl4965_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2568 | if (sta_id != IWL_INVALID_STATION) |
| 2569 | return sta_id; |
| 2570 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2571 | /* Create new station table entry */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 2572 | sta_id = iwl4965_add_station_flags(priv, hdr->addr1, |
| 2573 | 0, CMD_ASYNC, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2574 | |
| 2575 | if (sta_id != IWL_INVALID_STATION) |
| 2576 | return sta_id; |
| 2577 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2578 | IWL_DEBUG_DROP("Station %s not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2579 | "Defaulting to broadcast...\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2580 | print_mac(mac, hdr->addr1)); |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2581 | iwl_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2582 | return priv->hw_setting.bcast_sta_id; |
| 2583 | |
| 2584 | default: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2585 | IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2586 | return priv->hw_setting.bcast_sta_id; |
| 2587 | } |
| 2588 | } |
| 2589 | |
| 2590 | /* |
| 2591 | * start REPLY_TX command process |
| 2592 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2593 | static int iwl4965_tx_skb(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2594 | struct sk_buff *skb, struct ieee80211_tx_control *ctl) |
| 2595 | { |
| 2596 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2597 | struct iwl4965_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2598 | u32 *control_flags; |
| 2599 | int txq_id = ctl->queue; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2600 | struct iwl4965_tx_queue *txq = NULL; |
| 2601 | struct iwl4965_queue *q = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2602 | dma_addr_t phys_addr; |
| 2603 | dma_addr_t txcmd_phys; |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2604 | dma_addr_t scratch_phys; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2605 | struct iwl4965_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2606 | u16 len, idx, len_org; |
| 2607 | u8 id, hdr_len, unicast; |
| 2608 | u8 sta_id; |
| 2609 | u16 seq_number = 0; |
| 2610 | u16 fc; |
| 2611 | __le16 *qc; |
| 2612 | u8 wait_write_ptr = 0; |
| 2613 | unsigned long flags; |
| 2614 | int rc; |
| 2615 | |
| 2616 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2617 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2618 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 2619 | goto drop_unlock; |
| 2620 | } |
| 2621 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 2622 | if (!priv->vif) { |
| 2623 | IWL_DEBUG_DROP("Dropping - !priv->vif\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2624 | goto drop_unlock; |
| 2625 | } |
| 2626 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2627 | if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2628 | IWL_ERROR("ERROR: No TX rate available.\n"); |
| 2629 | goto drop_unlock; |
| 2630 | } |
| 2631 | |
| 2632 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 2633 | id = 0; |
| 2634 | |
| 2635 | fc = le16_to_cpu(hdr->frame_control); |
| 2636 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2637 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2638 | if (ieee80211_is_auth(fc)) |
| 2639 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
| 2640 | else if (ieee80211_is_assoc_request(fc)) |
| 2641 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
| 2642 | else if (ieee80211_is_reassoc_request(fc)) |
| 2643 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 2644 | #endif |
| 2645 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2646 | /* drop all data frame if we are not associated */ |
Gregory Greenman | 76f3915 | 2008-01-23 10:15:21 -0800 | [diff] [blame] | 2647 | if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) && |
| 2648 | (!iwl4965_is_associated(priv) || |
Reinette Chatre | a647724 | 2008-02-14 10:40:28 -0800 | [diff] [blame] | 2649 | ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id) || |
Gregory Greenman | 76f3915 | 2008-01-23 10:15:21 -0800 | [diff] [blame] | 2650 | !priv->assoc_station_added)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2651 | IWL_DEBUG_DROP("Dropping - !iwl4965_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2652 | goto drop_unlock; |
| 2653 | } |
| 2654 | |
| 2655 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2656 | |
| 2657 | hdr_len = ieee80211_get_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2658 | |
| 2659 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2660 | sta_id = iwl4965_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2661 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2662 | DECLARE_MAC_BUF(mac); |
| 2663 | |
| 2664 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n", |
| 2665 | print_mac(mac, hdr->addr1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2666 | goto drop; |
| 2667 | } |
| 2668 | |
| 2669 | IWL_DEBUG_RATE("station Id %d\n", sta_id); |
| 2670 | |
| 2671 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2672 | if (qc) { |
| 2673 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2674 | seq_number = priv->stations[sta_id].tid[tid].seq_number & |
| 2675 | IEEE80211_SCTL_SEQ; |
| 2676 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 2677 | (hdr->seq_ctrl & |
| 2678 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 2679 | seq_number += 0x10; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2680 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2681 | /* aggregation is on for this <sta,tid> */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2682 | if (ctl->flags & IEEE80211_TXCTL_AMPDU) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2683 | txq_id = priv->stations[sta_id].tid[tid].agg.txq_id; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2684 | priv->stations[sta_id].tid[tid].tfds_in_queue++; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2685 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2686 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2687 | |
| 2688 | /* Descriptor for chosen Tx queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2689 | txq = &priv->txq[txq_id]; |
| 2690 | q = &txq->q; |
| 2691 | |
| 2692 | spin_lock_irqsave(&priv->lock, flags); |
| 2693 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2694 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2695 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2696 | memset(tfd, 0, sizeof(*tfd)); |
| 2697 | control_flags = (u32 *) tfd; |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2698 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2699 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2700 | /* Set up driver data for this TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2701 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2702 | txq->txb[q->write_ptr].skb[0] = skb; |
| 2703 | memcpy(&(txq->txb[q->write_ptr].status.control), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2704 | ctl, sizeof(struct ieee80211_tx_control)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2705 | |
| 2706 | /* 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] | 2707 | out_cmd = &txq->cmd[idx]; |
| 2708 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 2709 | memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2710 | |
| 2711 | /* |
| 2712 | * Set up the Tx-command (not MAC!) header. |
| 2713 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 2714 | * after Tx, uCode's Tx response will return this value so driver can |
| 2715 | * locate the frame within the tx queue and do post-tx processing. |
| 2716 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2717 | out_cmd->hdr.cmd = REPLY_TX; |
| 2718 | 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] | 2719 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2720 | |
| 2721 | /* Copy MAC header from skb into command buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2722 | memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); |
| 2723 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2724 | /* |
| 2725 | * Use the first empty entry in this queue's command buffer array |
| 2726 | * to contain the Tx command and MAC header concatenated together |
| 2727 | * (payload data will be in another buffer). |
| 2728 | * Size of this varies, due to varying MAC header length. |
| 2729 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 2730 | * of the MAC header (device reads on dword boundaries). |
| 2731 | * We'll tell device about this padding later. |
| 2732 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2733 | len = priv->hw_setting.tx_cmd_len + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2734 | sizeof(struct iwl4965_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2735 | |
| 2736 | len_org = len; |
| 2737 | len = (len + 3) & ~3; |
| 2738 | |
| 2739 | if (len_org != len) |
| 2740 | len_org = 1; |
| 2741 | else |
| 2742 | len_org = 0; |
| 2743 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2744 | /* Physical address of this Tx command's header (not MAC header!), |
| 2745 | * within command buffer array. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2746 | txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl4965_cmd) * idx + |
| 2747 | offsetof(struct iwl4965_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2748 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2749 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 2750 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2751 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2752 | |
| 2753 | if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2754 | iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2755 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2756 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 2757 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2758 | len = skb->len - hdr_len; |
| 2759 | if (len) { |
| 2760 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 2761 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2762 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2763 | } |
| 2764 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2765 | /* Tell 4965 about any 2-byte padding after MAC header */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2766 | if (len_org) |
| 2767 | out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK; |
| 2768 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2769 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2770 | len = (u16)skb->len; |
| 2771 | out_cmd->cmd.tx.len = cpu_to_le16(len); |
| 2772 | |
| 2773 | /* TODO need this for burst mode later on */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2774 | 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] | 2775 | |
| 2776 | /* set is_hcca to 0; it probably will never be implemented */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2777 | 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] | 2778 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2779 | scratch_phys = txcmd_phys + sizeof(struct iwl4965_cmd_header) + |
| 2780 | offsetof(struct iwl4965_tx_cmd, scratch); |
| 2781 | out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys); |
| 2782 | out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys); |
| 2783 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2784 | if (!ieee80211_get_morefrag(hdr)) { |
| 2785 | txq->need_update = 1; |
| 2786 | if (qc) { |
| 2787 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2788 | priv->stations[sta_id].tid[tid].seq_number = seq_number; |
| 2789 | } |
| 2790 | } else { |
| 2791 | wait_write_ptr = 1; |
| 2792 | txq->need_update = 0; |
| 2793 | } |
| 2794 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2795 | iwl_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2796 | sizeof(out_cmd->cmd.tx)); |
| 2797 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2798 | iwl_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2799 | ieee80211_get_hdrlen(fc)); |
| 2800 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2801 | /* Set up entry for this TFD in Tx byte-count array */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2802 | iwl4965_tx_queue_update_wr_ptr(priv, txq, len); |
| 2803 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2804 | /* Tell device the write index *just past* this latest filled TFD */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2805 | q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2806 | rc = iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2807 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2808 | |
| 2809 | if (rc) |
| 2810 | return rc; |
| 2811 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2812 | if ((iwl4965_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2813 | && priv->mac80211_registered) { |
| 2814 | if (wait_write_ptr) { |
| 2815 | spin_lock_irqsave(&priv->lock, flags); |
| 2816 | txq->need_update = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2817 | iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2818 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2819 | } |
| 2820 | |
| 2821 | ieee80211_stop_queue(priv->hw, ctl->queue); |
| 2822 | } |
| 2823 | |
| 2824 | return 0; |
| 2825 | |
| 2826 | drop_unlock: |
| 2827 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2828 | drop: |
| 2829 | return -1; |
| 2830 | } |
| 2831 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2832 | static void iwl4965_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2833 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2834 | const struct ieee80211_supported_band *hw = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2835 | struct ieee80211_rate *rate; |
| 2836 | int i; |
| 2837 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2838 | hw = iwl4965_get_hw_mode(priv, priv->band); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 2839 | if (!hw) { |
| 2840 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 2841 | return; |
| 2842 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2843 | |
| 2844 | priv->active_rate = 0; |
| 2845 | priv->active_rate_basic = 0; |
| 2846 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2847 | for (i = 0; i < hw->n_bitrates; i++) { |
| 2848 | rate = &(hw->bitrates[i]); |
| 2849 | if (rate->hw_value < IWL_RATE_COUNT) |
| 2850 | priv->active_rate |= (1 << rate->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 2854 | priv->active_rate, priv->active_rate_basic); |
| 2855 | |
| 2856 | /* |
| 2857 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 2858 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 2859 | * OFDM |
| 2860 | */ |
| 2861 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 2862 | priv->staging_rxon.cck_basic_rates = |
| 2863 | ((priv->active_rate_basic & |
| 2864 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2865 | else |
| 2866 | priv->staging_rxon.cck_basic_rates = |
| 2867 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2868 | |
| 2869 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 2870 | priv->staging_rxon.ofdm_basic_rates = |
| 2871 | ((priv->active_rate_basic & |
| 2872 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 2873 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2874 | else |
| 2875 | priv->staging_rxon.ofdm_basic_rates = |
| 2876 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2877 | } |
| 2878 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2879 | static void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2880 | { |
| 2881 | unsigned long flags; |
| 2882 | |
| 2883 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 2884 | return; |
| 2885 | |
| 2886 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 2887 | disable_radio ? "OFF" : "ON"); |
| 2888 | |
| 2889 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2890 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2891 | /* FIXME: This is a workaround for AP */ |
| 2892 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 2893 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2894 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2895 | CSR_UCODE_SW_BIT_RFKILL); |
| 2896 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2897 | iwl4965_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2898 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2899 | } |
| 2900 | return; |
| 2901 | } |
| 2902 | |
| 2903 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2904 | 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] | 2905 | |
| 2906 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2907 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2908 | |
| 2909 | /* wake up ucode */ |
| 2910 | msleep(10); |
| 2911 | |
| 2912 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2913 | iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
| 2914 | if (!iwl4965_grab_nic_access(priv)) |
| 2915 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2916 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2917 | |
| 2918 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 2919 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 2920 | "disabled by HW switch\n"); |
| 2921 | return; |
| 2922 | } |
| 2923 | |
| 2924 | queue_work(priv->workqueue, &priv->restart); |
| 2925 | return; |
| 2926 | } |
| 2927 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2928 | void iwl4965_set_decrypted_flag(struct iwl_priv *priv, struct sk_buff *skb, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2929 | u32 decrypt_res, struct ieee80211_rx_status *stats) |
| 2930 | { |
| 2931 | u16 fc = |
| 2932 | le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control); |
| 2933 | |
| 2934 | if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
| 2935 | return; |
| 2936 | |
| 2937 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 2938 | return; |
| 2939 | |
| 2940 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 2941 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 2942 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 2943 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2944 | RX_RES_STATUS_BAD_ICV_MIC) |
| 2945 | stats->flag |= RX_FLAG_MMIC_ERROR; |
| 2946 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 2947 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 2948 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2949 | RX_RES_STATUS_DECRYPT_OK) { |
| 2950 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 2951 | stats->flag |= RX_FLAG_DECRYPTED; |
| 2952 | } |
| 2953 | break; |
| 2954 | |
| 2955 | default: |
| 2956 | break; |
| 2957 | } |
| 2958 | } |
| 2959 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2960 | |
| 2961 | #define IWL_PACKET_RETRY_TIME HZ |
| 2962 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 2963 | int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2964 | { |
| 2965 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 2966 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 2967 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 2968 | u16 *last_seq, *last_frag; |
| 2969 | unsigned long *last_time; |
| 2970 | |
| 2971 | switch (priv->iw_mode) { |
| 2972 | case IEEE80211_IF_TYPE_IBSS:{ |
| 2973 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2974 | struct iwl4965_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2975 | u8 *mac = header->addr2; |
| 2976 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 2977 | |
| 2978 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2979 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2980 | if (!compare_ether_addr(entry->mac, mac)) |
| 2981 | break; |
| 2982 | } |
| 2983 | if (p == &priv->ibss_mac_hash[index]) { |
| 2984 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 2985 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2986 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2987 | return 0; |
| 2988 | } |
| 2989 | memcpy(entry->mac, mac, ETH_ALEN); |
| 2990 | entry->seq_num = seq; |
| 2991 | entry->frag_num = frag; |
| 2992 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2993 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2994 | return 0; |
| 2995 | } |
| 2996 | last_seq = &entry->seq_num; |
| 2997 | last_frag = &entry->frag_num; |
| 2998 | last_time = &entry->packet_time; |
| 2999 | break; |
| 3000 | } |
| 3001 | case IEEE80211_IF_TYPE_STA: |
| 3002 | last_seq = &priv->last_seq_num; |
| 3003 | last_frag = &priv->last_frag_num; |
| 3004 | last_time = &priv->last_packet_time; |
| 3005 | break; |
| 3006 | default: |
| 3007 | return 0; |
| 3008 | } |
| 3009 | if ((*last_seq == seq) && |
| 3010 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 3011 | if (*last_frag == frag) |
| 3012 | goto drop; |
| 3013 | if (*last_frag + 1 != frag) |
| 3014 | /* out-of-order fragment */ |
| 3015 | goto drop; |
| 3016 | } else |
| 3017 | *last_seq = seq; |
| 3018 | |
| 3019 | *last_frag = frag; |
| 3020 | *last_time = jiffies; |
| 3021 | return 0; |
| 3022 | |
| 3023 | drop: |
| 3024 | return 1; |
| 3025 | } |
| 3026 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3027 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3028 | |
| 3029 | #include "iwl-spectrum.h" |
| 3030 | |
| 3031 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 3032 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 3033 | #define TIME_UNIT 1024 |
| 3034 | |
| 3035 | /* |
| 3036 | * extended beacon time format |
| 3037 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 3038 | * the high 1 byte is the beacon counts |
| 3039 | * the lower 3 bytes is the time in usec within one beacon interval |
| 3040 | */ |
| 3041 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3042 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3043 | { |
| 3044 | u32 quot; |
| 3045 | u32 rem; |
| 3046 | u32 interval = beacon_interval * 1024; |
| 3047 | |
| 3048 | if (!interval || !usec) |
| 3049 | return 0; |
| 3050 | |
| 3051 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 3052 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 3053 | |
| 3054 | return (quot << 24) + rem; |
| 3055 | } |
| 3056 | |
| 3057 | /* base is usually what we get from ucode with each received frame, |
| 3058 | * the same as HW timer counter counting down |
| 3059 | */ |
| 3060 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3061 | 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] | 3062 | { |
| 3063 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 3064 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 3065 | u32 interval = beacon_interval * TIME_UNIT; |
| 3066 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 3067 | (addon & BEACON_TIME_MASK_HIGH); |
| 3068 | |
| 3069 | if (base_low > addon_low) |
| 3070 | res += base_low - addon_low; |
| 3071 | else if (base_low < addon_low) { |
| 3072 | res += interval + base_low - addon_low; |
| 3073 | res += (1 << 24); |
| 3074 | } else |
| 3075 | res += (1 << 24); |
| 3076 | |
| 3077 | return cpu_to_le32(res); |
| 3078 | } |
| 3079 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3080 | static int iwl4965_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3081 | struct ieee80211_measurement_params *params, |
| 3082 | u8 type) |
| 3083 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3084 | struct iwl4965_spectrum_cmd spectrum; |
| 3085 | struct iwl4965_rx_packet *res; |
| 3086 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3087 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 3088 | .data = (void *)&spectrum, |
| 3089 | .meta.flags = CMD_WANT_SKB, |
| 3090 | }; |
| 3091 | u32 add_time = le64_to_cpu(params->start_time); |
| 3092 | int rc; |
| 3093 | int spectrum_resp_status; |
| 3094 | int duration = le16_to_cpu(params->duration); |
| 3095 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3096 | if (iwl4965_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3097 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3098 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3099 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 3100 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3101 | |
| 3102 | memset(&spectrum, 0, sizeof(spectrum)); |
| 3103 | |
| 3104 | spectrum.channel_count = cpu_to_le16(1); |
| 3105 | spectrum.flags = |
| 3106 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 3107 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 3108 | cmd.len = sizeof(spectrum); |
| 3109 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 3110 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3111 | if (iwl4965_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3112 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3113 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3114 | add_time, |
| 3115 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3116 | else |
| 3117 | spectrum.start_time = 0; |
| 3118 | |
| 3119 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 3120 | spectrum.channels[0].channel = params->channel; |
| 3121 | spectrum.channels[0].type = type; |
| 3122 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 3123 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 3124 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 3125 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3126 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3127 | if (rc) |
| 3128 | return rc; |
| 3129 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3130 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3131 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 3132 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 3133 | rc = -EIO; |
| 3134 | } |
| 3135 | |
| 3136 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 3137 | switch (spectrum_resp_status) { |
| 3138 | case 0: /* Command will be handled */ |
| 3139 | if (res->u.spectrum.id != 0xff) { |
| 3140 | IWL_DEBUG_INFO |
| 3141 | ("Replaced existing measurement: %d\n", |
| 3142 | res->u.spectrum.id); |
| 3143 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 3144 | } |
| 3145 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 3146 | rc = 0; |
| 3147 | break; |
| 3148 | |
| 3149 | case 1: /* Command will not be handled */ |
| 3150 | rc = -EAGAIN; |
| 3151 | break; |
| 3152 | } |
| 3153 | |
| 3154 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 3155 | |
| 3156 | return rc; |
| 3157 | } |
| 3158 | #endif |
| 3159 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3160 | static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3161 | struct iwl4965_tx_info *tx_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3162 | { |
| 3163 | |
| 3164 | tx_sta->status.ack_signal = 0; |
| 3165 | tx_sta->status.excessive_retries = 0; |
| 3166 | tx_sta->status.queue_length = 0; |
| 3167 | tx_sta->status.queue_number = 0; |
| 3168 | |
| 3169 | if (in_interrupt()) |
| 3170 | ieee80211_tx_status_irqsafe(priv->hw, |
| 3171 | tx_sta->skb[0], &(tx_sta->status)); |
| 3172 | else |
| 3173 | ieee80211_tx_status(priv->hw, |
| 3174 | tx_sta->skb[0], &(tx_sta->status)); |
| 3175 | |
| 3176 | tx_sta->skb[0] = NULL; |
| 3177 | } |
| 3178 | |
| 3179 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3180 | * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3181 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3182 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 3183 | * need to be reclaimed. As result, some free space forms. If there is |
| 3184 | * enough free space (> low mark), wake the stack that feeds us. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3185 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3186 | int iwl4965_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3187 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3188 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
| 3189 | struct iwl4965_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3190 | int nfreed = 0; |
| 3191 | |
| 3192 | if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) { |
| 3193 | IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " |
| 3194 | "is out of range [0-%d] %d %d.\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3195 | index, q->n_bd, q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3196 | return 0; |
| 3197 | } |
| 3198 | |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 3199 | for (index = iwl_queue_inc_wrap(index, q->n_bd); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3200 | q->read_ptr != index; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 3201 | q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3202 | if (txq_id != IWL_CMD_QUEUE_NUM) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3203 | iwl4965_txstatus_to_ieee(priv, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3204 | &(txq->txb[txq->q.read_ptr])); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3205 | iwl4965_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3206 | } else if (nfreed > 1) { |
| 3207 | IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3208 | q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3209 | queue_work(priv->workqueue, &priv->restart); |
| 3210 | } |
| 3211 | nfreed++; |
| 3212 | } |
| 3213 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3214 | /* if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3215 | (txq_id != IWL_CMD_QUEUE_NUM) && |
| 3216 | priv->mac80211_registered) |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3217 | ieee80211_wake_queue(priv->hw, txq_id); */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3218 | |
| 3219 | |
| 3220 | return nfreed; |
| 3221 | } |
| 3222 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3223 | static int iwl4965_is_tx_success(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3224 | { |
| 3225 | status &= TX_STATUS_MSK; |
| 3226 | return (status == TX_STATUS_SUCCESS) |
| 3227 | || (status == TX_STATUS_DIRECT_DONE); |
| 3228 | } |
| 3229 | |
| 3230 | /****************************************************************************** |
| 3231 | * |
| 3232 | * Generic RX handler implementations |
| 3233 | * |
| 3234 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3235 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3236 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3237 | static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3238 | struct ieee80211_hdr *hdr) |
| 3239 | { |
| 3240 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) |
| 3241 | return IWL_AP_ID; |
| 3242 | else { |
| 3243 | u8 *da = ieee80211_get_DA(hdr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3244 | return iwl4965_hw_find_station(priv, da); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3245 | } |
| 3246 | } |
| 3247 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3248 | static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr( |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3249 | struct iwl_priv *priv, int txq_id, int idx) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3250 | { |
| 3251 | if (priv->txq[txq_id].txb[idx].skb[0]) |
| 3252 | return (struct ieee80211_hdr *)priv->txq[txq_id]. |
| 3253 | txb[idx].skb[0]->data; |
| 3254 | return NULL; |
| 3255 | } |
| 3256 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3257 | 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] | 3258 | { |
| 3259 | __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + |
| 3260 | tx_resp->frame_count); |
| 3261 | return le32_to_cpu(*scd_ssn) & MAX_SN; |
| 3262 | |
| 3263 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3264 | |
| 3265 | /** |
| 3266 | * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue |
| 3267 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3268 | static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3269 | struct iwl4965_ht_agg *agg, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3270 | struct iwl4965_tx_resp_agg *tx_resp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3271 | u16 start_idx) |
| 3272 | { |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3273 | u16 status; |
| 3274 | struct agg_tx_status *frame_status = &tx_resp->status; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3275 | struct ieee80211_tx_status *tx_status = NULL; |
| 3276 | struct ieee80211_hdr *hdr = NULL; |
| 3277 | int i, sh; |
| 3278 | int txq_id, idx; |
| 3279 | u16 seq; |
| 3280 | |
| 3281 | if (agg->wait_for_ba) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3282 | IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3283 | |
| 3284 | agg->frame_count = tx_resp->frame_count; |
| 3285 | agg->start_idx = start_idx; |
| 3286 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3287 | agg->bitmap = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3288 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3289 | /* # frames attempted by Tx command */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3290 | if (agg->frame_count == 1) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3291 | /* Only one frame was attempted; no block-ack will arrive */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3292 | status = le16_to_cpu(frame_status[0].status); |
| 3293 | seq = le16_to_cpu(frame_status[0].sequence); |
| 3294 | idx = SEQ_TO_INDEX(seq); |
| 3295 | txq_id = SEQ_TO_QUEUE(seq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3296 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3297 | /* FIXME: code repetition */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3298 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n", |
| 3299 | agg->frame_count, agg->start_idx, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3300 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3301 | tx_status = &(priv->txq[txq_id].txb[idx].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3302 | tx_status->retry_count = tx_resp->failure_frame; |
| 3303 | tx_status->queue_number = status & 0xff; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3304 | tx_status->queue_length = tx_resp->failure_rts; |
| 3305 | tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3306 | tx_status->flags = iwl4965_is_tx_success(status)? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3307 | IEEE80211_TX_STATUS_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 3308 | iwl4965_hwrate_to_tx_control(priv, |
| 3309 | le32_to_cpu(tx_resp->rate_n_flags), |
| 3310 | &tx_status->control); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3311 | /* FIXME: code repetition end */ |
| 3312 | |
| 3313 | IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", |
| 3314 | status & 0xff, tx_resp->failure_frame); |
| 3315 | IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3316 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3317 | |
| 3318 | agg->wait_for_ba = 0; |
| 3319 | } else { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3320 | /* Two or more frames were attempted; expect block-ack */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3321 | u64 bitmap = 0; |
| 3322 | int start = agg->start_idx; |
| 3323 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3324 | /* Construct bit-map of pending frames within Tx window */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3325 | for (i = 0; i < agg->frame_count; i++) { |
| 3326 | u16 sc; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3327 | status = le16_to_cpu(frame_status[i].status); |
| 3328 | seq = le16_to_cpu(frame_status[i].sequence); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3329 | idx = SEQ_TO_INDEX(seq); |
| 3330 | txq_id = SEQ_TO_QUEUE(seq); |
| 3331 | |
| 3332 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 3333 | AGG_TX_STATE_ABORT_MSK)) |
| 3334 | continue; |
| 3335 | |
| 3336 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
| 3337 | agg->frame_count, txq_id, idx); |
| 3338 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3339 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3340 | |
| 3341 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 3342 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
| 3343 | IWL_ERROR("BUG_ON idx doesn't match seq control" |
| 3344 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 3345 | idx, SEQ_TO_SN(sc), |
| 3346 | hdr->seq_ctrl); |
| 3347 | return -1; |
| 3348 | } |
| 3349 | |
| 3350 | IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
| 3351 | i, idx, SEQ_TO_SN(sc)); |
| 3352 | |
| 3353 | sh = idx - start; |
| 3354 | if (sh > 64) { |
| 3355 | sh = (start - idx) + 0xff; |
| 3356 | bitmap = bitmap << sh; |
| 3357 | sh = 0; |
| 3358 | start = idx; |
| 3359 | } else if (sh < -64) |
| 3360 | sh = 0xff - (start - idx); |
| 3361 | else if (sh < 0) { |
| 3362 | sh = start - idx; |
| 3363 | start = idx; |
| 3364 | bitmap = bitmap << sh; |
| 3365 | sh = 0; |
| 3366 | } |
| 3367 | bitmap |= (1 << sh); |
| 3368 | IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n", |
| 3369 | start, (u32)(bitmap & 0xFFFFFFFF)); |
| 3370 | } |
| 3371 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3372 | agg->bitmap = bitmap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3373 | agg->start_idx = start; |
| 3374 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3375 | 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] | 3376 | agg->frame_count, agg->start_idx, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3377 | agg->bitmap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3378 | |
| 3379 | if (bitmap) |
| 3380 | agg->wait_for_ba = 1; |
| 3381 | } |
| 3382 | return 0; |
| 3383 | } |
| 3384 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3385 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3386 | /** |
| 3387 | * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response |
| 3388 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3389 | static void iwl4965_rx_reply_tx(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3390 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3391 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3392 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3393 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3394 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3395 | int index = SEQ_TO_INDEX(sequence); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3396 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3397 | struct ieee80211_tx_status *tx_status; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3398 | struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3399 | u32 status = le32_to_cpu(tx_resp->status); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3400 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3401 | int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION; |
| 3402 | struct ieee80211_hdr *hdr; |
| 3403 | __le16 *qc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3404 | #endif |
| 3405 | |
| 3406 | if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) { |
| 3407 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 3408 | "is out of range [0-%d] %d %d\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3409 | index, txq->q.n_bd, txq->q.write_ptr, |
| 3410 | txq->q.read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3411 | return; |
| 3412 | } |
| 3413 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3414 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3415 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index); |
| 3416 | qc = ieee80211_get_qos_ctrl(hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3417 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3418 | if (qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3419 | tid = le16_to_cpu(*qc) & 0xf; |
| 3420 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3421 | sta_id = iwl4965_get_ra_sta_id(priv, hdr); |
| 3422 | if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) { |
| 3423 | IWL_ERROR("Station not known\n"); |
| 3424 | return; |
| 3425 | } |
| 3426 | |
| 3427 | if (txq->sched_retry) { |
| 3428 | const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp); |
| 3429 | struct iwl4965_ht_agg *agg = NULL; |
| 3430 | |
| 3431 | if (!qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3432 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3433 | |
| 3434 | agg = &priv->stations[sta_id].tid[tid].agg; |
| 3435 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3436 | iwl4965_tx_status_reply_tx(priv, agg, |
| 3437 | (struct iwl4965_tx_resp_agg *)tx_resp, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3438 | |
| 3439 | if ((tx_resp->frame_count == 1) && |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3440 | !iwl4965_is_tx_success(status)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3441 | /* TODO: send BAR */ |
| 3442 | } |
| 3443 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3444 | if (txq->q.read_ptr != (scd_ssn & 0xff)) { |
| 3445 | int freed; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 3446 | index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3447 | IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " |
| 3448 | "%d index %d\n", scd_ssn , index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3449 | freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
| 3450 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 3451 | |
| 3452 | if (iwl4965_queue_space(&txq->q) > txq->q.low_mark && |
| 3453 | txq_id >= 0 && priv->mac80211_registered && |
| 3454 | agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) |
| 3455 | ieee80211_wake_queue(priv->hw, txq_id); |
| 3456 | |
| 3457 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3458 | } |
| 3459 | } else { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3460 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3461 | tx_status = &(txq->txb[txq->q.read_ptr].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3462 | |
| 3463 | tx_status->retry_count = tx_resp->failure_frame; |
| 3464 | tx_status->queue_number = status; |
| 3465 | tx_status->queue_length = tx_resp->bt_kill_count; |
| 3466 | tx_status->queue_length |= tx_resp->failure_rts; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3467 | tx_status->flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3468 | iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 3469 | iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags), |
| 3470 | &tx_status->control); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3471 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3472 | 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] | 3473 | "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3474 | status, le32_to_cpu(tx_resp->rate_n_flags), |
| 3475 | tx_resp->failure_frame); |
| 3476 | |
| 3477 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3478 | if (index != -1) { |
| 3479 | int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3480 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3481 | if (tid != MAX_TID_COUNT) |
| 3482 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 3483 | if (iwl4965_queue_space(&txq->q) > txq->q.low_mark && |
| 3484 | (txq_id >= 0) && |
| 3485 | priv->mac80211_registered) |
| 3486 | ieee80211_wake_queue(priv->hw, txq_id); |
| 3487 | if (tid != MAX_TID_COUNT) |
| 3488 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
| 3489 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3490 | } |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3491 | #ifdef CONFIG_IWL4965_HT |
| 3492 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3493 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3494 | |
| 3495 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 3496 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 3497 | } |
| 3498 | |
| 3499 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3500 | static void iwl4965_rx_reply_alive(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3501 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3502 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3503 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3504 | struct iwl4965_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3505 | struct delayed_work *pwork; |
| 3506 | |
| 3507 | palive = &pkt->u.alive_frame; |
| 3508 | |
| 3509 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 3510 | "0x%01X 0x%01X\n", |
| 3511 | palive->is_valid, palive->ver_type, |
| 3512 | palive->ver_subtype); |
| 3513 | |
| 3514 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 3515 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 3516 | memcpy(&priv->card_alive_init, |
| 3517 | &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3518 | sizeof(struct iwl4965_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3519 | pwork = &priv->init_alive_start; |
| 3520 | } else { |
| 3521 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 3522 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3523 | sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3524 | pwork = &priv->alive_start; |
| 3525 | } |
| 3526 | |
| 3527 | /* We delay the ALIVE response by 5ms to |
| 3528 | * give the HW RF Kill time to activate... */ |
| 3529 | if (palive->is_valid == UCODE_VALID_OK) |
| 3530 | queue_delayed_work(priv->workqueue, pwork, |
| 3531 | msecs_to_jiffies(5)); |
| 3532 | else |
| 3533 | IWL_WARNING("uCode did not respond OK.\n"); |
| 3534 | } |
| 3535 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3536 | static void iwl4965_rx_reply_add_sta(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3537 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3538 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3539 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3540 | |
| 3541 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 3542 | return; |
| 3543 | } |
| 3544 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3545 | static void iwl4965_rx_reply_error(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3546 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3547 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3548 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3549 | |
| 3550 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 3551 | "seq 0x%04X ser 0x%08X\n", |
| 3552 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 3553 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 3554 | pkt->u.err_resp.cmd_id, |
| 3555 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 3556 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 3557 | } |
| 3558 | |
| 3559 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 3560 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3561 | static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3562 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3563 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3564 | struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon; |
| 3565 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3566 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 3567 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 3568 | rxon->channel = csa->channel; |
| 3569 | priv->staging_rxon.channel = csa->channel; |
| 3570 | } |
| 3571 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3572 | static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3573 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3574 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3575 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3576 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3577 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3578 | |
| 3579 | if (!report->state) { |
| 3580 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 3581 | "Spectrum Measure Notification: Start\n"); |
| 3582 | return; |
| 3583 | } |
| 3584 | |
| 3585 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 3586 | priv->measurement_status |= MEASUREMENT_READY; |
| 3587 | #endif |
| 3588 | } |
| 3589 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3590 | static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3591 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3592 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3593 | #ifdef CONFIG_IWLWIFI_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3594 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3595 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3596 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 3597 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 3598 | #endif |
| 3599 | } |
| 3600 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3601 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3602 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3603 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3604 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3605 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 3606 | "notification for %s:\n", |
| 3607 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3608 | iwl_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] | 3609 | } |
| 3610 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3611 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3612 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3613 | struct iwl_priv *priv = |
| 3614 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3615 | struct sk_buff *beacon; |
| 3616 | |
| 3617 | /* 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] | 3618 | beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3619 | |
| 3620 | if (!beacon) { |
| 3621 | IWL_ERROR("update beacon failed\n"); |
| 3622 | return; |
| 3623 | } |
| 3624 | |
| 3625 | mutex_lock(&priv->mutex); |
| 3626 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 3627 | if (priv->ibss_beacon) |
| 3628 | dev_kfree_skb(priv->ibss_beacon); |
| 3629 | |
| 3630 | priv->ibss_beacon = beacon; |
| 3631 | mutex_unlock(&priv->mutex); |
| 3632 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3633 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3634 | } |
| 3635 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3636 | static void iwl4965_rx_beacon_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3637 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3638 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3639 | #ifdef CONFIG_IWLWIFI_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3640 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3641 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 3642 | 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] | 3643 | |
| 3644 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 3645 | "tsf %d %d rate %d\n", |
| 3646 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 3647 | beacon->beacon_notify_hdr.failure_frame, |
| 3648 | le32_to_cpu(beacon->ibss_mgr_status), |
| 3649 | le32_to_cpu(beacon->high_tsf), |
| 3650 | le32_to_cpu(beacon->low_tsf), rate); |
| 3651 | #endif |
| 3652 | |
| 3653 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 3654 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 3655 | queue_work(priv->workqueue, &priv->beacon_update); |
| 3656 | } |
| 3657 | |
| 3658 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3659 | static void iwl4965_rx_reply_scan(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3660 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3661 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3662 | #ifdef CONFIG_IWLWIFI_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3663 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3664 | struct iwl4965_scanreq_notification *notif = |
| 3665 | (struct iwl4965_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3666 | |
| 3667 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 3668 | #endif |
| 3669 | } |
| 3670 | |
| 3671 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3672 | static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3673 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3674 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3675 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3676 | struct iwl4965_scanstart_notification *notif = |
| 3677 | (struct iwl4965_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3678 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 3679 | IWL_DEBUG_SCAN("Scan start: " |
| 3680 | "%d [802.11%s] " |
| 3681 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 3682 | notif->channel, |
| 3683 | notif->band ? "bg" : "a", |
| 3684 | notif->tsf_high, |
| 3685 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 3686 | } |
| 3687 | |
| 3688 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3689 | static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3690 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3691 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3692 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3693 | struct iwl4965_scanresults_notification *notif = |
| 3694 | (struct iwl4965_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3695 | |
| 3696 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 3697 | "%d [802.11%s] " |
| 3698 | "(TSF: 0x%08X:%08X) - %d " |
| 3699 | "elapsed=%lu usec (%dms since last)\n", |
| 3700 | notif->channel, |
| 3701 | notif->band ? "bg" : "a", |
| 3702 | le32_to_cpu(notif->tsf_high), |
| 3703 | le32_to_cpu(notif->tsf_low), |
| 3704 | le32_to_cpu(notif->statistics[0]), |
| 3705 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 3706 | jiffies_to_msecs(elapsed_jiffies |
| 3707 | (priv->last_scan_jiffies, jiffies))); |
| 3708 | |
| 3709 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3710 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3711 | } |
| 3712 | |
| 3713 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3714 | static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3715 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3716 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3717 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3718 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3719 | |
| 3720 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 3721 | scan_notif->scanned_channels, |
| 3722 | scan_notif->tsf_low, |
| 3723 | scan_notif->tsf_high, scan_notif->status); |
| 3724 | |
| 3725 | /* The HW is no longer scanning */ |
| 3726 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 3727 | |
| 3728 | /* The scan completion notification came in, so kill that timer... */ |
| 3729 | cancel_delayed_work(&priv->scan_check); |
| 3730 | |
| 3731 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 3732 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 3733 | jiffies_to_msecs(elapsed_jiffies |
| 3734 | (priv->scan_pass_start, jiffies))); |
| 3735 | |
| 3736 | /* Remove this scanned band from the list |
| 3737 | * of pending bands to scan */ |
| 3738 | priv->scan_bands--; |
| 3739 | |
| 3740 | /* If a request to abort was given, or the scan did not succeed |
| 3741 | * then we reset the scan state machine and terminate, |
| 3742 | * re-queuing another scan if one has been requested */ |
| 3743 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 3744 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 3745 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 3746 | } else { |
| 3747 | /* If there are more bands on this scan pass reschedule */ |
| 3748 | if (priv->scan_bands > 0) |
| 3749 | goto reschedule; |
| 3750 | } |
| 3751 | |
| 3752 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3753 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3754 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 3755 | |
| 3756 | clear_bit(STATUS_SCANNING, &priv->status); |
| 3757 | |
| 3758 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 3759 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 3760 | |
| 3761 | queue_work(priv->workqueue, &priv->scan_completed); |
| 3762 | |
| 3763 | return; |
| 3764 | |
| 3765 | reschedule: |
| 3766 | priv->scan_pass_start = jiffies; |
| 3767 | queue_work(priv->workqueue, &priv->request_scan); |
| 3768 | } |
| 3769 | |
| 3770 | /* Handle notification from uCode that card's power state is changing |
| 3771 | * due to software, hardware, or critical temperature RFKILL */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3772 | static void iwl4965_rx_card_state_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3773 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3774 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3775 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3776 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 3777 | unsigned long status = priv->status; |
| 3778 | |
| 3779 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 3780 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 3781 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 3782 | |
| 3783 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 3784 | RF_CARD_DISABLED)) { |
| 3785 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3786 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3787 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 3788 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3789 | if (!iwl4965_grab_nic_access(priv)) { |
| 3790 | iwl4965_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3791 | priv, HBUS_TARG_MBX_C, |
| 3792 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 3793 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3794 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3795 | } |
| 3796 | |
| 3797 | if (!(flags & RXON_CARD_DISABLED)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3798 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3799 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3800 | if (!iwl4965_grab_nic_access(priv)) { |
| 3801 | iwl4965_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3802 | priv, HBUS_TARG_MBX_C, |
| 3803 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 3804 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3805 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3806 | } |
| 3807 | } |
| 3808 | |
| 3809 | if (flags & RF_CARD_DISABLED) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3810 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3811 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3812 | iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
| 3813 | if (!iwl4965_grab_nic_access(priv)) |
| 3814 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3815 | } |
| 3816 | } |
| 3817 | |
| 3818 | if (flags & HW_CARD_DISABLED) |
| 3819 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3820 | else |
| 3821 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3822 | |
| 3823 | |
| 3824 | if (flags & SW_CARD_DISABLED) |
| 3825 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3826 | else |
| 3827 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3828 | |
| 3829 | if (!(flags & RXON_CARD_DISABLED)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3830 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3831 | |
| 3832 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 3833 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 3834 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 3835 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 3836 | queue_work(priv->workqueue, &priv->rf_kill); |
| 3837 | else |
| 3838 | wake_up_interruptible(&priv->wait_command_queue); |
| 3839 | } |
| 3840 | |
| 3841 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3842 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3843 | * |
| 3844 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 3845 | * to the host. |
| 3846 | * |
| 3847 | * This function chains into the hardware specific files for them to setup |
| 3848 | * any hardware specific handlers as well. |
| 3849 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3850 | static void iwl4965_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3851 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3852 | priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive; |
| 3853 | priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta; |
| 3854 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 3855 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3856 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3857 | iwl4965_rx_spectrum_measure_notif; |
| 3858 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3859 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3860 | iwl4965_rx_pm_debug_statistics_notif; |
| 3861 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3862 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3863 | /* |
| 3864 | * The same handler is used for both the REPLY to a discrete |
| 3865 | * statistics request from the host as well as for the periodic |
| 3866 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3867 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3868 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
| 3869 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3870 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3871 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
| 3872 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3873 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3874 | iwl4965_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3875 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3876 | iwl4965_rx_scan_complete_notif; |
| 3877 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
| 3878 | priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3879 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3880 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3881 | iwl4965_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3882 | } |
| 3883 | |
| 3884 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3885 | * 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] | 3886 | * @rxb: Rx buffer to reclaim |
| 3887 | * |
| 3888 | * If an Rx buffer has an async callback associated with it the callback |
| 3889 | * will be executed. The attached skb (if present) will only be freed |
| 3890 | * if the callback returns 1 |
| 3891 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 3892 | static void iwl4965_tx_cmd_complete(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3893 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3894 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3895 | struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3896 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3897 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3898 | int index = SEQ_TO_INDEX(sequence); |
| 3899 | int huge = sequence & SEQ_HUGE_FRAME; |
| 3900 | int cmd_index; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3901 | struct iwl4965_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3902 | |
| 3903 | /* If a Tx command is being handled and it isn't in the actual |
| 3904 | * command queue then there a command routing bug has been introduced |
| 3905 | * in the queue management code. */ |
| 3906 | if (txq_id != IWL_CMD_QUEUE_NUM) |
| 3907 | IWL_ERROR("Error wrong command queue %d command id 0x%X\n", |
| 3908 | txq_id, pkt->hdr.cmd); |
| 3909 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 3910 | |
| 3911 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 3912 | cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
| 3913 | |
| 3914 | /* Input error checking is done when commands are added to queue. */ |
| 3915 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 3916 | cmd->meta.source->u.skb = rxb->skb; |
| 3917 | rxb->skb = NULL; |
| 3918 | } else if (cmd->meta.u.callback && |
| 3919 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 3920 | rxb->skb = NULL; |
| 3921 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3922 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3923 | |
| 3924 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 3925 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3926 | wake_up_interruptible(&priv->wait_command_queue); |
| 3927 | } |
| 3928 | } |
| 3929 | |
| 3930 | /************************** RX-FUNCTIONS ****************************/ |
| 3931 | /* |
| 3932 | * Rx theory of operation |
| 3933 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3934 | * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs), |
| 3935 | * each of which point to Receive Buffers to be filled by 4965. These get |
| 3936 | * used not only for Rx frames, but for any command response or notification |
| 3937 | * from the 4965. The driver and 4965 manage the Rx buffers by means |
| 3938 | * of indexes into the circular buffer. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3939 | * |
| 3940 | * Rx Queue Indexes |
| 3941 | * The host/firmware share two index registers for managing the Rx buffers. |
| 3942 | * |
| 3943 | * The READ index maps to the first position that the firmware may be writing |
| 3944 | * to -- the driver can read up to (but not including) this position and get |
| 3945 | * good data. |
| 3946 | * The READ index is managed by the firmware once the card is enabled. |
| 3947 | * |
| 3948 | * The WRITE index maps to the last position the driver has read from -- the |
| 3949 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 3950 | * |
| 3951 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 3952 | * WRITE = READ. |
| 3953 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3954 | * 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] | 3955 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 3956 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3957 | * 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] | 3958 | * and fire the RX interrupt. The driver can then query the READ index and |
| 3959 | * process as many packets as possible, moving the WRITE index forward as it |
| 3960 | * resets the Rx queue buffers with new memory. |
| 3961 | * |
| 3962 | * The management in the driver is as follows: |
| 3963 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 3964 | * 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] | 3965 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3966 | * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3967 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 3968 | * 'processed' and 'read' driver indexes as well) |
| 3969 | * + A received packet is processed and handed to the kernel network stack, |
| 3970 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 3971 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 3972 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 3973 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 3974 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 3975 | * |
| 3976 | * |
| 3977 | * Driver sequence: |
| 3978 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3979 | * iwl4965_rx_queue_alloc() Allocates rx_free |
| 3980 | * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3981 | * iwl4965_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3982 | * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3983 | * queue, updates firmware pointers, and updates |
| 3984 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3985 | * are available, schedules iwl4965_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3986 | * |
| 3987 | * -- enable interrupts -- |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3988 | * 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] | 3989 | * READ INDEX, detaching the SKB from the pool. |
| 3990 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3991 | * Calls iwl4965_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3992 | * slots. |
| 3993 | * ... |
| 3994 | * |
| 3995 | */ |
| 3996 | |
| 3997 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3998 | * iwl4965_rx_queue_space - Return number of free slots available in queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3999 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4000 | static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4001 | { |
| 4002 | int s = q->read - q->write; |
| 4003 | if (s <= 0) |
| 4004 | s += RX_QUEUE_SIZE; |
| 4005 | /* keep some buffer to not confuse full and empty queue */ |
| 4006 | s -= 2; |
| 4007 | if (s < 0) |
| 4008 | s = 0; |
| 4009 | return s; |
| 4010 | } |
| 4011 | |
| 4012 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4013 | * 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] | 4014 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4015 | int iwl4965_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl4965_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4016 | { |
| 4017 | u32 reg = 0; |
| 4018 | int rc = 0; |
| 4019 | unsigned long flags; |
| 4020 | |
| 4021 | spin_lock_irqsave(&q->lock, flags); |
| 4022 | |
| 4023 | if (q->need_update == 0) |
| 4024 | goto exit_unlock; |
| 4025 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4026 | /* If power-saving is in use, make sure device is awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4027 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4028 | reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4029 | |
| 4030 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4031 | iwl4965_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4032 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4033 | goto exit_unlock; |
| 4034 | } |
| 4035 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4036 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4037 | if (rc) |
| 4038 | goto exit_unlock; |
| 4039 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4040 | /* Device expects a multiple of 8 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4041 | iwl4965_write_direct32(priv, FH_RSCSR_CHNL0_WPTR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4042 | q->write & ~0x7); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4043 | iwl4965_release_nic_access(priv); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4044 | |
| 4045 | /* Else device is assumed to be awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4046 | } else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4047 | /* Device expects a multiple of 8 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4048 | iwl4965_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4049 | |
| 4050 | |
| 4051 | q->need_update = 0; |
| 4052 | |
| 4053 | exit_unlock: |
| 4054 | spin_unlock_irqrestore(&q->lock, flags); |
| 4055 | return rc; |
| 4056 | } |
| 4057 | |
| 4058 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4059 | * 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] | 4060 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4061 | static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4062 | dma_addr_t dma_addr) |
| 4063 | { |
| 4064 | return cpu_to_le32((u32)(dma_addr >> 8)); |
| 4065 | } |
| 4066 | |
| 4067 | |
| 4068 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4069 | * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4070 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4071 | * 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] | 4072 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4073 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4074 | * |
| 4075 | * This moves the 'write' index forward to catch up with 'processed', and |
| 4076 | * also updates the memory address in the firmware to reference the new |
| 4077 | * target buffer. |
| 4078 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4079 | static int iwl4965_rx_queue_restock(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4080 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4081 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4082 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4083 | struct iwl4965_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4084 | unsigned long flags; |
| 4085 | int write, rc; |
| 4086 | |
| 4087 | spin_lock_irqsave(&rxq->lock, flags); |
| 4088 | write = rxq->write & ~0x7; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4089 | while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4090 | /* Get next free Rx buffer, remove from free list */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4091 | element = rxq->rx_free.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4092 | rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4093 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4094 | |
| 4095 | /* Point to Rx buffer via next RBD in circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4096 | rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4097 | rxq->queue[rxq->write] = rxb; |
| 4098 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 4099 | rxq->free_count--; |
| 4100 | } |
| 4101 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4102 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 4103 | * refill it */ |
| 4104 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 4105 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 4106 | |
| 4107 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4108 | /* If we've added more space for the firmware to place data, tell it. |
| 4109 | * Increment device's write pointer in multiples of 8. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4110 | if ((write != (rxq->write & ~0x7)) |
| 4111 | || (abs(rxq->write - rxq->read) > 7)) { |
| 4112 | spin_lock_irqsave(&rxq->lock, flags); |
| 4113 | rxq->need_update = 1; |
| 4114 | spin_unlock_irqrestore(&rxq->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4115 | rc = iwl4965_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4116 | if (rc) |
| 4117 | return rc; |
| 4118 | } |
| 4119 | |
| 4120 | return 0; |
| 4121 | } |
| 4122 | |
| 4123 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4124 | * 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] | 4125 | * |
| 4126 | * When moving to rx_free an SKB is allocated for the slot. |
| 4127 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4128 | * Also restock the Rx queue via iwl4965_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 4129 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4130 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4131 | static void iwl4965_rx_allocate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4132 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4133 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4134 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4135 | struct iwl4965_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4136 | unsigned long flags; |
| 4137 | spin_lock_irqsave(&rxq->lock, flags); |
| 4138 | while (!list_empty(&rxq->rx_used)) { |
| 4139 | element = rxq->rx_used.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4140 | rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4141 | |
| 4142 | /* Alloc a new receive buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4143 | rxb->skb = |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4144 | alloc_skb(priv->hw_setting.rx_buf_size, |
| 4145 | __GFP_NOWARN | GFP_ATOMIC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4146 | if (!rxb->skb) { |
| 4147 | if (net_ratelimit()) |
| 4148 | printk(KERN_CRIT DRV_NAME |
| 4149 | ": Can not allocate SKB buffers\n"); |
| 4150 | /* We don't reschedule replenish work here -- we will |
| 4151 | * call the restock method and if it still needs |
| 4152 | * more buffers it will schedule replenish */ |
| 4153 | break; |
| 4154 | } |
| 4155 | priv->alloc_rxb_skb++; |
| 4156 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4157 | |
| 4158 | /* Get physical address of RB/SKB */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4159 | rxb->dma_addr = |
| 4160 | pci_map_single(priv->pci_dev, rxb->skb->data, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4161 | priv->hw_setting.rx_buf_size, PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4162 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 4163 | rxq->free_count++; |
| 4164 | } |
| 4165 | spin_unlock_irqrestore(&rxq->lock, flags); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | /* |
| 4169 | * this should be called while priv->lock is locked |
| 4170 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 4171 | static void __iwl4965_rx_replenish(void *data) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4172 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4173 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4174 | |
| 4175 | iwl4965_rx_allocate(priv); |
| 4176 | iwl4965_rx_queue_restock(priv); |
| 4177 | } |
| 4178 | |
| 4179 | |
| 4180 | void iwl4965_rx_replenish(void *data) |
| 4181 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4182 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4183 | unsigned long flags; |
| 4184 | |
| 4185 | iwl4965_rx_allocate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4186 | |
| 4187 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4188 | iwl4965_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4189 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4190 | } |
| 4191 | |
| 4192 | /* 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] | 4193 | * 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] | 4194 | * This free routine walks the list of POOL entries and if SKB is set to |
| 4195 | * non NULL it is unmapped and freed |
| 4196 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4197 | static void iwl4965_rx_queue_free(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4198 | { |
| 4199 | int i; |
| 4200 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 4201 | if (rxq->pool[i].skb != NULL) { |
| 4202 | pci_unmap_single(priv->pci_dev, |
| 4203 | rxq->pool[i].dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4204 | priv->hw_setting.rx_buf_size, |
| 4205 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4206 | dev_kfree_skb(rxq->pool[i].skb); |
| 4207 | } |
| 4208 | } |
| 4209 | |
| 4210 | pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd, |
| 4211 | rxq->dma_addr); |
| 4212 | rxq->bd = NULL; |
| 4213 | } |
| 4214 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4215 | int iwl4965_rx_queue_alloc(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4216 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4217 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4218 | struct pci_dev *dev = priv->pci_dev; |
| 4219 | int i; |
| 4220 | |
| 4221 | spin_lock_init(&rxq->lock); |
| 4222 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4223 | INIT_LIST_HEAD(&rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4224 | |
| 4225 | /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4226 | rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr); |
| 4227 | if (!rxq->bd) |
| 4228 | return -ENOMEM; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4229 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4230 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4231 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
| 4232 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4233 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4234 | /* Set us so that we have processed and used all buffers, but have |
| 4235 | * not restocked the Rx queue with fresh buffers */ |
| 4236 | rxq->read = rxq->write = 0; |
| 4237 | rxq->free_count = 0; |
| 4238 | rxq->need_update = 0; |
| 4239 | return 0; |
| 4240 | } |
| 4241 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4242 | void iwl4965_rx_queue_reset(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4243 | { |
| 4244 | unsigned long flags; |
| 4245 | int i; |
| 4246 | spin_lock_irqsave(&rxq->lock, flags); |
| 4247 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4248 | INIT_LIST_HEAD(&rxq->rx_used); |
| 4249 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4250 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 4251 | /* In the reset function, these buffers may have been allocated |
| 4252 | * to an SKB, so we need to unmap and free potential storage */ |
| 4253 | if (rxq->pool[i].skb != NULL) { |
| 4254 | pci_unmap_single(priv->pci_dev, |
| 4255 | rxq->pool[i].dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4256 | priv->hw_setting.rx_buf_size, |
| 4257 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4258 | priv->alloc_rxb_skb--; |
| 4259 | dev_kfree_skb(rxq->pool[i].skb); |
| 4260 | rxq->pool[i].skb = NULL; |
| 4261 | } |
| 4262 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 4263 | } |
| 4264 | |
| 4265 | /* Set us so that we have processed and used all buffers, but have |
| 4266 | * not restocked the Rx queue with fresh buffers */ |
| 4267 | rxq->read = rxq->write = 0; |
| 4268 | rxq->free_count = 0; |
| 4269 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4270 | } |
| 4271 | |
| 4272 | /* Convert linear signal-to-noise ratio into dB */ |
| 4273 | static u8 ratio2dB[100] = { |
| 4274 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 4275 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 4276 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 4277 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 4278 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 4279 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 4280 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 4281 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 4282 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 4283 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 4284 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 4285 | }; |
| 4286 | |
| 4287 | /* Calculates a relative dB value from a ratio of linear |
| 4288 | * (i.e. not dB) signal levels. |
| 4289 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4290 | int iwl4965_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4291 | { |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4292 | /* 1000:1 or higher just report as 60 dB */ |
| 4293 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4294 | return 60; |
| 4295 | |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4296 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4297 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 4298 | if (sig_ratio >= 100) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4299 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 4300 | |
| 4301 | /* We shouldn't see this */ |
| 4302 | if (sig_ratio < 1) |
| 4303 | return 0; |
| 4304 | |
| 4305 | /* Use table for ratios 1:1 - 99:1 */ |
| 4306 | return (int)ratio2dB[sig_ratio]; |
| 4307 | } |
| 4308 | |
| 4309 | #define PERFECT_RSSI (-20) /* dBm */ |
| 4310 | #define WORST_RSSI (-95) /* dBm */ |
| 4311 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 4312 | |
| 4313 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 4314 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 4315 | * about formulas used below. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4316 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4317 | { |
| 4318 | int sig_qual; |
| 4319 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 4320 | |
| 4321 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 4322 | * as indicator; formula is (signal dbm - noise dbm). |
| 4323 | * SNR at or above 40 is a great signal (100%). |
| 4324 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 4325 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 4326 | if (noise_dbm) { |
| 4327 | if (rssi_dbm - noise_dbm >= 40) |
| 4328 | return 100; |
| 4329 | else if (rssi_dbm < noise_dbm) |
| 4330 | return 0; |
| 4331 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 4332 | |
| 4333 | /* Else use just the signal level. |
| 4334 | * This formula is a least squares fit of data points collected and |
| 4335 | * compared with a reference system that had a percentage (%) display |
| 4336 | * for signal quality. */ |
| 4337 | } else |
| 4338 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 4339 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 4340 | (RSSI_RANGE * RSSI_RANGE); |
| 4341 | |
| 4342 | if (sig_qual > 100) |
| 4343 | sig_qual = 100; |
| 4344 | else if (sig_qual < 1) |
| 4345 | sig_qual = 0; |
| 4346 | |
| 4347 | return sig_qual; |
| 4348 | } |
| 4349 | |
| 4350 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4351 | * iwl4965_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4352 | * |
| 4353 | * Uses the priv->rx_handlers callback function array to invoke |
| 4354 | * the appropriate handlers, including command responses, |
| 4355 | * frame-received notifications, and other notifications. |
| 4356 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4357 | static void iwl4965_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4358 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4359 | struct iwl4965_rx_mem_buffer *rxb; |
| 4360 | struct iwl4965_rx_packet *pkt; |
| 4361 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4362 | u32 r, i; |
| 4363 | int reclaim; |
| 4364 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4365 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 4366 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4367 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4368 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 4369 | * buffer that the driver may process (last buffer filled by ucode). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4370 | r = iwl4965_hw_get_rx_read(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4371 | i = rxq->read; |
| 4372 | |
| 4373 | /* Rx interrupt, but nothing sent from uCode */ |
| 4374 | if (i == r) |
| 4375 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 4376 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4377 | if (iwl4965_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
| 4378 | fill_rx = 1; |
| 4379 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4380 | while (i != r) { |
| 4381 | rxb = rxq->queue[i]; |
| 4382 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4383 | /* 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] | 4384 | * then a bug has been introduced in the queue refilling |
| 4385 | * routines -- catch it here */ |
| 4386 | BUG_ON(rxb == NULL); |
| 4387 | |
| 4388 | rxq->queue[i] = NULL; |
| 4389 | |
| 4390 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4391 | priv->hw_setting.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4392 | PCI_DMA_FROMDEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4393 | pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4394 | |
| 4395 | /* Reclaim a command buffer only if this packet is a response |
| 4396 | * to a (driver-originated) command. |
| 4397 | * If the packet (e.g. Rx frame) originated from uCode, |
| 4398 | * there is no command buffer to reclaim. |
| 4399 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 4400 | * but apparently a few don't get set; catch them here. */ |
| 4401 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 4402 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
| 4403 | (pkt->hdr.cmd != REPLY_4965_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 4404 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4405 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 4406 | (pkt->hdr.cmd != REPLY_TX); |
| 4407 | |
| 4408 | /* Based on type of command response or notification, |
| 4409 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4410 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4411 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
| 4412 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4413 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 4414 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 4415 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 4416 | } else { |
| 4417 | /* No handling needed */ |
| 4418 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4419 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 4420 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 4421 | pkt->hdr.cmd); |
| 4422 | } |
| 4423 | |
| 4424 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4425 | /* Invoke any callbacks, transfer the skb to caller, and |
| 4426 | * fire off the (possibly) blocking iwl4965_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4427 | * as we reclaim the driver command queue */ |
| 4428 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4429 | iwl4965_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4430 | else |
| 4431 | IWL_WARNING("Claim null rxb?\n"); |
| 4432 | } |
| 4433 | |
| 4434 | /* For now we just don't re-use anything. We can tweak this |
| 4435 | * later to try and re-use notification packets and SKBs that |
| 4436 | * fail to Rx correctly */ |
| 4437 | if (rxb->skb != NULL) { |
| 4438 | priv->alloc_rxb_skb--; |
| 4439 | dev_kfree_skb_any(rxb->skb); |
| 4440 | rxb->skb = NULL; |
| 4441 | } |
| 4442 | |
| 4443 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 4444 | priv->hw_setting.rx_buf_size, |
| 4445 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4446 | spin_lock_irqsave(&rxq->lock, flags); |
| 4447 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 4448 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4449 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4450 | /* If there are a lot of unused frames, |
| 4451 | * restock the Rx queue so ucode wont assert. */ |
| 4452 | if (fill_rx) { |
| 4453 | count++; |
| 4454 | if (count >= 8) { |
| 4455 | priv->rxq.read = i; |
| 4456 | __iwl4965_rx_replenish(priv); |
| 4457 | count = 0; |
| 4458 | } |
| 4459 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4460 | } |
| 4461 | |
| 4462 | /* Backtrack one entry */ |
| 4463 | priv->rxq.read = i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4464 | iwl4965_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4465 | } |
| 4466 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4467 | /** |
| 4468 | * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware |
| 4469 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4470 | static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4471 | struct iwl4965_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4472 | { |
| 4473 | u32 reg = 0; |
| 4474 | int rc = 0; |
| 4475 | int txq_id = txq->q.id; |
| 4476 | |
| 4477 | if (txq->need_update == 0) |
| 4478 | return rc; |
| 4479 | |
| 4480 | /* if we're trying to save power */ |
| 4481 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 4482 | /* wake up nic if it's powered down ... |
| 4483 | * uCode will wake up, and interrupt us again, so next |
| 4484 | * time we'll skip this part. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4485 | reg = iwl4965_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4486 | |
| 4487 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 4488 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4489 | iwl4965_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4490 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4491 | return rc; |
| 4492 | } |
| 4493 | |
| 4494 | /* restore this queue's parameters in nic hardware. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4495 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4496 | if (rc) |
| 4497 | return rc; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4498 | iwl4965_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 4499 | txq->q.write_ptr | (txq_id << 8)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4500 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4501 | |
| 4502 | /* else not in power-save mode, uCode will never sleep when we're |
| 4503 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 4504 | } else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4505 | iwl4965_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 4506 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4507 | |
| 4508 | txq->need_update = 0; |
| 4509 | |
| 4510 | return rc; |
| 4511 | } |
| 4512 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4513 | #ifdef CONFIG_IWLWIFI_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4514 | static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4515 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4516 | DECLARE_MAC_BUF(mac); |
| 4517 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4518 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4519 | iwl_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4520 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 4521 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 4522 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 4523 | le32_to_cpu(rxon->filter_flags)); |
| 4524 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 4525 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 4526 | rxon->ofdm_basic_rates); |
| 4527 | 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] | 4528 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 4529 | print_mac(mac, rxon->node_addr)); |
| 4530 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 4531 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4532 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 4533 | } |
| 4534 | #endif |
| 4535 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4536 | static void iwl4965_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4537 | { |
| 4538 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 4539 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4540 | iwl4965_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4541 | } |
| 4542 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4543 | static inline void iwl4965_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4544 | { |
| 4545 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 4546 | |
| 4547 | /* disable interrupts from uCode/NIC to host */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4548 | iwl4965_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4549 | |
| 4550 | /* acknowledge/clear/reset any interrupts still pending |
| 4551 | * from uCode or flow handler (Rx/Tx DMA) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4552 | iwl4965_write32(priv, CSR_INT, 0xffffffff); |
| 4553 | iwl4965_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4554 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 4555 | } |
| 4556 | |
| 4557 | static const char *desc_lookup(int i) |
| 4558 | { |
| 4559 | switch (i) { |
| 4560 | case 1: |
| 4561 | return "FAIL"; |
| 4562 | case 2: |
| 4563 | return "BAD_PARAM"; |
| 4564 | case 3: |
| 4565 | return "BAD_CHECKSUM"; |
| 4566 | case 4: |
| 4567 | return "NMI_INTERRUPT"; |
| 4568 | case 5: |
| 4569 | return "SYSASSERT"; |
| 4570 | case 6: |
| 4571 | return "FATAL_ERROR"; |
| 4572 | } |
| 4573 | |
| 4574 | return "UNKNOWN"; |
| 4575 | } |
| 4576 | |
| 4577 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 4578 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 4579 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4580 | static void iwl4965_dump_nic_error_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4581 | { |
| 4582 | u32 data2, line; |
| 4583 | u32 desc, time, count, base, data1; |
| 4584 | u32 blink1, blink2, ilink1, ilink2; |
| 4585 | int rc; |
| 4586 | |
| 4587 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 4588 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4589 | if (!iwl4965_hw_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4590 | IWL_ERROR("Not valid error log pointer 0x%08X\n", base); |
| 4591 | return; |
| 4592 | } |
| 4593 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4594 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4595 | if (rc) { |
| 4596 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4597 | return; |
| 4598 | } |
| 4599 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4600 | count = iwl4965_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4601 | |
| 4602 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
| 4603 | IWL_ERROR("Start IWL Error Log Dump:\n"); |
Tomas Winkler | 2acae16 | 2008-03-02 01:25:59 +0200 | [diff] [blame] | 4604 | IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4605 | } |
| 4606 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4607 | desc = iwl4965_read_targ_mem(priv, base + 1 * sizeof(u32)); |
| 4608 | blink1 = iwl4965_read_targ_mem(priv, base + 3 * sizeof(u32)); |
| 4609 | blink2 = iwl4965_read_targ_mem(priv, base + 4 * sizeof(u32)); |
| 4610 | ilink1 = iwl4965_read_targ_mem(priv, base + 5 * sizeof(u32)); |
| 4611 | ilink2 = iwl4965_read_targ_mem(priv, base + 6 * sizeof(u32)); |
| 4612 | data1 = iwl4965_read_targ_mem(priv, base + 7 * sizeof(u32)); |
| 4613 | data2 = iwl4965_read_targ_mem(priv, base + 8 * sizeof(u32)); |
| 4614 | line = iwl4965_read_targ_mem(priv, base + 9 * sizeof(u32)); |
| 4615 | time = iwl4965_read_targ_mem(priv, base + 11 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4616 | |
| 4617 | IWL_ERROR("Desc Time " |
| 4618 | "data1 data2 line\n"); |
| 4619 | IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n", |
| 4620 | desc_lookup(desc), desc, time, data1, data2, line); |
| 4621 | IWL_ERROR("blink1 blink2 ilink1 ilink2\n"); |
| 4622 | IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2, |
| 4623 | ilink1, ilink2); |
| 4624 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4625 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4626 | } |
| 4627 | |
| 4628 | #define EVENT_START_OFFSET (4 * sizeof(u32)) |
| 4629 | |
| 4630 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4631 | * iwl4965_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4632 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4633 | * NOTE: Must be called with iwl4965_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4634 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4635 | static void iwl4965_print_event_log(struct iwl_priv *priv, u32 start_idx, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4636 | u32 num_events, u32 mode) |
| 4637 | { |
| 4638 | u32 i; |
| 4639 | u32 base; /* SRAM byte address of event log header */ |
| 4640 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 4641 | u32 ptr; /* SRAM byte address of log data */ |
| 4642 | u32 ev, time, data; /* event log data */ |
| 4643 | |
| 4644 | if (num_events == 0) |
| 4645 | return; |
| 4646 | |
| 4647 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 4648 | |
| 4649 | if (mode == 0) |
| 4650 | event_size = 2 * sizeof(u32); |
| 4651 | else |
| 4652 | event_size = 3 * sizeof(u32); |
| 4653 | |
| 4654 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 4655 | |
| 4656 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 4657 | * place event id # at far right for easier visual parsing. */ |
| 4658 | for (i = 0; i < num_events; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4659 | ev = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4660 | ptr += sizeof(u32); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4661 | time = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4662 | ptr += sizeof(u32); |
| 4663 | if (mode == 0) |
| 4664 | IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */ |
| 4665 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4666 | data = iwl4965_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4667 | ptr += sizeof(u32); |
| 4668 | IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev); |
| 4669 | } |
| 4670 | } |
| 4671 | } |
| 4672 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4673 | static void iwl4965_dump_nic_event_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4674 | { |
| 4675 | int rc; |
| 4676 | u32 base; /* SRAM byte address of event log header */ |
| 4677 | u32 capacity; /* event log capacity in # entries */ |
| 4678 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 4679 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 4680 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 4681 | u32 size; /* # entries that we'll print */ |
| 4682 | |
| 4683 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4684 | if (!iwl4965_hw_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4685 | IWL_ERROR("Invalid event log pointer 0x%08X\n", base); |
| 4686 | return; |
| 4687 | } |
| 4688 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4689 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4690 | if (rc) { |
| 4691 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4692 | return; |
| 4693 | } |
| 4694 | |
| 4695 | /* event log header */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4696 | capacity = iwl4965_read_targ_mem(priv, base); |
| 4697 | mode = iwl4965_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 4698 | num_wraps = iwl4965_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 4699 | next_entry = iwl4965_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4700 | |
| 4701 | size = num_wraps ? capacity : next_entry; |
| 4702 | |
| 4703 | /* bail out if nothing in log */ |
| 4704 | if (size == 0) { |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 4705 | IWL_ERROR("Start IWL Event Log Dump: nothing in log\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4706 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4707 | return; |
| 4708 | } |
| 4709 | |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 4710 | 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] | 4711 | size, num_wraps); |
| 4712 | |
| 4713 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 4714 | * i.e the next one that uCode would fill. */ |
| 4715 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4716 | iwl4965_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4717 | capacity - next_entry, mode); |
| 4718 | |
| 4719 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4720 | iwl4965_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4721 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4722 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4723 | } |
| 4724 | |
| 4725 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4726 | * 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] | 4727 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4728 | static void iwl4965_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4729 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4730 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4731 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 4732 | |
| 4733 | /* Cancel currently queued command. */ |
| 4734 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 4735 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4736 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 4737 | if (iwl_debug_level & IWL_DL_FW_ERRORS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4738 | iwl4965_dump_nic_error_log(priv); |
| 4739 | iwl4965_dump_nic_event_log(priv); |
| 4740 | iwl4965_print_rx_config_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4741 | } |
| 4742 | #endif |
| 4743 | |
| 4744 | wake_up_interruptible(&priv->wait_command_queue); |
| 4745 | |
| 4746 | /* Keep the restart process from trying to send host |
| 4747 | * commands by clearing the INIT status bit */ |
| 4748 | clear_bit(STATUS_READY, &priv->status); |
| 4749 | |
| 4750 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 4751 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 4752 | "Restarting adapter due to uCode error.\n"); |
| 4753 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4754 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4755 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 4756 | sizeof(priv->recovery_rxon)); |
| 4757 | priv->error_recovering = 1; |
| 4758 | } |
| 4759 | queue_work(priv->workqueue, &priv->restart); |
| 4760 | } |
| 4761 | } |
| 4762 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4763 | static void iwl4965_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4764 | { |
| 4765 | unsigned long flags; |
| 4766 | |
| 4767 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 4768 | sizeof(priv->staging_rxon)); |
| 4769 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4770 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4771 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4772 | iwl4965_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4773 | |
| 4774 | spin_lock_irqsave(&priv->lock, flags); |
| 4775 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 4776 | priv->error_recovering = 0; |
| 4777 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4778 | } |
| 4779 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4780 | static void iwl4965_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4781 | { |
| 4782 | u32 inta, handled = 0; |
| 4783 | u32 inta_fh; |
| 4784 | unsigned long flags; |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4785 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4786 | u32 inta_mask; |
| 4787 | #endif |
| 4788 | |
| 4789 | spin_lock_irqsave(&priv->lock, flags); |
| 4790 | |
| 4791 | /* Ack/clear/reset pending uCode interrupts. |
| 4792 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 4793 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4794 | inta = iwl4965_read32(priv, CSR_INT); |
| 4795 | iwl4965_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4796 | |
| 4797 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 4798 | * Any new interrupts that happen after this, either while we're |
| 4799 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4800 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
| 4801 | iwl4965_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4802 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4803 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 4804 | if (iwl_debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4805 | /* just for debug */ |
| 4806 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4807 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4808 | inta, inta_mask, inta_fh); |
| 4809 | } |
| 4810 | #endif |
| 4811 | |
| 4812 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 4813 | * atomic, make sure that inta covers all the interrupts that |
| 4814 | * we've discovered, even if FH interrupt came in just after |
| 4815 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 4816 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4817 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 4818 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4819 | inta |= CSR_INT_BIT_FH_TX; |
| 4820 | |
| 4821 | /* Now service all interrupt bits discovered above. */ |
| 4822 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 4823 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 4824 | |
| 4825 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4826 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4827 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4828 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4829 | |
| 4830 | handled |= CSR_INT_BIT_HW_ERR; |
| 4831 | |
| 4832 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4833 | |
| 4834 | return; |
| 4835 | } |
| 4836 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4837 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 4838 | if (iwl_debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4839 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4840 | if (inta & CSR_INT_BIT_SCD) |
| 4841 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 4842 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4843 | |
| 4844 | /* Alive notification via Rx interrupt will do the real work */ |
| 4845 | if (inta & CSR_INT_BIT_ALIVE) |
| 4846 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 4847 | } |
| 4848 | #endif |
| 4849 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4850 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4851 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4852 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4853 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 4854 | int hw_rf_kill = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4855 | if (!(iwl4965_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4856 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 4857 | hw_rf_kill = 1; |
| 4858 | |
| 4859 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR, |
| 4860 | "RF_KILL bit toggled to %s.\n", |
| 4861 | hw_rf_kill ? "disable radio":"enable radio"); |
| 4862 | |
| 4863 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 4864 | * when we loaded driver, and is now set to "enable". |
| 4865 | * After we're Alive, RF_KILL gets handled by |
Reinette Chatre | 3230455 | 2008-02-15 14:34:37 -0800 | [diff] [blame] | 4866 | * iwl4965_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 4867 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 4868 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4869 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 4870 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4871 | |
| 4872 | handled |= CSR_INT_BIT_RF_KILL; |
| 4873 | } |
| 4874 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4875 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4876 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 4877 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 4878 | handled |= CSR_INT_BIT_CT_KILL; |
| 4879 | } |
| 4880 | |
| 4881 | /* Error detected by uCode */ |
| 4882 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 4883 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 4884 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4885 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4886 | handled |= CSR_INT_BIT_SW_ERR; |
| 4887 | } |
| 4888 | |
| 4889 | /* uCode wakes up after power-down sleep */ |
| 4890 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 4891 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4892 | iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq); |
| 4893 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]); |
| 4894 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]); |
| 4895 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]); |
| 4896 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]); |
| 4897 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]); |
| 4898 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4899 | |
| 4900 | handled |= CSR_INT_BIT_WAKEUP; |
| 4901 | } |
| 4902 | |
| 4903 | /* All uCode command responses, including Tx command responses, |
| 4904 | * Rx "responses" (frame-received notification), and other |
| 4905 | * notifications from uCode come through here*/ |
| 4906 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4907 | iwl4965_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4908 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 4909 | } |
| 4910 | |
| 4911 | if (inta & CSR_INT_BIT_FH_TX) { |
| 4912 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 4913 | handled |= CSR_INT_BIT_FH_TX; |
| 4914 | } |
| 4915 | |
| 4916 | if (inta & ~handled) |
| 4917 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 4918 | |
| 4919 | if (inta & ~CSR_INI_SET_MASK) { |
| 4920 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 4921 | inta & ~CSR_INI_SET_MASK); |
| 4922 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 4923 | } |
| 4924 | |
| 4925 | /* Re-enable all interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4926 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4927 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4928 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 4929 | if (iwl_debug_level & (IWL_DL_ISR)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4930 | inta = iwl4965_read32(priv, CSR_INT); |
| 4931 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); |
| 4932 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4933 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 4934 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 4935 | } |
| 4936 | #endif |
| 4937 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4938 | } |
| 4939 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4940 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4941 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 4942 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4943 | u32 inta, inta_mask; |
| 4944 | u32 inta_fh; |
| 4945 | if (!priv) |
| 4946 | return IRQ_NONE; |
| 4947 | |
| 4948 | spin_lock(&priv->lock); |
| 4949 | |
| 4950 | /* Disable (but don't clear!) interrupts here to avoid |
| 4951 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 4952 | * If we have something to service, the tasklet will re-enable ints. |
| 4953 | * 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] | 4954 | inta_mask = iwl4965_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 4955 | iwl4965_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4956 | |
| 4957 | /* Discover which interrupts are active/pending */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4958 | inta = iwl4965_read32(priv, CSR_INT); |
| 4959 | inta_fh = iwl4965_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4960 | |
| 4961 | /* Ignore interrupt if there's nothing in NIC to service. |
| 4962 | * This may be due to IRQ shared with another device, |
| 4963 | * or due to sporadic interrupts thrown from our NIC. */ |
| 4964 | if (!inta && !inta_fh) { |
| 4965 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 4966 | goto none; |
| 4967 | } |
| 4968 | |
| 4969 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 4970 | /* Hardware disappeared. It might have already raised |
| 4971 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4972 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 4973 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4974 | } |
| 4975 | |
| 4976 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4977 | inta, inta_mask, inta_fh); |
| 4978 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4979 | inta &= ~CSR_INT_BIT_SCD; |
| 4980 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4981 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4982 | if (likely(inta || inta_fh)) |
| 4983 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4984 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 4985 | unplugged: |
| 4986 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4987 | return IRQ_HANDLED; |
| 4988 | |
| 4989 | none: |
| 4990 | /* re-enable interrupts here since we don't have anything to service. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4991 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4992 | spin_unlock(&priv->lock); |
| 4993 | return IRQ_NONE; |
| 4994 | } |
| 4995 | |
| 4996 | /************************** EEPROM BANDS **************************** |
| 4997 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4998 | * The iwl4965_eeprom_band definitions below provide the mapping from the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4999 | * EEPROM contents to the specific channel number supported for each |
| 5000 | * band. |
| 5001 | * |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5002 | * For example, iwl_priv->eeprom.band_3_channels[4] from the band_3 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5003 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. |
| 5004 | * The specific geography and calibration information for that channel |
| 5005 | * is contained in the eeprom map itself. |
| 5006 | * |
| 5007 | * During init, we copy the eeprom information and channel map |
| 5008 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 |
| 5009 | * |
| 5010 | * channel_map_24/52 provides the index in the channel_info array for a |
| 5011 | * given channel. We have to have two separate maps as there is channel |
| 5012 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and |
| 5013 | * band_2 |
| 5014 | * |
| 5015 | * A value of 0xff stored in the channel_map indicates that the channel |
| 5016 | * is not supported by the hardware at all. |
| 5017 | * |
| 5018 | * A value of 0xfe in the channel_map indicates that the channel is not |
| 5019 | * valid for Tx with the current hardware. This means that |
| 5020 | * while the system can tune and receive on a given channel, it may not |
| 5021 | * be able to associate or transmit any frames on that |
| 5022 | * channel. There is no corresponding channel information for that |
| 5023 | * entry. |
| 5024 | * |
| 5025 | *********************************************************************/ |
| 5026 | |
| 5027 | /* 2.4 GHz */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5028 | static const u8 iwl4965_eeprom_band_1[14] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5029 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
| 5030 | }; |
| 5031 | |
| 5032 | /* 5.2 GHz bands */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5033 | static const u8 iwl4965_eeprom_band_2[] = { /* 4915-5080MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5034 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
| 5035 | }; |
| 5036 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5037 | static const u8 iwl4965_eeprom_band_3[] = { /* 5170-5320MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5038 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
| 5039 | }; |
| 5040 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5041 | static const u8 iwl4965_eeprom_band_4[] = { /* 5500-5700MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5042 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
| 5043 | }; |
| 5044 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5045 | static const u8 iwl4965_eeprom_band_5[] = { /* 5725-5825MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5046 | 145, 149, 153, 157, 161, 165 |
| 5047 | }; |
| 5048 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5049 | static u8 iwl4965_eeprom_band_6[] = { /* 2.4 FAT channel */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5050 | 1, 2, 3, 4, 5, 6, 7 |
| 5051 | }; |
| 5052 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5053 | static u8 iwl4965_eeprom_band_7[] = { /* 5.2 FAT channel */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5054 | 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157 |
| 5055 | }; |
| 5056 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5057 | static void iwl4965_init_band_reference(const struct iwl_priv *priv, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5058 | int band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5059 | int *eeprom_ch_count, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5060 | const struct iwl4965_eeprom_channel |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5061 | **eeprom_ch_info, |
| 5062 | const u8 **eeprom_ch_index) |
| 5063 | { |
| 5064 | switch (band) { |
| 5065 | case 1: /* 2.4GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5066 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5067 | *eeprom_ch_info = priv->eeprom.band_1_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5068 | *eeprom_ch_index = iwl4965_eeprom_band_1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5069 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5070 | case 2: /* 4.9GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5071 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5072 | *eeprom_ch_info = priv->eeprom.band_2_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5073 | *eeprom_ch_index = iwl4965_eeprom_band_2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5074 | break; |
| 5075 | case 3: /* 5.2GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5076 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5077 | *eeprom_ch_info = priv->eeprom.band_3_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5078 | *eeprom_ch_index = iwl4965_eeprom_band_3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5079 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5080 | case 4: /* 5.5GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5081 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_4); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5082 | *eeprom_ch_info = priv->eeprom.band_4_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5083 | *eeprom_ch_index = iwl4965_eeprom_band_4; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5084 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5085 | case 5: /* 5.7GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5086 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5087 | *eeprom_ch_info = priv->eeprom.band_5_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5088 | *eeprom_ch_index = iwl4965_eeprom_band_5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5089 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5090 | case 6: /* 2.4GHz FAT channels */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5091 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_6); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5092 | *eeprom_ch_info = priv->eeprom.band_24_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5093 | *eeprom_ch_index = iwl4965_eeprom_band_6; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5094 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5095 | case 7: /* 5 GHz FAT channels */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5096 | *eeprom_ch_count = ARRAY_SIZE(iwl4965_eeprom_band_7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5097 | *eeprom_ch_info = priv->eeprom.band_52_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5098 | *eeprom_ch_index = iwl4965_eeprom_band_7; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5099 | break; |
| 5100 | default: |
| 5101 | BUG(); |
| 5102 | return; |
| 5103 | } |
| 5104 | } |
| 5105 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5106 | /** |
| 5107 | * iwl4965_get_channel_info - Find driver's private channel info |
| 5108 | * |
| 5109 | * Based on band and channel number. |
| 5110 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5111 | const struct iwl4965_channel_info *iwl4965_get_channel_info(const struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5112 | enum ieee80211_band band, u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5113 | { |
| 5114 | int i; |
| 5115 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5116 | switch (band) { |
| 5117 | case IEEE80211_BAND_5GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5118 | for (i = 14; i < priv->channel_count; i++) { |
| 5119 | if (priv->channel_info[i].channel == channel) |
| 5120 | return &priv->channel_info[i]; |
| 5121 | } |
| 5122 | break; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5123 | case IEEE80211_BAND_2GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5124 | if (channel >= 1 && channel <= 14) |
| 5125 | return &priv->channel_info[channel - 1]; |
| 5126 | break; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5127 | default: |
| 5128 | BUG(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5129 | } |
| 5130 | |
| 5131 | return NULL; |
| 5132 | } |
| 5133 | |
| 5134 | #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ |
| 5135 | ? # x " " : "") |
| 5136 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5137 | /** |
| 5138 | * iwl4965_init_channel_map - Set up driver's info for all possible channels |
| 5139 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5140 | static int iwl4965_init_channel_map(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5141 | { |
| 5142 | int eeprom_ch_count = 0; |
| 5143 | const u8 *eeprom_ch_index = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5144 | const struct iwl4965_eeprom_channel *eeprom_ch_info = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5145 | int band, ch; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5146 | struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5147 | |
| 5148 | if (priv->channel_count) { |
| 5149 | IWL_DEBUG_INFO("Channel map already initialized.\n"); |
| 5150 | return 0; |
| 5151 | } |
| 5152 | |
| 5153 | if (priv->eeprom.version < 0x2f) { |
| 5154 | IWL_WARNING("Unsupported EEPROM version: 0x%04X\n", |
| 5155 | priv->eeprom.version); |
| 5156 | return -EINVAL; |
| 5157 | } |
| 5158 | |
| 5159 | IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); |
| 5160 | |
| 5161 | priv->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5162 | ARRAY_SIZE(iwl4965_eeprom_band_1) + |
| 5163 | ARRAY_SIZE(iwl4965_eeprom_band_2) + |
| 5164 | ARRAY_SIZE(iwl4965_eeprom_band_3) + |
| 5165 | ARRAY_SIZE(iwl4965_eeprom_band_4) + |
| 5166 | ARRAY_SIZE(iwl4965_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5167 | |
| 5168 | IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); |
| 5169 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5170 | priv->channel_info = kzalloc(sizeof(struct iwl4965_channel_info) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5171 | priv->channel_count, GFP_KERNEL); |
| 5172 | if (!priv->channel_info) { |
| 5173 | IWL_ERROR("Could not allocate channel_info\n"); |
| 5174 | priv->channel_count = 0; |
| 5175 | return -ENOMEM; |
| 5176 | } |
| 5177 | |
| 5178 | ch_info = priv->channel_info; |
| 5179 | |
| 5180 | /* Loop through the 5 EEPROM bands adding them in order to the |
| 5181 | * channel map we maintain (that contains additional information than |
| 5182 | * what just in the EEPROM) */ |
| 5183 | for (band = 1; band <= 5; band++) { |
| 5184 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5185 | iwl4965_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5186 | &eeprom_ch_info, &eeprom_ch_index); |
| 5187 | |
| 5188 | /* Loop through each band adding each of the channels */ |
| 5189 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5190 | ch_info->channel = eeprom_ch_index[ch]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5191 | ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ : |
| 5192 | IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5193 | |
| 5194 | /* permanently store EEPROM's channel regulatory flags |
| 5195 | * and max power in channel info database. */ |
| 5196 | ch_info->eeprom = eeprom_ch_info[ch]; |
| 5197 | |
| 5198 | /* Copy the run-time flags so they are there even on |
| 5199 | * invalid channels */ |
| 5200 | ch_info->flags = eeprom_ch_info[ch].flags; |
| 5201 | |
| 5202 | if (!(is_channel_valid(ch_info))) { |
| 5203 | IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - " |
| 5204 | "No traffic\n", |
| 5205 | ch_info->channel, |
| 5206 | ch_info->flags, |
| 5207 | is_channel_a_band(ch_info) ? |
| 5208 | "5.2" : "2.4"); |
| 5209 | ch_info++; |
| 5210 | continue; |
| 5211 | } |
| 5212 | |
| 5213 | /* Initialize regulatory-based run-time data */ |
| 5214 | ch_info->max_power_avg = ch_info->curr_txpow = |
| 5215 | eeprom_ch_info[ch].max_power_avg; |
| 5216 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; |
| 5217 | ch_info->min_power = 0; |
| 5218 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5219 | 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] | 5220 | " %ddBm): Ad-Hoc %ssupported\n", |
| 5221 | ch_info->channel, |
| 5222 | is_channel_a_band(ch_info) ? |
| 5223 | "5.2" : "2.4", |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5224 | CHECK_AND_PRINT(VALID), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5225 | CHECK_AND_PRINT(IBSS), |
| 5226 | CHECK_AND_PRINT(ACTIVE), |
| 5227 | CHECK_AND_PRINT(RADAR), |
| 5228 | CHECK_AND_PRINT(WIDE), |
| 5229 | CHECK_AND_PRINT(NARROW), |
| 5230 | CHECK_AND_PRINT(DFS), |
| 5231 | eeprom_ch_info[ch].flags, |
| 5232 | eeprom_ch_info[ch].max_power_avg, |
| 5233 | ((eeprom_ch_info[ch]. |
| 5234 | flags & EEPROM_CHANNEL_IBSS) |
| 5235 | && !(eeprom_ch_info[ch]. |
| 5236 | flags & EEPROM_CHANNEL_RADAR)) |
| 5237 | ? "" : "not "); |
| 5238 | |
| 5239 | /* Set the user_txpower_limit to the highest power |
| 5240 | * supported by any channel */ |
| 5241 | if (eeprom_ch_info[ch].max_power_avg > |
| 5242 | priv->user_txpower_limit) |
| 5243 | priv->user_txpower_limit = |
| 5244 | eeprom_ch_info[ch].max_power_avg; |
| 5245 | |
| 5246 | ch_info++; |
| 5247 | } |
| 5248 | } |
| 5249 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5250 | /* Two additional EEPROM bands for 2.4 and 5 GHz FAT channels */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5251 | for (band = 6; band <= 7; band++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5252 | enum ieee80211_band ieeeband; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5253 | u8 fat_extension_chan; |
| 5254 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5255 | iwl4965_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5256 | &eeprom_ch_info, &eeprom_ch_index); |
| 5257 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5258 | /* EEPROM band 6 is 2.4, band 7 is 5 GHz */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5259 | ieeeband = (band == 6) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5260 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5261 | /* Loop through each band adding each of the channels */ |
| 5262 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5263 | |
| 5264 | if ((band == 6) && |
| 5265 | ((eeprom_ch_index[ch] == 5) || |
| 5266 | (eeprom_ch_index[ch] == 6) || |
| 5267 | (eeprom_ch_index[ch] == 7))) |
| 5268 | fat_extension_chan = HT_IE_EXT_CHANNEL_MAX; |
| 5269 | else |
| 5270 | fat_extension_chan = HT_IE_EXT_CHANNEL_ABOVE; |
| 5271 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5272 | /* Set up driver's info for lower half */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5273 | iwl4965_set_fat_chan_info(priv, ieeeband, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5274 | eeprom_ch_index[ch], |
| 5275 | &(eeprom_ch_info[ch]), |
| 5276 | fat_extension_chan); |
| 5277 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5278 | /* Set up driver's info for upper half */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5279 | iwl4965_set_fat_chan_info(priv, ieeeband, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5280 | (eeprom_ch_index[ch] + 4), |
| 5281 | &(eeprom_ch_info[ch]), |
| 5282 | HT_IE_EXT_CHANNEL_BELOW); |
| 5283 | } |
| 5284 | } |
| 5285 | |
| 5286 | return 0; |
| 5287 | } |
| 5288 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5289 | /* |
| 5290 | * iwl4965_free_channel_map - undo allocations in iwl4965_init_channel_map |
| 5291 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5292 | static void iwl4965_free_channel_map(struct iwl_priv *priv) |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5293 | { |
| 5294 | kfree(priv->channel_info); |
| 5295 | priv->channel_count = 0; |
| 5296 | } |
| 5297 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5298 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 5299 | * sending probe req. This should be set long enough to hear probe responses |
| 5300 | * from more than one AP. */ |
| 5301 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5302 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 5303 | |
| 5304 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 5305 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 5306 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 5307 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 5308 | * no other traffic). |
| 5309 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 5310 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 5311 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 5312 | |
| 5313 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 5314 | * Must be set longer than active dwell time. |
| 5315 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 5316 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5317 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 5318 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 5319 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 5320 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5321 | static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5322 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5323 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5324 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5325 | return IWL_ACTIVE_DWELL_TIME_52; |
| 5326 | else |
| 5327 | return IWL_ACTIVE_DWELL_TIME_24; |
| 5328 | } |
| 5329 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5330 | static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5331 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5332 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5333 | u16 active = iwl4965_get_active_dwell_time(priv, band); |
| 5334 | u16 passive = (band != IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5335 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 5336 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 5337 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5338 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5339 | /* If we're associated, we clamp the maximum passive |
| 5340 | * dwell time to be 98% of the beacon interval (minus |
| 5341 | * 2 * channel tune time) */ |
| 5342 | passive = priv->beacon_int; |
| 5343 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 5344 | passive = IWL_PASSIVE_DWELL_BASE; |
| 5345 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 5346 | } |
| 5347 | |
| 5348 | if (passive <= active) |
| 5349 | passive = active + 1; |
| 5350 | |
| 5351 | return passive; |
| 5352 | } |
| 5353 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5354 | static int iwl4965_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5355 | enum ieee80211_band band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5356 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5357 | struct iwl4965_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5358 | { |
| 5359 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5360 | const struct ieee80211_supported_band *sband; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5361 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5362 | u16 passive_dwell = 0; |
| 5363 | u16 active_dwell = 0; |
| 5364 | int added, i; |
| 5365 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5366 | sband = iwl4965_get_hw_mode(priv, band); |
| 5367 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5368 | return 0; |
| 5369 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5370 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5371 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5372 | active_dwell = iwl4965_get_active_dwell_time(priv, band); |
| 5373 | passive_dwell = iwl4965_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5374 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5375 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
| 5376 | if (ieee80211_frequency_to_channel(channels[i].center_freq) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5377 | le16_to_cpu(priv->active_rxon.channel)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5378 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5379 | IWL_DEBUG_SCAN |
| 5380 | ("Skipping current channel %d\n", |
| 5381 | le16_to_cpu(priv->active_rxon.channel)); |
| 5382 | continue; |
| 5383 | } |
| 5384 | } else if (priv->only_active_channel) |
| 5385 | continue; |
| 5386 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5387 | scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5388 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5389 | ch_info = iwl4965_get_channel_info(priv, band, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5390 | scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5391 | if (!is_channel_valid(ch_info)) { |
| 5392 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 5393 | scan_ch->channel); |
| 5394 | continue; |
| 5395 | } |
| 5396 | |
| 5397 | if (!is_active || is_channel_passive(ch_info) || |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5398 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5399 | scan_ch->type = 0; /* passive */ |
| 5400 | else |
| 5401 | scan_ch->type = 1; /* active */ |
| 5402 | |
| 5403 | if (scan_ch->type & 1) |
| 5404 | scan_ch->type |= (direct_mask << 1); |
| 5405 | |
| 5406 | if (is_channel_narrow(ch_info)) |
| 5407 | scan_ch->type |= (1 << 7); |
| 5408 | |
| 5409 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 5410 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 5411 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5412 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5413 | scan_ch->tpc.dsp_atten = 110; |
| 5414 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 5415 | |
| 5416 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5417 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5418 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 5419 | else { |
| 5420 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 5421 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5422 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 5423 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5424 | */ |
| 5425 | } |
| 5426 | |
| 5427 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 5428 | scan_ch->channel, |
| 5429 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 5430 | (scan_ch->type & 1) ? |
| 5431 | active_dwell : passive_dwell); |
| 5432 | |
| 5433 | scan_ch++; |
| 5434 | added++; |
| 5435 | } |
| 5436 | |
| 5437 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 5438 | return added; |
| 5439 | } |
| 5440 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5441 | static void iwl4965_init_hw_rates(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5442 | struct ieee80211_rate *rates) |
| 5443 | { |
| 5444 | int i; |
| 5445 | |
| 5446 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5447 | rates[i].bitrate = iwl4965_rates[i].ieee * 5; |
| 5448 | rates[i].hw_value = i; /* Rate scaling will work on indexes */ |
| 5449 | rates[i].hw_value_short = i; |
| 5450 | rates[i].flags = 0; |
| 5451 | if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5452 | /* |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5453 | * If CCK != 1M then set short preamble rate flag. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5454 | */ |
Tomas Winkler | 35cdeaf | 2008-03-11 16:17:20 -0700 | [diff] [blame] | 5455 | rates[i].flags |= |
| 5456 | (iwl4965_rates[i].plcp == IWL_RATE_1M_PLCP) ? |
| 5457 | 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5458 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5459 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5460 | } |
| 5461 | |
| 5462 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5463 | * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5464 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5465 | static int iwl4965_init_geos(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5466 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5467 | struct iwl4965_channel_info *ch; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5468 | struct ieee80211_supported_band *sband; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5469 | struct ieee80211_channel *channels; |
| 5470 | struct ieee80211_channel *geo_ch; |
| 5471 | struct ieee80211_rate *rates; |
| 5472 | int i = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5473 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5474 | if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates || |
| 5475 | priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5476 | IWL_DEBUG_INFO("Geography modes already initialized.\n"); |
| 5477 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5478 | return 0; |
| 5479 | } |
| 5480 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5481 | channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 5482 | priv->channel_count, GFP_KERNEL); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5483 | if (!channels) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5484 | return -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5485 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5486 | rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5487 | GFP_KERNEL); |
| 5488 | if (!rates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5489 | kfree(channels); |
| 5490 | return -ENOMEM; |
| 5491 | } |
| 5492 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5493 | /* 5.2GHz channels start after the 2.4GHz channels */ |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5494 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
| 5495 | sband->channels = &channels[ARRAY_SIZE(iwl4965_eeprom_band_1)]; |
| 5496 | /* just OFDM */ |
| 5497 | sband->bitrates = &rates[IWL_FIRST_OFDM_RATE]; |
| 5498 | sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5499 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5500 | iwl4965_init_ht_hw_capab(&sband->ht_info, IEEE80211_BAND_5GHZ); |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5501 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5502 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 5503 | sband->channels = channels; |
| 5504 | /* OFDM & CCK */ |
| 5505 | sband->bitrates = rates; |
| 5506 | sband->n_bitrates = IWL_RATE_COUNT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5507 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5508 | iwl4965_init_ht_hw_capab(&sband->ht_info, IEEE80211_BAND_2GHZ); |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5509 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5510 | priv->ieee_channels = channels; |
| 5511 | priv->ieee_rates = rates; |
| 5512 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5513 | iwl4965_init_hw_rates(priv, rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5514 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5515 | for (i = 0; i < priv->channel_count; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5516 | ch = &priv->channel_info[i]; |
| 5517 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5518 | /* FIXME: might be removed if scan is OK */ |
| 5519 | if (!is_channel_valid(ch)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5520 | continue; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5521 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5522 | if (is_channel_a_band(ch)) |
| 5523 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
| 5524 | else |
| 5525 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5526 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5527 | geo_ch = &sband->channels[sband->n_channels++]; |
| 5528 | |
| 5529 | geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5530 | geo_ch->max_power = ch->max_power_avg; |
| 5531 | geo_ch->max_antenna_gain = 0xff; |
Mohamed Abbas | 7b72304 | 2008-01-31 21:46:40 -0800 | [diff] [blame] | 5532 | geo_ch->hw_value = ch->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5533 | |
| 5534 | if (is_channel_valid(ch)) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5535 | if (!(ch->flags & EEPROM_CHANNEL_IBSS)) |
| 5536 | geo_ch->flags |= IEEE80211_CHAN_NO_IBSS; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5537 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5538 | if (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) |
| 5539 | geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5540 | |
| 5541 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5542 | geo_ch->flags |= IEEE80211_CHAN_RADAR; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5543 | |
| 5544 | if (ch->max_power_avg > priv->max_channel_txpower_limit) |
| 5545 | priv->max_channel_txpower_limit = |
| 5546 | ch->max_power_avg; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5547 | } else { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5548 | geo_ch->flags |= IEEE80211_CHAN_DISABLED; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 5549 | } |
| 5550 | |
| 5551 | /* Save flags for reg domain usage */ |
| 5552 | geo_ch->orig_flags = geo_ch->flags; |
| 5553 | |
| 5554 | IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n", |
| 5555 | ch->channel, geo_ch->center_freq, |
| 5556 | is_channel_a_band(ch) ? "5.2" : "2.4", |
| 5557 | geo_ch->flags & IEEE80211_CHAN_DISABLED ? |
| 5558 | "restricted" : "valid", |
| 5559 | geo_ch->flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5560 | } |
| 5561 | |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 5562 | if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && |
| 5563 | priv->cfg->sku & IWL_SKU_A) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5564 | printk(KERN_INFO DRV_NAME |
| 5565 | ": Incorrectly detected BG card as ABG. Please send " |
| 5566 | "your PCI ID 0x%04X:0x%04X to maintainer.\n", |
| 5567 | priv->pci_dev->device, priv->pci_dev->subsystem_device); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 5568 | priv->cfg->sku &= ~IWL_SKU_A; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | printk(KERN_INFO DRV_NAME |
| 5572 | ": Tunable channels: %d 802.11bg, %d 802.11a channels\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5573 | priv->bands[IEEE80211_BAND_2GHZ].n_channels, |
| 5574 | priv->bands[IEEE80211_BAND_5GHZ].n_channels); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5575 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5576 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 5577 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->bands[IEEE80211_BAND_5GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5578 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5579 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5580 | |
| 5581 | return 0; |
| 5582 | } |
| 5583 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5584 | /* |
| 5585 | * iwl4965_free_geos - undo allocations in iwl4965_init_geos |
| 5586 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5587 | static void iwl4965_free_geos(struct iwl_priv *priv) |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5588 | { |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5589 | kfree(priv->ieee_channels); |
| 5590 | kfree(priv->ieee_rates); |
| 5591 | clear_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5592 | } |
| 5593 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5594 | /****************************************************************************** |
| 5595 | * |
| 5596 | * uCode download functions |
| 5597 | * |
| 5598 | ******************************************************************************/ |
| 5599 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5600 | static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5601 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5602 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 5603 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 5604 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 5605 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 5606 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 5607 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5608 | } |
| 5609 | |
| 5610 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5611 | * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5612 | * looking at all data. |
| 5613 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5614 | static int iwl4965_verify_inst_full(struct iwl_priv *priv, __le32 *image, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5615 | u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5616 | { |
| 5617 | u32 val; |
| 5618 | u32 save_len = len; |
| 5619 | int rc = 0; |
| 5620 | u32 errcnt; |
| 5621 | |
| 5622 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 5623 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5624 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5625 | if (rc) |
| 5626 | return rc; |
| 5627 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5628 | iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5629 | |
| 5630 | errcnt = 0; |
| 5631 | for (; len > 0; len -= sizeof(u32), image++) { |
| 5632 | /* read data comes through single port, auto-incr addr */ |
| 5633 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 5634 | * if IWL_DL_IO is set */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5635 | val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5636 | if (val != le32_to_cpu(*image)) { |
| 5637 | IWL_ERROR("uCode INST section is invalid at " |
| 5638 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 5639 | save_len - len, val, le32_to_cpu(*image)); |
| 5640 | rc = -EIO; |
| 5641 | errcnt++; |
| 5642 | if (errcnt >= 20) |
| 5643 | break; |
| 5644 | } |
| 5645 | } |
| 5646 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5647 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5648 | |
| 5649 | if (!errcnt) |
| 5650 | IWL_DEBUG_INFO |
| 5651 | ("ucode image in INSTRUCTION memory is good\n"); |
| 5652 | |
| 5653 | return rc; |
| 5654 | } |
| 5655 | |
| 5656 | |
| 5657 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5658 | * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5659 | * using sample data 100 bytes apart. If these sample points are good, |
| 5660 | * it's a pretty good bet that everything between them is good, too. |
| 5661 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5662 | static int iwl4965_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5663 | { |
| 5664 | u32 val; |
| 5665 | int rc = 0; |
| 5666 | u32 errcnt = 0; |
| 5667 | u32 i; |
| 5668 | |
| 5669 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 5670 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5671 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5672 | if (rc) |
| 5673 | return rc; |
| 5674 | |
| 5675 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 5676 | /* read data comes through single port, auto-incr addr */ |
| 5677 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 5678 | * if IWL_DL_IO is set */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5679 | iwl4965_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5680 | i + RTC_INST_LOWER_BOUND); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5681 | val = _iwl4965_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5682 | if (val != le32_to_cpu(*image)) { |
| 5683 | #if 0 /* Enable this if you want to see details */ |
| 5684 | IWL_ERROR("uCode INST section is invalid at " |
| 5685 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 5686 | i, val, *image); |
| 5687 | #endif |
| 5688 | rc = -EIO; |
| 5689 | errcnt++; |
| 5690 | if (errcnt >= 3) |
| 5691 | break; |
| 5692 | } |
| 5693 | } |
| 5694 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5695 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5696 | |
| 5697 | return rc; |
| 5698 | } |
| 5699 | |
| 5700 | |
| 5701 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5702 | * iwl4965_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5703 | * and verify its contents |
| 5704 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5705 | static int iwl4965_verify_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5706 | { |
| 5707 | __le32 *image; |
| 5708 | u32 len; |
| 5709 | int rc = 0; |
| 5710 | |
| 5711 | /* Try bootstrap */ |
| 5712 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 5713 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5714 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5715 | if (rc == 0) { |
| 5716 | IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); |
| 5717 | return 0; |
| 5718 | } |
| 5719 | |
| 5720 | /* Try initialize */ |
| 5721 | image = (__le32 *)priv->ucode_init.v_addr; |
| 5722 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5723 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5724 | if (rc == 0) { |
| 5725 | IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); |
| 5726 | return 0; |
| 5727 | } |
| 5728 | |
| 5729 | /* Try runtime/protocol */ |
| 5730 | image = (__le32 *)priv->ucode_code.v_addr; |
| 5731 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5732 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5733 | if (rc == 0) { |
| 5734 | IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); |
| 5735 | return 0; |
| 5736 | } |
| 5737 | |
| 5738 | IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
| 5739 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5740 | /* Since nothing seems to match, show first several data entries in |
| 5741 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 5742 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5743 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 5744 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5745 | rc = iwl4965_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5746 | |
| 5747 | return rc; |
| 5748 | } |
| 5749 | |
| 5750 | |
| 5751 | /* check contents of special bootstrap uCode SRAM */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5752 | static int iwl4965_verify_bsm(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5753 | { |
| 5754 | __le32 *image = priv->ucode_boot.v_addr; |
| 5755 | u32 len = priv->ucode_boot.len; |
| 5756 | u32 reg; |
| 5757 | u32 val; |
| 5758 | |
| 5759 | IWL_DEBUG_INFO("Begin verify bsm\n"); |
| 5760 | |
| 5761 | /* verify BSM SRAM contents */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5762 | val = iwl4965_read_prph(priv, BSM_WR_DWCOUNT_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5763 | for (reg = BSM_SRAM_LOWER_BOUND; |
| 5764 | reg < BSM_SRAM_LOWER_BOUND + len; |
| 5765 | reg += sizeof(u32), image ++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5766 | val = iwl4965_read_prph(priv, reg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5767 | if (val != le32_to_cpu(*image)) { |
| 5768 | IWL_ERROR("BSM uCode verification failed at " |
| 5769 | "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", |
| 5770 | BSM_SRAM_LOWER_BOUND, |
| 5771 | reg - BSM_SRAM_LOWER_BOUND, len, |
| 5772 | val, le32_to_cpu(*image)); |
| 5773 | return -EIO; |
| 5774 | } |
| 5775 | } |
| 5776 | |
| 5777 | IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n"); |
| 5778 | |
| 5779 | return 0; |
| 5780 | } |
| 5781 | |
| 5782 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5783 | * iwl4965_load_bsm - Load bootstrap instructions |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5784 | * |
| 5785 | * BSM operation: |
| 5786 | * |
| 5787 | * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program |
| 5788 | * in special SRAM that does not power down during RFKILL. When powering back |
| 5789 | * up after power-saving sleeps (or during initial uCode load), the BSM loads |
| 5790 | * the bootstrap program into the on-board processor, and starts it. |
| 5791 | * |
| 5792 | * The bootstrap program loads (via DMA) instructions and data for a new |
| 5793 | * program from host DRAM locations indicated by the host driver in the |
| 5794 | * BSM_DRAM_* registers. Once the new program is loaded, it starts |
| 5795 | * automatically. |
| 5796 | * |
| 5797 | * When initializing the NIC, the host driver points the BSM to the |
| 5798 | * "initialize" uCode image. This uCode sets up some internal data, then |
| 5799 | * notifies host via "initialize alive" that it is complete. |
| 5800 | * |
| 5801 | * The host then replaces the BSM_DRAM_* pointer values to point to the |
| 5802 | * normal runtime uCode instructions and a backup uCode data cache buffer |
| 5803 | * (filled initially with starting data values for the on-board processor), |
| 5804 | * then triggers the "initialize" uCode to load and launch the runtime uCode, |
| 5805 | * which begins normal operation. |
| 5806 | * |
| 5807 | * When doing a power-save shutdown, runtime uCode saves data SRAM into |
| 5808 | * the backup data cache in DRAM before SRAM is powered down. |
| 5809 | * |
| 5810 | * When powering back up, the BSM loads the bootstrap program. This reloads |
| 5811 | * the runtime uCode instructions and the backup data cache into SRAM, |
| 5812 | * and re-launches the runtime uCode from where it left off. |
| 5813 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5814 | static int iwl4965_load_bsm(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5815 | { |
| 5816 | __le32 *image = priv->ucode_boot.v_addr; |
| 5817 | u32 len = priv->ucode_boot.len; |
| 5818 | dma_addr_t pinst; |
| 5819 | dma_addr_t pdata; |
| 5820 | u32 inst_len; |
| 5821 | u32 data_len; |
| 5822 | int rc; |
| 5823 | int i; |
| 5824 | u32 done; |
| 5825 | u32 reg_offset; |
| 5826 | |
| 5827 | IWL_DEBUG_INFO("Begin load bsm\n"); |
| 5828 | |
| 5829 | /* make sure bootstrap program is no larger than BSM's SRAM size */ |
| 5830 | if (len > IWL_MAX_BSM_SIZE) |
| 5831 | return -EINVAL; |
| 5832 | |
| 5833 | /* Tell bootstrap uCode where to find the "Initialize" uCode |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5834 | * in host DRAM ... host DRAM physical address bits 35:4 for 4965. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5835 | * NOTE: iwl4965_initialize_alive_start() will replace these values, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5836 | * after the "initialize" uCode has run, to point to |
| 5837 | * runtime/protocol instructions and backup data cache. */ |
| 5838 | pinst = priv->ucode_init.p_addr >> 4; |
| 5839 | pdata = priv->ucode_init_data.p_addr >> 4; |
| 5840 | inst_len = priv->ucode_init.len; |
| 5841 | data_len = priv->ucode_init_data.len; |
| 5842 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5843 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5844 | if (rc) |
| 5845 | return rc; |
| 5846 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5847 | iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 5848 | iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 5849 | iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); |
| 5850 | iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5851 | |
| 5852 | /* Fill BSM memory with bootstrap instructions */ |
| 5853 | for (reg_offset = BSM_SRAM_LOWER_BOUND; |
| 5854 | reg_offset < BSM_SRAM_LOWER_BOUND + len; |
| 5855 | reg_offset += sizeof(u32), image++) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5856 | _iwl4965_write_prph(priv, reg_offset, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5857 | le32_to_cpu(*image)); |
| 5858 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5859 | rc = iwl4965_verify_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5860 | if (rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5861 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5862 | return rc; |
| 5863 | } |
| 5864 | |
| 5865 | /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5866 | iwl4965_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0); |
| 5867 | iwl4965_write_prph(priv, BSM_WR_MEM_DST_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5868 | RTC_INST_LOWER_BOUND); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5869 | iwl4965_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5870 | |
| 5871 | /* Load bootstrap code into instruction SRAM now, |
| 5872 | * to prepare to load "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5873 | iwl4965_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5874 | BSM_WR_CTRL_REG_BIT_START); |
| 5875 | |
| 5876 | /* Wait for load of bootstrap uCode to finish */ |
| 5877 | for (i = 0; i < 100; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5878 | done = iwl4965_read_prph(priv, BSM_WR_CTRL_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5879 | if (!(done & BSM_WR_CTRL_REG_BIT_START)) |
| 5880 | break; |
| 5881 | udelay(10); |
| 5882 | } |
| 5883 | if (i < 100) |
| 5884 | IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i); |
| 5885 | else { |
| 5886 | IWL_ERROR("BSM write did not complete!\n"); |
| 5887 | return -EIO; |
| 5888 | } |
| 5889 | |
| 5890 | /* Enable future boot loads whenever power management unit triggers it |
| 5891 | * (e.g. when powering back up after power-save shutdown) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5892 | iwl4965_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5893 | BSM_WR_CTRL_REG_BIT_START_EN); |
| 5894 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5895 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5896 | |
| 5897 | return 0; |
| 5898 | } |
| 5899 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5900 | static void iwl4965_nic_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5901 | { |
| 5902 | /* Remove all resets to allow NIC to operate */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5903 | iwl4965_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5904 | } |
| 5905 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5906 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5907 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5908 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5909 | * |
| 5910 | * Copy into buffers for card to fetch via bus-mastering |
| 5911 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 5912 | static int iwl4965_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5913 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5914 | struct iwl4965_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5915 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5916 | const struct firmware *ucode_raw; |
Tomas Winkler | 4bf775c | 2008-03-04 18:09:31 -0800 | [diff] [blame] | 5917 | const char *name = priv->cfg->fw_name; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5918 | u8 *src; |
| 5919 | size_t len; |
| 5920 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 5921 | |
| 5922 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 5923 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5924 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 5925 | if (ret < 0) { |
| 5926 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 5927 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5928 | goto error; |
| 5929 | } |
| 5930 | |
| 5931 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 5932 | name, ucode_raw->size); |
| 5933 | |
| 5934 | /* Make sure that we got at least our header! */ |
| 5935 | if (ucode_raw->size < sizeof(*ucode)) { |
| 5936 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5937 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5938 | goto err_release; |
| 5939 | } |
| 5940 | |
| 5941 | /* Data from ucode file: header followed by uCode images */ |
| 5942 | ucode = (void *)ucode_raw->data; |
| 5943 | |
| 5944 | ver = le32_to_cpu(ucode->ver); |
| 5945 | inst_size = le32_to_cpu(ucode->inst_size); |
| 5946 | data_size = le32_to_cpu(ucode->data_size); |
| 5947 | init_size = le32_to_cpu(ucode->init_size); |
| 5948 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 5949 | boot_size = le32_to_cpu(ucode->boot_size); |
| 5950 | |
| 5951 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 5952 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 5953 | inst_size); |
| 5954 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 5955 | data_size); |
| 5956 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 5957 | init_size); |
| 5958 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 5959 | init_data_size); |
| 5960 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 5961 | boot_size); |
| 5962 | |
| 5963 | /* Verify size of file vs. image size info in file's header */ |
| 5964 | if (ucode_raw->size < sizeof(*ucode) + |
| 5965 | inst_size + data_size + init_size + |
| 5966 | init_data_size + boot_size) { |
| 5967 | |
| 5968 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 5969 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5970 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5971 | goto err_release; |
| 5972 | } |
| 5973 | |
| 5974 | /* Verify that uCode images will fit in card's SRAM */ |
| 5975 | if (inst_size > IWL_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5976 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 5977 | inst_size); |
| 5978 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5979 | goto err_release; |
| 5980 | } |
| 5981 | |
| 5982 | if (data_size > IWL_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5983 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 5984 | data_size); |
| 5985 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5986 | goto err_release; |
| 5987 | } |
| 5988 | if (init_size > IWL_MAX_INST_SIZE) { |
| 5989 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5990 | ("uCode init instr len %d too large to fit in\n", |
| 5991 | init_size); |
| 5992 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5993 | goto err_release; |
| 5994 | } |
| 5995 | if (init_data_size > IWL_MAX_DATA_SIZE) { |
| 5996 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5997 | ("uCode init data len %d too large to fit in\n", |
| 5998 | init_data_size); |
| 5999 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6000 | goto err_release; |
| 6001 | } |
| 6002 | if (boot_size > IWL_MAX_BSM_SIZE) { |
| 6003 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6004 | ("uCode boot instr len %d too large to fit in\n", |
| 6005 | boot_size); |
| 6006 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6007 | goto err_release; |
| 6008 | } |
| 6009 | |
| 6010 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 6011 | |
| 6012 | /* Runtime instructions and 2 copies of data: |
| 6013 | * 1) unmodified from disk |
| 6014 | * 2) backup cache for save/restore during power-downs */ |
| 6015 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6016 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6017 | |
| 6018 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6019 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6020 | |
| 6021 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6022 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6023 | |
| 6024 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6025 | if (init_size && init_data_size) { |
| 6026 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6027 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6028 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6029 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6030 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6031 | |
| 6032 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 6033 | goto err_pci_alloc; |
| 6034 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6035 | |
| 6036 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6037 | if (boot_size) { |
| 6038 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 6039 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6040 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6041 | if (!priv->ucode_boot.v_addr) |
| 6042 | goto err_pci_alloc; |
| 6043 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6044 | |
| 6045 | /* Copy images into buffers for card's bus-master reads ... */ |
| 6046 | |
| 6047 | /* Runtime instructions (first block of data in file) */ |
| 6048 | src = &ucode->data[0]; |
| 6049 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6050 | 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] | 6051 | memcpy(priv->ucode_code.v_addr, src, len); |
| 6052 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 6053 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 6054 | |
| 6055 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6056 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6057 | src = &ucode->data[inst_size]; |
| 6058 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6059 | 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] | 6060 | memcpy(priv->ucode_data.v_addr, src, len); |
| 6061 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 6062 | |
| 6063 | /* Initialization instructions (3rd block) */ |
| 6064 | if (init_size) { |
| 6065 | src = &ucode->data[inst_size + data_size]; |
| 6066 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6067 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 6068 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6069 | memcpy(priv->ucode_init.v_addr, src, len); |
| 6070 | } |
| 6071 | |
| 6072 | /* Initialization data (4th block) */ |
| 6073 | if (init_data_size) { |
| 6074 | src = &ucode->data[inst_size + data_size + init_size]; |
| 6075 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6076 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 6077 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6078 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 6079 | } |
| 6080 | |
| 6081 | /* Bootstrap instructions (5th block) */ |
| 6082 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 6083 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6084 | 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] | 6085 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 6086 | |
| 6087 | /* We have our copies now, allow OS release its copies */ |
| 6088 | release_firmware(ucode_raw); |
| 6089 | return 0; |
| 6090 | |
| 6091 | err_pci_alloc: |
| 6092 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6093 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6094 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6095 | |
| 6096 | err_release: |
| 6097 | release_firmware(ucode_raw); |
| 6098 | |
| 6099 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 6100 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6101 | } |
| 6102 | |
| 6103 | |
| 6104 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6105 | * iwl4965_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6106 | * |
| 6107 | * Tell initialization uCode where to find runtime uCode. |
| 6108 | * |
| 6109 | * BSM registers initially contain pointers to initialization uCode. |
| 6110 | * We need to replace them to load runtime uCode inst and data, |
| 6111 | * and to save runtime data when powering down. |
| 6112 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6113 | static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6114 | { |
| 6115 | dma_addr_t pinst; |
| 6116 | dma_addr_t pdata; |
| 6117 | int rc = 0; |
| 6118 | unsigned long flags; |
| 6119 | |
| 6120 | /* bits 35:4 for 4965 */ |
| 6121 | pinst = priv->ucode_code.p_addr >> 4; |
| 6122 | pdata = priv->ucode_data_backup.p_addr >> 4; |
| 6123 | |
| 6124 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6125 | rc = iwl4965_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6126 | if (rc) { |
| 6127 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6128 | return rc; |
| 6129 | } |
| 6130 | |
| 6131 | /* Tell bootstrap uCode where to find image to load */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6132 | iwl4965_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 6133 | iwl4965_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 6134 | iwl4965_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6135 | priv->ucode_data.len); |
| 6136 | |
| 6137 | /* Inst bytecount must be last to set up, bit 31 signals uCode |
| 6138 | * that all new ptr/size info is in place */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6139 | iwl4965_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6140 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 6141 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6142 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6143 | |
| 6144 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6145 | |
| 6146 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 6147 | |
| 6148 | return rc; |
| 6149 | } |
| 6150 | |
| 6151 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6152 | * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6153 | * |
| 6154 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 6155 | * |
| 6156 | * The 4965 "initialize" ALIVE reply contains calibration data for: |
| 6157 | * Voltage, temperature, and MIMO tx gain correction, now stored in priv |
| 6158 | * (3945 does not contain this data). |
| 6159 | * |
| 6160 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
| 6161 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6162 | static void iwl4965_init_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6163 | { |
| 6164 | /* Check alive response for "valid" sign from uCode */ |
| 6165 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 6166 | /* We had an error bringing up the hardware, so take it |
| 6167 | * all the way back down so we can try again */ |
| 6168 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 6169 | goto restart; |
| 6170 | } |
| 6171 | |
| 6172 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 6173 | * This is a paranoid check, because we would not have gotten the |
| 6174 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6175 | if (iwl4965_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6176 | /* Runtime instruction load was bad; |
| 6177 | * take it all the way back down so we can try again */ |
| 6178 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 6179 | goto restart; |
| 6180 | } |
| 6181 | |
| 6182 | /* Calculate temperature */ |
| 6183 | priv->temperature = iwl4965_get_temperature(priv); |
| 6184 | |
| 6185 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 6186 | * load and launch runtime uCode, which will send us another "Alive" |
| 6187 | * notification. */ |
| 6188 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6189 | if (iwl4965_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6190 | /* Runtime instruction load won't happen; |
| 6191 | * take it all the way back down so we can try again */ |
| 6192 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 6193 | goto restart; |
| 6194 | } |
| 6195 | return; |
| 6196 | |
| 6197 | restart: |
| 6198 | queue_work(priv->workqueue, &priv->restart); |
| 6199 | } |
| 6200 | |
| 6201 | |
| 6202 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6203 | * iwl4965_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6204 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6205 | * Alive gets handled by iwl4965_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6206 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6207 | static void iwl4965_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6208 | { |
| 6209 | int rc = 0; |
| 6210 | |
| 6211 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 6212 | |
| 6213 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 6214 | /* We had an error bringing up the hardware, so take it |
| 6215 | * all the way back down so we can try again */ |
| 6216 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 6217 | goto restart; |
| 6218 | } |
| 6219 | |
| 6220 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 6221 | * This is a paranoid check, because we would not have gotten the |
| 6222 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6223 | if (iwl4965_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6224 | /* Runtime instruction load was bad; |
| 6225 | * take it all the way back down so we can try again */ |
| 6226 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 6227 | goto restart; |
| 6228 | } |
| 6229 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6230 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6231 | |
| 6232 | rc = iwl4965_alive_notify(priv); |
| 6233 | if (rc) { |
| 6234 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
| 6235 | rc); |
| 6236 | goto restart; |
| 6237 | } |
| 6238 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6239 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6240 | set_bit(STATUS_ALIVE, &priv->status); |
| 6241 | |
| 6242 | /* Clear out the uCode error bit if it is set */ |
| 6243 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 6244 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6245 | if (iwl4965_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6246 | return; |
| 6247 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6248 | ieee80211_start_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6249 | |
| 6250 | priv->active_rate = priv->rates_mask; |
| 6251 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 6252 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6253 | iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6254 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6255 | if (iwl4965_is_associated(priv)) { |
| 6256 | struct iwl4965_rxon_cmd *active_rxon = |
| 6257 | (struct iwl4965_rxon_cmd *)(&priv->active_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6258 | |
| 6259 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 6260 | sizeof(priv->staging_rxon)); |
| 6261 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 6262 | } else { |
| 6263 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6264 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6265 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 6266 | } |
| 6267 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6268 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6269 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6270 | |
| 6271 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6272 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6273 | |
| 6274 | /* At this point, the NIC is initialized and operational */ |
| 6275 | priv->notif_missed_beacons = 0; |
| 6276 | set_bit(STATUS_READY, &priv->status); |
| 6277 | |
| 6278 | iwl4965_rf_kill_ct_config(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6279 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6280 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6281 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6282 | |
| 6283 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6284 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6285 | |
| 6286 | return; |
| 6287 | |
| 6288 | restart: |
| 6289 | queue_work(priv->workqueue, &priv->restart); |
| 6290 | } |
| 6291 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6292 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6293 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6294 | static void __iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6295 | { |
| 6296 | unsigned long flags; |
| 6297 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6298 | struct ieee80211_conf *conf = NULL; |
| 6299 | |
| 6300 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 6301 | |
| 6302 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6303 | |
| 6304 | if (!exit_pending) |
| 6305 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6306 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6307 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6308 | |
| 6309 | /* Unblock any waiting calls */ |
| 6310 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 6311 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6312 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 6313 | * exiting the module */ |
| 6314 | if (!exit_pending) |
| 6315 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6316 | |
| 6317 | /* stop and reset the on-board processor */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6318 | iwl4965_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6319 | |
| 6320 | /* tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6321 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6322 | |
| 6323 | if (priv->mac80211_registered) |
| 6324 | ieee80211_stop_queues(priv->hw); |
| 6325 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6326 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6327 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6328 | if (!iwl4965_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6329 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6330 | STATUS_RF_KILL_HW | |
| 6331 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6332 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 6333 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 6334 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6335 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6336 | STATUS_IN_SUSPEND; |
| 6337 | goto exit; |
| 6338 | } |
| 6339 | |
| 6340 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 6341 | * SUSPEND bits and continue taking the NIC down. */ |
| 6342 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6343 | STATUS_RF_KILL_HW | |
| 6344 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6345 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 6346 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 6347 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6348 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6349 | STATUS_IN_SUSPEND | |
| 6350 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 6351 | STATUS_FW_ERROR; |
| 6352 | |
| 6353 | spin_lock_irqsave(&priv->lock, flags); |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6354 | iwl4965_clear_bit(priv, CSR_GP_CNTRL, |
| 6355 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6356 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6357 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6358 | iwl4965_hw_txq_ctx_stop(priv); |
| 6359 | iwl4965_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6360 | |
| 6361 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6362 | if (!iwl4965_grab_nic_access(priv)) { |
| 6363 | iwl4965_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6364 | APMG_CLK_VAL_DMA_CLK_RQT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6365 | iwl4965_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6366 | } |
| 6367 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6368 | |
| 6369 | udelay(5); |
| 6370 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6371 | iwl4965_hw_nic_stop_master(priv); |
| 6372 | iwl4965_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
| 6373 | iwl4965_hw_nic_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6374 | |
| 6375 | exit: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6376 | memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6377 | |
| 6378 | if (priv->ibss_beacon) |
| 6379 | dev_kfree_skb(priv->ibss_beacon); |
| 6380 | priv->ibss_beacon = NULL; |
| 6381 | |
| 6382 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6383 | iwl4965_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6384 | } |
| 6385 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6386 | static void iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6387 | { |
| 6388 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6389 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6390 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 6391 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6392 | iwl4965_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6393 | } |
| 6394 | |
| 6395 | #define MAX_HW_RESTARTS 5 |
| 6396 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6397 | static int __iwl4965_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6398 | { |
| 6399 | int rc, i; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6400 | |
| 6401 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6402 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 6403 | return -EIO; |
| 6404 | } |
| 6405 | |
| 6406 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 6407 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 6408 | "parameter)\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6409 | return -ENODEV; |
| 6410 | } |
| 6411 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 6412 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 6413 | IWL_ERROR("ucode not available for device bringup\n"); |
| 6414 | return -EIO; |
| 6415 | } |
| 6416 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6417 | /* If platform's RF_KILL switch is NOT set to KILL */ |
| 6418 | if (iwl4965_read32(priv, CSR_GP_CNTRL) & |
| 6419 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 6420 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 6421 | else { |
| 6422 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 6423 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
| 6424 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 6425 | return -ENODEV; |
| 6426 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6427 | } |
| 6428 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6429 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6430 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6431 | rc = iwl4965_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6432 | if (rc) { |
| 6433 | IWL_ERROR("Unable to int nic\n"); |
| 6434 | return rc; |
| 6435 | } |
| 6436 | |
| 6437 | /* make sure rfkill handshake bits are cleared */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6438 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6439 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6440 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 6441 | |
| 6442 | /* clear (again), then enable host interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6443 | iwl4965_write32(priv, CSR_INT, 0xFFFFFFFF); |
| 6444 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6445 | |
| 6446 | /* really make sure rfkill handshake bits are cleared */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6447 | iwl4965_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6448 | 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] | 6449 | |
| 6450 | /* Copy original ucode data image from disk into backup cache. |
| 6451 | * This will be used to initialize the on-board processor's |
| 6452 | * data SRAM for a clean start when the runtime program first loads. */ |
| 6453 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6454 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6455 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6456 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 6457 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6458 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6459 | |
| 6460 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 6461 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6462 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6463 | |
| 6464 | /* load bootstrap state machine, |
| 6465 | * load bootstrap program into processor's memory, |
| 6466 | * prepare to load the "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6467 | rc = iwl4965_load_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6468 | |
| 6469 | if (rc) { |
| 6470 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc); |
| 6471 | continue; |
| 6472 | } |
| 6473 | |
| 6474 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6475 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6476 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6477 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 6478 | |
| 6479 | return 0; |
| 6480 | } |
| 6481 | |
| 6482 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6483 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6484 | |
| 6485 | /* tried to restart and config the device for as long as our |
| 6486 | * patience could withstand */ |
| 6487 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 6488 | return -EIO; |
| 6489 | } |
| 6490 | |
| 6491 | |
| 6492 | /***************************************************************************** |
| 6493 | * |
| 6494 | * Workqueue callbacks |
| 6495 | * |
| 6496 | *****************************************************************************/ |
| 6497 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6498 | static void iwl4965_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6499 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6500 | struct iwl_priv *priv = |
| 6501 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6502 | |
| 6503 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6504 | return; |
| 6505 | |
| 6506 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6507 | iwl4965_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6508 | mutex_unlock(&priv->mutex); |
| 6509 | } |
| 6510 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6511 | static void iwl4965_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6512 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6513 | struct iwl_priv *priv = |
| 6514 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6515 | |
| 6516 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6517 | return; |
| 6518 | |
| 6519 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6520 | iwl4965_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6521 | mutex_unlock(&priv->mutex); |
| 6522 | } |
| 6523 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6524 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6525 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6526 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6527 | |
| 6528 | wake_up_interruptible(&priv->wait_command_queue); |
| 6529 | |
| 6530 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6531 | return; |
| 6532 | |
| 6533 | mutex_lock(&priv->mutex); |
| 6534 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6535 | if (!iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6536 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 6537 | "HW and/or SW RF Kill no longer active, restarting " |
| 6538 | "device\n"); |
| 6539 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6540 | queue_work(priv->workqueue, &priv->restart); |
| 6541 | } else { |
| 6542 | |
| 6543 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 6544 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 6545 | "disabled by SW switch\n"); |
| 6546 | else |
| 6547 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 6548 | "Kill switch must be turned off for " |
| 6549 | "wireless networking to work.\n"); |
| 6550 | } |
| 6551 | mutex_unlock(&priv->mutex); |
| 6552 | } |
| 6553 | |
| 6554 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 6555 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6556 | static void iwl4965_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6557 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6558 | struct iwl_priv *priv = |
| 6559 | container_of(data, struct iwl_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6560 | |
| 6561 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6562 | return; |
| 6563 | |
| 6564 | mutex_lock(&priv->mutex); |
| 6565 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 6566 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6567 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 6568 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 6569 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6570 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6571 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6572 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6573 | } |
| 6574 | mutex_unlock(&priv->mutex); |
| 6575 | } |
| 6576 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6577 | static void iwl4965_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6578 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6579 | struct iwl_priv *priv = |
| 6580 | container_of(data, struct iwl_priv, request_scan); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6581 | struct iwl4965_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6582 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6583 | .len = sizeof(struct iwl4965_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6584 | .meta.flags = CMD_SIZE_HUGE, |
| 6585 | }; |
| 6586 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6587 | struct iwl4965_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6588 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 6589 | u16 cmd_len; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6590 | enum ieee80211_band band; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 6591 | u8 direct_mask; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6592 | |
| 6593 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6594 | |
| 6595 | mutex_lock(&priv->mutex); |
| 6596 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6597 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6598 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 6599 | goto done; |
| 6600 | } |
| 6601 | |
| 6602 | /* Make sure the scan wasn't cancelled before this queued work |
| 6603 | * was given the chance to run... */ |
| 6604 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 6605 | goto done; |
| 6606 | |
| 6607 | /* This should never be called or scheduled if there is currently |
| 6608 | * a scan active in the hardware. */ |
| 6609 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 6610 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 6611 | "Ignoring second request.\n"); |
| 6612 | rc = -EIO; |
| 6613 | goto done; |
| 6614 | } |
| 6615 | |
| 6616 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6617 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 6618 | goto done; |
| 6619 | } |
| 6620 | |
| 6621 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6622 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 6623 | goto done; |
| 6624 | } |
| 6625 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6626 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6627 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 6628 | goto done; |
| 6629 | } |
| 6630 | |
| 6631 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 6632 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 6633 | goto done; |
| 6634 | } |
| 6635 | |
| 6636 | if (!priv->scan_bands) { |
| 6637 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 6638 | goto done; |
| 6639 | } |
| 6640 | |
| 6641 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6642 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6643 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 6644 | if (!priv->scan) { |
| 6645 | rc = -ENOMEM; |
| 6646 | goto done; |
| 6647 | } |
| 6648 | } |
| 6649 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6650 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6651 | |
| 6652 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 6653 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 6654 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6655 | if (iwl4965_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6656 | u16 interval = 0; |
| 6657 | u32 extra; |
| 6658 | u32 suspend_time = 100; |
| 6659 | u32 scan_suspend_time = 100; |
| 6660 | unsigned long flags; |
| 6661 | |
| 6662 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 6663 | |
| 6664 | spin_lock_irqsave(&priv->lock, flags); |
| 6665 | interval = priv->beacon_int; |
| 6666 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6667 | |
| 6668 | scan->suspend_time = 0; |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6669 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6670 | if (!interval) |
| 6671 | interval = suspend_time; |
| 6672 | |
| 6673 | extra = (suspend_time / interval) << 22; |
| 6674 | scan_suspend_time = (extra | |
| 6675 | ((suspend_time % interval) * 1024)); |
| 6676 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 6677 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 6678 | scan_suspend_time, interval); |
| 6679 | } |
| 6680 | |
| 6681 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 6682 | if (priv->one_direct_scan) { |
| 6683 | IWL_DEBUG_SCAN |
| 6684 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6685 | iwl4965_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6686 | priv->direct_ssid_len)); |
| 6687 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 6688 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 6689 | memcpy(scan->direct_scan[0].ssid, |
| 6690 | priv->direct_ssid, priv->direct_ssid_len); |
| 6691 | direct_mask = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6692 | } else if (!iwl4965_is_associated(priv) && priv->essid_len) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6693 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 6694 | scan->direct_scan[0].len = priv->essid_len; |
| 6695 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 6696 | direct_mask = 1; |
| 6697 | } else |
| 6698 | direct_mask = 0; |
| 6699 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6700 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
| 6701 | scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id; |
| 6702 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 6703 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6704 | |
| 6705 | switch (priv->scan_bands) { |
| 6706 | case 2: |
| 6707 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 6708 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6709 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6710 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 6711 | |
| 6712 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6713 | band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6714 | break; |
| 6715 | |
| 6716 | case 1: |
| 6717 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6718 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6719 | RATE_MCS_ANT_B_MSK); |
| 6720 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6721 | band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6722 | break; |
| 6723 | |
| 6724 | default: |
| 6725 | IWL_WARNING("Invalid scan band count\n"); |
| 6726 | goto done; |
| 6727 | } |
| 6728 | |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 6729 | /* We don't build a direct scan probe request; the uCode will do |
| 6730 | * that based on the direct_mask added to each channel entry */ |
| 6731 | cmd_len = iwl4965_fill_probe_req(priv, band, |
| 6732 | (struct ieee80211_mgmt *)scan->data, |
| 6733 | IWL_MAX_SCAN_SIZE - sizeof(*scan), 0); |
| 6734 | |
| 6735 | scan->tx_cmd.len = cpu_to_le16(cmd_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6736 | /* select Rx chains */ |
| 6737 | |
| 6738 | /* Force use of chains B and C (0x6) for scan Rx. |
| 6739 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 6740 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 6741 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 6742 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 6743 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 6744 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 6745 | |
| 6746 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 6747 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 6748 | |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 6749 | if (direct_mask) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6750 | IWL_DEBUG_SCAN |
| 6751 | ("Initiating direct scan for %s.\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6752 | iwl4965_escape_essid(priv->essid, priv->essid_len)); |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 6753 | scan->channel_count = |
| 6754 | iwl4965_get_channels_for_scan( |
| 6755 | priv, band, 1, /* active */ |
| 6756 | direct_mask, |
| 6757 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
| 6758 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6759 | IWL_DEBUG_SCAN("Initiating indirect scan.\n"); |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 6760 | scan->channel_count = |
| 6761 | iwl4965_get_channels_for_scan( |
| 6762 | priv, band, 0, /* passive */ |
| 6763 | direct_mask, |
| 6764 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
| 6765 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6766 | |
| 6767 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6768 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6769 | cmd.data = scan; |
| 6770 | scan->len = cpu_to_le16(cmd.len); |
| 6771 | |
| 6772 | set_bit(STATUS_SCAN_HW, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6773 | rc = iwl4965_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6774 | if (rc) |
| 6775 | goto done; |
| 6776 | |
| 6777 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 6778 | IWL_SCAN_CHECK_WATCHDOG); |
| 6779 | |
| 6780 | mutex_unlock(&priv->mutex); |
| 6781 | return; |
| 6782 | |
| 6783 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 6784 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6785 | queue_work(priv->workqueue, &priv->scan_completed); |
| 6786 | mutex_unlock(&priv->mutex); |
| 6787 | } |
| 6788 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6789 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6790 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6791 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6792 | |
| 6793 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6794 | return; |
| 6795 | |
| 6796 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6797 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6798 | mutex_unlock(&priv->mutex); |
| 6799 | } |
| 6800 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6801 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6802 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6803 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6804 | |
| 6805 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6806 | return; |
| 6807 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6808 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6809 | queue_work(priv->workqueue, &priv->up); |
| 6810 | } |
| 6811 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6812 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6813 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6814 | struct iwl_priv *priv = |
| 6815 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6816 | |
| 6817 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6818 | return; |
| 6819 | |
| 6820 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6821 | iwl4965_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6822 | mutex_unlock(&priv->mutex); |
| 6823 | } |
| 6824 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6825 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 6826 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6827 | static void iwl4965_bg_post_associate(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6828 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6829 | struct iwl_priv *priv = container_of(data, struct iwl_priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6830 | post_associate.work); |
| 6831 | |
| 6832 | int rc = 0; |
| 6833 | struct ieee80211_conf *conf = NULL; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6834 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6835 | |
| 6836 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 6837 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 6838 | return; |
| 6839 | } |
| 6840 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6841 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 6842 | priv->assoc_id, |
| 6843 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6844 | |
| 6845 | |
| 6846 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6847 | return; |
| 6848 | |
| 6849 | mutex_lock(&priv->mutex); |
| 6850 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6851 | if (!priv->vif || !priv->is_open) { |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 6852 | mutex_unlock(&priv->mutex); |
| 6853 | return; |
| 6854 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6855 | iwl4965_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6856 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6857 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6858 | |
| 6859 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6860 | iwl4965_commit_rxon(priv); |
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 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 6863 | iwl4965_setup_rxon_timing(priv); |
| 6864 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6865 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 6866 | if (rc) |
| 6867 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 6868 | "Attempting to continue.\n"); |
| 6869 | |
| 6870 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 6871 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6872 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 6873 | if (priv->current_ht_config.is_ht) |
| 6874 | iwl4965_set_rxon_ht(priv, &priv->current_ht_config); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6875 | #endif /* CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6876 | iwl4965_set_rxon_chain(priv); |
| 6877 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 6878 | |
| 6879 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 6880 | priv->assoc_id, priv->beacon_int); |
| 6881 | |
| 6882 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 6883 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6884 | else |
| 6885 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6886 | |
| 6887 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 6888 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 6889 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 6890 | else |
| 6891 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 6892 | |
| 6893 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 6894 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 6895 | |
| 6896 | } |
| 6897 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6898 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6899 | |
| 6900 | switch (priv->iw_mode) { |
| 6901 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6902 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6903 | break; |
| 6904 | |
| 6905 | case IEEE80211_IF_TYPE_IBSS: |
| 6906 | |
| 6907 | /* clear out the station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6908 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6909 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6910 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
| 6911 | iwl4965_rxon_add_station(priv, priv->bssid, 0); |
| 6912 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
| 6913 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6914 | |
| 6915 | break; |
| 6916 | |
| 6917 | default: |
| 6918 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 6919 | __FUNCTION__, priv->iw_mode); |
| 6920 | break; |
| 6921 | } |
| 6922 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6923 | iwl4965_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6924 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6925 | #ifdef CONFIG_IWL4965_SENSITIVITY |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6926 | /* Enable Rx differential gain and sensitivity calibrations */ |
| 6927 | iwl4965_chain_noise_reset(priv); |
| 6928 | priv->start_calib = 1; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6929 | #endif /* CONFIG_IWL4965_SENSITIVITY */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6930 | |
| 6931 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 6932 | priv->assoc_station_added = 1; |
| 6933 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6934 | iwl4965_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 6935 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6936 | /* we have just associated, don't start scan too early */ |
| 6937 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6938 | mutex_unlock(&priv->mutex); |
| 6939 | } |
| 6940 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6941 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6942 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6943 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6944 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6945 | if (!iwl4965_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6946 | return; |
| 6947 | |
| 6948 | mutex_lock(&priv->mutex); |
| 6949 | |
| 6950 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6951 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6952 | |
| 6953 | mutex_unlock(&priv->mutex); |
| 6954 | } |
| 6955 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6956 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 6957 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6958 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6959 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6960 | struct iwl_priv *priv = |
| 6961 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6962 | |
| 6963 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 6964 | |
| 6965 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6966 | return; |
| 6967 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6968 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
| 6969 | iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6970 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6971 | ieee80211_scan_completed(priv->hw); |
| 6972 | |
| 6973 | /* Since setting the TXPOWER may have been deferred while |
| 6974 | * performing the scan, fire one off */ |
| 6975 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6976 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6977 | mutex_unlock(&priv->mutex); |
| 6978 | } |
| 6979 | |
| 6980 | /***************************************************************************** |
| 6981 | * |
| 6982 | * mac80211 entry point functions |
| 6983 | * |
| 6984 | *****************************************************************************/ |
| 6985 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6986 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 6987 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6988 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6989 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 6990 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6991 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6992 | |
| 6993 | IWL_DEBUG_MAC80211("enter\n"); |
| 6994 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6995 | if (pci_enable_device(priv->pci_dev)) { |
| 6996 | IWL_ERROR("Fail to pci_enable_device\n"); |
| 6997 | return -ENODEV; |
| 6998 | } |
| 6999 | pci_restore_state(priv->pci_dev); |
| 7000 | pci_enable_msi(priv->pci_dev); |
| 7001 | |
| 7002 | ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, |
| 7003 | DRV_NAME, priv); |
| 7004 | if (ret) { |
| 7005 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 7006 | goto out_disable_msi; |
| 7007 | } |
| 7008 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7009 | /* we should be verifying the device is ready to be opened */ |
| 7010 | mutex_lock(&priv->mutex); |
| 7011 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7012 | memset(&priv->staging_rxon, 0, sizeof(struct iwl4965_rxon_cmd)); |
| 7013 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 7014 | * ucode filename and max sizes are card-specific. */ |
| 7015 | |
| 7016 | if (!priv->ucode_code.len) { |
| 7017 | ret = iwl4965_read_ucode(priv); |
| 7018 | if (ret) { |
| 7019 | IWL_ERROR("Could not read microcode: %d\n", ret); |
| 7020 | mutex_unlock(&priv->mutex); |
| 7021 | goto out_release_irq; |
| 7022 | } |
| 7023 | } |
| 7024 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7025 | ret = __iwl4965_up(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7026 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7027 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7028 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7029 | if (ret) |
| 7030 | goto out_release_irq; |
| 7031 | |
| 7032 | IWL_DEBUG_INFO("Start UP work done.\n"); |
| 7033 | |
| 7034 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 7035 | return 0; |
| 7036 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7037 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 7038 | * mac80211 will not be run successfully. */ |
| 7039 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 7040 | test_bit(STATUS_READY, &priv->status), |
| 7041 | UCODE_READY_TIMEOUT); |
| 7042 | if (!ret) { |
| 7043 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 7044 | IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n", |
| 7045 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 7046 | ret = -ETIMEDOUT; |
| 7047 | goto out_release_irq; |
| 7048 | } |
| 7049 | } |
| 7050 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7051 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7052 | IWL_DEBUG_MAC80211("leave\n"); |
| 7053 | return 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7054 | |
| 7055 | out_release_irq: |
| 7056 | free_irq(priv->pci_dev->irq, priv); |
| 7057 | out_disable_msi: |
| 7058 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7059 | pci_disable_device(priv->pci_dev); |
| 7060 | priv->is_open = 0; |
| 7061 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7062 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7063 | } |
| 7064 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7065 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7066 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7067 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7068 | |
| 7069 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7070 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7071 | if (!priv->is_open) { |
| 7072 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 7073 | return; |
| 7074 | } |
| 7075 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7076 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7077 | |
| 7078 | if (iwl4965_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7079 | /* stop mac, cancel any scan request and clear |
| 7080 | * RXON_FILTER_ASSOC_MSK BIT |
| 7081 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7082 | mutex_lock(&priv->mutex); |
| 7083 | iwl4965_scan_cancel_timeout(priv, 100); |
| 7084 | cancel_delayed_work(&priv->post_associate); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7085 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7086 | } |
| 7087 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7088 | iwl4965_down(priv); |
| 7089 | |
| 7090 | flush_workqueue(priv->workqueue); |
| 7091 | free_irq(priv->pci_dev->irq, priv); |
| 7092 | pci_disable_msi(priv->pci_dev); |
| 7093 | pci_save_state(priv->pci_dev); |
| 7094 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7095 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7096 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7097 | } |
| 7098 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7099 | 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] | 7100 | struct ieee80211_tx_control *ctl) |
| 7101 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7102 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7103 | |
| 7104 | IWL_DEBUG_MAC80211("enter\n"); |
| 7105 | |
| 7106 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 7107 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 7108 | return -1; |
| 7109 | } |
| 7110 | |
| 7111 | 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] | 7112 | ctl->tx_rate->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7113 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7114 | if (iwl4965_tx_skb(priv, skb, ctl)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7115 | dev_kfree_skb_any(skb); |
| 7116 | |
| 7117 | IWL_DEBUG_MAC80211("leave\n"); |
| 7118 | return 0; |
| 7119 | } |
| 7120 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7121 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7122 | struct ieee80211_if_init_conf *conf) |
| 7123 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7124 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7125 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7126 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7127 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7128 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7129 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7130 | if (priv->vif) { |
| 7131 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Reinette Chatre | 75849d2 | 2008-01-23 10:15:17 -0800 | [diff] [blame] | 7132 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7133 | } |
| 7134 | |
| 7135 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7136 | priv->vif = conf->vif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7137 | |
| 7138 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7139 | |
| 7140 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 7141 | |
| 7142 | if (conf->mac_addr) { |
| 7143 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 7144 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 7145 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7146 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7147 | if (iwl4965_is_ready(priv)) |
| 7148 | iwl4965_set_mode(priv, conf->type); |
| 7149 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7150 | mutex_unlock(&priv->mutex); |
| 7151 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7152 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7153 | return 0; |
| 7154 | } |
| 7155 | |
| 7156 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7157 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7158 | * |
| 7159 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 7160 | * be set inappropriately and the driver currently sets the hardware up to |
| 7161 | * use it whenever needed. |
| 7162 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7163 | 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] | 7164 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7165 | struct iwl_priv *priv = hw->priv; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7166 | const struct iwl4965_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7167 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7168 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7169 | |
| 7170 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7171 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7172 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 7173 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
| 7174 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7175 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7176 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7177 | ret = -EIO; |
| 7178 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7179 | } |
| 7180 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7181 | if (unlikely(!iwl4965_param_disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7182 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7183 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 7184 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7185 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7186 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7187 | } |
| 7188 | |
| 7189 | spin_lock_irqsave(&priv->lock, flags); |
| 7190 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7191 | ch_info = iwl4965_get_channel_info(priv, conf->channel->band, |
| 7192 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7193 | if (!is_channel_valid(ch_info)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7194 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 7195 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7196 | ret = -EINVAL; |
| 7197 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7198 | } |
| 7199 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7200 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 7201 | /* if we are switching from ht to 2.4 clear flags |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7202 | * from any ht related info since 2.4 does not |
| 7203 | * support ht */ |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 7204 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7205 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7206 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 7207 | #endif |
| 7208 | ) |
| 7209 | priv->staging_rxon.flags = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7210 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7211 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7212 | iwl4965_set_rxon_channel(priv, conf->channel->band, |
| 7213 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7214 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7215 | iwl4965_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7216 | |
| 7217 | /* The list of supported rates and rate mask can be different |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7218 | * for each band; since the band may have changed, reset |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7219 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7220 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7221 | |
| 7222 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7223 | |
| 7224 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7225 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7226 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7227 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7228 | } |
| 7229 | #endif |
| 7230 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7231 | iwl4965_radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7232 | |
| 7233 | if (!conf->radio_enabled) { |
| 7234 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7235 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7236 | } |
| 7237 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7238 | if (iwl4965_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7239 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7240 | ret = -EIO; |
| 7241 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7242 | } |
| 7243 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7244 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7245 | |
| 7246 | if (memcmp(&priv->active_rxon, |
| 7247 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7248 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7249 | else |
| 7250 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 7251 | |
| 7252 | IWL_DEBUG_MAC80211("leave\n"); |
| 7253 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7254 | out: |
| 7255 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7256 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7257 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7258 | } |
| 7259 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7260 | static void iwl4965_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7261 | { |
| 7262 | int rc = 0; |
| 7263 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 7264 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7265 | return; |
| 7266 | |
| 7267 | /* The following should be done only at AP bring up */ |
| 7268 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 7269 | |
| 7270 | /* RXON - unassoc (to set timing command) */ |
| 7271 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7272 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7273 | |
| 7274 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7275 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 7276 | iwl4965_setup_rxon_timing(priv); |
| 7277 | rc = iwl4965_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7278 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 7279 | if (rc) |
| 7280 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 7281 | "Attempting to continue.\n"); |
| 7282 | |
| 7283 | iwl4965_set_rxon_chain(priv); |
| 7284 | |
| 7285 | /* FIXME: what should be the assoc_id for AP? */ |
| 7286 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 7287 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7288 | priv->staging_rxon.flags |= |
| 7289 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7290 | else |
| 7291 | priv->staging_rxon.flags &= |
| 7292 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7293 | |
| 7294 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 7295 | if (priv->assoc_capability & |
| 7296 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 7297 | priv->staging_rxon.flags |= |
| 7298 | RXON_FLG_SHORT_SLOT_MSK; |
| 7299 | else |
| 7300 | priv->staging_rxon.flags &= |
| 7301 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7302 | |
| 7303 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7304 | priv->staging_rxon.flags &= |
| 7305 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7306 | } |
| 7307 | /* restore RXON assoc */ |
| 7308 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7309 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7310 | iwl4965_activate_qos(priv, 1); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7311 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 7312 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7313 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7314 | |
| 7315 | /* FIXME - we need to add code here to detect a totally new |
| 7316 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 7317 | * clear sta table, add BCAST sta... */ |
| 7318 | } |
| 7319 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7320 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, |
| 7321 | struct ieee80211_vif *vif, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7322 | struct ieee80211_if_conf *conf) |
| 7323 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7324 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7325 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7326 | unsigned long flags; |
| 7327 | int rc; |
| 7328 | |
| 7329 | if (conf == NULL) |
| 7330 | return -EIO; |
| 7331 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 7332 | if (priv->vif != vif) { |
| 7333 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
| 7334 | mutex_unlock(&priv->mutex); |
| 7335 | return 0; |
| 7336 | } |
| 7337 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7338 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 7339 | (!conf->beacon || !conf->ssid_len)) { |
| 7340 | IWL_DEBUG_MAC80211 |
| 7341 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 7342 | return 0; |
| 7343 | } |
| 7344 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7345 | if (!iwl4965_is_alive(priv)) |
| 7346 | return -EAGAIN; |
| 7347 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7348 | mutex_lock(&priv->mutex); |
| 7349 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7350 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7351 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 7352 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7353 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7354 | /* |
| 7355 | * very dubious code was here; the probe filtering flag is never set: |
| 7356 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7357 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 7358 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7359 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7360 | |
| 7361 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 7362 | if (!conf->bssid) { |
| 7363 | conf->bssid = priv->mac_addr; |
| 7364 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7365 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 7366 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7367 | } |
| 7368 | if (priv->ibss_beacon) |
| 7369 | dev_kfree_skb(priv->ibss_beacon); |
| 7370 | |
| 7371 | priv->ibss_beacon = conf->beacon; |
| 7372 | } |
| 7373 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7374 | if (iwl4965_is_rfkill(priv)) |
| 7375 | goto done; |
| 7376 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7377 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 7378 | !is_multicast_ether_addr(conf->bssid)) { |
| 7379 | /* If there is currently a HW scan going on in the background |
| 7380 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7381 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7382 | IWL_WARNING("Aborted scan still in progress " |
| 7383 | "after 100ms\n"); |
| 7384 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 7385 | mutex_unlock(&priv->mutex); |
| 7386 | return -EAGAIN; |
| 7387 | } |
| 7388 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 7389 | |
| 7390 | /* TODO: Audit driver for usage of these members and see |
| 7391 | * if mac80211 deprecates them (priv->bssid looks like it |
| 7392 | * shouldn't be there, but I haven't scanned the IBSS code |
| 7393 | * to verify) - jpk */ |
| 7394 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 7395 | |
| 7396 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7397 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7398 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7399 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7400 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7401 | iwl4965_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7402 | priv, priv->active_rxon.bssid_addr, 1); |
| 7403 | } |
| 7404 | |
| 7405 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7406 | iwl4965_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7407 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7408 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7409 | } |
| 7410 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7411 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7412 | spin_lock_irqsave(&priv->lock, flags); |
| 7413 | if (!conf->ssid_len) |
| 7414 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7415 | else |
| 7416 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 7417 | |
| 7418 | priv->essid_len = conf->ssid_len; |
| 7419 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7420 | |
| 7421 | IWL_DEBUG_MAC80211("leave\n"); |
| 7422 | mutex_unlock(&priv->mutex); |
| 7423 | |
| 7424 | return 0; |
| 7425 | } |
| 7426 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7427 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7428 | unsigned int changed_flags, |
| 7429 | unsigned int *total_flags, |
| 7430 | int mc_count, struct dev_addr_list *mc_list) |
| 7431 | { |
| 7432 | /* |
| 7433 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7434 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7435 | */ |
| 7436 | *total_flags = 0; |
| 7437 | } |
| 7438 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7439 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7440 | struct ieee80211_if_init_conf *conf) |
| 7441 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7442 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7443 | |
| 7444 | IWL_DEBUG_MAC80211("enter\n"); |
| 7445 | |
| 7446 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7447 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7448 | if (iwl4965_is_ready_rf(priv)) { |
| 7449 | iwl4965_scan_cancel_timeout(priv, 100); |
| 7450 | cancel_delayed_work(&priv->post_associate); |
| 7451 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 7452 | iwl4965_commit_rxon(priv); |
| 7453 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7454 | if (priv->vif == conf->vif) { |
| 7455 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7456 | memset(priv->bssid, 0, ETH_ALEN); |
| 7457 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7458 | priv->essid_len = 0; |
| 7459 | } |
| 7460 | mutex_unlock(&priv->mutex); |
| 7461 | |
| 7462 | IWL_DEBUG_MAC80211("leave\n"); |
| 7463 | |
| 7464 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7465 | |
| 7466 | static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, |
| 7467 | struct ieee80211_vif *vif, |
| 7468 | struct ieee80211_bss_conf *bss_conf, |
| 7469 | u32 changes) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7470 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7471 | struct iwl_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7472 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7473 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
| 7474 | if (bss_conf->use_short_preamble) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7475 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7476 | else |
| 7477 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7478 | } |
| 7479 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7480 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7481 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7482 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 7483 | else |
| 7484 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 7485 | } |
| 7486 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7487 | if (changes & BSS_CHANGED_ASSOC) { |
| 7488 | /* |
| 7489 | * TODO: |
| 7490 | * do stuff instead of sniffing assoc resp |
| 7491 | */ |
| 7492 | } |
| 7493 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7494 | if (iwl4965_is_associated(priv)) |
| 7495 | iwl4965_send_rxon_assoc(priv); |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 7496 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7497 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7498 | 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] | 7499 | { |
| 7500 | int rc = 0; |
| 7501 | unsigned long flags; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7502 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7503 | |
| 7504 | IWL_DEBUG_MAC80211("enter\n"); |
| 7505 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7506 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7507 | spin_lock_irqsave(&priv->lock, flags); |
| 7508 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7509 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7510 | rc = -EIO; |
| 7511 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 7512 | goto out_unlock; |
| 7513 | } |
| 7514 | |
| 7515 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 7516 | rc = -EIO; |
| 7517 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 7518 | goto out_unlock; |
| 7519 | } |
| 7520 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7521 | /* we don't schedule scan within next_scan_jiffies period */ |
| 7522 | if (priv->next_scan_jiffies && |
| 7523 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 7524 | rc = -EAGAIN; |
| 7525 | goto out_unlock; |
| 7526 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7527 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7528 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 7529 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7530 | rc = -EAGAIN; |
| 7531 | goto out_unlock; |
| 7532 | } |
| 7533 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7534 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7535 | iwl4965_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7536 | |
| 7537 | priv->one_direct_scan = 1; |
| 7538 | priv->direct_ssid_len = (u8) |
| 7539 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 7540 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7541 | } else |
| 7542 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7543 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7544 | rc = iwl4965_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7545 | |
| 7546 | IWL_DEBUG_MAC80211("leave\n"); |
| 7547 | |
| 7548 | out_unlock: |
| 7549 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7550 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7551 | |
| 7552 | return rc; |
| 7553 | } |
| 7554 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7555 | 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] | 7556 | const u8 *local_addr, const u8 *addr, |
| 7557 | struct ieee80211_key_conf *key) |
| 7558 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7559 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7560 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7561 | int rc = 0; |
| 7562 | u8 sta_id; |
| 7563 | |
| 7564 | IWL_DEBUG_MAC80211("enter\n"); |
| 7565 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7566 | if (!iwl4965_param_hwcrypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7567 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 7568 | return -EOPNOTSUPP; |
| 7569 | } |
| 7570 | |
| 7571 | if (is_zero_ether_addr(addr)) |
| 7572 | /* only support pairwise keys */ |
| 7573 | return -EOPNOTSUPP; |
| 7574 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7575 | sta_id = iwl4965_hw_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7576 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7577 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 7578 | print_mac(mac, addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7579 | return -EINVAL; |
| 7580 | } |
| 7581 | |
| 7582 | mutex_lock(&priv->mutex); |
| 7583 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7584 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7585 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7586 | switch (cmd) { |
| 7587 | case SET_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7588 | rc = iwl4965_update_sta_key_info(priv, key, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7589 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7590 | iwl4965_set_rxon_hwcrypto(priv, 1); |
| 7591 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7592 | key->hw_key_idx = sta_id; |
| 7593 | IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); |
| 7594 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 7595 | } |
| 7596 | break; |
| 7597 | case DISABLE_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7598 | rc = iwl4965_clear_sta_key_info(priv, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7599 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7600 | iwl4965_set_rxon_hwcrypto(priv, 0); |
| 7601 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7602 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
| 7603 | } |
| 7604 | break; |
| 7605 | default: |
| 7606 | rc = -EINVAL; |
| 7607 | } |
| 7608 | |
| 7609 | IWL_DEBUG_MAC80211("leave\n"); |
| 7610 | mutex_unlock(&priv->mutex); |
| 7611 | |
| 7612 | return rc; |
| 7613 | } |
| 7614 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7615 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7616 | const struct ieee80211_tx_queue_params *params) |
| 7617 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7618 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7619 | unsigned long flags; |
| 7620 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7621 | |
| 7622 | IWL_DEBUG_MAC80211("enter\n"); |
| 7623 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7624 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7625 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7626 | return -EIO; |
| 7627 | } |
| 7628 | |
| 7629 | if (queue >= AC_NUM) { |
| 7630 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 7631 | return 0; |
| 7632 | } |
| 7633 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7634 | if (!priv->qos_data.qos_enable) { |
| 7635 | priv->qos_data.qos_active = 0; |
| 7636 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 7637 | return 0; |
| 7638 | } |
| 7639 | q = AC_NUM - 1 - queue; |
| 7640 | |
| 7641 | spin_lock_irqsave(&priv->lock, flags); |
| 7642 | |
| 7643 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 7644 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 7645 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 7646 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 7647 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7648 | |
| 7649 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 7650 | priv->qos_data.qos_active = 1; |
| 7651 | |
| 7652 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7653 | |
| 7654 | mutex_lock(&priv->mutex); |
| 7655 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7656 | iwl4965_activate_qos(priv, 1); |
| 7657 | else if (priv->assoc_id && iwl4965_is_associated(priv)) |
| 7658 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7659 | |
| 7660 | mutex_unlock(&priv->mutex); |
| 7661 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7662 | IWL_DEBUG_MAC80211("leave\n"); |
| 7663 | return 0; |
| 7664 | } |
| 7665 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7666 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7667 | struct ieee80211_tx_queue_stats *stats) |
| 7668 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7669 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7670 | int i, avail; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7671 | struct iwl4965_tx_queue *txq; |
| 7672 | struct iwl4965_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7673 | unsigned long flags; |
| 7674 | |
| 7675 | IWL_DEBUG_MAC80211("enter\n"); |
| 7676 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7677 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7678 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7679 | return -EIO; |
| 7680 | } |
| 7681 | |
| 7682 | spin_lock_irqsave(&priv->lock, flags); |
| 7683 | |
| 7684 | for (i = 0; i < AC_NUM; i++) { |
| 7685 | txq = &priv->txq[i]; |
| 7686 | q = &txq->q; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7687 | avail = iwl4965_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7688 | |
| 7689 | stats->data[i].len = q->n_window - avail; |
| 7690 | stats->data[i].limit = q->n_window - q->high_mark; |
| 7691 | stats->data[i].count = q->n_window; |
| 7692 | |
| 7693 | } |
| 7694 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7695 | |
| 7696 | IWL_DEBUG_MAC80211("leave\n"); |
| 7697 | |
| 7698 | return 0; |
| 7699 | } |
| 7700 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7701 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7702 | struct ieee80211_low_level_stats *stats) |
| 7703 | { |
| 7704 | IWL_DEBUG_MAC80211("enter\n"); |
| 7705 | IWL_DEBUG_MAC80211("leave\n"); |
| 7706 | |
| 7707 | return 0; |
| 7708 | } |
| 7709 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7710 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7711 | { |
| 7712 | IWL_DEBUG_MAC80211("enter\n"); |
| 7713 | IWL_DEBUG_MAC80211("leave\n"); |
| 7714 | |
| 7715 | return 0; |
| 7716 | } |
| 7717 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7718 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7719 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7720 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7721 | unsigned long flags; |
| 7722 | |
| 7723 | mutex_lock(&priv->mutex); |
| 7724 | IWL_DEBUG_MAC80211("enter\n"); |
| 7725 | |
| 7726 | priv->lq_mngr.lq_ready = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7727 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7728 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7729 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7730 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7731 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7732 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7733 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7734 | |
| 7735 | cancel_delayed_work(&priv->post_associate); |
| 7736 | |
| 7737 | spin_lock_irqsave(&priv->lock, flags); |
| 7738 | priv->assoc_id = 0; |
| 7739 | priv->assoc_capability = 0; |
| 7740 | priv->call_post_assoc_from_beacon = 0; |
| 7741 | priv->assoc_station_added = 0; |
| 7742 | |
| 7743 | /* new association get rid of ibss beacon skb */ |
| 7744 | if (priv->ibss_beacon) |
| 7745 | dev_kfree_skb(priv->ibss_beacon); |
| 7746 | |
| 7747 | priv->ibss_beacon = NULL; |
| 7748 | |
| 7749 | priv->beacon_int = priv->hw->conf.beacon_int; |
| 7750 | priv->timestamp1 = 0; |
| 7751 | priv->timestamp0 = 0; |
| 7752 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 7753 | priv->beacon_int = 0; |
| 7754 | |
| 7755 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7756 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7757 | if (!iwl4965_is_ready_rf(priv)) { |
| 7758 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 7759 | mutex_unlock(&priv->mutex); |
| 7760 | return; |
| 7761 | } |
| 7762 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7763 | /* we are restarting association process |
| 7764 | * clear RXON_FILTER_ASSOC_MSK bit |
| 7765 | */ |
| 7766 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7767 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7768 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7769 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7770 | } |
| 7771 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7772 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 7773 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 7774 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7775 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 7776 | mutex_unlock(&priv->mutex); |
| 7777 | return; |
| 7778 | } |
| 7779 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7780 | priv->only_active_channel = 0; |
| 7781 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7782 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7783 | |
| 7784 | mutex_unlock(&priv->mutex); |
| 7785 | |
| 7786 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7787 | } |
| 7788 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7789 | 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] | 7790 | struct ieee80211_tx_control *control) |
| 7791 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7792 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7793 | unsigned long flags; |
| 7794 | |
| 7795 | mutex_lock(&priv->mutex); |
| 7796 | IWL_DEBUG_MAC80211("enter\n"); |
| 7797 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7798 | if (!iwl4965_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7799 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7800 | mutex_unlock(&priv->mutex); |
| 7801 | return -EIO; |
| 7802 | } |
| 7803 | |
| 7804 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 7805 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 7806 | mutex_unlock(&priv->mutex); |
| 7807 | return -EIO; |
| 7808 | } |
| 7809 | |
| 7810 | spin_lock_irqsave(&priv->lock, flags); |
| 7811 | |
| 7812 | if (priv->ibss_beacon) |
| 7813 | dev_kfree_skb(priv->ibss_beacon); |
| 7814 | |
| 7815 | priv->ibss_beacon = skb; |
| 7816 | |
| 7817 | priv->assoc_id = 0; |
| 7818 | |
| 7819 | IWL_DEBUG_MAC80211("leave\n"); |
| 7820 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7821 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7822 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7823 | |
| 7824 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 7825 | |
| 7826 | mutex_unlock(&priv->mutex); |
| 7827 | |
| 7828 | return 0; |
| 7829 | } |
| 7830 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7831 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7832 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7833 | static void iwl4965_ht_info_fill(struct ieee80211_conf *conf, |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7834 | struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7835 | { |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7836 | struct iwl_ht_info *iwl_conf = &priv->current_ht_config; |
| 7837 | struct ieee80211_ht_info *ht_conf = &conf->ht_conf; |
| 7838 | struct ieee80211_ht_bss_info *ht_bss_conf = &conf->ht_bss_conf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7839 | |
| 7840 | IWL_DEBUG_MAC80211("enter: \n"); |
| 7841 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7842 | if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) { |
| 7843 | iwl_conf->is_ht = 0; |
| 7844 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7845 | } |
| 7846 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7847 | iwl_conf->is_ht = 1; |
| 7848 | 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] | 7849 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7850 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) |
| 7851 | iwl_conf->sgf |= 0x1; |
| 7852 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) |
| 7853 | iwl_conf->sgf |= 0x2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7854 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7855 | iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); |
| 7856 | iwl_conf->max_amsdu_size = |
| 7857 | !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); |
Guy Cohen | 134eb5d | 2008-03-04 18:09:25 -0800 | [diff] [blame] | 7858 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7859 | iwl_conf->supported_chan_width = |
| 7860 | !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); |
Guy Cohen | 134eb5d | 2008-03-04 18:09:25 -0800 | [diff] [blame] | 7861 | iwl_conf->extension_chan_offset = |
| 7862 | ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; |
| 7863 | /* If no above or below channel supplied disable FAT channel */ |
| 7864 | if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE && |
| 7865 | iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW) |
| 7866 | iwl_conf->supported_chan_width = 0; |
| 7867 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7868 | iwl_conf->tx_mimo_ps_mode = |
| 7869 | (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 7870 | memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7871 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7872 | iwl_conf->control_channel = ht_bss_conf->primary_channel; |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7873 | iwl_conf->tx_chan_width = |
| 7874 | !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); |
| 7875 | iwl_conf->ht_protection = |
| 7876 | ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; |
| 7877 | iwl_conf->non_GF_STA_present = |
| 7878 | !!(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] | 7879 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7880 | IWL_DEBUG_MAC80211("control channel %d\n", |
| 7881 | iwl_conf->control_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7882 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7883 | } |
| 7884 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7885 | static int iwl4965_mac_conf_ht(struct ieee80211_hw *hw, |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7886 | struct ieee80211_conf *conf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7887 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7888 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7889 | |
| 7890 | IWL_DEBUG_MAC80211("enter: \n"); |
| 7891 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7892 | iwl4965_ht_info_fill(conf, priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7893 | iwl4965_set_rxon_chain(priv); |
| 7894 | |
| 7895 | if (priv && priv->assoc_id && |
| 7896 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
| 7897 | unsigned long flags; |
| 7898 | |
| 7899 | spin_lock_irqsave(&priv->lock, flags); |
| 7900 | if (priv->beacon_int) |
| 7901 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 7902 | else |
| 7903 | priv->call_post_assoc_from_beacon = 1; |
| 7904 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7905 | } |
| 7906 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 7907 | IWL_DEBUG_MAC80211("leave:\n"); |
| 7908 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7909 | } |
| 7910 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7911 | #endif /*CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7912 | |
| 7913 | /***************************************************************************** |
| 7914 | * |
| 7915 | * sysfs attributes |
| 7916 | * |
| 7917 | *****************************************************************************/ |
| 7918 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 7919 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7920 | |
| 7921 | /* |
| 7922 | * The following adds a new attribute to the sysfs representation |
| 7923 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 7924 | * used for controlling the debug level. |
| 7925 | * |
| 7926 | * See the level definitions in iwl for details. |
| 7927 | */ |
| 7928 | |
| 7929 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 7930 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 7931 | return sprintf(buf, "0x%08X\n", iwl_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7932 | } |
| 7933 | static ssize_t store_debug_level(struct device_driver *d, |
| 7934 | const char *buf, size_t count) |
| 7935 | { |
| 7936 | char *p = (char *)buf; |
| 7937 | u32 val; |
| 7938 | |
| 7939 | val = simple_strtoul(p, &p, 0); |
| 7940 | if (p == buf) |
| 7941 | printk(KERN_INFO DRV_NAME |
| 7942 | ": %s is not in hex or decimal form.\n", buf); |
| 7943 | else |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 7944 | iwl_debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7945 | |
| 7946 | return strnlen(buf, count); |
| 7947 | } |
| 7948 | |
| 7949 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 7950 | show_debug_level, store_debug_level); |
| 7951 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 7952 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7953 | |
| 7954 | static ssize_t show_rf_kill(struct device *d, |
| 7955 | struct device_attribute *attr, char *buf) |
| 7956 | { |
| 7957 | /* |
| 7958 | * 0 - RF kill not enabled |
| 7959 | * 1 - SW based RF kill active (sysfs) |
| 7960 | * 2 - HW based RF kill active |
| 7961 | * 3 - Both HW and SW based RF kill active |
| 7962 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7963 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7964 | int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) | |
| 7965 | (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0); |
| 7966 | |
| 7967 | return sprintf(buf, "%i\n", val); |
| 7968 | } |
| 7969 | |
| 7970 | static ssize_t store_rf_kill(struct device *d, |
| 7971 | struct device_attribute *attr, |
| 7972 | const char *buf, size_t count) |
| 7973 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7974 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7975 | |
| 7976 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7977 | iwl4965_radio_kill_sw(priv, buf[0] == '1'); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7978 | mutex_unlock(&priv->mutex); |
| 7979 | |
| 7980 | return count; |
| 7981 | } |
| 7982 | |
| 7983 | static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); |
| 7984 | |
| 7985 | static ssize_t show_temperature(struct device *d, |
| 7986 | struct device_attribute *attr, char *buf) |
| 7987 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 7988 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7989 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7990 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7991 | return -EAGAIN; |
| 7992 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7993 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7994 | } |
| 7995 | |
| 7996 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 7997 | |
| 7998 | static ssize_t show_rs_window(struct device *d, |
| 7999 | struct device_attribute *attr, |
| 8000 | char *buf) |
| 8001 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8002 | struct iwl_priv *priv = d->driver_data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8003 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8004 | } |
| 8005 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 8006 | |
| 8007 | static ssize_t show_tx_power(struct device *d, |
| 8008 | struct device_attribute *attr, char *buf) |
| 8009 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8010 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8011 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 8012 | } |
| 8013 | |
| 8014 | static ssize_t store_tx_power(struct device *d, |
| 8015 | struct device_attribute *attr, |
| 8016 | const char *buf, size_t count) |
| 8017 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8018 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8019 | char *p = (char *)buf; |
| 8020 | u32 val; |
| 8021 | |
| 8022 | val = simple_strtoul(p, &p, 10); |
| 8023 | if (p == buf) |
| 8024 | printk(KERN_INFO DRV_NAME |
| 8025 | ": %s is not in decimal form.\n", buf); |
| 8026 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8027 | iwl4965_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8028 | |
| 8029 | return count; |
| 8030 | } |
| 8031 | |
| 8032 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 8033 | |
| 8034 | static ssize_t show_flags(struct device *d, |
| 8035 | struct device_attribute *attr, char *buf) |
| 8036 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8037 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8038 | |
| 8039 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 8040 | } |
| 8041 | |
| 8042 | static ssize_t store_flags(struct device *d, |
| 8043 | struct device_attribute *attr, |
| 8044 | const char *buf, size_t count) |
| 8045 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8046 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8047 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 8048 | |
| 8049 | mutex_lock(&priv->mutex); |
| 8050 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 8051 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8052 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8053 | IWL_WARNING("Could not cancel scan.\n"); |
| 8054 | else { |
| 8055 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 8056 | flags); |
| 8057 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8058 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8059 | } |
| 8060 | } |
| 8061 | mutex_unlock(&priv->mutex); |
| 8062 | |
| 8063 | return count; |
| 8064 | } |
| 8065 | |
| 8066 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 8067 | |
| 8068 | static ssize_t show_filter_flags(struct device *d, |
| 8069 | struct device_attribute *attr, char *buf) |
| 8070 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8071 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8072 | |
| 8073 | return sprintf(buf, "0x%04X\n", |
| 8074 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 8075 | } |
| 8076 | |
| 8077 | static ssize_t store_filter_flags(struct device *d, |
| 8078 | struct device_attribute *attr, |
| 8079 | const char *buf, size_t count) |
| 8080 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8081 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8082 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 8083 | |
| 8084 | mutex_lock(&priv->mutex); |
| 8085 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 8086 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8087 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8088 | IWL_WARNING("Could not cancel scan.\n"); |
| 8089 | else { |
| 8090 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 8091 | "0x%04X\n", filter_flags); |
| 8092 | priv->staging_rxon.filter_flags = |
| 8093 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8094 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8095 | } |
| 8096 | } |
| 8097 | mutex_unlock(&priv->mutex); |
| 8098 | |
| 8099 | return count; |
| 8100 | } |
| 8101 | |
| 8102 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 8103 | store_filter_flags); |
| 8104 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8105 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8106 | |
| 8107 | static ssize_t show_measurement(struct device *d, |
| 8108 | struct device_attribute *attr, char *buf) |
| 8109 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8110 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8111 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8112 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 8113 | u8 *data = (u8 *) & measure_report; |
| 8114 | unsigned long flags; |
| 8115 | |
| 8116 | spin_lock_irqsave(&priv->lock, flags); |
| 8117 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 8118 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8119 | return 0; |
| 8120 | } |
| 8121 | memcpy(&measure_report, &priv->measure_report, size); |
| 8122 | priv->measurement_status = 0; |
| 8123 | spin_unlock_irqrestore(&priv->lock, flags); |
| 8124 | |
| 8125 | while (size && (PAGE_SIZE - len)) { |
| 8126 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8127 | PAGE_SIZE - len, 1); |
| 8128 | len = strlen(buf); |
| 8129 | if (PAGE_SIZE - len) |
| 8130 | buf[len++] = '\n'; |
| 8131 | |
| 8132 | ofs += 16; |
| 8133 | size -= min(size, 16U); |
| 8134 | } |
| 8135 | |
| 8136 | return len; |
| 8137 | } |
| 8138 | |
| 8139 | static ssize_t store_measurement(struct device *d, |
| 8140 | struct device_attribute *attr, |
| 8141 | const char *buf, size_t count) |
| 8142 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8143 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8144 | struct ieee80211_measurement_params params = { |
| 8145 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 8146 | .start_time = cpu_to_le64(priv->last_tsf), |
| 8147 | .duration = cpu_to_le16(1), |
| 8148 | }; |
| 8149 | u8 type = IWL_MEASURE_BASIC; |
| 8150 | u8 buffer[32]; |
| 8151 | u8 channel; |
| 8152 | |
| 8153 | if (count) { |
| 8154 | char *p = buffer; |
| 8155 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 8156 | channel = simple_strtoul(p, NULL, 0); |
| 8157 | if (channel) |
| 8158 | params.channel = channel; |
| 8159 | |
| 8160 | p = buffer; |
| 8161 | while (*p && *p != ' ') |
| 8162 | p++; |
| 8163 | if (*p) |
| 8164 | type = simple_strtoul(p + 1, NULL, 0); |
| 8165 | } |
| 8166 | |
| 8167 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 8168 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8169 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8170 | |
| 8171 | return count; |
| 8172 | } |
| 8173 | |
| 8174 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 8175 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8176 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8177 | |
| 8178 | static ssize_t store_retry_rate(struct device *d, |
| 8179 | struct device_attribute *attr, |
| 8180 | const char *buf, size_t count) |
| 8181 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8182 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8183 | |
| 8184 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 8185 | if (priv->retry_rate <= 0) |
| 8186 | priv->retry_rate = 1; |
| 8187 | |
| 8188 | return count; |
| 8189 | } |
| 8190 | |
| 8191 | static ssize_t show_retry_rate(struct device *d, |
| 8192 | struct device_attribute *attr, char *buf) |
| 8193 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8194 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8195 | return sprintf(buf, "%d", priv->retry_rate); |
| 8196 | } |
| 8197 | |
| 8198 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 8199 | store_retry_rate); |
| 8200 | |
| 8201 | static ssize_t store_power_level(struct device *d, |
| 8202 | struct device_attribute *attr, |
| 8203 | const char *buf, size_t count) |
| 8204 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8205 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8206 | int rc; |
| 8207 | int mode; |
| 8208 | |
| 8209 | mode = simple_strtoul(buf, NULL, 0); |
| 8210 | mutex_lock(&priv->mutex); |
| 8211 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8212 | if (!iwl4965_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8213 | rc = -EAGAIN; |
| 8214 | goto out; |
| 8215 | } |
| 8216 | |
| 8217 | if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC)) |
| 8218 | mode = IWL_POWER_AC; |
| 8219 | else |
| 8220 | mode |= IWL_POWER_ENABLED; |
| 8221 | |
| 8222 | if (mode != priv->power_mode) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8223 | rc = iwl4965_send_power_mode(priv, IWL_POWER_LEVEL(mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8224 | if (rc) { |
| 8225 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 8226 | goto out; |
| 8227 | } |
| 8228 | priv->power_mode = mode; |
| 8229 | } |
| 8230 | |
| 8231 | rc = count; |
| 8232 | |
| 8233 | out: |
| 8234 | mutex_unlock(&priv->mutex); |
| 8235 | return rc; |
| 8236 | } |
| 8237 | |
| 8238 | #define MAX_WX_STRING 80 |
| 8239 | |
| 8240 | /* Values are in microsecond */ |
| 8241 | static const s32 timeout_duration[] = { |
| 8242 | 350000, |
| 8243 | 250000, |
| 8244 | 75000, |
| 8245 | 37000, |
| 8246 | 25000, |
| 8247 | }; |
| 8248 | static const s32 period_duration[] = { |
| 8249 | 400000, |
| 8250 | 700000, |
| 8251 | 1000000, |
| 8252 | 1000000, |
| 8253 | 1000000 |
| 8254 | }; |
| 8255 | |
| 8256 | static ssize_t show_power_level(struct device *d, |
| 8257 | struct device_attribute *attr, char *buf) |
| 8258 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8259 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8260 | int level = IWL_POWER_LEVEL(priv->power_mode); |
| 8261 | char *p = buf; |
| 8262 | |
| 8263 | p += sprintf(p, "%d ", level); |
| 8264 | switch (level) { |
| 8265 | case IWL_POWER_MODE_CAM: |
| 8266 | case IWL_POWER_AC: |
| 8267 | p += sprintf(p, "(AC)"); |
| 8268 | break; |
| 8269 | case IWL_POWER_BATTERY: |
| 8270 | p += sprintf(p, "(BATTERY)"); |
| 8271 | break; |
| 8272 | default: |
| 8273 | p += sprintf(p, |
| 8274 | "(Timeout %dms, Period %dms)", |
| 8275 | timeout_duration[level - 1] / 1000, |
| 8276 | period_duration[level - 1] / 1000); |
| 8277 | } |
| 8278 | |
| 8279 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 8280 | p += sprintf(p, " OFF\n"); |
| 8281 | else |
| 8282 | p += sprintf(p, " \n"); |
| 8283 | |
| 8284 | return (p - buf + 1); |
| 8285 | |
| 8286 | } |
| 8287 | |
| 8288 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 8289 | store_power_level); |
| 8290 | |
| 8291 | static ssize_t show_channels(struct device *d, |
| 8292 | struct device_attribute *attr, char *buf) |
| 8293 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 8294 | /* all this shit doesn't belong into sysfs anyway */ |
| 8295 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8296 | } |
| 8297 | |
| 8298 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 8299 | |
| 8300 | static ssize_t show_statistics(struct device *d, |
| 8301 | struct device_attribute *attr, char *buf) |
| 8302 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8303 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8304 | u32 size = sizeof(struct iwl4965_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8305 | u32 len = 0, ofs = 0; |
| 8306 | u8 *data = (u8 *) & priv->statistics; |
| 8307 | int rc = 0; |
| 8308 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8309 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8310 | return -EAGAIN; |
| 8311 | |
| 8312 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8313 | rc = iwl4965_send_statistics_request(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8314 | mutex_unlock(&priv->mutex); |
| 8315 | |
| 8316 | if (rc) { |
| 8317 | len = sprintf(buf, |
| 8318 | "Error sending statistics request: 0x%08X\n", rc); |
| 8319 | return len; |
| 8320 | } |
| 8321 | |
| 8322 | while (size && (PAGE_SIZE - len)) { |
| 8323 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8324 | PAGE_SIZE - len, 1); |
| 8325 | len = strlen(buf); |
| 8326 | if (PAGE_SIZE - len) |
| 8327 | buf[len++] = '\n'; |
| 8328 | |
| 8329 | ofs += 16; |
| 8330 | size -= min(size, 16U); |
| 8331 | } |
| 8332 | |
| 8333 | return len; |
| 8334 | } |
| 8335 | |
| 8336 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 8337 | |
| 8338 | static ssize_t show_antenna(struct device *d, |
| 8339 | struct device_attribute *attr, char *buf) |
| 8340 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8341 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8342 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8343 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8344 | return -EAGAIN; |
| 8345 | |
| 8346 | return sprintf(buf, "%d\n", priv->antenna); |
| 8347 | } |
| 8348 | |
| 8349 | static ssize_t store_antenna(struct device *d, |
| 8350 | struct device_attribute *attr, |
| 8351 | const char *buf, size_t count) |
| 8352 | { |
| 8353 | int ant; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8354 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8355 | |
| 8356 | if (count == 0) |
| 8357 | return 0; |
| 8358 | |
| 8359 | if (sscanf(buf, "%1i", &ant) != 1) { |
| 8360 | IWL_DEBUG_INFO("not in hex or decimal form.\n"); |
| 8361 | return count; |
| 8362 | } |
| 8363 | |
| 8364 | if ((ant >= 0) && (ant <= 2)) { |
| 8365 | IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8366 | priv->antenna = (enum iwl4965_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8367 | } else |
| 8368 | IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); |
| 8369 | |
| 8370 | |
| 8371 | return count; |
| 8372 | } |
| 8373 | |
| 8374 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 8375 | |
| 8376 | static ssize_t show_status(struct device *d, |
| 8377 | struct device_attribute *attr, char *buf) |
| 8378 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8379 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8380 | if (!iwl4965_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8381 | return -EAGAIN; |
| 8382 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 8383 | } |
| 8384 | |
| 8385 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 8386 | |
| 8387 | static ssize_t dump_error_log(struct device *d, |
| 8388 | struct device_attribute *attr, |
| 8389 | const char *buf, size_t count) |
| 8390 | { |
| 8391 | char *p = (char *)buf; |
| 8392 | |
| 8393 | if (p[0] == '1') |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8394 | iwl4965_dump_nic_error_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8395 | |
| 8396 | return strnlen(buf, count); |
| 8397 | } |
| 8398 | |
| 8399 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 8400 | |
| 8401 | static ssize_t dump_event_log(struct device *d, |
| 8402 | struct device_attribute *attr, |
| 8403 | const char *buf, size_t count) |
| 8404 | { |
| 8405 | char *p = (char *)buf; |
| 8406 | |
| 8407 | if (p[0] == '1') |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8408 | iwl4965_dump_nic_event_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8409 | |
| 8410 | return strnlen(buf, count); |
| 8411 | } |
| 8412 | |
| 8413 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 8414 | |
| 8415 | /***************************************************************************** |
| 8416 | * |
| 8417 | * driver setup and teardown |
| 8418 | * |
| 8419 | *****************************************************************************/ |
| 8420 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8421 | static void iwl4965_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8422 | { |
| 8423 | priv->workqueue = create_workqueue(DRV_NAME); |
| 8424 | |
| 8425 | init_waitqueue_head(&priv->wait_command_queue); |
| 8426 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8427 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 8428 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 8429 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
| 8430 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); |
| 8431 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); |
| 8432 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); |
| 8433 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 8434 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
| 8435 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
| 8436 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start); |
| 8437 | INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start); |
| 8438 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8439 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8440 | iwl4965_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8441 | |
| 8442 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8443 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8444 | } |
| 8445 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8446 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8447 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8448 | iwl4965_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8449 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 8450 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8451 | cancel_delayed_work(&priv->scan_check); |
| 8452 | cancel_delayed_work(&priv->alive_start); |
| 8453 | cancel_delayed_work(&priv->post_associate); |
| 8454 | cancel_work_sync(&priv->beacon_update); |
| 8455 | } |
| 8456 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8457 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8458 | &dev_attr_antenna.attr, |
| 8459 | &dev_attr_channels.attr, |
| 8460 | &dev_attr_dump_errors.attr, |
| 8461 | &dev_attr_dump_events.attr, |
| 8462 | &dev_attr_flags.attr, |
| 8463 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8464 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8465 | &dev_attr_measurement.attr, |
| 8466 | #endif |
| 8467 | &dev_attr_power_level.attr, |
| 8468 | &dev_attr_retry_rate.attr, |
| 8469 | &dev_attr_rf_kill.attr, |
| 8470 | &dev_attr_rs_window.attr, |
| 8471 | &dev_attr_statistics.attr, |
| 8472 | &dev_attr_status.attr, |
| 8473 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8474 | &dev_attr_tx_power.attr, |
| 8475 | |
| 8476 | NULL |
| 8477 | }; |
| 8478 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8479 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8480 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8481 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8482 | }; |
| 8483 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8484 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 8485 | .tx = iwl4965_mac_tx, |
| 8486 | .start = iwl4965_mac_start, |
| 8487 | .stop = iwl4965_mac_stop, |
| 8488 | .add_interface = iwl4965_mac_add_interface, |
| 8489 | .remove_interface = iwl4965_mac_remove_interface, |
| 8490 | .config = iwl4965_mac_config, |
| 8491 | .config_interface = iwl4965_mac_config_interface, |
| 8492 | .configure_filter = iwl4965_configure_filter, |
| 8493 | .set_key = iwl4965_mac_set_key, |
| 8494 | .get_stats = iwl4965_mac_get_stats, |
| 8495 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 8496 | .conf_tx = iwl4965_mac_conf_tx, |
| 8497 | .get_tsf = iwl4965_mac_get_tsf, |
| 8498 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 8499 | .beacon_update = iwl4965_mac_beacon_update, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 8500 | .bss_info_changed = iwl4965_bss_info_changed, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8501 | #ifdef CONFIG_IWL4965_HT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8502 | .conf_ht = iwl4965_mac_conf_ht, |
Ron Rindjunsky | 9ab4617 | 2007-12-25 17:00:38 +0200 | [diff] [blame] | 8503 | .ampdu_action = iwl4965_mac_ampdu_action, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8504 | #endif /* CONFIG_IWL4965_HT */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8505 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8506 | }; |
| 8507 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8508 | 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] | 8509 | { |
| 8510 | int err = 0; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8511 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8512 | struct ieee80211_hw *hw; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 8513 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8514 | int i; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8515 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8516 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8517 | /* Disabling hardware scan means that mac80211 will perform scans |
| 8518 | * "the hard way", rather than using device's scan. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8519 | if (iwl4965_param_disable_hw_scan) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8520 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8521 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8522 | } |
| 8523 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8524 | if ((iwl4965_param_queues_num > IWL_MAX_NUM_QUEUES) || |
| 8525 | (iwl4965_param_queues_num < IWL_MIN_NUM_QUEUES)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8526 | IWL_ERROR("invalid queues_num, should be between %d and %d\n", |
| 8527 | IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES); |
| 8528 | err = -EINVAL; |
| 8529 | goto out; |
| 8530 | } |
| 8531 | |
| 8532 | /* mac80211 allocates memory for this device instance, including |
| 8533 | * space for this driver's private structure */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8534 | hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwl4965_hw_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8535 | if (hw == NULL) { |
| 8536 | IWL_ERROR("Can not allocate network device\n"); |
| 8537 | err = -ENOMEM; |
| 8538 | goto out; |
| 8539 | } |
| 8540 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 8541 | |
Johannes Berg | f51359a | 2007-10-28 14:53:36 +0100 | [diff] [blame] | 8542 | hw->rate_control_algorithm = "iwl-4965-rs"; |
| 8543 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8544 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
| 8545 | priv = hw->priv; |
| 8546 | priv->hw = hw; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 8547 | priv->cfg = cfg; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8548 | |
| 8549 | priv->pci_dev = pdev; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8550 | priv->antenna = (enum iwl4965_antenna)iwl4965_param_antenna; |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 8551 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 8552 | iwl_debug_level = iwl4965_param_debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8553 | atomic_set(&priv->restrict_refcnt, 0); |
| 8554 | #endif |
| 8555 | priv->retry_rate = 1; |
| 8556 | |
| 8557 | priv->ibss_beacon = NULL; |
| 8558 | |
| 8559 | /* Tell mac80211 and its clients (e.g. Wireless Extensions) |
| 8560 | * the range of signal quality values that we'll provide. |
| 8561 | * Negative values for level/noise indicate that we'll provide dBm. |
| 8562 | * For WE, at least, non-0 values here *enable* display of values |
| 8563 | * in app (iwconfig). */ |
| 8564 | hw->max_rssi = -20; /* signal level, negative indicates dBm */ |
| 8565 | hw->max_noise = -20; /* noise level, negative indicates dBm */ |
| 8566 | hw->max_signal = 100; /* link quality indication (%) */ |
| 8567 | |
| 8568 | /* Tell mac80211 our Tx characteristics */ |
| 8569 | hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE; |
| 8570 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8571 | /* Default value; 4 EDCA QOS priorities */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8572 | hw->queues = 4; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8573 | #ifdef CONFIG_IWL4965_HT |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8574 | /* Enhanced value; more queues, to support 11n aggregation */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8575 | hw->queues = 16; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8576 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8577 | |
| 8578 | spin_lock_init(&priv->lock); |
| 8579 | spin_lock_init(&priv->power_data.lock); |
| 8580 | spin_lock_init(&priv->sta_lock); |
| 8581 | spin_lock_init(&priv->hcmd_lock); |
| 8582 | spin_lock_init(&priv->lq_mngr.lock); |
| 8583 | |
| 8584 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) |
| 8585 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
| 8586 | |
| 8587 | INIT_LIST_HEAD(&priv->free_frames); |
| 8588 | |
| 8589 | mutex_init(&priv->mutex); |
| 8590 | if (pci_enable_device(pdev)) { |
| 8591 | err = -ENODEV; |
| 8592 | goto out_ieee80211_free_hw; |
| 8593 | } |
| 8594 | |
| 8595 | pci_set_master(pdev); |
| 8596 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8597 | /* Clear the driver's (not device's) station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8598 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8599 | |
| 8600 | priv->data_retry_limit = -1; |
| 8601 | priv->ieee_channels = NULL; |
| 8602 | priv->ieee_rates = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 8603 | priv->band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8604 | |
| 8605 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 8606 | if (!err) |
| 8607 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 8608 | if (err) { |
| 8609 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 8610 | goto out_pci_disable_device; |
| 8611 | } |
| 8612 | |
| 8613 | pci_set_drvdata(pdev, priv); |
| 8614 | err = pci_request_regions(pdev, DRV_NAME); |
| 8615 | if (err) |
| 8616 | goto out_pci_disable_device; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8617 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8618 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 8619 | * PCI Tx retries from interfering with C3 CPU state */ |
| 8620 | pci_write_config_byte(pdev, 0x41, 0x00); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8621 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8622 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 8623 | if (!priv->hw_base) { |
| 8624 | err = -ENODEV; |
| 8625 | goto out_pci_release_regions; |
| 8626 | } |
| 8627 | |
| 8628 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 8629 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 8630 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 8631 | |
| 8632 | /* Initialize module parameter values here */ |
| 8633 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8634 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8635 | if (iwl4965_param_disable) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8636 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 8637 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 8638 | } |
| 8639 | |
| 8640 | priv->iw_mode = IEEE80211_IF_TYPE_STA; |
| 8641 | |
| 8642 | priv->ps_mode = 0; |
| 8643 | priv->use_ant_b_for_management_frame = 1; /* start with ant B */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8644 | priv->valid_antenna = 0x7; /* assume all 3 connected */ |
| 8645 | priv->ps_mode = IWL_MIMO_PS_NONE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8646 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8647 | /* Choose which receivers/antennas to use */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8648 | iwl4965_set_rxon_chain(priv); |
| 8649 | |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 8650 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8651 | printk(KERN_INFO DRV_NAME |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 8652 | ": Detected Intel Wireless WiFi Link %s\n", priv->cfg->name); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8653 | |
| 8654 | /* Device-specific setup */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8655 | if (iwl4965_hw_set_hw_setting(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8656 | IWL_ERROR("failed to set hw settings\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8657 | goto out_iounmap; |
| 8658 | } |
| 8659 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8660 | if (iwl4965_param_qos_enable) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8661 | priv->qos_data.qos_enable = 1; |
| 8662 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8663 | iwl4965_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8664 | |
| 8665 | priv->qos_data.qos_active = 0; |
| 8666 | priv->qos_data.qos_cap.val = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8667 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 8668 | iwl4965_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8669 | iwl4965_setup_deferred_work(priv); |
| 8670 | iwl4965_setup_rx_handlers(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8671 | |
| 8672 | priv->rates_mask = IWL_RATES_MASK; |
| 8673 | /* If power management is turned on, default to AC mode */ |
| 8674 | priv->power_mode = IWL_POWER_AC; |
| 8675 | priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; |
| 8676 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8677 | iwl4965_disable_interrupts(priv); |
Jes Sorensen | 49df2b3 | 2007-10-26 16:10:39 +0200 | [diff] [blame] | 8678 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8679 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8680 | if (err) { |
| 8681 | IWL_ERROR("failed to create sysfs device attributes\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8682 | goto out_release_irq; |
| 8683 | } |
| 8684 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8685 | /* nic init */ |
| 8686 | iwl4965_set_bit(priv, CSR_GIO_CHICKEN_BITS, |
| 8687 | CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); |
| 8688 | |
| 8689 | iwl4965_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); |
| 8690 | err = iwl4965_poll_bit(priv, CSR_GP_CNTRL, |
| 8691 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, |
| 8692 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); |
| 8693 | if (err < 0) { |
| 8694 | IWL_DEBUG_INFO("Failed to init the card\n"); |
| 8695 | goto out_remove_sysfs; |
| 8696 | } |
| 8697 | /* Read the EEPROM */ |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 8698 | err = iwl_eeprom_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8699 | if (err) { |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8700 | IWL_ERROR("Unable to init EEPROM\n"); |
| 8701 | goto out_remove_sysfs; |
| 8702 | } |
| 8703 | /* MAC Address location in EEPROM same for 3945/4965 */ |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 8704 | iwl_eeprom_get_mac(priv, priv->mac_addr); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8705 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); |
| 8706 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 8707 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8708 | err = iwl4965_init_channel_map(priv); |
| 8709 | if (err) { |
| 8710 | IWL_ERROR("initializing regulatory failed: %d\n", err); |
| 8711 | goto out_remove_sysfs; |
| 8712 | } |
| 8713 | |
| 8714 | err = iwl4965_init_geos(priv); |
| 8715 | if (err) { |
| 8716 | IWL_ERROR("initializing geos failed: %d\n", err); |
| 8717 | goto out_free_channel_map; |
| 8718 | } |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8719 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8720 | iwl4965_rate_control_register(priv->hw); |
| 8721 | err = ieee80211_register_hw(priv->hw); |
| 8722 | if (err) { |
| 8723 | IWL_ERROR("Failed to register network device (error %d)\n", err); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8724 | goto out_free_geos; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8725 | } |
| 8726 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8727 | priv->hw->conf.beacon_int = 100; |
| 8728 | priv->mac80211_registered = 1; |
| 8729 | pci_save_state(pdev); |
| 8730 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8731 | |
| 8732 | return 0; |
| 8733 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8734 | out_free_geos: |
| 8735 | iwl4965_free_geos(priv); |
| 8736 | out_free_channel_map: |
| 8737 | iwl4965_free_channel_map(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8738 | out_remove_sysfs: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8739 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8740 | |
| 8741 | out_release_irq: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8742 | destroy_workqueue(priv->workqueue); |
| 8743 | priv->workqueue = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8744 | iwl4965_unset_hw_setting(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8745 | |
| 8746 | out_iounmap: |
| 8747 | pci_iounmap(pdev, priv->hw_base); |
| 8748 | out_pci_release_regions: |
| 8749 | pci_release_regions(pdev); |
| 8750 | out_pci_disable_device: |
| 8751 | pci_disable_device(pdev); |
| 8752 | pci_set_drvdata(pdev, NULL); |
| 8753 | out_ieee80211_free_hw: |
| 8754 | ieee80211_free_hw(priv->hw); |
| 8755 | out: |
| 8756 | return err; |
| 8757 | } |
| 8758 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8759 | static void iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8760 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8761 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8762 | struct list_head *p, *q; |
| 8763 | int i; |
| 8764 | |
| 8765 | if (!priv) |
| 8766 | return; |
| 8767 | |
| 8768 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 8769 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8770 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 8771 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8772 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8773 | |
| 8774 | /* Free MAC hash list for ADHOC */ |
| 8775 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 8776 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 8777 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8778 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8779 | } |
| 8780 | } |
| 8781 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8782 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8783 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8784 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8785 | |
| 8786 | if (priv->rxq.bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8787 | iwl4965_rx_queue_free(priv, &priv->rxq); |
| 8788 | iwl4965_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8789 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8790 | iwl4965_unset_hw_setting(priv); |
| 8791 | iwl4965_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8792 | |
| 8793 | if (priv->mac80211_registered) { |
| 8794 | ieee80211_unregister_hw(priv->hw); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8795 | iwl4965_rate_control_unregister(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8796 | } |
| 8797 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 8798 | /*netif_stop_queue(dev); */ |
| 8799 | flush_workqueue(priv->workqueue); |
| 8800 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8801 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8802 | * priv->workqueue... so we can't take down the workqueue |
| 8803 | * until now... */ |
| 8804 | destroy_workqueue(priv->workqueue); |
| 8805 | priv->workqueue = NULL; |
| 8806 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8807 | pci_iounmap(pdev, priv->hw_base); |
| 8808 | pci_release_regions(pdev); |
| 8809 | pci_disable_device(pdev); |
| 8810 | pci_set_drvdata(pdev, NULL); |
| 8811 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8812 | iwl4965_free_channel_map(priv); |
| 8813 | iwl4965_free_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8814 | |
| 8815 | if (priv->ibss_beacon) |
| 8816 | dev_kfree_skb(priv->ibss_beacon); |
| 8817 | |
| 8818 | ieee80211_free_hw(priv->hw); |
| 8819 | } |
| 8820 | |
| 8821 | #ifdef CONFIG_PM |
| 8822 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8823 | 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] | 8824 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8825 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8826 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 8827 | if (priv->is_open) { |
| 8828 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 8829 | iwl4965_mac_stop(priv->hw); |
| 8830 | priv->is_open = 1; |
| 8831 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8832 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8833 | pci_set_power_state(pdev, PCI_D3hot); |
| 8834 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8835 | return 0; |
| 8836 | } |
| 8837 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8838 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8839 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame^] | 8840 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8841 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8842 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8843 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 8844 | if (priv->is_open) |
| 8845 | iwl4965_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8846 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 8847 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8848 | return 0; |
| 8849 | } |
| 8850 | |
| 8851 | #endif /* CONFIG_PM */ |
| 8852 | |
| 8853 | /***************************************************************************** |
| 8854 | * |
| 8855 | * driver and module entry point |
| 8856 | * |
| 8857 | *****************************************************************************/ |
| 8858 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8859 | static struct pci_driver iwl4965_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8860 | .name = DRV_NAME, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8861 | .id_table = iwl4965_hw_card_ids, |
| 8862 | .probe = iwl4965_pci_probe, |
| 8863 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8864 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8865 | .suspend = iwl4965_pci_suspend, |
| 8866 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8867 | #endif |
| 8868 | }; |
| 8869 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8870 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8871 | { |
| 8872 | |
| 8873 | int ret; |
| 8874 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 8875 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8876 | ret = pci_register_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8877 | if (ret) { |
| 8878 | IWL_ERROR("Unable to initialize PCI module\n"); |
| 8879 | return ret; |
| 8880 | } |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 8881 | #ifdef CONFIG_IWLWIFI_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8882 | ret = driver_create_file(&iwl4965_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8883 | if (ret) { |
| 8884 | IWL_ERROR("Unable to create driver sysfs file\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8885 | pci_unregister_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8886 | return ret; |
| 8887 | } |
| 8888 | #endif |
| 8889 | |
| 8890 | return ret; |
| 8891 | } |
| 8892 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8893 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8894 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 8895 | #ifdef CONFIG_IWLWIFI_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8896 | driver_remove_file(&iwl4965_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8897 | #endif |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8898 | pci_unregister_driver(&iwl4965_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8899 | } |
| 8900 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8901 | module_param_named(antenna, iwl4965_param_antenna, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8902 | 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] | 8903 | module_param_named(disable, iwl4965_param_disable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8904 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8905 | module_param_named(hwcrypto, iwl4965_param_hwcrypto, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8906 | MODULE_PARM_DESC(hwcrypto, |
| 8907 | "using hardware crypto engine (default 0 [software])\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8908 | module_param_named(debug, iwl4965_param_debug, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8909 | MODULE_PARM_DESC(debug, "debug output mask"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8910 | 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] | 8911 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 8912 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8913 | module_param_named(queues_num, iwl4965_param_queues_num, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8914 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 8915 | |
| 8916 | /* QoS */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8917 | module_param_named(qos_enable, iwl4965_param_qos_enable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8918 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionality"); |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 8919 | module_param_named(amsdu_size_8K, iwl4965_param_amsdu_size_8K, int, 0444); |
| 8920 | MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8921 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8922 | module_exit(iwl4965_exit); |
| 8923 | module_init(iwl4965_init); |