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 | 3e0d4cb | 2008-04-24 11:55:38 -0700 | [diff] [blame] | 49 | #include "iwl-dev.h" |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 50 | #include "iwl-core.h" |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 51 | #include "iwl-io.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 52 | #include "iwl-helpers.h" |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 53 | #include "iwl-sta.h" |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 54 | #include "iwl-calib.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 55 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 56 | static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 57 | struct iwl4965_tx_queue *txq); |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 58 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 59 | /****************************************************************************** |
| 60 | * |
| 61 | * module boiler plate |
| 62 | * |
| 63 | ******************************************************************************/ |
| 64 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 65 | /* |
| 66 | * module name, copyright, version, etc. |
| 67 | * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk |
| 68 | */ |
| 69 | |
| 70 | #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux" |
| 71 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 72 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 73 | #define VD "d" |
| 74 | #else |
| 75 | #define VD |
| 76 | #endif |
| 77 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 78 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 79 | #define VS "s" |
| 80 | #else |
| 81 | #define VS |
| 82 | #endif |
| 83 | |
Tomas Winkler | df48c32 | 2008-03-06 10:40:19 -0800 | [diff] [blame] | 84 | #define DRV_VERSION IWLWIFI_VERSION VD VS |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 85 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 86 | |
| 87 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 88 | MODULE_VERSION(DRV_VERSION); |
| 89 | MODULE_AUTHOR(DRV_COPYRIGHT); |
| 90 | MODULE_LICENSE("GPL"); |
| 91 | |
| 92 | __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr) |
| 93 | { |
| 94 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 95 | int hdr_len = ieee80211_get_hdrlen(fc); |
| 96 | |
| 97 | if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA)) |
| 98 | return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN); |
| 99 | return NULL; |
| 100 | } |
| 101 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 102 | static const struct ieee80211_supported_band *iwl_get_hw_mode( |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 103 | struct iwl_priv *priv, enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 104 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 105 | return priv->hw->wiphy->bands[band]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 108 | static int iwl4965_is_empty_essid(const char *essid, int essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 109 | { |
| 110 | /* Single white space is for Linksys APs */ |
| 111 | if (essid_len == 1 && essid[0] == ' ') |
| 112 | return 1; |
| 113 | |
| 114 | /* Otherwise, if the entire essid is 0, we assume it is hidden */ |
| 115 | while (essid_len) { |
| 116 | essid_len--; |
| 117 | if (essid[essid_len] != '\0') |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | return 1; |
| 122 | } |
| 123 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 124 | static const char *iwl4965_escape_essid(const char *essid, u8 essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 125 | { |
| 126 | static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
| 127 | const char *s = essid; |
| 128 | char *d = escaped; |
| 129 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 130 | if (iwl4965_is_empty_essid(essid, essid_len)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 131 | memcpy(escaped, "<hidden>", sizeof("<hidden>")); |
| 132 | return escaped; |
| 133 | } |
| 134 | |
| 135 | essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE); |
| 136 | while (essid_len--) { |
| 137 | if (*s == '\0') { |
| 138 | *d++ = '\\'; |
| 139 | *d++ = '0'; |
| 140 | s++; |
| 141 | } else |
| 142 | *d++ = *s++; |
| 143 | } |
| 144 | *d = '\0'; |
| 145 | return escaped; |
| 146 | } |
| 147 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 148 | /*************** DMA-QUEUE-GENERAL-FUNCTIONS ***** |
| 149 | * DMA services |
| 150 | * |
| 151 | * Theory of operation |
| 152 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 153 | * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer |
| 154 | * of buffer descriptors, each of which points to one or more data buffers for |
| 155 | * the device to read from or fill. Driver and device exchange status of each |
| 156 | * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty |
| 157 | * entries in each circular buffer, to protect against confusing empty and full |
| 158 | * queue states. |
| 159 | * |
| 160 | * The device reads or writes the data in the queues via the device's several |
| 161 | * DMA/FIFO channels. Each queue is mapped to a single DMA channel. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 162 | * |
| 163 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 164 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 165 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 166 | * Tx queue resumed. |
| 167 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 168 | * The 4965 operates with up to 17 queues: One receive queue, one transmit |
| 169 | * queue (#4) for sending commands to the device firmware, and 15 other |
| 170 | * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels. |
Ben Cahill | e385144 | 2007-11-29 11:10:07 +0800 | [diff] [blame] | 171 | * |
| 172 | * See more detailed info in iwl-4965-hw.h. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 173 | ***************************************************/ |
| 174 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 175 | int iwl4965_queue_space(const struct iwl4965_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 176 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 177 | int s = q->read_ptr - q->write_ptr; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 178 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 179 | if (q->read_ptr > q->write_ptr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 180 | s -= q->n_bd; |
| 181 | |
| 182 | if (s <= 0) |
| 183 | s += q->n_window; |
| 184 | /* keep some reserve to not confuse empty and full situations */ |
| 185 | s -= 2; |
| 186 | if (s < 0) |
| 187 | s = 0; |
| 188 | return s; |
| 189 | } |
| 190 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 191 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 192 | 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] | 193 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 194 | return q->write_ptr > q->read_ptr ? |
| 195 | (i >= q->read_ptr && i < q->write_ptr) : |
| 196 | !(i < q->read_ptr && i >= q->write_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 199 | 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] | 200 | { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 201 | /* 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] | 202 | if (is_huge) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 203 | return q->n_window; /* must be power of 2 */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 204 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 205 | /* Otherwise, use normal size buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 206 | return index & (q->n_window - 1); |
| 207 | } |
| 208 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 209 | /** |
| 210 | * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes |
| 211 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 212 | 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] | 213 | int count, int slots_num, u32 id) |
| 214 | { |
| 215 | q->n_bd = count; |
| 216 | q->n_window = slots_num; |
| 217 | q->id = id; |
| 218 | |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 219 | /* count must be power-of-two size, otherwise iwl_queue_inc_wrap |
| 220 | * and iwl_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 221 | BUG_ON(!is_power_of_2(count)); |
| 222 | |
| 223 | /* slots_num must be power-of-two size, otherwise |
| 224 | * get_cmd_index is broken. */ |
| 225 | BUG_ON(!is_power_of_2(slots_num)); |
| 226 | |
| 227 | q->low_mark = q->n_window / 4; |
| 228 | if (q->low_mark < 4) |
| 229 | q->low_mark = 4; |
| 230 | |
| 231 | q->high_mark = q->n_window / 8; |
| 232 | if (q->high_mark < 2) |
| 233 | q->high_mark = 2; |
| 234 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 235 | q->write_ptr = q->read_ptr = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 240 | /** |
| 241 | * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue |
| 242 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 243 | static int iwl4965_tx_queue_alloc(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 244 | struct iwl4965_tx_queue *txq, u32 id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 245 | { |
| 246 | struct pci_dev *dev = priv->pci_dev; |
| 247 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 248 | /* Driver private data, only for Tx (not command) queues, |
| 249 | * not shared with device. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 250 | if (id != IWL_CMD_QUEUE_NUM) { |
| 251 | txq->txb = kmalloc(sizeof(txq->txb[0]) * |
| 252 | TFD_QUEUE_SIZE_MAX, GFP_KERNEL); |
| 253 | if (!txq->txb) { |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 254 | IWL_ERROR("kmalloc for auxiliary BD " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 255 | "structures failed\n"); |
| 256 | goto error; |
| 257 | } |
| 258 | } else |
| 259 | txq->txb = NULL; |
| 260 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 261 | /* Circular buffer of transmit frame descriptors (TFDs), |
| 262 | * shared with device */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 263 | txq->bd = pci_alloc_consistent(dev, |
| 264 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX, |
| 265 | &txq->q.dma_addr); |
| 266 | |
| 267 | if (!txq->bd) { |
| 268 | IWL_ERROR("pci_alloc_consistent(%zd) failed\n", |
| 269 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX); |
| 270 | goto error; |
| 271 | } |
| 272 | txq->q.id = id; |
| 273 | |
| 274 | return 0; |
| 275 | |
| 276 | error: |
| 277 | if (txq->txb) { |
| 278 | kfree(txq->txb); |
| 279 | txq->txb = NULL; |
| 280 | } |
| 281 | |
| 282 | return -ENOMEM; |
| 283 | } |
| 284 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 285 | /** |
| 286 | * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue |
| 287 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 288 | int iwl4965_tx_queue_init(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 289 | struct iwl4965_tx_queue *txq, int slots_num, u32 txq_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 290 | { |
| 291 | struct pci_dev *dev = priv->pci_dev; |
| 292 | int len; |
| 293 | int rc = 0; |
| 294 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 295 | /* |
| 296 | * Alloc buffer array for commands (Tx or other types of commands). |
| 297 | * For the command queue (#4), allocate command space + one big |
| 298 | * command for scan, since scan command is very huge; the system will |
| 299 | * 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] | 300 | * For normal Tx queues (all other queues), no super-size command |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 301 | * space is needed. |
| 302 | */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 303 | len = sizeof(struct iwl_cmd) * slots_num; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 304 | if (txq_id == IWL_CMD_QUEUE_NUM) |
| 305 | len += IWL_MAX_SCAN_SIZE; |
| 306 | txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd); |
| 307 | if (!txq->cmd) |
| 308 | return -ENOMEM; |
| 309 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 310 | /* Alloc driver data array and TFD circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 311 | rc = iwl4965_tx_queue_alloc(priv, txq, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 312 | if (rc) { |
| 313 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 314 | |
| 315 | return -ENOMEM; |
| 316 | } |
| 317 | txq->need_update = 0; |
| 318 | |
| 319 | /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 320 | * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 321 | 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] | 322 | |
| 323 | /* Initialize queue's high/low-water marks, and head/tail indexes */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 324 | 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] | 325 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 326 | /* Tell device where to find queue */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 327 | iwl4965_hw_tx_queue_init(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 328 | |
| 329 | return 0; |
| 330 | } |
| 331 | |
| 332 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 333 | * iwl4965_tx_queue_free - Deallocate DMA queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 334 | * @txq: Transmit queue to deallocate. |
| 335 | * |
| 336 | * Empty queue by removing and destroying all BD's. |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 337 | * Free all buffers. |
| 338 | * 0-fill, but do not free "txq" descriptor structure. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 339 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 340 | 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] | 341 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 342 | struct iwl4965_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 343 | struct pci_dev *dev = priv->pci_dev; |
| 344 | int len; |
| 345 | |
| 346 | if (q->n_bd == 0) |
| 347 | return; |
| 348 | |
| 349 | /* first, empty all BD's */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 350 | for (; q->write_ptr != q->read_ptr; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 351 | 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] | 352 | iwl4965_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 353 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 354 | len = sizeof(struct iwl_cmd) * q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 355 | if (q->id == IWL_CMD_QUEUE_NUM) |
| 356 | len += IWL_MAX_SCAN_SIZE; |
| 357 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 358 | /* De-alloc array of command/tx buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 359 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 360 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 361 | /* De-alloc circular buffer of TFDs */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 362 | if (txq->q.n_bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 363 | pci_free_consistent(dev, sizeof(struct iwl4965_tfd_frame) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 364 | txq->q.n_bd, txq->bd, txq->q.dma_addr); |
| 365 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 366 | /* De-alloc array of per-TFD driver data */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 367 | if (txq->txb) { |
| 368 | kfree(txq->txb); |
| 369 | txq->txb = NULL; |
| 370 | } |
| 371 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 372 | /* 0-fill queue descriptor structure */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 373 | memset(txq, 0, sizeof(*txq)); |
| 374 | } |
| 375 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 376 | 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] | 377 | |
| 378 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 379 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 380 | * the functionality provided here |
| 381 | */ |
| 382 | |
| 383 | /**************************************************************/ |
| 384 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 385 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 386 | /** |
| 387 | * iwl4965_remove_station - Remove driver's knowledge of station. |
| 388 | * |
| 389 | * NOTE: This does not remove station from device's station table. |
| 390 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 391 | 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] | 392 | { |
| 393 | int index = IWL_INVALID_STATION; |
| 394 | int i; |
| 395 | unsigned long flags; |
| 396 | |
| 397 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 398 | |
| 399 | if (is_ap) |
| 400 | index = IWL_AP_ID; |
| 401 | else if (is_broadcast_ether_addr(addr)) |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 402 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 403 | else |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 404 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 405 | if (priv->stations[i].used && |
| 406 | !compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 407 | addr)) { |
| 408 | index = i; |
| 409 | break; |
| 410 | } |
| 411 | |
| 412 | if (unlikely(index == IWL_INVALID_STATION)) |
| 413 | goto out; |
| 414 | |
| 415 | if (priv->stations[index].used) { |
| 416 | priv->stations[index].used = 0; |
| 417 | priv->num_stations--; |
| 418 | } |
| 419 | |
| 420 | BUG_ON(priv->num_stations < 0); |
| 421 | |
| 422 | out: |
| 423 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 424 | return 0; |
| 425 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 426 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 427 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 428 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 429 | * iwl4965_add_station_flags - Add station to tables in driver and device |
| 430 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 431 | u8 iwl4965_add_station_flags(struct iwl_priv *priv, const u8 *addr, |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 432 | int is_ap, u8 flags, void *ht_data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 433 | { |
| 434 | int i; |
| 435 | int index = IWL_INVALID_STATION; |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame^] | 436 | struct iwl_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 437 | unsigned long flags_spin; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 438 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 439 | |
| 440 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 441 | if (is_ap) |
| 442 | index = IWL_AP_ID; |
| 443 | else if (is_broadcast_ether_addr(addr)) |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 444 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 445 | else |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 446 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 447 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 448 | addr)) { |
| 449 | index = i; |
| 450 | break; |
| 451 | } |
| 452 | |
| 453 | if (!priv->stations[i].used && |
| 454 | index == IWL_INVALID_STATION) |
| 455 | index = i; |
| 456 | } |
| 457 | |
| 458 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 459 | /* These two conditions have the same outcome, but keep them separate |
| 460 | since they have different meanings */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 461 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 462 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 463 | return index; |
| 464 | } |
| 465 | |
| 466 | if (priv->stations[index].used && |
| 467 | !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) { |
| 468 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 469 | return index; |
| 470 | } |
| 471 | |
| 472 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 473 | 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] | 474 | station = &priv->stations[index]; |
| 475 | station->used = 1; |
| 476 | priv->num_stations++; |
| 477 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 478 | /* Set up the REPLY_ADD_STA command to send to device */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 479 | memset(&station->sta, 0, sizeof(struct iwl4965_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 480 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 481 | station->sta.mode = 0; |
| 482 | station->sta.sta.sta_id = index; |
| 483 | station->sta.station_flags = 0; |
| 484 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 485 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 486 | /* BCAST station and IBSS stations do not work in HT mode */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 487 | if (index != priv->hw_params.bcast_sta_id && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 488 | priv->iw_mode != IEEE80211_IF_TYPE_IBSS) |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 489 | iwl4965_set_ht_add_station(priv, index, |
| 490 | (struct ieee80211_ht_info *) ht_data); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 491 | #endif /*CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 492 | |
| 493 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 494 | |
| 495 | /* Add station to device's station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 496 | iwl4965_send_add_station(priv, &station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 497 | return index; |
| 498 | |
| 499 | } |
| 500 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 501 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 502 | |
| 503 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 504 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 505 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 506 | * iwl4965_enqueue_hcmd - enqueue a uCode command |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 507 | * @priv: device private data point |
| 508 | * @cmd: a point to the ucode command structure |
| 509 | * |
| 510 | * The function returns < 0 values to indicate the operation is |
| 511 | * failed. On success, it turns the index (> 0) of command in the |
| 512 | * command queue. |
| 513 | */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 514 | int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 515 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 516 | struct iwl4965_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
| 517 | struct iwl4965_queue *q = &txq->q; |
| 518 | struct iwl4965_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 519 | u32 *control_flags; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 520 | struct iwl_cmd *out_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 521 | u32 idx; |
| 522 | u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 523 | dma_addr_t phys_addr; |
| 524 | int ret; |
| 525 | unsigned long flags; |
| 526 | |
| 527 | /* If any of the command structures end up being larger than |
| 528 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
| 529 | * we will need to increase the size of the TFD entries */ |
| 530 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
| 531 | !(cmd->meta.flags & CMD_SIZE_HUGE)); |
| 532 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 533 | if (iwl_is_rfkill(priv)) { |
Gregory Greenman | c342a1b | 2008-02-06 11:20:40 -0800 | [diff] [blame] | 534 | IWL_DEBUG_INFO("Not sending command - RF KILL"); |
| 535 | return -EIO; |
| 536 | } |
| 537 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 538 | if (iwl4965_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 539 | IWL_ERROR("No space for Tx\n"); |
| 540 | return -ENOSPC; |
| 541 | } |
| 542 | |
| 543 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 544 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 545 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 546 | memset(tfd, 0, sizeof(*tfd)); |
| 547 | |
| 548 | control_flags = (u32 *) tfd; |
| 549 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 550 | 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] | 551 | out_cmd = &txq->cmd[idx]; |
| 552 | |
| 553 | out_cmd->hdr.cmd = cmd->id; |
| 554 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 555 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 556 | |
| 557 | /* At this point, the out_cmd now has all of the incoming cmd |
| 558 | * information */ |
| 559 | |
| 560 | out_cmd->hdr.flags = 0; |
| 561 | 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] | 562 | INDEX_TO_SEQ(q->write_ptr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 563 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
| 564 | out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME); |
| 565 | |
| 566 | phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx + |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 567 | offsetof(struct iwl_cmd, hdr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 568 | 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] | 569 | |
| 570 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 571 | "%d bytes at %d[%d]:%d\n", |
| 572 | get_cmd_string(out_cmd->hdr.cmd), |
| 573 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 574 | fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 575 | |
| 576 | txq->need_update = 1; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 577 | |
| 578 | /* Set up entry in queue's byte count circular buffer */ |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 579 | priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, 0); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 580 | |
| 581 | /* Increment and update queue's write index */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 582 | q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 583 | ret = iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 584 | |
| 585 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 586 | return ret ? ret : idx; |
| 587 | } |
| 588 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 589 | static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) |
| 590 | { |
| 591 | struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon; |
| 592 | |
| 593 | if (hw_decrypt) |
| 594 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 595 | else |
| 596 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 597 | |
| 598 | } |
| 599 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 600 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 601 | * iwl4965_rxon_add_station - add station into station table. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 602 | * |
| 603 | * there is only one AP station with id= IWL_AP_ID |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 604 | * NOTE: mutex must be held before calling this fnction |
| 605 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 606 | static int iwl4965_rxon_add_station(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 607 | const u8 *addr, int is_ap) |
| 608 | { |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 609 | u8 sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 610 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 611 | /* Add station to device's station table */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 612 | #ifdef CONFIG_IWL4965_HT |
| 613 | struct ieee80211_conf *conf = &priv->hw->conf; |
| 614 | struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf; |
| 615 | |
| 616 | if ((is_ap) && |
| 617 | (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) && |
| 618 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 619 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, |
| 620 | 0, cur_ht_config); |
| 621 | else |
| 622 | #endif /* CONFIG_IWL4965_HT */ |
| 623 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, |
| 624 | 0, NULL); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 625 | |
| 626 | /* Set up default rate scaling table in device's station table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 627 | iwl4965_add_station(priv, addr, is_ap); |
| 628 | |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 629 | return sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 633 | * iwl4965_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 634 | * |
| 635 | * NOTE: This is really only useful during development and can eventually |
| 636 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 637 | * making changes |
| 638 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 639 | static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 640 | { |
| 641 | int error = 0; |
| 642 | int counter = 1; |
| 643 | |
| 644 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 645 | error |= le32_to_cpu(rxon->flags & |
| 646 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 647 | RXON_FLG_RADAR_DETECT_MSK)); |
| 648 | if (error) |
| 649 | IWL_WARNING("check 24G fields %d | %d\n", |
| 650 | counter++, error); |
| 651 | } else { |
| 652 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 653 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 654 | if (error) |
| 655 | IWL_WARNING("check 52 fields %d | %d\n", |
| 656 | counter++, error); |
| 657 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 658 | if (error) |
| 659 | IWL_WARNING("check 52 CCK %d | %d\n", |
| 660 | counter++, error); |
| 661 | } |
| 662 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 663 | if (error) |
| 664 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); |
| 665 | |
| 666 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 667 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 668 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 669 | if (error) |
| 670 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); |
| 671 | |
| 672 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 673 | if (error) |
| 674 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); |
| 675 | |
| 676 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 677 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 678 | if (error) |
| 679 | IWL_WARNING("check CCK and short slot %d | %d\n", |
| 680 | counter++, error); |
| 681 | |
| 682 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 683 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 684 | if (error) |
| 685 | IWL_WARNING("check CCK & auto detect %d | %d\n", |
| 686 | counter++, error); |
| 687 | |
| 688 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 689 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 690 | if (error) |
| 691 | IWL_WARNING("check TGG and auto detect %d | %d\n", |
| 692 | counter++, error); |
| 693 | |
| 694 | if (error) |
| 695 | IWL_WARNING("Tuning to channel %d\n", |
| 696 | le16_to_cpu(rxon->channel)); |
| 697 | |
| 698 | if (error) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 699 | IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 700 | return -1; |
| 701 | } |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 706 | * 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] | 707 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 708 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 709 | * If the RXON structure is changing enough to require a new tune, |
| 710 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 711 | * 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] | 712 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 713 | static int iwl4965_full_rxon_required(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 714 | { |
| 715 | |
| 716 | /* These items are only settable from the full RXON command */ |
| 717 | if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || |
| 718 | compare_ether_addr(priv->staging_rxon.bssid_addr, |
| 719 | priv->active_rxon.bssid_addr) || |
| 720 | compare_ether_addr(priv->staging_rxon.node_addr, |
| 721 | priv->active_rxon.node_addr) || |
| 722 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, |
| 723 | priv->active_rxon.wlap_bssid_addr) || |
| 724 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || |
| 725 | (priv->staging_rxon.channel != priv->active_rxon.channel) || |
| 726 | (priv->staging_rxon.air_propagation != |
| 727 | priv->active_rxon.air_propagation) || |
| 728 | (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != |
| 729 | priv->active_rxon.ofdm_ht_single_stream_basic_rates) || |
| 730 | (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != |
| 731 | priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || |
| 732 | (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) || |
| 733 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) |
| 734 | return 1; |
| 735 | |
| 736 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 737 | * be updated with the RXON_ASSOC command -- however only some |
| 738 | * flag transitions are allowed using RXON_ASSOC */ |
| 739 | |
| 740 | /* Check if we are not switching bands */ |
| 741 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 742 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
| 743 | return 1; |
| 744 | |
| 745 | /* Check if we are switching association toggle */ |
| 746 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 747 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
| 748 | return 1; |
| 749 | |
| 750 | return 0; |
| 751 | } |
| 752 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 753 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 754 | * iwl4965_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 755 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 756 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 757 | * the active_rxon structure is updated with the new data. This |
| 758 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 759 | * a HW tune is required based on the RXON structure changes. |
| 760 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 761 | static int iwl4965_commit_rxon(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 762 | { |
| 763 | /* cast away the const for active_rxon in this function */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 764 | struct iwl4965_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 765 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 766 | int rc = 0; |
| 767 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 768 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 769 | return -1; |
| 770 | |
| 771 | /* always get timestamp with Rx frame */ |
| 772 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
| 773 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 774 | rc = iwl4965_check_rxon_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 775 | if (rc) { |
| 776 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); |
| 777 | return -EINVAL; |
| 778 | } |
| 779 | |
| 780 | /* 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] | 781 | * iwl4965_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 782 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 783 | if (!iwl4965_full_rxon_required(priv)) { |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 784 | rc = iwl_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 785 | if (rc) { |
| 786 | IWL_ERROR("Error setting RXON_ASSOC " |
| 787 | "configuration (%d).\n", rc); |
| 788 | return rc; |
| 789 | } |
| 790 | |
| 791 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 792 | |
| 793 | return 0; |
| 794 | } |
| 795 | |
| 796 | /* station table will be cleared */ |
| 797 | priv->assoc_station_added = 0; |
| 798 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 799 | /* If we are currently associated and the new config requires |
| 800 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 801 | * we must clear the associated from the active configuration |
| 802 | * before we apply the new config */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 803 | if (iwl_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 804 | (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
| 805 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 806 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 807 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 808 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 809 | sizeof(struct iwl4965_rxon_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 810 | &priv->active_rxon); |
| 811 | |
| 812 | /* If the mask clearing failed then we set |
| 813 | * active_rxon back to what it was previously */ |
| 814 | if (rc) { |
| 815 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 816 | IWL_ERROR("Error clearing ASSOC_MSK on current " |
| 817 | "configuration (%d).\n", rc); |
| 818 | return rc; |
| 819 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | IWL_DEBUG_INFO("Sending RXON\n" |
| 823 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 824 | "* channel = %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 825 | "* bssid = %s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 826 | ((priv->staging_rxon.filter_flags & |
| 827 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
| 828 | le16_to_cpu(priv->staging_rxon.channel), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 829 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 830 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 831 | iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 832 | /* Apply the new configuration */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 833 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 834 | sizeof(struct iwl4965_rxon_cmd), &priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 835 | if (rc) { |
| 836 | IWL_ERROR("Error setting new configuration (%d).\n", rc); |
| 837 | return rc; |
| 838 | } |
| 839 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 840 | iwlcore_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 841 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 842 | if (!priv->error_recovering) |
| 843 | priv->start_calib = 0; |
| 844 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 845 | iwl_init_sensitivity(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 846 | |
| 847 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 848 | |
| 849 | /* If we issue a new RXON command which required a tune then we must |
| 850 | * 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] | 851 | rc = iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 852 | if (rc) { |
| 853 | IWL_ERROR("Error setting Tx power (%d).\n", rc); |
| 854 | return rc; |
| 855 | } |
| 856 | |
| 857 | /* Add the broadcast address so we can send broadcast frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 858 | if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 859 | IWL_INVALID_STATION) { |
| 860 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); |
| 861 | return -EIO; |
| 862 | } |
| 863 | |
| 864 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 865 | * add the IWL_AP_ID to the station rate table */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 866 | if (iwl_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 867 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 868 | if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 869 | == IWL_INVALID_STATION) { |
| 870 | IWL_ERROR("Error adding AP address for transmit.\n"); |
| 871 | return -EIO; |
| 872 | } |
| 873 | priv->assoc_station_added = 1; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 874 | if (priv->default_wep_key && |
| 875 | iwl_send_static_wepkey_cmd(priv, 0)) |
| 876 | IWL_ERROR("Could not send WEP static key.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | return 0; |
| 880 | } |
| 881 | |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 882 | void iwl4965_update_chain_flags(struct iwl_priv *priv) |
| 883 | { |
| 884 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 885 | iwl_set_rxon_chain(priv); |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 886 | iwl4965_commit_rxon(priv); |
| 887 | } |
| 888 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 889 | static int iwl4965_send_bt_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 890 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 891 | struct iwl4965_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 892 | .flags = 3, |
| 893 | .lead_time = 0xAA, |
| 894 | .max_kill = 1, |
| 895 | .kill_ack_mask = 0, |
| 896 | .kill_cts_mask = 0, |
| 897 | }; |
| 898 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 899 | return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 900 | sizeof(struct iwl4965_bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 903 | static int iwl4965_send_scan_abort(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 904 | { |
| 905 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 906 | struct iwl4965_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 907 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 908 | .id = REPLY_SCAN_ABORT_CMD, |
| 909 | .meta.flags = CMD_WANT_SKB, |
| 910 | }; |
| 911 | |
| 912 | /* If there isn't a scan actively going on in the hardware |
| 913 | * then we are in between scan bands and not actually |
| 914 | * actively scanning, so don't send the abort command */ |
| 915 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 916 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 917 | return 0; |
| 918 | } |
| 919 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 920 | rc = iwl_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 921 | if (rc) { |
| 922 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 923 | return rc; |
| 924 | } |
| 925 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 926 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 927 | if (res->u.status != CAN_ABORT_STATUS) { |
| 928 | /* The scan abort will return 1 for success or |
| 929 | * 2 for "failure". A failure condition can be |
| 930 | * due to simply not being in an active scan which |
| 931 | * can occur if we send the scan abort before we |
| 932 | * the microcode has notified us that a scan is |
| 933 | * completed. */ |
| 934 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 935 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 936 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 937 | } |
| 938 | |
| 939 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 940 | |
| 941 | return rc; |
| 942 | } |
| 943 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 944 | /* |
| 945 | * CARD_STATE_CMD |
| 946 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 947 | * 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] | 948 | * |
| 949 | * When in the 'enable' state the card operates as normal. |
| 950 | * When in the 'disable' state, the card enters into a low power mode. |
| 951 | * When in the 'halt' state, the card is shut down and must be fully |
| 952 | * restarted to come back on. |
| 953 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 954 | 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] | 955 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 956 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 957 | .id = REPLY_CARD_STATE_CMD, |
| 958 | .len = sizeof(u32), |
| 959 | .data = &flags, |
| 960 | .meta.flags = meta_flag, |
| 961 | }; |
| 962 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 963 | return iwl_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 964 | } |
| 965 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 966 | int iwl4965_send_add_station(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 967 | struct iwl4965_addsta_cmd *sta, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 968 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 969 | struct iwl4965_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 970 | int rc = 0; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 971 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 972 | .id = REPLY_ADD_STA, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 973 | .len = sizeof(struct iwl4965_addsta_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 974 | .meta.flags = flags, |
| 975 | .data = sta, |
| 976 | }; |
| 977 | |
Emmanuel Grumbach | 9e5b806 | 2008-04-21 15:41:55 -0700 | [diff] [blame] | 978 | if (!(flags & CMD_ASYNC)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 979 | cmd.meta.flags |= CMD_WANT_SKB; |
| 980 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 981 | rc = iwl_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 982 | |
| 983 | if (rc || (flags & CMD_ASYNC)) |
| 984 | return rc; |
| 985 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 986 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 987 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 988 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 989 | res->hdr.flags); |
| 990 | rc = -EIO; |
| 991 | } |
| 992 | |
| 993 | if (rc == 0) { |
| 994 | switch (res->u.add_sta.status) { |
| 995 | case ADD_STA_SUCCESS_MSK: |
| 996 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 997 | break; |
| 998 | default: |
| 999 | rc = -EIO; |
| 1000 | IWL_WARNING("REPLY_ADD_STA failed\n"); |
| 1001 | break; |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | priv->alloc_rxb_skb--; |
| 1006 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1007 | |
| 1008 | return rc; |
| 1009 | } |
| 1010 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1011 | static void iwl4965_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1012 | { |
| 1013 | struct list_head *element; |
| 1014 | |
| 1015 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 1016 | priv->frames_count); |
| 1017 | |
| 1018 | while (!list_empty(&priv->free_frames)) { |
| 1019 | element = priv->free_frames.next; |
| 1020 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1021 | kfree(list_entry(element, struct iwl4965_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1022 | priv->frames_count--; |
| 1023 | } |
| 1024 | |
| 1025 | if (priv->frames_count) { |
| 1026 | IWL_WARNING("%d frames still in use. Did we lose one?\n", |
| 1027 | priv->frames_count); |
| 1028 | priv->frames_count = 0; |
| 1029 | } |
| 1030 | } |
| 1031 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1032 | static struct iwl4965_frame *iwl4965_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1033 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1034 | struct iwl4965_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1035 | struct list_head *element; |
| 1036 | if (list_empty(&priv->free_frames)) { |
| 1037 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 1038 | if (!frame) { |
| 1039 | IWL_ERROR("Could not allocate frame!\n"); |
| 1040 | return NULL; |
| 1041 | } |
| 1042 | |
| 1043 | priv->frames_count++; |
| 1044 | return frame; |
| 1045 | } |
| 1046 | |
| 1047 | element = priv->free_frames.next; |
| 1048 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1049 | return list_entry(element, struct iwl4965_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1052 | 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] | 1053 | { |
| 1054 | memset(frame, 0, sizeof(*frame)); |
| 1055 | list_add(&frame->list, &priv->free_frames); |
| 1056 | } |
| 1057 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1058 | unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1059 | struct ieee80211_hdr *hdr, |
| 1060 | const u8 *dest, int left) |
| 1061 | { |
| 1062 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1063 | if (!iwl_is_associated(priv) || !priv->ibss_beacon || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1064 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
| 1065 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) |
| 1066 | return 0; |
| 1067 | |
| 1068 | if (priv->ibss_beacon->len > left) |
| 1069 | return 0; |
| 1070 | |
| 1071 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 1072 | |
| 1073 | return priv->ibss_beacon->len; |
| 1074 | } |
| 1075 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1076 | static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1077 | { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1078 | int i; |
| 1079 | int rate_mask; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1080 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1081 | /* Set rate mask*/ |
| 1082 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 1083 | rate_mask = priv->active_rate_basic & 0xF; |
| 1084 | else |
| 1085 | rate_mask = priv->active_rate_basic & 0xFF0; |
| 1086 | |
| 1087 | /* Find lowest valid rate */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1088 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1089 | i = iwl4965_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1090 | if (rate_mask & (1 << i)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1091 | return iwl4965_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1094 | /* No valid rate was found. Assign the lowest one */ |
| 1095 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 1096 | return IWL_RATE_1M_PLCP; |
| 1097 | else |
| 1098 | return IWL_RATE_6M_PLCP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1101 | static int iwl4965_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1102 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1103 | struct iwl4965_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1104 | unsigned int frame_size; |
| 1105 | int rc; |
| 1106 | u8 rate; |
| 1107 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1108 | frame = iwl4965_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1109 | |
| 1110 | if (!frame) { |
| 1111 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 1112 | "command.\n"); |
| 1113 | return -ENOMEM; |
| 1114 | } |
| 1115 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 1116 | rate = iwl4965_rate_get_lowest_plcp(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1117 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1118 | frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1119 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1120 | rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1121 | &frame->u.cmd[0]); |
| 1122 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1123 | iwl4965_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1124 | |
| 1125 | return rc; |
| 1126 | } |
| 1127 | |
| 1128 | /****************************************************************************** |
| 1129 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1130 | * Misc. internal state and helper functions |
| 1131 | * |
| 1132 | ******************************************************************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1133 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1134 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1135 | * 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] | 1136 | * |
| 1137 | * return : set the bit for each supported rate insert in ie |
| 1138 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1139 | static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1140 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1141 | { |
| 1142 | u16 ret_rates = 0, bit; |
| 1143 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1144 | u8 *cnt = ie; |
| 1145 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1146 | |
| 1147 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1148 | if (bit & supported_rate) { |
| 1149 | ret_rates |= bit; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1150 | rates[*cnt] = iwl4965_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1151 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1152 | (*cnt)++; |
| 1153 | (*left)--; |
| 1154 | if ((*left <= 0) || |
| 1155 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1156 | break; |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | return ret_rates; |
| 1161 | } |
| 1162 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 1163 | #ifdef CONFIG_IWL4965_HT |
| 1164 | static void iwl4965_ht_conf(struct iwl_priv *priv, |
| 1165 | struct ieee80211_bss_conf *bss_conf) |
| 1166 | { |
| 1167 | struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf; |
| 1168 | struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf; |
| 1169 | struct iwl_ht_info *iwl_conf = &priv->current_ht_config; |
| 1170 | |
| 1171 | IWL_DEBUG_MAC80211("enter: \n"); |
| 1172 | |
| 1173 | iwl_conf->is_ht = bss_conf->assoc_ht; |
| 1174 | |
| 1175 | if (!iwl_conf->is_ht) |
| 1176 | return; |
| 1177 | |
| 1178 | priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 1179 | |
| 1180 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) |
| 1181 | iwl_conf->sgf |= 0x1; |
| 1182 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) |
| 1183 | iwl_conf->sgf |= 0x2; |
| 1184 | |
| 1185 | iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); |
| 1186 | iwl_conf->max_amsdu_size = |
| 1187 | !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); |
| 1188 | |
| 1189 | iwl_conf->supported_chan_width = |
| 1190 | !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); |
| 1191 | iwl_conf->extension_chan_offset = |
| 1192 | ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; |
| 1193 | /* If no above or below channel supplied disable FAT channel */ |
| 1194 | if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE && |
| 1195 | iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW) |
| 1196 | iwl_conf->supported_chan_width = 0; |
| 1197 | |
| 1198 | iwl_conf->tx_mimo_ps_mode = |
| 1199 | (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 1200 | memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); |
| 1201 | |
| 1202 | iwl_conf->control_channel = ht_bss_conf->primary_channel; |
| 1203 | iwl_conf->tx_chan_width = |
| 1204 | !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); |
| 1205 | iwl_conf->ht_protection = |
| 1206 | ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; |
| 1207 | iwl_conf->non_GF_STA_present = |
| 1208 | !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT); |
| 1209 | |
| 1210 | IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel); |
| 1211 | IWL_DEBUG_MAC80211("leave\n"); |
| 1212 | } |
| 1213 | |
| 1214 | static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband, |
| 1215 | u8 *pos, int *left) |
| 1216 | { |
| 1217 | struct ieee80211_ht_cap *ht_cap; |
| 1218 | |
| 1219 | if (!sband || !sband->ht_info.ht_supported) |
| 1220 | return; |
| 1221 | |
| 1222 | if (*left < sizeof(struct ieee80211_ht_cap)) |
| 1223 | return; |
| 1224 | |
| 1225 | *pos++ = sizeof(struct ieee80211_ht_cap); |
| 1226 | ht_cap = (struct ieee80211_ht_cap *) pos; |
| 1227 | |
| 1228 | ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap); |
| 1229 | memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16); |
| 1230 | ht_cap->ampdu_params_info = |
| 1231 | (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) | |
| 1232 | ((sband->ht_info.ampdu_density << 2) & |
| 1233 | IEEE80211_HT_CAP_AMPDU_DENSITY); |
| 1234 | *left -= sizeof(struct ieee80211_ht_cap); |
| 1235 | } |
| 1236 | #else |
| 1237 | static inline void iwl4965_ht_conf(struct iwl_priv *priv, |
| 1238 | struct ieee80211_bss_conf *bss_conf) |
| 1239 | { |
| 1240 | } |
| 1241 | static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband, |
| 1242 | u8 *pos, int *left) |
| 1243 | { |
| 1244 | } |
| 1245 | #endif |
| 1246 | |
| 1247 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1248 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1249 | * 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] | 1250 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1251 | static u16 iwl4965_fill_probe_req(struct iwl_priv *priv, |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1252 | enum ieee80211_band band, |
| 1253 | struct ieee80211_mgmt *frame, |
| 1254 | int left, int is_direct) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1255 | { |
| 1256 | int len = 0; |
| 1257 | u8 *pos = NULL; |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1258 | u16 active_rates, ret_rates, cck_rates, active_rate_basic; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1259 | const struct ieee80211_supported_band *sband = |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 1260 | iwl_get_hw_mode(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1261 | |
| 1262 | /* Make sure there is enough space for the probe request, |
| 1263 | * two mandatory IEs and the data */ |
| 1264 | left -= 24; |
| 1265 | if (left < 0) |
| 1266 | return 0; |
| 1267 | len += 24; |
| 1268 | |
| 1269 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1270 | memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1271 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1272 | memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1273 | frame->seq_ctrl = 0; |
| 1274 | |
| 1275 | /* fill in our indirect SSID IE */ |
| 1276 | /* ...next IE... */ |
| 1277 | |
| 1278 | left -= 2; |
| 1279 | if (left < 0) |
| 1280 | return 0; |
| 1281 | len += 2; |
| 1282 | pos = &(frame->u.probe_req.variable[0]); |
| 1283 | *pos++ = WLAN_EID_SSID; |
| 1284 | *pos++ = 0; |
| 1285 | |
| 1286 | /* fill in our direct SSID IE... */ |
| 1287 | if (is_direct) { |
| 1288 | /* ...next IE... */ |
| 1289 | left -= 2 + priv->essid_len; |
| 1290 | if (left < 0) |
| 1291 | return 0; |
| 1292 | /* ... fill it in... */ |
| 1293 | *pos++ = WLAN_EID_SSID; |
| 1294 | *pos++ = priv->essid_len; |
| 1295 | memcpy(pos, priv->essid, priv->essid_len); |
| 1296 | pos += priv->essid_len; |
| 1297 | len += 2 + priv->essid_len; |
| 1298 | } |
| 1299 | |
| 1300 | /* fill in supported rate */ |
| 1301 | /* ...next IE... */ |
| 1302 | left -= 2; |
| 1303 | if (left < 0) |
| 1304 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1305 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1306 | /* ... fill it in... */ |
| 1307 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1308 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1309 | |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1310 | /* exclude 60M rate */ |
| 1311 | active_rates = priv->rates_mask; |
| 1312 | active_rates &= ~IWL_RATE_60M_MASK; |
| 1313 | |
| 1314 | active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1315 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1316 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1317 | ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1318 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1319 | active_rates &= ~ret_rates; |
| 1320 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1321 | ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1322 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1323 | active_rates &= ~ret_rates; |
| 1324 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1325 | len += 2 + *pos; |
| 1326 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1327 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1328 | goto fill_end; |
| 1329 | |
| 1330 | /* fill in supported extended rate */ |
| 1331 | /* ...next IE... */ |
| 1332 | left -= 2; |
| 1333 | if (left < 0) |
| 1334 | return 0; |
| 1335 | /* ... fill it in... */ |
| 1336 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1337 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1338 | iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1339 | active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1340 | if (*pos > 0) |
| 1341 | len += 2 + *pos; |
| 1342 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1343 | fill_end: |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 1344 | /* fill in HT IE */ |
| 1345 | left -= 2; |
| 1346 | if (left < 0) |
| 1347 | return 0; |
| 1348 | |
| 1349 | *pos++ = WLAN_EID_HT_CAPABILITY; |
| 1350 | *pos = 0; |
| 1351 | |
| 1352 | iwl_ht_cap_to_ie(sband, pos, &left); |
| 1353 | |
| 1354 | if (*pos > 0) |
| 1355 | len += 2 + *pos; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1356 | return (u16)len; |
| 1357 | } |
| 1358 | |
| 1359 | /* |
| 1360 | * QoS support |
| 1361 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1362 | static int iwl4965_send_qos_params_command(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1363 | struct iwl4965_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1364 | { |
| 1365 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1366 | return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1367 | sizeof(struct iwl4965_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1368 | } |
| 1369 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1370 | static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1371 | { |
| 1372 | unsigned long flags; |
| 1373 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1374 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 1375 | return; |
| 1376 | |
| 1377 | if (!priv->qos_data.qos_enable) |
| 1378 | return; |
| 1379 | |
| 1380 | spin_lock_irqsave(&priv->lock, flags); |
| 1381 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 1382 | |
| 1383 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 1384 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 1385 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1386 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1387 | if (priv->qos_data.qos_active) |
| 1388 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1389 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 1390 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1391 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 1392 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1393 | 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] | 1394 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1395 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1396 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1397 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1398 | if (force || iwl_is_associated(priv)) { |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1399 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 1400 | priv->qos_data.qos_active, |
| 1401 | priv->qos_data.def_qos_parm.qos_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1402 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1403 | iwl4965_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1404 | &(priv->qos_data.def_qos_parm)); |
| 1405 | } |
| 1406 | } |
| 1407 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1408 | 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] | 1409 | { |
| 1410 | /* Filter incoming packets to determine if they are targeted toward |
| 1411 | * this network, discarding packets coming from ourselves */ |
| 1412 | switch (priv->iw_mode) { |
| 1413 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 1414 | /* packets from our adapter are dropped (echo) */ |
| 1415 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 1416 | return 0; |
| 1417 | /* {broad,multi}cast packets to our IBSS go through */ |
| 1418 | if (is_multicast_ether_addr(header->addr1)) |
| 1419 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 1420 | /* packets to our adapter go through */ |
| 1421 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 1422 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 1423 | /* packets from our adapter are dropped (echo) */ |
| 1424 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 1425 | return 0; |
| 1426 | /* {broad,multi}cast packets to our BSS go through */ |
| 1427 | if (is_multicast_ether_addr(header->addr1)) |
| 1428 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 1429 | /* packets to our adapter go through */ |
| 1430 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1431 | default: |
| 1432 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | return 1; |
| 1436 | } |
| 1437 | |
| 1438 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 1439 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1440 | static const char *iwl4965_get_tx_fail_reason(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1441 | { |
| 1442 | switch (status & TX_STATUS_MSK) { |
| 1443 | case TX_STATUS_SUCCESS: |
| 1444 | return "SUCCESS"; |
| 1445 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 1446 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 1447 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 1448 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 1449 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 1450 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 1451 | TX_STATUS_ENTRY(DEST_PS); |
| 1452 | TX_STATUS_ENTRY(ABORTED); |
| 1453 | TX_STATUS_ENTRY(BT_RETRY); |
| 1454 | TX_STATUS_ENTRY(STA_INVALID); |
| 1455 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 1456 | TX_STATUS_ENTRY(TID_DISABLE); |
| 1457 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 1458 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 1459 | TX_STATUS_ENTRY(TX_LOCKED); |
| 1460 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 1461 | } |
| 1462 | |
| 1463 | return "UNKNOWN"; |
| 1464 | } |
| 1465 | |
| 1466 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1467 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1468 | * |
| 1469 | * NOTE: priv->mutex is not required before calling this function |
| 1470 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1471 | static int iwl4965_scan_cancel(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1472 | { |
| 1473 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1474 | clear_bit(STATUS_SCANNING, &priv->status); |
| 1475 | return 0; |
| 1476 | } |
| 1477 | |
| 1478 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1479 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1480 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 1481 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1482 | queue_work(priv->workqueue, &priv->abort_scan); |
| 1483 | |
| 1484 | } else |
| 1485 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 1486 | |
| 1487 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1488 | } |
| 1489 | |
| 1490 | return 0; |
| 1491 | } |
| 1492 | |
| 1493 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1494 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1495 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 1496 | * |
| 1497 | * NOTE: priv->mutex must be held before calling this function |
| 1498 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1499 | 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] | 1500 | { |
| 1501 | unsigned long now = jiffies; |
| 1502 | int ret; |
| 1503 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1504 | ret = iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1505 | if (ret && ms) { |
| 1506 | mutex_unlock(&priv->mutex); |
| 1507 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 1508 | test_bit(STATUS_SCANNING, &priv->status)) |
| 1509 | msleep(1); |
| 1510 | mutex_lock(&priv->mutex); |
| 1511 | |
| 1512 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1513 | } |
| 1514 | |
| 1515 | return ret; |
| 1516 | } |
| 1517 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1518 | static void iwl4965_sequence_reset(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1519 | { |
| 1520 | /* Reset ieee stats */ |
| 1521 | |
| 1522 | /* We don't reset the net_device_stats (ieee->stats) on |
| 1523 | * re-association */ |
| 1524 | |
| 1525 | priv->last_seq_num = -1; |
| 1526 | priv->last_frag_num = -1; |
| 1527 | priv->last_packet_time = 0; |
| 1528 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1529 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 1533 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 1534 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1535 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1536 | { |
| 1537 | u16 new_val = 0; |
| 1538 | u16 beacon_factor = 0; |
| 1539 | |
| 1540 | beacon_factor = |
| 1541 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 1542 | / MAX_UCODE_BEACON_INTERVAL; |
| 1543 | new_val = beacon_val / beacon_factor; |
| 1544 | |
| 1545 | return cpu_to_le16(new_val); |
| 1546 | } |
| 1547 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1548 | static void iwl4965_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1549 | { |
| 1550 | u64 interval_tm_unit; |
| 1551 | u64 tsf, result; |
| 1552 | unsigned long flags; |
| 1553 | struct ieee80211_conf *conf = NULL; |
| 1554 | u16 beacon_int = 0; |
| 1555 | |
| 1556 | conf = ieee80211_get_hw_conf(priv->hw); |
| 1557 | |
| 1558 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1559 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32); |
| 1560 | priv->rxon_timing.timestamp.dw[0] = |
| 1561 | cpu_to_le32(priv->timestamp & 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1562 | |
| 1563 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 1564 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1565 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1566 | |
| 1567 | beacon_int = priv->beacon_int; |
| 1568 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1569 | |
| 1570 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 1571 | if (beacon_int == 0) { |
| 1572 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 1573 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 1574 | } else { |
| 1575 | priv->rxon_timing.beacon_interval = |
| 1576 | cpu_to_le16(beacon_int); |
| 1577 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1578 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1579 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1580 | } |
| 1581 | |
| 1582 | priv->rxon_timing.atim_window = 0; |
| 1583 | } else { |
| 1584 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1585 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1586 | /* TODO: we need to get atim_window from upper stack |
| 1587 | * for now we set to 0 */ |
| 1588 | priv->rxon_timing.atim_window = 0; |
| 1589 | } |
| 1590 | |
| 1591 | interval_tm_unit = |
| 1592 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 1593 | result = do_div(tsf, interval_tm_unit); |
| 1594 | priv->rxon_timing.beacon_init_val = |
| 1595 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 1596 | |
| 1597 | IWL_DEBUG_ASSOC |
| 1598 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 1599 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 1600 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 1601 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 1602 | } |
| 1603 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1604 | static int iwl4965_scan_initiate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1605 | { |
| 1606 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 1607 | IWL_ERROR("APs don't scan.\n"); |
| 1608 | return 0; |
| 1609 | } |
| 1610 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1611 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1612 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 1613 | return -EIO; |
| 1614 | } |
| 1615 | |
| 1616 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1617 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 1618 | return -EAGAIN; |
| 1619 | } |
| 1620 | |
| 1621 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1622 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 1623 | "Queuing.\n"); |
| 1624 | return -EAGAIN; |
| 1625 | } |
| 1626 | |
| 1627 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 1628 | priv->scan_bands = 2; |
| 1629 | set_bit(STATUS_SCANNING, &priv->status); |
| 1630 | priv->scan_start = jiffies; |
| 1631 | priv->scan_pass_start = priv->scan_start; |
| 1632 | |
| 1633 | queue_work(priv->workqueue, &priv->request_scan); |
| 1634 | |
| 1635 | return 0; |
| 1636 | } |
| 1637 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1638 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1639 | static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1640 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1641 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1642 | if (band == IEEE80211_BAND_5GHZ) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1643 | priv->staging_rxon.flags &= |
| 1644 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 1645 | | RXON_FLG_CCK_MSK); |
| 1646 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1647 | } else { |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 1648 | /* Copied from iwl4965_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1649 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 1650 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1651 | else |
| 1652 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1653 | |
| 1654 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 1655 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1656 | |
| 1657 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 1658 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 1659 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 1660 | } |
| 1661 | } |
| 1662 | |
| 1663 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1664 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1665 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1666 | static void iwl4965_connection_init_rx_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1667 | { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1668 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1669 | |
| 1670 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 1671 | |
| 1672 | switch (priv->iw_mode) { |
| 1673 | case IEEE80211_IF_TYPE_AP: |
| 1674 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 1675 | break; |
| 1676 | |
| 1677 | case IEEE80211_IF_TYPE_STA: |
| 1678 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 1679 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 1680 | break; |
| 1681 | |
| 1682 | case IEEE80211_IF_TYPE_IBSS: |
| 1683 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 1684 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1685 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 1686 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1687 | break; |
| 1688 | |
| 1689 | case IEEE80211_IF_TYPE_MNTR: |
| 1690 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 1691 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 1692 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1693 | break; |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1694 | default: |
| 1695 | IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode); |
| 1696 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | #if 0 |
| 1700 | /* TODO: Figure out when short_preamble would be set and cache from |
| 1701 | * that */ |
| 1702 | if (!hw_to_local(priv->hw)->short_preamble) |
| 1703 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1704 | else |
| 1705 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1706 | #endif |
| 1707 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1708 | ch_info = iwl_get_channel_info(priv, priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1709 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1710 | |
| 1711 | if (!ch_info) |
| 1712 | ch_info = &priv->channel_info[0]; |
| 1713 | |
| 1714 | /* |
| 1715 | * in some case A channels are all non IBSS |
| 1716 | * in this case force B/G channel |
| 1717 | */ |
| 1718 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 1719 | !(is_channel_ibss(ch_info))) |
| 1720 | ch_info = &priv->channel_info[0]; |
| 1721 | |
| 1722 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1723 | priv->band = ch_info->band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1724 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1725 | iwl4965_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1726 | |
| 1727 | priv->staging_rxon.ofdm_basic_rates = |
| 1728 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1729 | priv->staging_rxon.cck_basic_rates = |
| 1730 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1731 | |
| 1732 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 1733 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 1734 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1735 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 1736 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 1737 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 1738 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1741 | static int iwl4965_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1742 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1743 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1744 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1745 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1746 | ch_info = iwl_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1747 | priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1748 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1749 | |
| 1750 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 1751 | IWL_ERROR("channel %d not IBSS channel\n", |
| 1752 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1753 | return -EINVAL; |
| 1754 | } |
| 1755 | } |
| 1756 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1757 | priv->iw_mode = mode; |
| 1758 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1759 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1760 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1761 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1762 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1763 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1764 | /* dont commit rxon if rf-kill is on*/ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1765 | if (!iwl_is_ready_rf(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1766 | return -EAGAIN; |
| 1767 | |
| 1768 | cancel_delayed_work(&priv->scan_check); |
| 1769 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
| 1770 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 1771 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 1772 | return -EAGAIN; |
| 1773 | } |
| 1774 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1775 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1776 | |
| 1777 | return 0; |
| 1778 | } |
| 1779 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1780 | static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1781 | struct ieee80211_tx_control *ctl, |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1782 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1783 | struct sk_buff *skb_frag, |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 1784 | int sta_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1785 | { |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame^] | 1786 | struct iwl_hw_key *keyinfo = &priv->stations[sta_id].keyinfo; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1787 | struct iwl_wep_key *wepkey; |
| 1788 | int keyidx = 0; |
| 1789 | |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 1790 | BUG_ON(ctl->hw_key->hw_key_idx > 3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1791 | |
| 1792 | switch (keyinfo->alg) { |
| 1793 | case ALG_CCMP: |
| 1794 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM; |
| 1795 | memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen); |
Max Stepanov | 8236e18 | 2008-03-12 16:58:48 -0700 | [diff] [blame] | 1796 | if (ctl->flags & IEEE80211_TXCTL_AMPDU) |
| 1797 | cmd->cmd.tx.tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1798 | IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n"); |
| 1799 | break; |
| 1800 | |
| 1801 | case ALG_TKIP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1802 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP; |
Emmanuel Grumbach | 2bc7508 | 2008-03-19 16:41:45 -0700 | [diff] [blame] | 1803 | ieee80211_get_tkip_key(keyinfo->conf, skb_frag, |
| 1804 | IEEE80211_TKIP_P2_KEY, cmd->cmd.tx.key); |
| 1805 | IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1806 | break; |
| 1807 | |
| 1808 | case ALG_WEP: |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 1809 | wepkey = &priv->wep_keys[ctl->hw_key->hw_key_idx]; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1810 | cmd->cmd.tx.sec_ctl = 0; |
| 1811 | if (priv->default_wep_key) { |
| 1812 | /* the WEP key was sent as static */ |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 1813 | keyidx = ctl->hw_key->hw_key_idx; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1814 | memcpy(&cmd->cmd.tx.key[3], wepkey->key, |
| 1815 | wepkey->key_size); |
| 1816 | if (wepkey->key_size == WEP_KEY_LEN_128) |
| 1817 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
| 1818 | } else { |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 1819 | /* the WEP key was sent as dynamic */ |
| 1820 | keyidx = keyinfo->keyidx; |
| 1821 | memcpy(&cmd->cmd.tx.key[3], keyinfo->key, |
| 1822 | keyinfo->keylen); |
| 1823 | if (keyinfo->keylen == WEP_KEY_LEN_128) |
| 1824 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1825 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1826 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1827 | cmd->cmd.tx.sec_ctl |= (TX_CMD_SEC_WEP | |
| 1828 | (keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1829 | |
| 1830 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1831 | "with key %d\n", keyidx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1832 | break; |
| 1833 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1834 | default: |
| 1835 | printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg); |
| 1836 | break; |
| 1837 | } |
| 1838 | } |
| 1839 | |
| 1840 | /* |
| 1841 | * handle build REPLY_TX command notification. |
| 1842 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1843 | static void iwl4965_build_tx_cmd_basic(struct iwl_priv *priv, |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1844 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1845 | struct ieee80211_tx_control *ctrl, |
| 1846 | struct ieee80211_hdr *hdr, |
| 1847 | int is_unicast, u8 std_id) |
| 1848 | { |
| 1849 | __le16 *qc; |
| 1850 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 1851 | __le32 tx_flags = cmd->cmd.tx.tx_flags; |
| 1852 | |
| 1853 | cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 1854 | if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) { |
| 1855 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
| 1856 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 1857 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1858 | if (ieee80211_is_probe_response(fc) && |
| 1859 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 1860 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 1861 | } else { |
| 1862 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 1863 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1864 | } |
| 1865 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 1866 | if (ieee80211_is_back_request(fc)) |
| 1867 | tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK; |
| 1868 | |
| 1869 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1870 | cmd->cmd.tx.sta_id = std_id; |
| 1871 | if (ieee80211_get_morefrag(hdr)) |
| 1872 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 1873 | |
| 1874 | qc = ieee80211_get_qos_ctrl(hdr); |
| 1875 | if (qc) { |
| 1876 | cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf); |
| 1877 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
| 1878 | } else |
| 1879 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1880 | |
| 1881 | if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) { |
| 1882 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 1883 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
| 1884 | } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { |
| 1885 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 1886 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 1887 | } |
| 1888 | |
| 1889 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 1890 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 1891 | |
| 1892 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
| 1893 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { |
| 1894 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || |
| 1895 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1896 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1897 | else |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1898 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 1899 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1900 | cmd->cmd.tx.timeout.pm_frame_timeout = 0; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 1901 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1902 | |
| 1903 | cmd->cmd.tx.driver_txop = 0; |
| 1904 | cmd->cmd.tx.tx_flags = tx_flags; |
| 1905 | cmd->cmd.tx.next_frame_len = 0; |
| 1906 | } |
Tomas Winkler | 19758be | 2008-03-12 16:58:51 -0700 | [diff] [blame] | 1907 | static void iwl_update_tx_stats(struct iwl_priv *priv, u16 fc, u16 len) |
| 1908 | { |
| 1909 | /* 0 - mgmt, 1 - cnt, 2 - data */ |
| 1910 | int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2; |
| 1911 | priv->tx_stats[idx].cnt++; |
| 1912 | priv->tx_stats[idx].bytes += len; |
| 1913 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1914 | /** |
| 1915 | * iwl4965_get_sta_id - Find station's index within station table |
| 1916 | * |
| 1917 | * If new IBSS station, create new entry in station table |
| 1918 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1919 | static int iwl4965_get_sta_id(struct iwl_priv *priv, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1920 | struct ieee80211_hdr *hdr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1921 | { |
| 1922 | int sta_id; |
| 1923 | u16 fc = le16_to_cpu(hdr->frame_control); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1924 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1925 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1926 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1927 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 1928 | is_multicast_ether_addr(hdr->addr1)) |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1929 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1930 | |
| 1931 | switch (priv->iw_mode) { |
| 1932 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1933 | /* If we are a client station in a BSS network, use the special |
| 1934 | * AP station entry (that's the only station we communicate with) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1935 | case IEEE80211_IF_TYPE_STA: |
| 1936 | return IWL_AP_ID; |
| 1937 | |
| 1938 | /* If we are an AP, then find the station, or use BCAST */ |
| 1939 | case IEEE80211_IF_TYPE_AP: |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 1940 | sta_id = iwl_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1941 | if (sta_id != IWL_INVALID_STATION) |
| 1942 | return sta_id; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1943 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1944 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1945 | /* If this frame is going out to an IBSS network, find the station, |
| 1946 | * or create a new station table entry */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1947 | case IEEE80211_IF_TYPE_IBSS: |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 1948 | sta_id = iwl_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1949 | if (sta_id != IWL_INVALID_STATION) |
| 1950 | return sta_id; |
| 1951 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1952 | /* Create new station table entry */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 1953 | sta_id = iwl4965_add_station_flags(priv, hdr->addr1, |
| 1954 | 0, CMD_ASYNC, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1955 | |
| 1956 | if (sta_id != IWL_INVALID_STATION) |
| 1957 | return sta_id; |
| 1958 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1959 | IWL_DEBUG_DROP("Station %s not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1960 | "Defaulting to broadcast...\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1961 | print_mac(mac, hdr->addr1)); |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1962 | iwl_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1963 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1964 | |
| 1965 | default: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1966 | IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1967 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | /* |
| 1972 | * start REPLY_TX command process |
| 1973 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1974 | static int iwl4965_tx_skb(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1975 | struct sk_buff *skb, struct ieee80211_tx_control *ctl) |
| 1976 | { |
| 1977 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1978 | struct iwl4965_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1979 | u32 *control_flags; |
| 1980 | int txq_id = ctl->queue; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1981 | struct iwl4965_tx_queue *txq = NULL; |
| 1982 | struct iwl4965_queue *q = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1983 | dma_addr_t phys_addr; |
| 1984 | dma_addr_t txcmd_phys; |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 1985 | dma_addr_t scratch_phys; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1986 | struct iwl_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1987 | u16 len, idx, len_org; |
| 1988 | u8 id, hdr_len, unicast; |
| 1989 | u8 sta_id; |
| 1990 | u16 seq_number = 0; |
| 1991 | u16 fc; |
| 1992 | __le16 *qc; |
| 1993 | u8 wait_write_ptr = 0; |
| 1994 | unsigned long flags; |
| 1995 | int rc; |
| 1996 | |
| 1997 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1998 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1999 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 2000 | goto drop_unlock; |
| 2001 | } |
| 2002 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 2003 | if (!priv->vif) { |
| 2004 | IWL_DEBUG_DROP("Dropping - !priv->vif\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2005 | goto drop_unlock; |
| 2006 | } |
| 2007 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2008 | if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2009 | IWL_ERROR("ERROR: No TX rate available.\n"); |
| 2010 | goto drop_unlock; |
| 2011 | } |
| 2012 | |
| 2013 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 2014 | id = 0; |
| 2015 | |
| 2016 | fc = le16_to_cpu(hdr->frame_control); |
| 2017 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2018 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2019 | if (ieee80211_is_auth(fc)) |
| 2020 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
| 2021 | else if (ieee80211_is_assoc_request(fc)) |
| 2022 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
| 2023 | else if (ieee80211_is_reassoc_request(fc)) |
| 2024 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 2025 | #endif |
| 2026 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2027 | /* drop all data frame if we are not associated */ |
Gregory Greenman | 76f3915 | 2008-01-23 10:15:21 -0800 | [diff] [blame] | 2028 | if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) && |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2029 | (!iwl_is_associated(priv) || |
Reinette Chatre | a647724 | 2008-02-14 10:40:28 -0800 | [diff] [blame] | 2030 | ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id) || |
Gregory Greenman | 76f3915 | 2008-01-23 10:15:21 -0800 | [diff] [blame] | 2031 | !priv->assoc_station_added)) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2032 | IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2033 | goto drop_unlock; |
| 2034 | } |
| 2035 | |
| 2036 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2037 | |
| 2038 | hdr_len = ieee80211_get_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2039 | |
| 2040 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2041 | sta_id = iwl4965_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2042 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2043 | DECLARE_MAC_BUF(mac); |
| 2044 | |
| 2045 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n", |
| 2046 | print_mac(mac, hdr->addr1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2047 | goto drop; |
| 2048 | } |
| 2049 | |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 2050 | IWL_DEBUG_TX("station Id %d\n", sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2051 | |
| 2052 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2053 | if (qc) { |
| 2054 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2055 | seq_number = priv->stations[sta_id].tid[tid].seq_number & |
| 2056 | IEEE80211_SCTL_SEQ; |
| 2057 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 2058 | (hdr->seq_ctrl & |
| 2059 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 2060 | seq_number += 0x10; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2061 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2062 | /* aggregation is on for this <sta,tid> */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2063 | if (ctl->flags & IEEE80211_TXCTL_AMPDU) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2064 | txq_id = priv->stations[sta_id].tid[tid].agg.txq_id; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2065 | priv->stations[sta_id].tid[tid].tfds_in_queue++; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2066 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2067 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2068 | |
| 2069 | /* Descriptor for chosen Tx queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2070 | txq = &priv->txq[txq_id]; |
| 2071 | q = &txq->q; |
| 2072 | |
| 2073 | spin_lock_irqsave(&priv->lock, flags); |
| 2074 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2075 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2076 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2077 | memset(tfd, 0, sizeof(*tfd)); |
| 2078 | control_flags = (u32 *) tfd; |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2079 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2080 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2081 | /* Set up driver data for this TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2082 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2083 | txq->txb[q->write_ptr].skb[0] = skb; |
| 2084 | memcpy(&(txq->txb[q->write_ptr].status.control), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2085 | ctl, sizeof(struct ieee80211_tx_control)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2086 | |
| 2087 | /* 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] | 2088 | out_cmd = &txq->cmd[idx]; |
| 2089 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 2090 | memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2091 | |
| 2092 | /* |
| 2093 | * Set up the Tx-command (not MAC!) header. |
| 2094 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 2095 | * after Tx, uCode's Tx response will return this value so driver can |
| 2096 | * locate the frame within the tx queue and do post-tx processing. |
| 2097 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2098 | out_cmd->hdr.cmd = REPLY_TX; |
| 2099 | 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] | 2100 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2101 | |
| 2102 | /* Copy MAC header from skb into command buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2103 | memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); |
| 2104 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2105 | /* |
| 2106 | * Use the first empty entry in this queue's command buffer array |
| 2107 | * to contain the Tx command and MAC header concatenated together |
| 2108 | * (payload data will be in another buffer). |
| 2109 | * Size of this varies, due to varying MAC header length. |
| 2110 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 2111 | * of the MAC header (device reads on dword boundaries). |
| 2112 | * We'll tell device about this padding later. |
| 2113 | */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 2114 | len = priv->hw_params.tx_cmd_len + |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2115 | sizeof(struct iwl_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2116 | |
| 2117 | len_org = len; |
| 2118 | len = (len + 3) & ~3; |
| 2119 | |
| 2120 | if (len_org != len) |
| 2121 | len_org = 1; |
| 2122 | else |
| 2123 | len_org = 0; |
| 2124 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2125 | /* Physical address of this Tx command's header (not MAC header!), |
| 2126 | * within command buffer array. */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2127 | txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx + |
| 2128 | offsetof(struct iwl_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2129 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2130 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 2131 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2132 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2133 | |
| 2134 | if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 2135 | iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2136 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2137 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 2138 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2139 | len = skb->len - hdr_len; |
| 2140 | if (len) { |
| 2141 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 2142 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2143 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2144 | } |
| 2145 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2146 | /* Tell 4965 about any 2-byte padding after MAC header */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2147 | if (len_org) |
| 2148 | out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK; |
| 2149 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2150 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2151 | len = (u16)skb->len; |
| 2152 | out_cmd->cmd.tx.len = cpu_to_le16(len); |
| 2153 | |
| 2154 | /* TODO need this for burst mode later on */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2155 | 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] | 2156 | |
| 2157 | /* set is_hcca to 0; it probably will never be implemented */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2158 | 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] | 2159 | |
Tomas Winkler | 19758be | 2008-03-12 16:58:51 -0700 | [diff] [blame] | 2160 | iwl_update_tx_stats(priv, fc, len); |
| 2161 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2162 | scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) + |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2163 | offsetof(struct iwl4965_tx_cmd, scratch); |
| 2164 | out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys); |
| 2165 | out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys); |
| 2166 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2167 | if (!ieee80211_get_morefrag(hdr)) { |
| 2168 | txq->need_update = 1; |
| 2169 | if (qc) { |
| 2170 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2171 | priv->stations[sta_id].tid[tid].seq_number = seq_number; |
| 2172 | } |
| 2173 | } else { |
| 2174 | wait_write_ptr = 1; |
| 2175 | txq->need_update = 0; |
| 2176 | } |
| 2177 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2178 | iwl_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2179 | sizeof(out_cmd->cmd.tx)); |
| 2180 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2181 | 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] | 2182 | ieee80211_get_hdrlen(fc)); |
| 2183 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2184 | /* Set up entry for this TFD in Tx byte-count array */ |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 2185 | priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2186 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2187 | /* Tell device the write index *just past* this latest filled TFD */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2188 | 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] | 2189 | rc = iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2190 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2191 | |
| 2192 | if (rc) |
| 2193 | return rc; |
| 2194 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2195 | if ((iwl4965_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2196 | && priv->mac80211_registered) { |
| 2197 | if (wait_write_ptr) { |
| 2198 | spin_lock_irqsave(&priv->lock, flags); |
| 2199 | txq->need_update = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2200 | iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2201 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2202 | } |
| 2203 | |
| 2204 | ieee80211_stop_queue(priv->hw, ctl->queue); |
| 2205 | } |
| 2206 | |
| 2207 | return 0; |
| 2208 | |
| 2209 | drop_unlock: |
| 2210 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2211 | drop: |
| 2212 | return -1; |
| 2213 | } |
| 2214 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2215 | static void iwl4965_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2216 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2217 | const struct ieee80211_supported_band *hw = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2218 | struct ieee80211_rate *rate; |
| 2219 | int i; |
| 2220 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 2221 | hw = iwl_get_hw_mode(priv, priv->band); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 2222 | if (!hw) { |
| 2223 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 2224 | return; |
| 2225 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2226 | |
| 2227 | priv->active_rate = 0; |
| 2228 | priv->active_rate_basic = 0; |
| 2229 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2230 | for (i = 0; i < hw->n_bitrates; i++) { |
| 2231 | rate = &(hw->bitrates[i]); |
| 2232 | if (rate->hw_value < IWL_RATE_COUNT) |
| 2233 | priv->active_rate |= (1 << rate->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 2237 | priv->active_rate, priv->active_rate_basic); |
| 2238 | |
| 2239 | /* |
| 2240 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 2241 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 2242 | * OFDM |
| 2243 | */ |
| 2244 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 2245 | priv->staging_rxon.cck_basic_rates = |
| 2246 | ((priv->active_rate_basic & |
| 2247 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2248 | else |
| 2249 | priv->staging_rxon.cck_basic_rates = |
| 2250 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2251 | |
| 2252 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 2253 | priv->staging_rxon.ofdm_basic_rates = |
| 2254 | ((priv->active_rate_basic & |
| 2255 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 2256 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2257 | else |
| 2258 | priv->staging_rxon.ofdm_basic_rates = |
| 2259 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2260 | } |
| 2261 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2262 | void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2263 | { |
| 2264 | unsigned long flags; |
| 2265 | |
| 2266 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 2267 | return; |
| 2268 | |
| 2269 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 2270 | disable_radio ? "OFF" : "ON"); |
| 2271 | |
| 2272 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2273 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2274 | /* FIXME: This is a workaround for AP */ |
| 2275 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 2276 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2277 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2278 | CSR_UCODE_SW_BIT_RFKILL); |
| 2279 | spin_unlock_irqrestore(&priv->lock, flags); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2280 | /* call the host command only if no hw rf-kill set */ |
Mohamed Abbas | 5900383 | 2008-04-15 16:01:46 -0700 | [diff] [blame] | 2281 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status) && |
| 2282 | iwl_is_ready(priv)) |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2283 | iwl4965_send_card_state(priv, |
| 2284 | CARD_STATE_CMD_DISABLE, |
| 2285 | 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2286 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2287 | |
| 2288 | /* make sure mac80211 stop sending Tx frame */ |
| 2289 | if (priv->mac80211_registered) |
| 2290 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2291 | } |
| 2292 | return; |
| 2293 | } |
| 2294 | |
| 2295 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2296 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2297 | |
| 2298 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2299 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2300 | |
| 2301 | /* wake up ucode */ |
| 2302 | msleep(10); |
| 2303 | |
| 2304 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2305 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 2306 | if (!iwl_grab_nic_access(priv)) |
| 2307 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2308 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2309 | |
| 2310 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 2311 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 2312 | "disabled by HW switch\n"); |
| 2313 | return; |
| 2314 | } |
| 2315 | |
| 2316 | queue_work(priv->workqueue, &priv->restart); |
| 2317 | return; |
| 2318 | } |
| 2319 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2320 | #define IWL_PACKET_RETRY_TIME HZ |
| 2321 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2322 | 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] | 2323 | { |
| 2324 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 2325 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 2326 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 2327 | u16 *last_seq, *last_frag; |
| 2328 | unsigned long *last_time; |
| 2329 | |
| 2330 | switch (priv->iw_mode) { |
| 2331 | case IEEE80211_IF_TYPE_IBSS:{ |
| 2332 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2333 | struct iwl4965_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2334 | u8 *mac = header->addr2; |
| 2335 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 2336 | |
| 2337 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2338 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2339 | if (!compare_ether_addr(entry->mac, mac)) |
| 2340 | break; |
| 2341 | } |
| 2342 | if (p == &priv->ibss_mac_hash[index]) { |
| 2343 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 2344 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2345 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2346 | return 0; |
| 2347 | } |
| 2348 | memcpy(entry->mac, mac, ETH_ALEN); |
| 2349 | entry->seq_num = seq; |
| 2350 | entry->frag_num = frag; |
| 2351 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2352 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2353 | return 0; |
| 2354 | } |
| 2355 | last_seq = &entry->seq_num; |
| 2356 | last_frag = &entry->frag_num; |
| 2357 | last_time = &entry->packet_time; |
| 2358 | break; |
| 2359 | } |
| 2360 | case IEEE80211_IF_TYPE_STA: |
| 2361 | last_seq = &priv->last_seq_num; |
| 2362 | last_frag = &priv->last_frag_num; |
| 2363 | last_time = &priv->last_packet_time; |
| 2364 | break; |
| 2365 | default: |
| 2366 | return 0; |
| 2367 | } |
| 2368 | if ((*last_seq == seq) && |
| 2369 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 2370 | if (*last_frag == frag) |
| 2371 | goto drop; |
| 2372 | if (*last_frag + 1 != frag) |
| 2373 | /* out-of-order fragment */ |
| 2374 | goto drop; |
| 2375 | } else |
| 2376 | *last_seq = seq; |
| 2377 | |
| 2378 | *last_frag = frag; |
| 2379 | *last_time = jiffies; |
| 2380 | return 0; |
| 2381 | |
| 2382 | drop: |
| 2383 | return 1; |
| 2384 | } |
| 2385 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2386 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2387 | |
| 2388 | #include "iwl-spectrum.h" |
| 2389 | |
| 2390 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 2391 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 2392 | #define TIME_UNIT 1024 |
| 2393 | |
| 2394 | /* |
| 2395 | * extended beacon time format |
| 2396 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 2397 | * the high 1 byte is the beacon counts |
| 2398 | * the lower 3 bytes is the time in usec within one beacon interval |
| 2399 | */ |
| 2400 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2401 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2402 | { |
| 2403 | u32 quot; |
| 2404 | u32 rem; |
| 2405 | u32 interval = beacon_interval * 1024; |
| 2406 | |
| 2407 | if (!interval || !usec) |
| 2408 | return 0; |
| 2409 | |
| 2410 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 2411 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 2412 | |
| 2413 | return (quot << 24) + rem; |
| 2414 | } |
| 2415 | |
| 2416 | /* base is usually what we get from ucode with each received frame, |
| 2417 | * the same as HW timer counter counting down |
| 2418 | */ |
| 2419 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2420 | 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] | 2421 | { |
| 2422 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 2423 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 2424 | u32 interval = beacon_interval * TIME_UNIT; |
| 2425 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 2426 | (addon & BEACON_TIME_MASK_HIGH); |
| 2427 | |
| 2428 | if (base_low > addon_low) |
| 2429 | res += base_low - addon_low; |
| 2430 | else if (base_low < addon_low) { |
| 2431 | res += interval + base_low - addon_low; |
| 2432 | res += (1 << 24); |
| 2433 | } else |
| 2434 | res += (1 << 24); |
| 2435 | |
| 2436 | return cpu_to_le32(res); |
| 2437 | } |
| 2438 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2439 | static int iwl4965_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2440 | struct ieee80211_measurement_params *params, |
| 2441 | u8 type) |
| 2442 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2443 | struct iwl4965_spectrum_cmd spectrum; |
| 2444 | struct iwl4965_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2445 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2446 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 2447 | .data = (void *)&spectrum, |
| 2448 | .meta.flags = CMD_WANT_SKB, |
| 2449 | }; |
| 2450 | u32 add_time = le64_to_cpu(params->start_time); |
| 2451 | int rc; |
| 2452 | int spectrum_resp_status; |
| 2453 | int duration = le16_to_cpu(params->duration); |
| 2454 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2455 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2456 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2457 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2458 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 2459 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2460 | |
| 2461 | memset(&spectrum, 0, sizeof(spectrum)); |
| 2462 | |
| 2463 | spectrum.channel_count = cpu_to_le16(1); |
| 2464 | spectrum.flags = |
| 2465 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 2466 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 2467 | cmd.len = sizeof(spectrum); |
| 2468 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 2469 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2470 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2471 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2472 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2473 | add_time, |
| 2474 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2475 | else |
| 2476 | spectrum.start_time = 0; |
| 2477 | |
| 2478 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 2479 | spectrum.channels[0].channel = params->channel; |
| 2480 | spectrum.channels[0].type = type; |
| 2481 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 2482 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 2483 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 2484 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2485 | rc = iwl_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2486 | if (rc) |
| 2487 | return rc; |
| 2488 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2489 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2490 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 2491 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 2492 | rc = -EIO; |
| 2493 | } |
| 2494 | |
| 2495 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 2496 | switch (spectrum_resp_status) { |
| 2497 | case 0: /* Command will be handled */ |
| 2498 | if (res->u.spectrum.id != 0xff) { |
| 2499 | IWL_DEBUG_INFO |
| 2500 | ("Replaced existing measurement: %d\n", |
| 2501 | res->u.spectrum.id); |
| 2502 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 2503 | } |
| 2504 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 2505 | rc = 0; |
| 2506 | break; |
| 2507 | |
| 2508 | case 1: /* Command will not be handled */ |
| 2509 | rc = -EAGAIN; |
| 2510 | break; |
| 2511 | } |
| 2512 | |
| 2513 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 2514 | |
| 2515 | return rc; |
| 2516 | } |
| 2517 | #endif |
| 2518 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2519 | static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2520 | struct iwl4965_tx_info *tx_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2521 | { |
| 2522 | |
| 2523 | tx_sta->status.ack_signal = 0; |
| 2524 | tx_sta->status.excessive_retries = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2525 | |
| 2526 | if (in_interrupt()) |
| 2527 | ieee80211_tx_status_irqsafe(priv->hw, |
| 2528 | tx_sta->skb[0], &(tx_sta->status)); |
| 2529 | else |
| 2530 | ieee80211_tx_status(priv->hw, |
| 2531 | tx_sta->skb[0], &(tx_sta->status)); |
| 2532 | |
| 2533 | tx_sta->skb[0] = NULL; |
| 2534 | } |
| 2535 | |
| 2536 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2537 | * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2538 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2539 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 2540 | * need to be reclaimed. As result, some free space forms. If there is |
| 2541 | * enough free space (> low mark), wake the stack that feeds us. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2542 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2543 | 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] | 2544 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2545 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
| 2546 | struct iwl4965_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2547 | int nfreed = 0; |
| 2548 | |
| 2549 | if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) { |
| 2550 | IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " |
| 2551 | "is out of range [0-%d] %d %d.\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2552 | index, q->n_bd, q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2553 | return 0; |
| 2554 | } |
| 2555 | |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2556 | for (index = iwl_queue_inc_wrap(index, q->n_bd); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2557 | q->read_ptr != index; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2558 | 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] | 2559 | if (txq_id != IWL_CMD_QUEUE_NUM) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2560 | iwl4965_txstatus_to_ieee(priv, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2561 | &(txq->txb[txq->q.read_ptr])); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2562 | iwl4965_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2563 | } else if (nfreed > 1) { |
| 2564 | IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2565 | q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2566 | queue_work(priv->workqueue, &priv->restart); |
| 2567 | } |
| 2568 | nfreed++; |
| 2569 | } |
| 2570 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2571 | return nfreed; |
| 2572 | } |
| 2573 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2574 | static int iwl4965_is_tx_success(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2575 | { |
| 2576 | status &= TX_STATUS_MSK; |
| 2577 | return (status == TX_STATUS_SUCCESS) |
| 2578 | || (status == TX_STATUS_DIRECT_DONE); |
| 2579 | } |
| 2580 | |
| 2581 | /****************************************************************************** |
| 2582 | * |
| 2583 | * Generic RX handler implementations |
| 2584 | * |
| 2585 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2586 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2587 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2588 | static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2589 | struct ieee80211_hdr *hdr) |
| 2590 | { |
| 2591 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) |
| 2592 | return IWL_AP_ID; |
| 2593 | else { |
| 2594 | u8 *da = ieee80211_get_DA(hdr); |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 2595 | return iwl_find_station(priv, da); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2596 | } |
| 2597 | } |
| 2598 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2599 | static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr( |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2600 | struct iwl_priv *priv, int txq_id, int idx) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2601 | { |
| 2602 | if (priv->txq[txq_id].txb[idx].skb[0]) |
| 2603 | return (struct ieee80211_hdr *)priv->txq[txq_id]. |
| 2604 | txb[idx].skb[0]->data; |
| 2605 | return NULL; |
| 2606 | } |
| 2607 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2608 | 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] | 2609 | { |
| 2610 | __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + |
| 2611 | tx_resp->frame_count); |
| 2612 | return le32_to_cpu(*scd_ssn) & MAX_SN; |
| 2613 | |
| 2614 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2615 | |
| 2616 | /** |
| 2617 | * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue |
| 2618 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2619 | static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv, |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame^] | 2620 | struct iwl_ht_agg *agg, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2621 | struct iwl4965_tx_resp_agg *tx_resp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2622 | u16 start_idx) |
| 2623 | { |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2624 | u16 status; |
| 2625 | struct agg_tx_status *frame_status = &tx_resp->status; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2626 | struct ieee80211_tx_status *tx_status = NULL; |
| 2627 | struct ieee80211_hdr *hdr = NULL; |
| 2628 | int i, sh; |
| 2629 | int txq_id, idx; |
| 2630 | u16 seq; |
| 2631 | |
| 2632 | if (agg->wait_for_ba) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2633 | IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2634 | |
| 2635 | agg->frame_count = tx_resp->frame_count; |
| 2636 | agg->start_idx = start_idx; |
| 2637 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2638 | agg->bitmap = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2639 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2640 | /* # frames attempted by Tx command */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2641 | if (agg->frame_count == 1) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2642 | /* Only one frame was attempted; no block-ack will arrive */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2643 | status = le16_to_cpu(frame_status[0].status); |
| 2644 | seq = le16_to_cpu(frame_status[0].sequence); |
| 2645 | idx = SEQ_TO_INDEX(seq); |
| 2646 | txq_id = SEQ_TO_QUEUE(seq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2647 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2648 | /* FIXME: code repetition */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2649 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n", |
| 2650 | agg->frame_count, agg->start_idx, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2651 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2652 | tx_status = &(priv->txq[txq_id].txb[idx].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2653 | tx_status->retry_count = tx_resp->failure_frame; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2654 | tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2655 | tx_status->flags = iwl4965_is_tx_success(status)? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2656 | IEEE80211_TX_STATUS_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 2657 | iwl4965_hwrate_to_tx_control(priv, |
| 2658 | le32_to_cpu(tx_resp->rate_n_flags), |
| 2659 | &tx_status->control); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2660 | /* FIXME: code repetition end */ |
| 2661 | |
| 2662 | IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", |
| 2663 | status & 0xff, tx_resp->failure_frame); |
| 2664 | IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2665 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2666 | |
| 2667 | agg->wait_for_ba = 0; |
| 2668 | } else { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2669 | /* Two or more frames were attempted; expect block-ack */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2670 | u64 bitmap = 0; |
| 2671 | int start = agg->start_idx; |
| 2672 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2673 | /* Construct bit-map of pending frames within Tx window */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2674 | for (i = 0; i < agg->frame_count; i++) { |
| 2675 | u16 sc; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2676 | status = le16_to_cpu(frame_status[i].status); |
| 2677 | seq = le16_to_cpu(frame_status[i].sequence); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2678 | idx = SEQ_TO_INDEX(seq); |
| 2679 | txq_id = SEQ_TO_QUEUE(seq); |
| 2680 | |
| 2681 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 2682 | AGG_TX_STATE_ABORT_MSK)) |
| 2683 | continue; |
| 2684 | |
| 2685 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
| 2686 | agg->frame_count, txq_id, idx); |
| 2687 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2688 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2689 | |
| 2690 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 2691 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
| 2692 | IWL_ERROR("BUG_ON idx doesn't match seq control" |
| 2693 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 2694 | idx, SEQ_TO_SN(sc), |
| 2695 | hdr->seq_ctrl); |
| 2696 | return -1; |
| 2697 | } |
| 2698 | |
| 2699 | IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
| 2700 | i, idx, SEQ_TO_SN(sc)); |
| 2701 | |
| 2702 | sh = idx - start; |
| 2703 | if (sh > 64) { |
| 2704 | sh = (start - idx) + 0xff; |
| 2705 | bitmap = bitmap << sh; |
| 2706 | sh = 0; |
| 2707 | start = idx; |
| 2708 | } else if (sh < -64) |
| 2709 | sh = 0xff - (start - idx); |
| 2710 | else if (sh < 0) { |
| 2711 | sh = start - idx; |
| 2712 | start = idx; |
| 2713 | bitmap = bitmap << sh; |
| 2714 | sh = 0; |
| 2715 | } |
| 2716 | bitmap |= (1 << sh); |
| 2717 | IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n", |
| 2718 | start, (u32)(bitmap & 0xFFFFFFFF)); |
| 2719 | } |
| 2720 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2721 | agg->bitmap = bitmap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2722 | agg->start_idx = start; |
| 2723 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2724 | 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] | 2725 | agg->frame_count, agg->start_idx, |
John W. Linville | 06501d2 | 2008-04-01 17:38:47 -0400 | [diff] [blame] | 2726 | (unsigned long long)agg->bitmap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2727 | |
| 2728 | if (bitmap) |
| 2729 | agg->wait_for_ba = 1; |
| 2730 | } |
| 2731 | return 0; |
| 2732 | } |
| 2733 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2734 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2735 | /** |
| 2736 | * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response |
| 2737 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2738 | static void iwl4965_rx_reply_tx(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2739 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2740 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2741 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2742 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 2743 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 2744 | int index = SEQ_TO_INDEX(sequence); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2745 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2746 | struct ieee80211_tx_status *tx_status; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2747 | struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2748 | u32 status = le32_to_cpu(tx_resp->status); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2749 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2750 | int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION; |
| 2751 | struct ieee80211_hdr *hdr; |
| 2752 | __le16 *qc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2753 | #endif |
| 2754 | |
| 2755 | if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) { |
| 2756 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 2757 | "is out of range [0-%d] %d %d\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2758 | index, txq->q.n_bd, txq->q.write_ptr, |
| 2759 | txq->q.read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2760 | return; |
| 2761 | } |
| 2762 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2763 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2764 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index); |
| 2765 | qc = ieee80211_get_qos_ctrl(hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2766 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2767 | if (qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2768 | tid = le16_to_cpu(*qc) & 0xf; |
| 2769 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2770 | sta_id = iwl4965_get_ra_sta_id(priv, hdr); |
| 2771 | if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) { |
| 2772 | IWL_ERROR("Station not known\n"); |
| 2773 | return; |
| 2774 | } |
| 2775 | |
| 2776 | if (txq->sched_retry) { |
| 2777 | const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp); |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame^] | 2778 | struct iwl_ht_agg *agg = NULL; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2779 | |
| 2780 | if (!qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2781 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2782 | |
| 2783 | agg = &priv->stations[sta_id].tid[tid].agg; |
| 2784 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2785 | iwl4965_tx_status_reply_tx(priv, agg, |
| 2786 | (struct iwl4965_tx_resp_agg *)tx_resp, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2787 | |
| 2788 | if ((tx_resp->frame_count == 1) && |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2789 | !iwl4965_is_tx_success(status)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2790 | /* TODO: send BAR */ |
| 2791 | } |
| 2792 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2793 | if (txq->q.read_ptr != (scd_ssn & 0xff)) { |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 2794 | int freed, ampdu_q; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2795 | index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2796 | IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " |
| 2797 | "%d index %d\n", scd_ssn , index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2798 | freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
| 2799 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 2800 | |
| 2801 | if (iwl4965_queue_space(&txq->q) > txq->q.low_mark && |
| 2802 | txq_id >= 0 && priv->mac80211_registered && |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 2803 | agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) { |
| 2804 | /* calculate mac80211 ampdu sw queue to wake */ |
| 2805 | ampdu_q = txq_id - IWL_BACK_QUEUE_FIRST_ID + |
| 2806 | priv->hw->queues; |
| 2807 | if (agg->state == IWL_AGG_OFF) |
| 2808 | ieee80211_wake_queue(priv->hw, txq_id); |
| 2809 | else |
| 2810 | ieee80211_wake_queue(priv->hw, ampdu_q); |
| 2811 | } |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2812 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2813 | } |
| 2814 | } else { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2815 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2816 | tx_status = &(txq->txb[txq->q.read_ptr].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2817 | |
| 2818 | tx_status->retry_count = tx_resp->failure_frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2819 | tx_status->flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2820 | iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 2821 | iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags), |
| 2822 | &tx_status->control); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2823 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2824 | 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] | 2825 | "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2826 | status, le32_to_cpu(tx_resp->rate_n_flags), |
| 2827 | tx_resp->failure_frame); |
| 2828 | |
| 2829 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2830 | if (index != -1) { |
| 2831 | int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2832 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2833 | if (tid != MAX_TID_COUNT) |
| 2834 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 2835 | if (iwl4965_queue_space(&txq->q) > txq->q.low_mark && |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 2836 | (txq_id >= 0) && priv->mac80211_registered) |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2837 | ieee80211_wake_queue(priv->hw, txq_id); |
| 2838 | if (tid != MAX_TID_COUNT) |
| 2839 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
| 2840 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2841 | } |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2842 | #ifdef CONFIG_IWL4965_HT |
| 2843 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2844 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2845 | |
| 2846 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 2847 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 2848 | } |
| 2849 | |
| 2850 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2851 | static void iwl4965_rx_reply_alive(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2852 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2853 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2854 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 2855 | struct iwl4965_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2856 | struct delayed_work *pwork; |
| 2857 | |
| 2858 | palive = &pkt->u.alive_frame; |
| 2859 | |
| 2860 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 2861 | "0x%01X 0x%01X\n", |
| 2862 | palive->is_valid, palive->ver_type, |
| 2863 | palive->ver_subtype); |
| 2864 | |
| 2865 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 2866 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 2867 | memcpy(&priv->card_alive_init, |
| 2868 | &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2869 | sizeof(struct iwl4965_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2870 | pwork = &priv->init_alive_start; |
| 2871 | } else { |
| 2872 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 2873 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2874 | sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2875 | pwork = &priv->alive_start; |
| 2876 | } |
| 2877 | |
| 2878 | /* We delay the ALIVE response by 5ms to |
| 2879 | * give the HW RF Kill time to activate... */ |
| 2880 | if (palive->is_valid == UCODE_VALID_OK) |
| 2881 | queue_delayed_work(priv->workqueue, pwork, |
| 2882 | msecs_to_jiffies(5)); |
| 2883 | else |
| 2884 | IWL_WARNING("uCode did not respond OK.\n"); |
| 2885 | } |
| 2886 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2887 | static void iwl4965_rx_reply_add_sta(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2888 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2889 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2890 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2891 | |
| 2892 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 2893 | return; |
| 2894 | } |
| 2895 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2896 | static void iwl4965_rx_reply_error(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2897 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2898 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2899 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2900 | |
| 2901 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 2902 | "seq 0x%04X ser 0x%08X\n", |
| 2903 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 2904 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 2905 | pkt->u.err_resp.cmd_id, |
| 2906 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 2907 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 2908 | } |
| 2909 | |
| 2910 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2911 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2912 | static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2913 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2914 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 2915 | struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon; |
| 2916 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2917 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 2918 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 2919 | rxon->channel = csa->channel; |
| 2920 | priv->staging_rxon.channel = csa->channel; |
| 2921 | } |
| 2922 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2923 | static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2924 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2925 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2926 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2927 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 2928 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2929 | |
| 2930 | if (!report->state) { |
| 2931 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 2932 | "Spectrum Measure Notification: Start\n"); |
| 2933 | return; |
| 2934 | } |
| 2935 | |
| 2936 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 2937 | priv->measurement_status |= MEASUREMENT_READY; |
| 2938 | #endif |
| 2939 | } |
| 2940 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2941 | static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2942 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2943 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2944 | #ifdef CONFIG_IWLWIFI_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2945 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 2946 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2947 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 2948 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 2949 | #endif |
| 2950 | } |
| 2951 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2952 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2953 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2954 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2955 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2956 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 2957 | "notification for %s:\n", |
| 2958 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2959 | 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] | 2960 | } |
| 2961 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2962 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2963 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2964 | struct iwl_priv *priv = |
| 2965 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2966 | struct sk_buff *beacon; |
| 2967 | |
| 2968 | /* 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] | 2969 | beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2970 | |
| 2971 | if (!beacon) { |
| 2972 | IWL_ERROR("update beacon failed\n"); |
| 2973 | return; |
| 2974 | } |
| 2975 | |
| 2976 | mutex_lock(&priv->mutex); |
| 2977 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 2978 | if (priv->ibss_beacon) |
| 2979 | dev_kfree_skb(priv->ibss_beacon); |
| 2980 | |
| 2981 | priv->ibss_beacon = beacon; |
| 2982 | mutex_unlock(&priv->mutex); |
| 2983 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2984 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2987 | static void iwl4965_rx_beacon_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2988 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2989 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2990 | #ifdef CONFIG_IWLWIFI_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2991 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 2992 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 2993 | 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] | 2994 | |
| 2995 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 2996 | "tsf %d %d rate %d\n", |
| 2997 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 2998 | beacon->beacon_notify_hdr.failure_frame, |
| 2999 | le32_to_cpu(beacon->ibss_mgr_status), |
| 3000 | le32_to_cpu(beacon->high_tsf), |
| 3001 | le32_to_cpu(beacon->low_tsf), rate); |
| 3002 | #endif |
| 3003 | |
| 3004 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 3005 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 3006 | queue_work(priv->workqueue, &priv->beacon_update); |
| 3007 | } |
| 3008 | |
| 3009 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3010 | static void iwl4965_rx_reply_scan(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3011 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3012 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3013 | #ifdef CONFIG_IWLWIFI_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3014 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3015 | struct iwl4965_scanreq_notification *notif = |
| 3016 | (struct iwl4965_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3017 | |
| 3018 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 3019 | #endif |
| 3020 | } |
| 3021 | |
| 3022 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3023 | static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3024 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3025 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3026 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3027 | struct iwl4965_scanstart_notification *notif = |
| 3028 | (struct iwl4965_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3029 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 3030 | IWL_DEBUG_SCAN("Scan start: " |
| 3031 | "%d [802.11%s] " |
| 3032 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 3033 | notif->channel, |
| 3034 | notif->band ? "bg" : "a", |
| 3035 | notif->tsf_high, |
| 3036 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 3037 | } |
| 3038 | |
| 3039 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3040 | static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3041 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3042 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3043 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3044 | struct iwl4965_scanresults_notification *notif = |
| 3045 | (struct iwl4965_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3046 | |
| 3047 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 3048 | "%d [802.11%s] " |
| 3049 | "(TSF: 0x%08X:%08X) - %d " |
| 3050 | "elapsed=%lu usec (%dms since last)\n", |
| 3051 | notif->channel, |
| 3052 | notif->band ? "bg" : "a", |
| 3053 | le32_to_cpu(notif->tsf_high), |
| 3054 | le32_to_cpu(notif->tsf_low), |
| 3055 | le32_to_cpu(notif->statistics[0]), |
| 3056 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 3057 | jiffies_to_msecs(elapsed_jiffies |
| 3058 | (priv->last_scan_jiffies, jiffies))); |
| 3059 | |
| 3060 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3061 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3065 | static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3066 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3067 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3068 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3069 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3070 | |
| 3071 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 3072 | scan_notif->scanned_channels, |
| 3073 | scan_notif->tsf_low, |
| 3074 | scan_notif->tsf_high, scan_notif->status); |
| 3075 | |
| 3076 | /* The HW is no longer scanning */ |
| 3077 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 3078 | |
| 3079 | /* The scan completion notification came in, so kill that timer... */ |
| 3080 | cancel_delayed_work(&priv->scan_check); |
| 3081 | |
| 3082 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 3083 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 3084 | jiffies_to_msecs(elapsed_jiffies |
| 3085 | (priv->scan_pass_start, jiffies))); |
| 3086 | |
| 3087 | /* Remove this scanned band from the list |
| 3088 | * of pending bands to scan */ |
| 3089 | priv->scan_bands--; |
| 3090 | |
| 3091 | /* If a request to abort was given, or the scan did not succeed |
| 3092 | * then we reset the scan state machine and terminate, |
| 3093 | * re-queuing another scan if one has been requested */ |
| 3094 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 3095 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 3096 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 3097 | } else { |
| 3098 | /* If there are more bands on this scan pass reschedule */ |
| 3099 | if (priv->scan_bands > 0) |
| 3100 | goto reschedule; |
| 3101 | } |
| 3102 | |
| 3103 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3104 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3105 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 3106 | |
| 3107 | clear_bit(STATUS_SCANNING, &priv->status); |
| 3108 | |
| 3109 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 3110 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 3111 | |
| 3112 | queue_work(priv->workqueue, &priv->scan_completed); |
| 3113 | |
| 3114 | return; |
| 3115 | |
| 3116 | reschedule: |
| 3117 | priv->scan_pass_start = jiffies; |
| 3118 | queue_work(priv->workqueue, &priv->request_scan); |
| 3119 | } |
| 3120 | |
| 3121 | /* Handle notification from uCode that card's power state is changing |
| 3122 | * due to software, hardware, or critical temperature RFKILL */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3123 | static void iwl4965_rx_card_state_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3124 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3125 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3126 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3127 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 3128 | unsigned long status = priv->status; |
| 3129 | |
| 3130 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 3131 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 3132 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 3133 | |
| 3134 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 3135 | RF_CARD_DISABLED)) { |
| 3136 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3137 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3138 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 3139 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3140 | if (!iwl_grab_nic_access(priv)) { |
| 3141 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3142 | priv, HBUS_TARG_MBX_C, |
| 3143 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 3144 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3145 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | if (!(flags & RXON_CARD_DISABLED)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3149 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3150 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3151 | if (!iwl_grab_nic_access(priv)) { |
| 3152 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3153 | priv, HBUS_TARG_MBX_C, |
| 3154 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 3155 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3156 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3157 | } |
| 3158 | } |
| 3159 | |
| 3160 | if (flags & RF_CARD_DISABLED) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3161 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3162 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3163 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 3164 | if (!iwl_grab_nic_access(priv)) |
| 3165 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3166 | } |
| 3167 | } |
| 3168 | |
| 3169 | if (flags & HW_CARD_DISABLED) |
| 3170 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3171 | else |
| 3172 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3173 | |
| 3174 | |
| 3175 | if (flags & SW_CARD_DISABLED) |
| 3176 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3177 | else |
| 3178 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3179 | |
| 3180 | if (!(flags & RXON_CARD_DISABLED)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3181 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3182 | |
| 3183 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 3184 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 3185 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 3186 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 3187 | queue_work(priv->workqueue, &priv->rf_kill); |
| 3188 | else |
| 3189 | wake_up_interruptible(&priv->wait_command_queue); |
| 3190 | } |
| 3191 | |
| 3192 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3193 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3194 | * |
| 3195 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 3196 | * to the host. |
| 3197 | * |
| 3198 | * This function chains into the hardware specific files for them to setup |
| 3199 | * any hardware specific handlers as well. |
| 3200 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3201 | static void iwl4965_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3202 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3203 | priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive; |
| 3204 | priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta; |
| 3205 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 3206 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3207 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3208 | iwl4965_rx_spectrum_measure_notif; |
| 3209 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3210 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3211 | iwl4965_rx_pm_debug_statistics_notif; |
| 3212 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3213 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3214 | /* |
| 3215 | * The same handler is used for both the REPLY to a discrete |
| 3216 | * statistics request from the host as well as for the periodic |
| 3217 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3218 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3219 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
| 3220 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3221 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3222 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
| 3223 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3224 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3225 | iwl4965_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3226 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3227 | iwl4965_rx_scan_complete_notif; |
| 3228 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
| 3229 | priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3230 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3231 | /* Set up hardware specific Rx handlers */ |
Emmanuel Grumbach | d4789ef | 2008-04-24 11:55:20 -0700 | [diff] [blame] | 3232 | priv->cfg->ops->lib->rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3233 | } |
| 3234 | |
| 3235 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3236 | * 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] | 3237 | * @rxb: Rx buffer to reclaim |
| 3238 | * |
| 3239 | * If an Rx buffer has an async callback associated with it the callback |
| 3240 | * will be executed. The attached skb (if present) will only be freed |
| 3241 | * if the callback returns 1 |
| 3242 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3243 | static void iwl4965_tx_cmd_complete(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3244 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3245 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3246 | struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3247 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3248 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3249 | int index = SEQ_TO_INDEX(sequence); |
| 3250 | int huge = sequence & SEQ_HUGE_FRAME; |
| 3251 | int cmd_index; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3252 | struct iwl_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3253 | |
| 3254 | /* If a Tx command is being handled and it isn't in the actual |
| 3255 | * command queue then there a command routing bug has been introduced |
| 3256 | * in the queue management code. */ |
| 3257 | if (txq_id != IWL_CMD_QUEUE_NUM) |
| 3258 | IWL_ERROR("Error wrong command queue %d command id 0x%X\n", |
| 3259 | txq_id, pkt->hdr.cmd); |
| 3260 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 3261 | |
| 3262 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 3263 | cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
| 3264 | |
| 3265 | /* Input error checking is done when commands are added to queue. */ |
| 3266 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 3267 | cmd->meta.source->u.skb = rxb->skb; |
| 3268 | rxb->skb = NULL; |
| 3269 | } else if (cmd->meta.u.callback && |
| 3270 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 3271 | rxb->skb = NULL; |
| 3272 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3273 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3274 | |
| 3275 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 3276 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3277 | wake_up_interruptible(&priv->wait_command_queue); |
| 3278 | } |
| 3279 | } |
| 3280 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3281 | /* |
| 3282 | * this should be called while priv->lock is locked |
| 3283 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3284 | static void __iwl_rx_replenish(struct iwl_priv *priv) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3285 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3286 | iwl_rx_allocate(priv); |
| 3287 | iwl_rx_queue_restock(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3288 | } |
| 3289 | |
| 3290 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3291 | /** |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3292 | * iwl_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3293 | * |
| 3294 | * Uses the priv->rx_handlers callback function array to invoke |
| 3295 | * the appropriate handlers, including command responses, |
| 3296 | * frame-received notifications, and other notifications. |
| 3297 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3298 | void iwl_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3299 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3300 | struct iwl_rx_mem_buffer *rxb; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3301 | struct iwl4965_rx_packet *pkt; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3302 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3303 | u32 r, i; |
| 3304 | int reclaim; |
| 3305 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3306 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 3307 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3308 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3309 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 3310 | * buffer that the driver may process (last buffer filled by ucode). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3311 | r = iwl4965_hw_get_rx_read(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3312 | i = rxq->read; |
| 3313 | |
| 3314 | /* Rx interrupt, but nothing sent from uCode */ |
| 3315 | if (i == r) |
| 3316 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 3317 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3318 | if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3319 | fill_rx = 1; |
| 3320 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3321 | while (i != r) { |
| 3322 | rxb = rxq->queue[i]; |
| 3323 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3324 | /* 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] | 3325 | * then a bug has been introduced in the queue refilling |
| 3326 | * routines -- catch it here */ |
| 3327 | BUG_ON(rxb == NULL); |
| 3328 | |
| 3329 | rxq->queue[i] = NULL; |
| 3330 | |
| 3331 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3332 | priv->hw_params.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3333 | PCI_DMA_FROMDEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3334 | pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3335 | |
| 3336 | /* Reclaim a command buffer only if this packet is a response |
| 3337 | * to a (driver-originated) command. |
| 3338 | * If the packet (e.g. Rx frame) originated from uCode, |
| 3339 | * there is no command buffer to reclaim. |
| 3340 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 3341 | * but apparently a few don't get set; catch them here. */ |
| 3342 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 3343 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3344 | (pkt->hdr.cmd != REPLY_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 3345 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3346 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 3347 | (pkt->hdr.cmd != REPLY_TX); |
| 3348 | |
| 3349 | /* Based on type of command response or notification, |
| 3350 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3351 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3352 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
| 3353 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 3354 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 3355 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 3356 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 3357 | } else { |
| 3358 | /* No handling needed */ |
| 3359 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 3360 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 3361 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 3362 | pkt->hdr.cmd); |
| 3363 | } |
| 3364 | |
| 3365 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3366 | /* Invoke any callbacks, transfer the skb to caller, and |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3367 | * fire off the (possibly) blocking iwl_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3368 | * as we reclaim the driver command queue */ |
| 3369 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3370 | iwl4965_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3371 | else |
| 3372 | IWL_WARNING("Claim null rxb?\n"); |
| 3373 | } |
| 3374 | |
| 3375 | /* For now we just don't re-use anything. We can tweak this |
| 3376 | * later to try and re-use notification packets and SKBs that |
| 3377 | * fail to Rx correctly */ |
| 3378 | if (rxb->skb != NULL) { |
| 3379 | priv->alloc_rxb_skb--; |
| 3380 | dev_kfree_skb_any(rxb->skb); |
| 3381 | rxb->skb = NULL; |
| 3382 | } |
| 3383 | |
| 3384 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3385 | priv->hw_params.rx_buf_size, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 3386 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3387 | spin_lock_irqsave(&rxq->lock, flags); |
| 3388 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 3389 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3390 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3391 | /* If there are a lot of unused frames, |
| 3392 | * restock the Rx queue so ucode wont assert. */ |
| 3393 | if (fill_rx) { |
| 3394 | count++; |
| 3395 | if (count >= 8) { |
| 3396 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3397 | __iwl_rx_replenish(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3398 | count = 0; |
| 3399 | } |
| 3400 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | /* Backtrack one entry */ |
| 3404 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3405 | iwl_rx_queue_restock(priv); |
| 3406 | } |
| 3407 | /* Convert linear signal-to-noise ratio into dB */ |
| 3408 | static u8 ratio2dB[100] = { |
| 3409 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 3410 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 3411 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 3412 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 3413 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 3414 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 3415 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 3416 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 3417 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 3418 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 3419 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 3420 | }; |
| 3421 | |
| 3422 | /* Calculates a relative dB value from a ratio of linear |
| 3423 | * (i.e. not dB) signal levels. |
| 3424 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
| 3425 | int iwl4965_calc_db_from_ratio(int sig_ratio) |
| 3426 | { |
| 3427 | /* 1000:1 or higher just report as 60 dB */ |
| 3428 | if (sig_ratio >= 1000) |
| 3429 | return 60; |
| 3430 | |
| 3431 | /* 100:1 or higher, divide by 10 and use table, |
| 3432 | * add 20 dB to make up for divide by 10 */ |
| 3433 | if (sig_ratio >= 100) |
| 3434 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 3435 | |
| 3436 | /* We shouldn't see this */ |
| 3437 | if (sig_ratio < 1) |
| 3438 | return 0; |
| 3439 | |
| 3440 | /* Use table for ratios 1:1 - 99:1 */ |
| 3441 | return (int)ratio2dB[sig_ratio]; |
| 3442 | } |
| 3443 | |
| 3444 | #define PERFECT_RSSI (-20) /* dBm */ |
| 3445 | #define WORST_RSSI (-95) /* dBm */ |
| 3446 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 3447 | |
| 3448 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 3449 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 3450 | * about formulas used below. */ |
| 3451 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) |
| 3452 | { |
| 3453 | int sig_qual; |
| 3454 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 3455 | |
| 3456 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 3457 | * as indicator; formula is (signal dbm - noise dbm). |
| 3458 | * SNR at or above 40 is a great signal (100%). |
| 3459 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 3460 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 3461 | if (noise_dbm) { |
| 3462 | if (rssi_dbm - noise_dbm >= 40) |
| 3463 | return 100; |
| 3464 | else if (rssi_dbm < noise_dbm) |
| 3465 | return 0; |
| 3466 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 3467 | |
| 3468 | /* Else use just the signal level. |
| 3469 | * This formula is a least squares fit of data points collected and |
| 3470 | * compared with a reference system that had a percentage (%) display |
| 3471 | * for signal quality. */ |
| 3472 | } else |
| 3473 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 3474 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 3475 | (RSSI_RANGE * RSSI_RANGE); |
| 3476 | |
| 3477 | if (sig_qual > 100) |
| 3478 | sig_qual = 100; |
| 3479 | else if (sig_qual < 1) |
| 3480 | sig_qual = 0; |
| 3481 | |
| 3482 | return sig_qual; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3485 | /** |
| 3486 | * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware |
| 3487 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3488 | static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3489 | struct iwl4965_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3490 | { |
| 3491 | u32 reg = 0; |
| 3492 | int rc = 0; |
| 3493 | int txq_id = txq->q.id; |
| 3494 | |
| 3495 | if (txq->need_update == 0) |
| 3496 | return rc; |
| 3497 | |
| 3498 | /* if we're trying to save power */ |
| 3499 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 3500 | /* wake up nic if it's powered down ... |
| 3501 | * uCode will wake up, and interrupt us again, so next |
| 3502 | * time we'll skip this part. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3503 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3504 | |
| 3505 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 3506 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3507 | iwl_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3508 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 3509 | return rc; |
| 3510 | } |
| 3511 | |
| 3512 | /* restore this queue's parameters in nic hardware. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3513 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3514 | if (rc) |
| 3515 | return rc; |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3516 | iwl_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3517 | txq->q.write_ptr | (txq_id << 8)); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3518 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3519 | |
| 3520 | /* else not in power-save mode, uCode will never sleep when we're |
| 3521 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 3522 | } else |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3523 | iwl_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3524 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3525 | |
| 3526 | txq->need_update = 0; |
| 3527 | |
| 3528 | return rc; |
| 3529 | } |
| 3530 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3531 | #ifdef CONFIG_IWLWIFI_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3532 | static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3533 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3534 | DECLARE_MAC_BUF(mac); |
| 3535 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3536 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3537 | iwl_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3538 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 3539 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 3540 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 3541 | le32_to_cpu(rxon->filter_flags)); |
| 3542 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 3543 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 3544 | rxon->ofdm_basic_rates); |
| 3545 | 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] | 3546 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 3547 | print_mac(mac, rxon->node_addr)); |
| 3548 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 3549 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3550 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 3551 | } |
| 3552 | #endif |
| 3553 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3554 | static void iwl4965_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3555 | { |
| 3556 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 3557 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3558 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3559 | } |
| 3560 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3561 | /* call this function to flush any scheduled tasklet */ |
| 3562 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
| 3563 | { |
| 3564 | /* wait to make sure we flush pedding tasklet*/ |
| 3565 | synchronize_irq(priv->pci_dev->irq); |
| 3566 | tasklet_kill(&priv->irq_tasklet); |
| 3567 | } |
| 3568 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3569 | static inline void iwl4965_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3570 | { |
| 3571 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 3572 | |
| 3573 | /* disable interrupts from uCode/NIC to host */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3574 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3575 | |
| 3576 | /* acknowledge/clear/reset any interrupts still pending |
| 3577 | * from uCode or flow handler (Rx/Tx DMA) */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3578 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 3579 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3580 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 3581 | } |
| 3582 | |
| 3583 | static const char *desc_lookup(int i) |
| 3584 | { |
| 3585 | switch (i) { |
| 3586 | case 1: |
| 3587 | return "FAIL"; |
| 3588 | case 2: |
| 3589 | return "BAD_PARAM"; |
| 3590 | case 3: |
| 3591 | return "BAD_CHECKSUM"; |
| 3592 | case 4: |
| 3593 | return "NMI_INTERRUPT"; |
| 3594 | case 5: |
| 3595 | return "SYSASSERT"; |
| 3596 | case 6: |
| 3597 | return "FATAL_ERROR"; |
| 3598 | } |
| 3599 | |
| 3600 | return "UNKNOWN"; |
| 3601 | } |
| 3602 | |
| 3603 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 3604 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 3605 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3606 | static void iwl4965_dump_nic_error_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3607 | { |
| 3608 | u32 data2, line; |
| 3609 | u32 desc, time, count, base, data1; |
| 3610 | u32 blink1, blink2, ilink1, ilink2; |
| 3611 | int rc; |
| 3612 | |
| 3613 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 3614 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3615 | if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3616 | IWL_ERROR("Not valid error log pointer 0x%08X\n", base); |
| 3617 | return; |
| 3618 | } |
| 3619 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3620 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3621 | if (rc) { |
| 3622 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 3623 | return; |
| 3624 | } |
| 3625 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3626 | count = iwl_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3627 | |
| 3628 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
| 3629 | IWL_ERROR("Start IWL Error Log Dump:\n"); |
Tomas Winkler | 2acae16 | 2008-03-02 01:25:59 +0200 | [diff] [blame] | 3630 | IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3631 | } |
| 3632 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3633 | desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32)); |
| 3634 | blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32)); |
| 3635 | blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32)); |
| 3636 | ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32)); |
| 3637 | ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32)); |
| 3638 | data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32)); |
| 3639 | data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32)); |
| 3640 | line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32)); |
| 3641 | time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3642 | |
| 3643 | IWL_ERROR("Desc Time " |
| 3644 | "data1 data2 line\n"); |
| 3645 | IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n", |
| 3646 | desc_lookup(desc), desc, time, data1, data2, line); |
| 3647 | IWL_ERROR("blink1 blink2 ilink1 ilink2\n"); |
| 3648 | IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2, |
| 3649 | ilink1, ilink2); |
| 3650 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3651 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3652 | } |
| 3653 | |
| 3654 | #define EVENT_START_OFFSET (4 * sizeof(u32)) |
| 3655 | |
| 3656 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3657 | * iwl4965_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3658 | * |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3659 | * NOTE: Must be called with iwl_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3660 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3661 | 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] | 3662 | u32 num_events, u32 mode) |
| 3663 | { |
| 3664 | u32 i; |
| 3665 | u32 base; /* SRAM byte address of event log header */ |
| 3666 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 3667 | u32 ptr; /* SRAM byte address of log data */ |
| 3668 | u32 ev, time, data; /* event log data */ |
| 3669 | |
| 3670 | if (num_events == 0) |
| 3671 | return; |
| 3672 | |
| 3673 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 3674 | |
| 3675 | if (mode == 0) |
| 3676 | event_size = 2 * sizeof(u32); |
| 3677 | else |
| 3678 | event_size = 3 * sizeof(u32); |
| 3679 | |
| 3680 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 3681 | |
| 3682 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 3683 | * place event id # at far right for easier visual parsing. */ |
| 3684 | for (i = 0; i < num_events; i++) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3685 | ev = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3686 | ptr += sizeof(u32); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3687 | time = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3688 | ptr += sizeof(u32); |
| 3689 | if (mode == 0) |
| 3690 | IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */ |
| 3691 | else { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3692 | data = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3693 | ptr += sizeof(u32); |
| 3694 | IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev); |
| 3695 | } |
| 3696 | } |
| 3697 | } |
| 3698 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3699 | static void iwl4965_dump_nic_event_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3700 | { |
| 3701 | int rc; |
| 3702 | u32 base; /* SRAM byte address of event log header */ |
| 3703 | u32 capacity; /* event log capacity in # entries */ |
| 3704 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 3705 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 3706 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 3707 | u32 size; /* # entries that we'll print */ |
| 3708 | |
| 3709 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3710 | if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3711 | IWL_ERROR("Invalid event log pointer 0x%08X\n", base); |
| 3712 | return; |
| 3713 | } |
| 3714 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3715 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3716 | if (rc) { |
| 3717 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 3718 | return; |
| 3719 | } |
| 3720 | |
| 3721 | /* event log header */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3722 | capacity = iwl_read_targ_mem(priv, base); |
| 3723 | mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 3724 | num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 3725 | next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3726 | |
| 3727 | size = num_wraps ? capacity : next_entry; |
| 3728 | |
| 3729 | /* bail out if nothing in log */ |
| 3730 | if (size == 0) { |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 3731 | IWL_ERROR("Start IWL Event Log Dump: nothing in log\n"); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3732 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3733 | return; |
| 3734 | } |
| 3735 | |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 3736 | 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] | 3737 | size, num_wraps); |
| 3738 | |
| 3739 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 3740 | * i.e the next one that uCode would fill. */ |
| 3741 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3742 | iwl4965_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3743 | capacity - next_entry, mode); |
| 3744 | |
| 3745 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3746 | iwl4965_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3747 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3748 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3752 | * 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] | 3753 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3754 | static void iwl4965_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3755 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3756 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3757 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 3758 | |
| 3759 | /* Cancel currently queued command. */ |
| 3760 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3761 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3762 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 3763 | if (iwl_debug_level & IWL_DL_FW_ERRORS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3764 | iwl4965_dump_nic_error_log(priv); |
| 3765 | iwl4965_dump_nic_event_log(priv); |
| 3766 | iwl4965_print_rx_config_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3767 | } |
| 3768 | #endif |
| 3769 | |
| 3770 | wake_up_interruptible(&priv->wait_command_queue); |
| 3771 | |
| 3772 | /* Keep the restart process from trying to send host |
| 3773 | * commands by clearing the INIT status bit */ |
| 3774 | clear_bit(STATUS_READY, &priv->status); |
| 3775 | |
| 3776 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 3777 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 3778 | "Restarting adapter due to uCode error.\n"); |
| 3779 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3780 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3781 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 3782 | sizeof(priv->recovery_rxon)); |
| 3783 | priv->error_recovering = 1; |
| 3784 | } |
| 3785 | queue_work(priv->workqueue, &priv->restart); |
| 3786 | } |
| 3787 | } |
| 3788 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3789 | static void iwl4965_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3790 | { |
| 3791 | unsigned long flags; |
| 3792 | |
| 3793 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 3794 | sizeof(priv->staging_rxon)); |
| 3795 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3796 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3797 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3798 | iwl4965_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3799 | |
| 3800 | spin_lock_irqsave(&priv->lock, flags); |
| 3801 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 3802 | priv->error_recovering = 0; |
| 3803 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3804 | } |
| 3805 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3806 | static void iwl4965_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3807 | { |
| 3808 | u32 inta, handled = 0; |
| 3809 | u32 inta_fh; |
| 3810 | unsigned long flags; |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3811 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3812 | u32 inta_mask; |
| 3813 | #endif |
| 3814 | |
| 3815 | spin_lock_irqsave(&priv->lock, flags); |
| 3816 | |
| 3817 | /* Ack/clear/reset pending uCode interrupts. |
| 3818 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 3819 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3820 | inta = iwl_read32(priv, CSR_INT); |
| 3821 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3822 | |
| 3823 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 3824 | * Any new interrupts that happen after this, either while we're |
| 3825 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3826 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 3827 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3828 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3829 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 3830 | if (iwl_debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3831 | /* just for debug */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3832 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3833 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 3834 | inta, inta_mask, inta_fh); |
| 3835 | } |
| 3836 | #endif |
| 3837 | |
| 3838 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 3839 | * atomic, make sure that inta covers all the interrupts that |
| 3840 | * we've discovered, even if FH interrupt came in just after |
| 3841 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 3842 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3843 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 3844 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3845 | inta |= CSR_INT_BIT_FH_TX; |
| 3846 | |
| 3847 | /* Now service all interrupt bits discovered above. */ |
| 3848 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 3849 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 3850 | |
| 3851 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3852 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3853 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3854 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3855 | |
| 3856 | handled |= CSR_INT_BIT_HW_ERR; |
| 3857 | |
| 3858 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3859 | |
| 3860 | return; |
| 3861 | } |
| 3862 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3863 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 3864 | if (iwl_debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3865 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3866 | if (inta & CSR_INT_BIT_SCD) |
| 3867 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 3868 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3869 | |
| 3870 | /* Alive notification via Rx interrupt will do the real work */ |
| 3871 | if (inta & CSR_INT_BIT_ALIVE) |
| 3872 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 3873 | } |
| 3874 | #endif |
| 3875 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3876 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3877 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3878 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3879 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 3880 | int hw_rf_kill = 0; |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3881 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3882 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 3883 | hw_rf_kill = 1; |
| 3884 | |
| 3885 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR, |
| 3886 | "RF_KILL bit toggled to %s.\n", |
| 3887 | hw_rf_kill ? "disable radio":"enable radio"); |
| 3888 | |
| 3889 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 3890 | * when we loaded driver, and is now set to "enable". |
| 3891 | * After we're Alive, RF_KILL gets handled by |
Reinette Chatre | 3230455 | 2008-02-15 14:34:37 -0800 | [diff] [blame] | 3892 | * iwl4965_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 3893 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 3894 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3895 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 3896 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3897 | |
| 3898 | handled |= CSR_INT_BIT_RF_KILL; |
| 3899 | } |
| 3900 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3901 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3902 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 3903 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 3904 | handled |= CSR_INT_BIT_CT_KILL; |
| 3905 | } |
| 3906 | |
| 3907 | /* Error detected by uCode */ |
| 3908 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 3909 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 3910 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3911 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3912 | handled |= CSR_INT_BIT_SW_ERR; |
| 3913 | } |
| 3914 | |
| 3915 | /* uCode wakes up after power-down sleep */ |
| 3916 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 3917 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3918 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3919 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]); |
| 3920 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]); |
| 3921 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]); |
| 3922 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]); |
| 3923 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]); |
| 3924 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3925 | |
| 3926 | handled |= CSR_INT_BIT_WAKEUP; |
| 3927 | } |
| 3928 | |
| 3929 | /* All uCode command responses, including Tx command responses, |
| 3930 | * Rx "responses" (frame-received notification), and other |
| 3931 | * notifications from uCode come through here*/ |
| 3932 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3933 | iwl_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3934 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 3935 | } |
| 3936 | |
| 3937 | if (inta & CSR_INT_BIT_FH_TX) { |
| 3938 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 3939 | handled |= CSR_INT_BIT_FH_TX; |
| 3940 | } |
| 3941 | |
| 3942 | if (inta & ~handled) |
| 3943 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 3944 | |
| 3945 | if (inta & ~CSR_INI_SET_MASK) { |
| 3946 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 3947 | inta & ~CSR_INI_SET_MASK); |
| 3948 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 3949 | } |
| 3950 | |
| 3951 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3952 | /* only Re-enable if diabled by irq */ |
| 3953 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 3954 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3955 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3956 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 3957 | if (iwl_debug_level & (IWL_DL_ISR)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3958 | inta = iwl_read32(priv, CSR_INT); |
| 3959 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 3960 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3961 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 3962 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 3963 | } |
| 3964 | #endif |
| 3965 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3966 | } |
| 3967 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3968 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3969 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3970 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3971 | u32 inta, inta_mask; |
| 3972 | u32 inta_fh; |
| 3973 | if (!priv) |
| 3974 | return IRQ_NONE; |
| 3975 | |
| 3976 | spin_lock(&priv->lock); |
| 3977 | |
| 3978 | /* Disable (but don't clear!) interrupts here to avoid |
| 3979 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 3980 | * If we have something to service, the tasklet will re-enable ints. |
| 3981 | * If we *don't* have something, we'll re-enable before leaving here. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3982 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 3983 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3984 | |
| 3985 | /* Discover which interrupts are active/pending */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3986 | inta = iwl_read32(priv, CSR_INT); |
| 3987 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3988 | |
| 3989 | /* Ignore interrupt if there's nothing in NIC to service. |
| 3990 | * This may be due to IRQ shared with another device, |
| 3991 | * or due to sporadic interrupts thrown from our NIC. */ |
| 3992 | if (!inta && !inta_fh) { |
| 3993 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 3994 | goto none; |
| 3995 | } |
| 3996 | |
| 3997 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 3998 | /* Hardware disappeared. It might have already raised |
| 3999 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4000 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 4001 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4002 | } |
| 4003 | |
| 4004 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4005 | inta, inta_mask, inta_fh); |
| 4006 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4007 | inta &= ~CSR_INT_BIT_SCD; |
| 4008 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4009 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4010 | if (likely(inta || inta_fh)) |
| 4011 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4012 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 4013 | unplugged: |
| 4014 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4015 | return IRQ_HANDLED; |
| 4016 | |
| 4017 | none: |
| 4018 | /* re-enable interrupts here since we don't have anything to service. */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4019 | /* only Re-enable if diabled by irq */ |
| 4020 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 4021 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4022 | spin_unlock(&priv->lock); |
| 4023 | return IRQ_NONE; |
| 4024 | } |
| 4025 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4026 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 4027 | * sending probe req. This should be set long enough to hear probe responses |
| 4028 | * from more than one AP. */ |
| 4029 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 4030 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 4031 | |
| 4032 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 4033 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 4034 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 4035 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 4036 | * no other traffic). |
| 4037 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 4038 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 4039 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 4040 | |
| 4041 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 4042 | * Must be set longer than active dwell time. |
| 4043 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 4044 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 4045 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 4046 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 4047 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 4048 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4049 | static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4050 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4051 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4052 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4053 | return IWL_ACTIVE_DWELL_TIME_52; |
| 4054 | else |
| 4055 | return IWL_ACTIVE_DWELL_TIME_24; |
| 4056 | } |
| 4057 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4058 | static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4059 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4060 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4061 | u16 active = iwl4965_get_active_dwell_time(priv, band); |
| 4062 | u16 passive = (band != IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4063 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 4064 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 4065 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4066 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4067 | /* If we're associated, we clamp the maximum passive |
| 4068 | * dwell time to be 98% of the beacon interval (minus |
| 4069 | * 2 * channel tune time) */ |
| 4070 | passive = priv->beacon_int; |
| 4071 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 4072 | passive = IWL_PASSIVE_DWELL_BASE; |
| 4073 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 4074 | } |
| 4075 | |
| 4076 | if (passive <= active) |
| 4077 | passive = active + 1; |
| 4078 | |
| 4079 | return passive; |
| 4080 | } |
| 4081 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4082 | static int iwl4965_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4083 | enum ieee80211_band band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4084 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4085 | struct iwl4965_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4086 | { |
| 4087 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4088 | const struct ieee80211_supported_band *sband; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4089 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4090 | u16 passive_dwell = 0; |
| 4091 | u16 active_dwell = 0; |
| 4092 | int added, i; |
| 4093 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 4094 | sband = iwl_get_hw_mode(priv, band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4095 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4096 | return 0; |
| 4097 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4098 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4099 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4100 | active_dwell = iwl4965_get_active_dwell_time(priv, band); |
| 4101 | passive_dwell = iwl4965_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4102 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4103 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 4104 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 4105 | continue; |
| 4106 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4107 | scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4108 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 4109 | ch_info = iwl_get_channel_info(priv, band, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4110 | scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4111 | if (!is_channel_valid(ch_info)) { |
| 4112 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 4113 | scan_ch->channel); |
| 4114 | continue; |
| 4115 | } |
| 4116 | |
| 4117 | if (!is_active || is_channel_passive(ch_info) || |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4118 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4119 | scan_ch->type = 0; /* passive */ |
| 4120 | else |
| 4121 | scan_ch->type = 1; /* active */ |
| 4122 | |
| 4123 | if (scan_ch->type & 1) |
| 4124 | scan_ch->type |= (direct_mask << 1); |
| 4125 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4126 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 4127 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 4128 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4129 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4130 | scan_ch->tpc.dsp_atten = 110; |
| 4131 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 4132 | |
| 4133 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4134 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4135 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 4136 | else { |
| 4137 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 4138 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4139 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 4140 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4141 | */ |
| 4142 | } |
| 4143 | |
| 4144 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 4145 | scan_ch->channel, |
| 4146 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 4147 | (scan_ch->type & 1) ? |
| 4148 | active_dwell : passive_dwell); |
| 4149 | |
| 4150 | scan_ch++; |
| 4151 | added++; |
| 4152 | } |
| 4153 | |
| 4154 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 4155 | return added; |
| 4156 | } |
| 4157 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4158 | /****************************************************************************** |
| 4159 | * |
| 4160 | * uCode download functions |
| 4161 | * |
| 4162 | ******************************************************************************/ |
| 4163 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4164 | static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4165 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4166 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 4167 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 4168 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 4169 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 4170 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 4171 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4172 | } |
| 4173 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4174 | static void iwl4965_nic_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4175 | { |
| 4176 | /* Remove all resets to allow NIC to operate */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4177 | iwl_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4178 | } |
| 4179 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4180 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4181 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4182 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4183 | * |
| 4184 | * Copy into buffers for card to fetch via bus-mastering |
| 4185 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4186 | static int iwl4965_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4187 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4188 | struct iwl4965_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4189 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4190 | const struct firmware *ucode_raw; |
Tomas Winkler | 4bf775cd | 2008-03-04 18:09:31 -0800 | [diff] [blame] | 4191 | const char *name = priv->cfg->fw_name; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4192 | u8 *src; |
| 4193 | size_t len; |
| 4194 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 4195 | |
| 4196 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 4197 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4198 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 4199 | if (ret < 0) { |
| 4200 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 4201 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4202 | goto error; |
| 4203 | } |
| 4204 | |
| 4205 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 4206 | name, ucode_raw->size); |
| 4207 | |
| 4208 | /* Make sure that we got at least our header! */ |
| 4209 | if (ucode_raw->size < sizeof(*ucode)) { |
| 4210 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4211 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4212 | goto err_release; |
| 4213 | } |
| 4214 | |
| 4215 | /* Data from ucode file: header followed by uCode images */ |
| 4216 | ucode = (void *)ucode_raw->data; |
| 4217 | |
| 4218 | ver = le32_to_cpu(ucode->ver); |
| 4219 | inst_size = le32_to_cpu(ucode->inst_size); |
| 4220 | data_size = le32_to_cpu(ucode->data_size); |
| 4221 | init_size = le32_to_cpu(ucode->init_size); |
| 4222 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 4223 | boot_size = le32_to_cpu(ucode->boot_size); |
| 4224 | |
| 4225 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 4226 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 4227 | inst_size); |
| 4228 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 4229 | data_size); |
| 4230 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 4231 | init_size); |
| 4232 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 4233 | init_data_size); |
| 4234 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 4235 | boot_size); |
| 4236 | |
| 4237 | /* Verify size of file vs. image size info in file's header */ |
| 4238 | if (ucode_raw->size < sizeof(*ucode) + |
| 4239 | inst_size + data_size + init_size + |
| 4240 | init_data_size + boot_size) { |
| 4241 | |
| 4242 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 4243 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4244 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4245 | goto err_release; |
| 4246 | } |
| 4247 | |
| 4248 | /* Verify that uCode images will fit in card's SRAM */ |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4249 | if (inst_size > priv->hw_params.max_inst_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4250 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 4251 | inst_size); |
| 4252 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4253 | goto err_release; |
| 4254 | } |
| 4255 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4256 | if (data_size > priv->hw_params.max_data_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4257 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 4258 | data_size); |
| 4259 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4260 | goto err_release; |
| 4261 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4262 | if (init_size > priv->hw_params.max_inst_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4263 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4264 | ("uCode init instr len %d too large to fit in\n", |
| 4265 | init_size); |
| 4266 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4267 | goto err_release; |
| 4268 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4269 | if (init_data_size > priv->hw_params.max_data_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4270 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4271 | ("uCode init data len %d too large to fit in\n", |
| 4272 | init_data_size); |
| 4273 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4274 | goto err_release; |
| 4275 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4276 | if (boot_size > priv->hw_params.max_bsm_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4277 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4278 | ("uCode boot instr len %d too large to fit in\n", |
| 4279 | boot_size); |
| 4280 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4281 | goto err_release; |
| 4282 | } |
| 4283 | |
| 4284 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 4285 | |
| 4286 | /* Runtime instructions and 2 copies of data: |
| 4287 | * 1) unmodified from disk |
| 4288 | * 2) backup cache for save/restore during power-downs */ |
| 4289 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4290 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4291 | |
| 4292 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4293 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4294 | |
| 4295 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4296 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4297 | |
| 4298 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4299 | if (init_size && init_data_size) { |
| 4300 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4301 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4302 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4303 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4304 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4305 | |
| 4306 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 4307 | goto err_pci_alloc; |
| 4308 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4309 | |
| 4310 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4311 | if (boot_size) { |
| 4312 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4313 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4314 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4315 | if (!priv->ucode_boot.v_addr) |
| 4316 | goto err_pci_alloc; |
| 4317 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4318 | |
| 4319 | /* Copy images into buffers for card's bus-master reads ... */ |
| 4320 | |
| 4321 | /* Runtime instructions (first block of data in file) */ |
| 4322 | src = &ucode->data[0]; |
| 4323 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4324 | 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] | 4325 | memcpy(priv->ucode_code.v_addr, src, len); |
| 4326 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 4327 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 4328 | |
| 4329 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4330 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4331 | src = &ucode->data[inst_size]; |
| 4332 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4333 | 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] | 4334 | memcpy(priv->ucode_data.v_addr, src, len); |
| 4335 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 4336 | |
| 4337 | /* Initialization instructions (3rd block) */ |
| 4338 | if (init_size) { |
| 4339 | src = &ucode->data[inst_size + data_size]; |
| 4340 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4341 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 4342 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4343 | memcpy(priv->ucode_init.v_addr, src, len); |
| 4344 | } |
| 4345 | |
| 4346 | /* Initialization data (4th block) */ |
| 4347 | if (init_data_size) { |
| 4348 | src = &ucode->data[inst_size + data_size + init_size]; |
| 4349 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4350 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 4351 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4352 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 4353 | } |
| 4354 | |
| 4355 | /* Bootstrap instructions (5th block) */ |
| 4356 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 4357 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4358 | 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] | 4359 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 4360 | |
| 4361 | /* We have our copies now, allow OS release its copies */ |
| 4362 | release_firmware(ucode_raw); |
| 4363 | return 0; |
| 4364 | |
| 4365 | err_pci_alloc: |
| 4366 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4367 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4368 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4369 | |
| 4370 | err_release: |
| 4371 | release_firmware(ucode_raw); |
| 4372 | |
| 4373 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4374 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4375 | } |
| 4376 | |
| 4377 | |
| 4378 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4379 | * iwl4965_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4380 | * |
| 4381 | * Tell initialization uCode where to find runtime uCode. |
| 4382 | * |
| 4383 | * BSM registers initially contain pointers to initialization uCode. |
| 4384 | * We need to replace them to load runtime uCode inst and data, |
| 4385 | * and to save runtime data when powering down. |
| 4386 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4387 | static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4388 | { |
| 4389 | dma_addr_t pinst; |
| 4390 | dma_addr_t pdata; |
| 4391 | int rc = 0; |
| 4392 | unsigned long flags; |
| 4393 | |
| 4394 | /* bits 35:4 for 4965 */ |
| 4395 | pinst = priv->ucode_code.p_addr >> 4; |
| 4396 | pdata = priv->ucode_data_backup.p_addr >> 4; |
| 4397 | |
| 4398 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4399 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4400 | if (rc) { |
| 4401 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4402 | return rc; |
| 4403 | } |
| 4404 | |
| 4405 | /* Tell bootstrap uCode where to find image to load */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4406 | iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 4407 | iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 4408 | iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4409 | priv->ucode_data.len); |
| 4410 | |
| 4411 | /* Inst bytecount must be last to set up, bit 31 signals uCode |
| 4412 | * that all new ptr/size info is in place */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4413 | iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4414 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 4415 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4416 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4417 | |
| 4418 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4419 | |
| 4420 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 4421 | |
| 4422 | return rc; |
| 4423 | } |
| 4424 | |
| 4425 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4426 | * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4427 | * |
| 4428 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 4429 | * |
| 4430 | * The 4965 "initialize" ALIVE reply contains calibration data for: |
| 4431 | * Voltage, temperature, and MIMO tx gain correction, now stored in priv |
| 4432 | * (3945 does not contain this data). |
| 4433 | * |
| 4434 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
| 4435 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4436 | static void iwl4965_init_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4437 | { |
| 4438 | /* Check alive response for "valid" sign from uCode */ |
| 4439 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 4440 | /* We had an error bringing up the hardware, so take it |
| 4441 | * all the way back down so we can try again */ |
| 4442 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 4443 | goto restart; |
| 4444 | } |
| 4445 | |
| 4446 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 4447 | * This is a paranoid check, because we would not have gotten the |
| 4448 | * "initialize" alive if code weren't properly loaded. */ |
Emmanuel Grumbach | b0692f2 | 2008-04-24 11:55:18 -0700 | [diff] [blame] | 4449 | if (iwl_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4450 | /* Runtime instruction load was bad; |
| 4451 | * take it all the way back down so we can try again */ |
| 4452 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 4453 | goto restart; |
| 4454 | } |
| 4455 | |
| 4456 | /* Calculate temperature */ |
| 4457 | priv->temperature = iwl4965_get_temperature(priv); |
| 4458 | |
| 4459 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 4460 | * load and launch runtime uCode, which will send us another "Alive" |
| 4461 | * notification. */ |
| 4462 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4463 | if (iwl4965_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4464 | /* Runtime instruction load won't happen; |
| 4465 | * take it all the way back down so we can try again */ |
| 4466 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 4467 | goto restart; |
| 4468 | } |
| 4469 | return; |
| 4470 | |
| 4471 | restart: |
| 4472 | queue_work(priv->workqueue, &priv->restart); |
| 4473 | } |
| 4474 | |
| 4475 | |
| 4476 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4477 | * iwl4965_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4478 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4479 | * Alive gets handled by iwl4965_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4480 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4481 | static void iwl4965_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4482 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4483 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4484 | |
| 4485 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 4486 | |
| 4487 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 4488 | /* We had an error bringing up the hardware, so take it |
| 4489 | * all the way back down so we can try again */ |
| 4490 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 4491 | goto restart; |
| 4492 | } |
| 4493 | |
| 4494 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 4495 | * This is a paranoid check, because we would not have gotten the |
| 4496 | * "runtime" alive if code weren't properly loaded. */ |
Emmanuel Grumbach | b0692f2 | 2008-04-24 11:55:18 -0700 | [diff] [blame] | 4497 | if (iwl_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4498 | /* Runtime instruction load was bad; |
| 4499 | * take it all the way back down so we can try again */ |
| 4500 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 4501 | goto restart; |
| 4502 | } |
| 4503 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4504 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4505 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4506 | ret = priv->cfg->ops->lib->alive_notify(priv); |
| 4507 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4508 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4509 | ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4510 | goto restart; |
| 4511 | } |
| 4512 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4513 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4514 | set_bit(STATUS_ALIVE, &priv->status); |
| 4515 | |
| 4516 | /* Clear out the uCode error bit if it is set */ |
| 4517 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 4518 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4519 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4520 | return; |
| 4521 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4522 | ieee80211_start_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4523 | |
| 4524 | priv->active_rate = priv->rates_mask; |
| 4525 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 4526 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4527 | if (iwl_is_associated(priv)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4528 | struct iwl4965_rxon_cmd *active_rxon = |
| 4529 | (struct iwl4965_rxon_cmd *)(&priv->active_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4530 | |
| 4531 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 4532 | sizeof(priv->staging_rxon)); |
| 4533 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 4534 | } else { |
| 4535 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4536 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4537 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 4538 | } |
| 4539 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4540 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4541 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4542 | |
| 4543 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4544 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4545 | |
| 4546 | /* At this point, the NIC is initialized and operational */ |
| 4547 | priv->notif_missed_beacons = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4548 | |
| 4549 | iwl4965_rf_kill_ct_config(priv); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4550 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 4551 | iwl_leds_register(priv); |
| 4552 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4553 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 4554 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4555 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4556 | |
| 4557 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4558 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4559 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 4560 | iwlcore_low_level_notify(priv, IWLCORE_START_EVT); |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 4561 | ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4562 | return; |
| 4563 | |
| 4564 | restart: |
| 4565 | queue_work(priv->workqueue, &priv->restart); |
| 4566 | } |
| 4567 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4568 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4569 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4570 | static void __iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4571 | { |
| 4572 | unsigned long flags; |
| 4573 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 4574 | struct ieee80211_conf *conf = NULL; |
| 4575 | |
| 4576 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 4577 | |
| 4578 | conf = ieee80211_get_hw_conf(priv->hw); |
| 4579 | |
| 4580 | if (!exit_pending) |
| 4581 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 4582 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 4583 | iwl_leds_unregister(priv); |
| 4584 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 4585 | iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT); |
| 4586 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4587 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4588 | |
| 4589 | /* Unblock any waiting calls */ |
| 4590 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 4591 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4592 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 4593 | * exiting the module */ |
| 4594 | if (!exit_pending) |
| 4595 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 4596 | |
| 4597 | /* stop and reset the on-board processor */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4598 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4599 | |
| 4600 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4601 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4602 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4603 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4604 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4605 | |
| 4606 | if (priv->mac80211_registered) |
| 4607 | ieee80211_stop_queues(priv->hw); |
| 4608 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4609 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4610 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4611 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4612 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 4613 | STATUS_RF_KILL_HW | |
| 4614 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 4615 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 4616 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 4617 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4618 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 4619 | STATUS_IN_SUSPEND; |
| 4620 | goto exit; |
| 4621 | } |
| 4622 | |
| 4623 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 4624 | * SUSPEND bits and continue taking the NIC down. */ |
| 4625 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 4626 | STATUS_RF_KILL_HW | |
| 4627 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 4628 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 4629 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 4630 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4631 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 4632 | STATUS_IN_SUSPEND | |
| 4633 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 4634 | STATUS_FW_ERROR; |
| 4635 | |
| 4636 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4637 | iwl_clear_bit(priv, CSR_GP_CNTRL, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4638 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4639 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4640 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4641 | iwl4965_hw_txq_ctx_stop(priv); |
| 4642 | iwl4965_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4643 | |
| 4644 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4645 | if (!iwl_grab_nic_access(priv)) { |
| 4646 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4647 | APMG_CLK_VAL_DMA_CLK_RQT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4648 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4649 | } |
| 4650 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4651 | |
| 4652 | udelay(5); |
| 4653 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4654 | iwl4965_hw_nic_stop_master(priv); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4655 | iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4656 | iwl4965_hw_nic_reset(priv); |
Ron Rindjunsky | 399f4900 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 4657 | priv->cfg->ops->lib->free_shared_mem(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4658 | |
| 4659 | exit: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4660 | memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4661 | |
| 4662 | if (priv->ibss_beacon) |
| 4663 | dev_kfree_skb(priv->ibss_beacon); |
| 4664 | priv->ibss_beacon = NULL; |
| 4665 | |
| 4666 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4667 | iwl4965_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4668 | } |
| 4669 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4670 | static void iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4671 | { |
| 4672 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4673 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4674 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 4675 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4676 | iwl4965_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4677 | } |
| 4678 | |
| 4679 | #define MAX_HW_RESTARTS 5 |
| 4680 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4681 | static int __iwl4965_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4682 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4683 | int i; |
| 4684 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4685 | |
| 4686 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 4687 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 4688 | return -EIO; |
| 4689 | } |
| 4690 | |
| 4691 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 4692 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 4693 | "parameter)\n"); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4694 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4695 | return -ENODEV; |
| 4696 | } |
| 4697 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 4698 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 4699 | IWL_ERROR("ucode not available for device bringup\n"); |
| 4700 | return -EIO; |
| 4701 | } |
| 4702 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4703 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4704 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4705 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 4706 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4707 | else { |
| 4708 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4709 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4710 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4711 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 4712 | return -ENODEV; |
| 4713 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4714 | } |
| 4715 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4716 | iwl_rfkill_set_hw_state(priv); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4717 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4718 | |
Ron Rindjunsky | 399f4900 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 4719 | ret = priv->cfg->ops->lib->alloc_shared_mem(priv); |
| 4720 | if (ret) { |
| 4721 | IWL_ERROR("Unable to allocate shared memory\n"); |
| 4722 | return ret; |
| 4723 | } |
| 4724 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4725 | ret = priv->cfg->ops->lib->hw_nic_init(priv); |
| 4726 | if (ret) { |
| 4727 | IWL_ERROR("Unable to init nic\n"); |
| 4728 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | /* make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4732 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 4733 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4734 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 4735 | |
| 4736 | /* clear (again), then enable host interrupts */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4737 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4738 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4739 | |
| 4740 | /* really make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4741 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 4742 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4743 | |
| 4744 | /* Copy original ucode data image from disk into backup cache. |
| 4745 | * This will be used to initialize the on-board processor's |
| 4746 | * data SRAM for a clean start when the runtime program first loads. */ |
| 4747 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4748 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4749 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4750 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 4751 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4752 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4753 | |
| 4754 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 4755 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4756 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4757 | |
| 4758 | /* load bootstrap state machine, |
| 4759 | * load bootstrap program into processor's memory, |
| 4760 | * prepare to load the "initialize" uCode */ |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4761 | ret = priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4762 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4763 | if (ret) { |
| 4764 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4765 | continue; |
| 4766 | } |
| 4767 | |
| 4768 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4769 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4770 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4771 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 4772 | |
| 4773 | return 0; |
| 4774 | } |
| 4775 | |
| 4776 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4777 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4778 | |
| 4779 | /* tried to restart and config the device for as long as our |
| 4780 | * patience could withstand */ |
| 4781 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 4782 | return -EIO; |
| 4783 | } |
| 4784 | |
| 4785 | |
| 4786 | /***************************************************************************** |
| 4787 | * |
| 4788 | * Workqueue callbacks |
| 4789 | * |
| 4790 | *****************************************************************************/ |
| 4791 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4792 | static void iwl4965_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4793 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4794 | struct iwl_priv *priv = |
| 4795 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4796 | |
| 4797 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4798 | return; |
| 4799 | |
| 4800 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4801 | iwl4965_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4802 | mutex_unlock(&priv->mutex); |
| 4803 | } |
| 4804 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4805 | static void iwl4965_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4806 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4807 | struct iwl_priv *priv = |
| 4808 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4809 | |
| 4810 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4811 | return; |
| 4812 | |
| 4813 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4814 | iwl4965_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4815 | mutex_unlock(&priv->mutex); |
| 4816 | } |
| 4817 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4818 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4819 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4820 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4821 | |
| 4822 | wake_up_interruptible(&priv->wait_command_queue); |
| 4823 | |
| 4824 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4825 | return; |
| 4826 | |
| 4827 | mutex_lock(&priv->mutex); |
| 4828 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4829 | if (!iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4830 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 4831 | "HW and/or SW RF Kill no longer active, restarting " |
| 4832 | "device\n"); |
| 4833 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4834 | queue_work(priv->workqueue, &priv->restart); |
| 4835 | } else { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4836 | /* make sure mac80211 stop sending Tx frame */ |
| 4837 | if (priv->mac80211_registered) |
| 4838 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4839 | |
| 4840 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 4841 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 4842 | "disabled by SW switch\n"); |
| 4843 | else |
| 4844 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 4845 | "Kill switch must be turned off for " |
| 4846 | "wireless networking to work.\n"); |
| 4847 | } |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4848 | iwl_rfkill_set_hw_state(priv); |
| 4849 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4850 | mutex_unlock(&priv->mutex); |
| 4851 | } |
| 4852 | |
| 4853 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 4854 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4855 | static void iwl4965_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4856 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4857 | struct iwl_priv *priv = |
| 4858 | container_of(data, struct iwl_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4859 | |
| 4860 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4861 | return; |
| 4862 | |
| 4863 | mutex_lock(&priv->mutex); |
| 4864 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 4865 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 4866 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 4867 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 4868 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4869 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4870 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4871 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4872 | } |
| 4873 | mutex_unlock(&priv->mutex); |
| 4874 | } |
| 4875 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4876 | static void iwl4965_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4877 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4878 | struct iwl_priv *priv = |
| 4879 | container_of(data, struct iwl_priv, request_scan); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4880 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4881 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4882 | .len = sizeof(struct iwl4965_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4883 | .meta.flags = CMD_SIZE_HUGE, |
| 4884 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4885 | struct iwl4965_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4886 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 4887 | u16 cmd_len; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4888 | enum ieee80211_band band; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 4889 | u8 direct_mask; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4890 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4891 | |
| 4892 | conf = ieee80211_get_hw_conf(priv->hw); |
| 4893 | |
| 4894 | mutex_lock(&priv->mutex); |
| 4895 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4896 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4897 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 4898 | goto done; |
| 4899 | } |
| 4900 | |
| 4901 | /* Make sure the scan wasn't cancelled before this queued work |
| 4902 | * was given the chance to run... */ |
| 4903 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 4904 | goto done; |
| 4905 | |
| 4906 | /* This should never be called or scheduled if there is currently |
| 4907 | * a scan active in the hardware. */ |
| 4908 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 4909 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 4910 | "Ignoring second request.\n"); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4911 | ret = -EIO; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4912 | goto done; |
| 4913 | } |
| 4914 | |
| 4915 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 4916 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 4917 | goto done; |
| 4918 | } |
| 4919 | |
| 4920 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 4921 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 4922 | goto done; |
| 4923 | } |
| 4924 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4925 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4926 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 4927 | goto done; |
| 4928 | } |
| 4929 | |
| 4930 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 4931 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 4932 | goto done; |
| 4933 | } |
| 4934 | |
| 4935 | if (!priv->scan_bands) { |
| 4936 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 4937 | goto done; |
| 4938 | } |
| 4939 | |
| 4940 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4941 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4942 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 4943 | if (!priv->scan) { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4944 | ret = -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4945 | goto done; |
| 4946 | } |
| 4947 | } |
| 4948 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4949 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4950 | |
| 4951 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 4952 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 4953 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4954 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4955 | u16 interval = 0; |
| 4956 | u32 extra; |
| 4957 | u32 suspend_time = 100; |
| 4958 | u32 scan_suspend_time = 100; |
| 4959 | unsigned long flags; |
| 4960 | |
| 4961 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 4962 | |
| 4963 | spin_lock_irqsave(&priv->lock, flags); |
| 4964 | interval = priv->beacon_int; |
| 4965 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4966 | |
| 4967 | scan->suspend_time = 0; |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4968 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4969 | if (!interval) |
| 4970 | interval = suspend_time; |
| 4971 | |
| 4972 | extra = (suspend_time / interval) << 22; |
| 4973 | scan_suspend_time = (extra | |
| 4974 | ((suspend_time % interval) * 1024)); |
| 4975 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 4976 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 4977 | scan_suspend_time, interval); |
| 4978 | } |
| 4979 | |
| 4980 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 4981 | if (priv->one_direct_scan) { |
| 4982 | IWL_DEBUG_SCAN |
| 4983 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4984 | iwl4965_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4985 | priv->direct_ssid_len)); |
| 4986 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 4987 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 4988 | memcpy(scan->direct_scan[0].ssid, |
| 4989 | priv->direct_ssid, priv->direct_ssid_len); |
| 4990 | direct_mask = 1; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4991 | } else if (!iwl_is_associated(priv) && priv->essid_len) { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 4992 | IWL_DEBUG_SCAN |
| 4993 | ("Kicking off one direct scan for '%s' when not associated\n", |
| 4994 | iwl4965_escape_essid(priv->essid, priv->essid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4995 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 4996 | scan->direct_scan[0].len = priv->essid_len; |
| 4997 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 4998 | direct_mask = 1; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4999 | } else { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 5000 | IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5001 | direct_mask = 0; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5002 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5003 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5004 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 5005 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5006 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 5007 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5008 | |
| 5009 | switch (priv->scan_bands) { |
| 5010 | case 2: |
| 5011 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 5012 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5013 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5014 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 5015 | |
| 5016 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5017 | band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5018 | break; |
| 5019 | |
| 5020 | case 1: |
| 5021 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5022 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5023 | RATE_MCS_ANT_B_MSK); |
| 5024 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5025 | band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5026 | break; |
| 5027 | |
| 5028 | default: |
| 5029 | IWL_WARNING("Invalid scan band count\n"); |
| 5030 | goto done; |
| 5031 | } |
| 5032 | |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5033 | /* We don't build a direct scan probe request; the uCode will do |
| 5034 | * that based on the direct_mask added to each channel entry */ |
| 5035 | cmd_len = iwl4965_fill_probe_req(priv, band, |
| 5036 | (struct ieee80211_mgmt *)scan->data, |
| 5037 | IWL_MAX_SCAN_SIZE - sizeof(*scan), 0); |
| 5038 | |
| 5039 | scan->tx_cmd.len = cpu_to_le16(cmd_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5040 | /* select Rx chains */ |
| 5041 | |
| 5042 | /* Force use of chains B and C (0x6) for scan Rx. |
| 5043 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 5044 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 5045 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 5046 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 5047 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 5048 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 5049 | |
| 5050 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 5051 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 5052 | |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 5053 | if (direct_mask) |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 5054 | scan->channel_count = |
| 5055 | iwl4965_get_channels_for_scan( |
| 5056 | priv, band, 1, /* active */ |
| 5057 | direct_mask, |
| 5058 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 5059 | else |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 5060 | scan->channel_count = |
| 5061 | iwl4965_get_channels_for_scan( |
| 5062 | priv, band, 0, /* passive */ |
| 5063 | direct_mask, |
| 5064 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5065 | |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 5066 | scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | |
| 5067 | RXON_FILTER_BCON_AWARE_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5068 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5069 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5070 | cmd.data = scan; |
| 5071 | scan->len = cpu_to_le16(cmd.len); |
| 5072 | |
| 5073 | set_bit(STATUS_SCAN_HW, &priv->status); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5074 | ret = iwl_send_cmd_sync(priv, &cmd); |
| 5075 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5076 | goto done; |
| 5077 | |
| 5078 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 5079 | IWL_SCAN_CHECK_WATCHDOG); |
| 5080 | |
| 5081 | mutex_unlock(&priv->mutex); |
| 5082 | return; |
| 5083 | |
| 5084 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 5085 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5086 | queue_work(priv->workqueue, &priv->scan_completed); |
| 5087 | mutex_unlock(&priv->mutex); |
| 5088 | } |
| 5089 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5090 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5091 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5092 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5093 | |
| 5094 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5095 | return; |
| 5096 | |
| 5097 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5098 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5099 | mutex_unlock(&priv->mutex); |
| 5100 | } |
| 5101 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5102 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5103 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5104 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5105 | |
| 5106 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5107 | return; |
| 5108 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5109 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5110 | queue_work(priv->workqueue, &priv->up); |
| 5111 | } |
| 5112 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5113 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5114 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5115 | struct iwl_priv *priv = |
| 5116 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5117 | |
| 5118 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5119 | return; |
| 5120 | |
| 5121 | mutex_lock(&priv->mutex); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 5122 | iwl_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5123 | mutex_unlock(&priv->mutex); |
| 5124 | } |
| 5125 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5126 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 5127 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5128 | static void iwl4965_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5129 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5130 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5131 | int ret = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5132 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5133 | |
| 5134 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 5135 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 5136 | return; |
| 5137 | } |
| 5138 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5139 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 5140 | priv->assoc_id, |
| 5141 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5142 | |
| 5143 | |
| 5144 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5145 | return; |
| 5146 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5147 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5148 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5149 | return; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5150 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5151 | iwl4965_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5152 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5153 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5154 | |
| 5155 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5156 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5157 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5158 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 5159 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5160 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5161 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5162 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5163 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 5164 | "Attempting to continue.\n"); |
| 5165 | |
| 5166 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 5167 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5168 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 5169 | if (priv->current_ht_config.is_ht) |
| 5170 | iwl4965_set_rxon_ht(priv, &priv->current_ht_config); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5171 | #endif /* CONFIG_IWL4965_HT*/ |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5172 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5173 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 5174 | |
| 5175 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 5176 | priv->assoc_id, priv->beacon_int); |
| 5177 | |
| 5178 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 5179 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5180 | else |
| 5181 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5182 | |
| 5183 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 5184 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 5185 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 5186 | else |
| 5187 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 5188 | |
| 5189 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 5190 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 5191 | |
| 5192 | } |
| 5193 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5194 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5195 | |
| 5196 | switch (priv->iw_mode) { |
| 5197 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5198 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5199 | break; |
| 5200 | |
| 5201 | case IEEE80211_IF_TYPE_IBSS: |
| 5202 | |
| 5203 | /* clear out the station table */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5204 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5205 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5206 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
| 5207 | iwl4965_rxon_add_station(priv, priv->bssid, 0); |
| 5208 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
| 5209 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5210 | |
| 5211 | break; |
| 5212 | |
| 5213 | default: |
| 5214 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 5215 | __FUNCTION__, priv->iw_mode); |
| 5216 | break; |
| 5217 | } |
| 5218 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5219 | iwl4965_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5220 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5221 | /* Enable Rx differential gain and sensitivity calibrations */ |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 5222 | iwl_chain_noise_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5223 | priv->start_calib = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5224 | |
| 5225 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 5226 | priv->assoc_station_added = 1; |
| 5227 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5228 | iwl4965_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 5229 | |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 5230 | iwl_power_update_mode(priv, 0); |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5231 | /* we have just associated, don't start scan too early */ |
| 5232 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5233 | } |
| 5234 | |
| 5235 | |
| 5236 | static void iwl4965_bg_post_associate(struct work_struct *data) |
| 5237 | { |
| 5238 | struct iwl_priv *priv = container_of(data, struct iwl_priv, |
| 5239 | post_associate.work); |
| 5240 | |
| 5241 | mutex_lock(&priv->mutex); |
| 5242 | iwl4965_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5243 | mutex_unlock(&priv->mutex); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5244 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5245 | } |
| 5246 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5247 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5248 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5249 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5250 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5251 | if (!iwl_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5252 | return; |
| 5253 | |
| 5254 | mutex_lock(&priv->mutex); |
| 5255 | |
| 5256 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5257 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5258 | |
| 5259 | mutex_unlock(&priv->mutex); |
| 5260 | } |
| 5261 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5262 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 5263 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5264 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5265 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5266 | struct iwl_priv *priv = |
| 5267 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5268 | |
| 5269 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 5270 | |
| 5271 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5272 | return; |
| 5273 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 5274 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
| 5275 | iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5276 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5277 | ieee80211_scan_completed(priv->hw); |
| 5278 | |
| 5279 | /* Since setting the TXPOWER may have been deferred while |
| 5280 | * performing the scan, fire one off */ |
| 5281 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5282 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5283 | mutex_unlock(&priv->mutex); |
| 5284 | } |
| 5285 | |
| 5286 | /***************************************************************************** |
| 5287 | * |
| 5288 | * mac80211 entry point functions |
| 5289 | * |
| 5290 | *****************************************************************************/ |
| 5291 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5292 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 5293 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5294 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5295 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5296 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5297 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5298 | |
| 5299 | IWL_DEBUG_MAC80211("enter\n"); |
| 5300 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5301 | if (pci_enable_device(priv->pci_dev)) { |
| 5302 | IWL_ERROR("Fail to pci_enable_device\n"); |
| 5303 | return -ENODEV; |
| 5304 | } |
| 5305 | pci_restore_state(priv->pci_dev); |
| 5306 | pci_enable_msi(priv->pci_dev); |
| 5307 | |
| 5308 | ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, |
| 5309 | DRV_NAME, priv); |
| 5310 | if (ret) { |
| 5311 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 5312 | goto out_disable_msi; |
| 5313 | } |
| 5314 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5315 | /* we should be verifying the device is ready to be opened */ |
| 5316 | mutex_lock(&priv->mutex); |
| 5317 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5318 | memset(&priv->staging_rxon, 0, sizeof(struct iwl4965_rxon_cmd)); |
| 5319 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 5320 | * ucode filename and max sizes are card-specific. */ |
| 5321 | |
| 5322 | if (!priv->ucode_code.len) { |
| 5323 | ret = iwl4965_read_ucode(priv); |
| 5324 | if (ret) { |
| 5325 | IWL_ERROR("Could not read microcode: %d\n", ret); |
| 5326 | mutex_unlock(&priv->mutex); |
| 5327 | goto out_release_irq; |
| 5328 | } |
| 5329 | } |
| 5330 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5331 | ret = __iwl4965_up(priv); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5332 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5333 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5334 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5335 | if (ret) |
| 5336 | goto out_release_irq; |
| 5337 | |
| 5338 | IWL_DEBUG_INFO("Start UP work done.\n"); |
| 5339 | |
| 5340 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 5341 | return 0; |
| 5342 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5343 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 5344 | * mac80211 will not be run successfully. */ |
| 5345 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 5346 | test_bit(STATUS_READY, &priv->status), |
| 5347 | UCODE_READY_TIMEOUT); |
| 5348 | if (!ret) { |
| 5349 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 5350 | IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n", |
| 5351 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 5352 | ret = -ETIMEDOUT; |
| 5353 | goto out_release_irq; |
| 5354 | } |
| 5355 | } |
| 5356 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5357 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5358 | IWL_DEBUG_MAC80211("leave\n"); |
| 5359 | return 0; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5360 | |
| 5361 | out_release_irq: |
| 5362 | free_irq(priv->pci_dev->irq, priv); |
| 5363 | out_disable_msi: |
| 5364 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5365 | pci_disable_device(priv->pci_dev); |
| 5366 | priv->is_open = 0; |
| 5367 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5368 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5369 | } |
| 5370 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5371 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5372 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5373 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5374 | |
| 5375 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5376 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5377 | if (!priv->is_open) { |
| 5378 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 5379 | return; |
| 5380 | } |
| 5381 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5382 | priv->is_open = 0; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5383 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5384 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5385 | /* stop mac, cancel any scan request and clear |
| 5386 | * RXON_FILTER_ASSOC_MSK BIT |
| 5387 | */ |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5388 | mutex_lock(&priv->mutex); |
| 5389 | iwl4965_scan_cancel_timeout(priv, 100); |
| 5390 | cancel_delayed_work(&priv->post_associate); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5391 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5392 | } |
| 5393 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5394 | iwl4965_down(priv); |
| 5395 | |
| 5396 | flush_workqueue(priv->workqueue); |
| 5397 | free_irq(priv->pci_dev->irq, priv); |
| 5398 | pci_disable_msi(priv->pci_dev); |
| 5399 | pci_save_state(priv->pci_dev); |
| 5400 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5401 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5402 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5403 | } |
| 5404 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5405 | 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] | 5406 | struct ieee80211_tx_control *ctl) |
| 5407 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5408 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5409 | |
| 5410 | IWL_DEBUG_MAC80211("enter\n"); |
| 5411 | |
| 5412 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 5413 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 5414 | return -1; |
| 5415 | } |
| 5416 | |
| 5417 | 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] | 5418 | ctl->tx_rate->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5419 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5420 | if (iwl4965_tx_skb(priv, skb, ctl)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5421 | dev_kfree_skb_any(skb); |
| 5422 | |
| 5423 | IWL_DEBUG_MAC80211("leave\n"); |
| 5424 | return 0; |
| 5425 | } |
| 5426 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5427 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5428 | struct ieee80211_if_init_conf *conf) |
| 5429 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5430 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5431 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5432 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5433 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5434 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5435 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5436 | if (priv->vif) { |
| 5437 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Reinette Chatre | 75849d2 | 2008-01-23 10:15:17 -0800 | [diff] [blame] | 5438 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5439 | } |
| 5440 | |
| 5441 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5442 | priv->vif = conf->vif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5443 | |
| 5444 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5445 | |
| 5446 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 5447 | |
| 5448 | if (conf->mac_addr) { |
| 5449 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 5450 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 5451 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5452 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5453 | if (iwl_is_ready(priv)) |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5454 | iwl4965_set_mode(priv, conf->type); |
| 5455 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5456 | mutex_unlock(&priv->mutex); |
| 5457 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5458 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5459 | return 0; |
| 5460 | } |
| 5461 | |
| 5462 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5463 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5464 | * |
| 5465 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 5466 | * be set inappropriately and the driver currently sets the hardware up to |
| 5467 | * use it whenever needed. |
| 5468 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5469 | 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] | 5470 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5471 | struct iwl_priv *priv = hw->priv; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5472 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5473 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5474 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5475 | |
| 5476 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5477 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5478 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 5479 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
| 5480 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5481 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5482 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5483 | ret = -EIO; |
| 5484 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5485 | } |
| 5486 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 5487 | if (unlikely(!priv->cfg->mod_params->disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5488 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 5489 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 5490 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5491 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 5492 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5493 | } |
| 5494 | |
| 5495 | spin_lock_irqsave(&priv->lock, flags); |
| 5496 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 5497 | ch_info = iwl_get_channel_info(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5498 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5499 | if (!is_channel_valid(ch_info)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5500 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 5501 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5502 | ret = -EINVAL; |
| 5503 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5504 | } |
| 5505 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5506 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5507 | /* if we are switching from ht to 2.4 clear flags |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5508 | * from any ht related info since 2.4 does not |
| 5509 | * support ht */ |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5510 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5511 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 5512 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 5513 | #endif |
| 5514 | ) |
| 5515 | priv->staging_rxon.flags = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5516 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5517 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5518 | iwl_set_rxon_channel(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5519 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5520 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5521 | iwl4965_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5522 | |
| 5523 | /* The list of supported rates and rate mask can be different |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5524 | * for each band; since the band may have changed, reset |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5525 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5526 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5527 | |
| 5528 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5529 | |
| 5530 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 5531 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5532 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5533 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5534 | } |
| 5535 | #endif |
| 5536 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 5537 | if (priv->cfg->ops->lib->radio_kill_sw) |
| 5538 | priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5539 | |
| 5540 | if (!conf->radio_enabled) { |
| 5541 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5542 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5543 | } |
| 5544 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5545 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5546 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5547 | ret = -EIO; |
| 5548 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5549 | } |
| 5550 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5551 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5552 | |
| 5553 | if (memcmp(&priv->active_rxon, |
| 5554 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5555 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5556 | else |
| 5557 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 5558 | |
| 5559 | IWL_DEBUG_MAC80211("leave\n"); |
| 5560 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 5561 | out: |
| 5562 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5563 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5564 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5565 | } |
| 5566 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5567 | static void iwl4965_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5568 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5569 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5570 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 5571 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5572 | return; |
| 5573 | |
| 5574 | /* The following should be done only at AP bring up */ |
| 5575 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 5576 | |
| 5577 | /* RXON - unassoc (to set timing command) */ |
| 5578 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5579 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5580 | |
| 5581 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5582 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 5583 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5584 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5585 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5586 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5587 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 5588 | "Attempting to continue.\n"); |
| 5589 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5590 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5591 | |
| 5592 | /* FIXME: what should be the assoc_id for AP? */ |
| 5593 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 5594 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 5595 | priv->staging_rxon.flags |= |
| 5596 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5597 | else |
| 5598 | priv->staging_rxon.flags &= |
| 5599 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5600 | |
| 5601 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 5602 | if (priv->assoc_capability & |
| 5603 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 5604 | priv->staging_rxon.flags |= |
| 5605 | RXON_FLG_SHORT_SLOT_MSK; |
| 5606 | else |
| 5607 | priv->staging_rxon.flags &= |
| 5608 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 5609 | |
| 5610 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 5611 | priv->staging_rxon.flags &= |
| 5612 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 5613 | } |
| 5614 | /* restore RXON assoc */ |
| 5615 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5616 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5617 | iwl4965_activate_qos(priv, 1); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5618 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 5619 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5620 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5621 | |
| 5622 | /* FIXME - we need to add code here to detect a totally new |
| 5623 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 5624 | * clear sta table, add BCAST sta... */ |
| 5625 | } |
| 5626 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5627 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, |
| 5628 | struct ieee80211_vif *vif, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5629 | struct ieee80211_if_conf *conf) |
| 5630 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5631 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5632 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5633 | unsigned long flags; |
| 5634 | int rc; |
| 5635 | |
| 5636 | if (conf == NULL) |
| 5637 | return -EIO; |
| 5638 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 5639 | if (priv->vif != vif) { |
| 5640 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 5641 | return 0; |
| 5642 | } |
| 5643 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5644 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 5645 | (!conf->beacon || !conf->ssid_len)) { |
| 5646 | IWL_DEBUG_MAC80211 |
| 5647 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 5648 | return 0; |
| 5649 | } |
| 5650 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5651 | if (!iwl_is_alive(priv)) |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5652 | return -EAGAIN; |
| 5653 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5654 | mutex_lock(&priv->mutex); |
| 5655 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5656 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5657 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 5658 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5659 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 5660 | /* |
| 5661 | * very dubious code was here; the probe filtering flag is never set: |
| 5662 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5663 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 5664 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 5665 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5666 | |
| 5667 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 5668 | if (!conf->bssid) { |
| 5669 | conf->bssid = priv->mac_addr; |
| 5670 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5671 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 5672 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5673 | } |
| 5674 | if (priv->ibss_beacon) |
| 5675 | dev_kfree_skb(priv->ibss_beacon); |
| 5676 | |
| 5677 | priv->ibss_beacon = conf->beacon; |
| 5678 | } |
| 5679 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5680 | if (iwl_is_rfkill(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5681 | goto done; |
| 5682 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5683 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 5684 | !is_multicast_ether_addr(conf->bssid)) { |
| 5685 | /* If there is currently a HW scan going on in the background |
| 5686 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5687 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5688 | IWL_WARNING("Aborted scan still in progress " |
| 5689 | "after 100ms\n"); |
| 5690 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 5691 | mutex_unlock(&priv->mutex); |
| 5692 | return -EAGAIN; |
| 5693 | } |
| 5694 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 5695 | |
| 5696 | /* TODO: Audit driver for usage of these members and see |
| 5697 | * if mac80211 deprecates them (priv->bssid looks like it |
| 5698 | * shouldn't be there, but I haven't scanned the IBSS code |
| 5699 | * to verify) - jpk */ |
| 5700 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 5701 | |
| 5702 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5703 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5704 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5705 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5706 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5707 | iwl4965_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5708 | priv, priv->active_rxon.bssid_addr, 1); |
| 5709 | } |
| 5710 | |
| 5711 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5712 | iwl4965_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5713 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5714 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5715 | } |
| 5716 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5717 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5718 | spin_lock_irqsave(&priv->lock, flags); |
| 5719 | if (!conf->ssid_len) |
| 5720 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 5721 | else |
| 5722 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 5723 | |
| 5724 | priv->essid_len = conf->ssid_len; |
| 5725 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5726 | |
| 5727 | IWL_DEBUG_MAC80211("leave\n"); |
| 5728 | mutex_unlock(&priv->mutex); |
| 5729 | |
| 5730 | return 0; |
| 5731 | } |
| 5732 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5733 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 5734 | unsigned int changed_flags, |
| 5735 | unsigned int *total_flags, |
| 5736 | int mc_count, struct dev_addr_list *mc_list) |
| 5737 | { |
| 5738 | /* |
| 5739 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5740 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 5741 | */ |
| 5742 | *total_flags = 0; |
| 5743 | } |
| 5744 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5745 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5746 | struct ieee80211_if_init_conf *conf) |
| 5747 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5748 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5749 | |
| 5750 | IWL_DEBUG_MAC80211("enter\n"); |
| 5751 | |
| 5752 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5753 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5754 | if (iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5755 | iwl4965_scan_cancel_timeout(priv, 100); |
| 5756 | cancel_delayed_work(&priv->post_associate); |
| 5757 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 5758 | iwl4965_commit_rxon(priv); |
| 5759 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5760 | if (priv->vif == conf->vif) { |
| 5761 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5762 | memset(priv->bssid, 0, ETH_ALEN); |
| 5763 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 5764 | priv->essid_len = 0; |
| 5765 | } |
| 5766 | mutex_unlock(&priv->mutex); |
| 5767 | |
| 5768 | IWL_DEBUG_MAC80211("leave\n"); |
| 5769 | |
| 5770 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5771 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5772 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5773 | static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, |
| 5774 | struct ieee80211_vif *vif, |
| 5775 | struct ieee80211_bss_conf *bss_conf, |
| 5776 | u32 changes) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5777 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5778 | struct iwl_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5779 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5780 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
| 5781 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5782 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5783 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
| 5784 | bss_conf->use_short_preamble); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5785 | if (bss_conf->use_short_preamble) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5786 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5787 | else |
| 5788 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5789 | } |
| 5790 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5791 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5792 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5793 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5794 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 5795 | else |
| 5796 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 5797 | } |
| 5798 | |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 5799 | if (changes & BSS_CHANGED_HT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5800 | IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 5801 | iwl4965_ht_conf(priv, bss_conf); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5802 | iwl_set_rxon_chain(priv); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 5803 | } |
| 5804 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5805 | if (changes & BSS_CHANGED_ASSOC) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5806 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5807 | /* This should never happen as this function should |
| 5808 | * never be called from interrupt context. */ |
| 5809 | if (WARN_ON_ONCE(in_interrupt())) |
| 5810 | return; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5811 | if (bss_conf->assoc) { |
| 5812 | priv->assoc_id = bss_conf->aid; |
| 5813 | priv->beacon_int = bss_conf->beacon_int; |
| 5814 | priv->timestamp = bss_conf->timestamp; |
| 5815 | priv->assoc_capability = bss_conf->assoc_capability; |
| 5816 | priv->next_scan_jiffies = jiffies + |
| 5817 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5818 | mutex_lock(&priv->mutex); |
| 5819 | iwl4965_post_associate(priv); |
| 5820 | mutex_unlock(&priv->mutex); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5821 | } else { |
| 5822 | priv->assoc_id = 0; |
| 5823 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); |
| 5824 | } |
| 5825 | } else if (changes && iwl_is_associated(priv) && priv->assoc_id) { |
| 5826 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 5827 | iwl_send_rxon_assoc(priv); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5828 | } |
| 5829 | |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5830 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5831 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5832 | 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] | 5833 | { |
| 5834 | int rc = 0; |
| 5835 | unsigned long flags; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5836 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5837 | |
| 5838 | IWL_DEBUG_MAC80211("enter\n"); |
| 5839 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5840 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5841 | spin_lock_irqsave(&priv->lock, flags); |
| 5842 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5843 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5844 | rc = -EIO; |
| 5845 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 5846 | goto out_unlock; |
| 5847 | } |
| 5848 | |
| 5849 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 5850 | rc = -EIO; |
| 5851 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 5852 | goto out_unlock; |
| 5853 | } |
| 5854 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5855 | /* we don't schedule scan within next_scan_jiffies period */ |
| 5856 | if (priv->next_scan_jiffies && |
| 5857 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 5858 | rc = -EAGAIN; |
| 5859 | goto out_unlock; |
| 5860 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5861 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5862 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 5863 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5864 | rc = -EAGAIN; |
| 5865 | goto out_unlock; |
| 5866 | } |
| 5867 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5868 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5869 | iwl4965_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5870 | |
| 5871 | priv->one_direct_scan = 1; |
| 5872 | priv->direct_ssid_len = (u8) |
| 5873 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 5874 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5875 | } else |
| 5876 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5877 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5878 | rc = iwl4965_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5879 | |
| 5880 | IWL_DEBUG_MAC80211("leave\n"); |
| 5881 | |
| 5882 | out_unlock: |
| 5883 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5884 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5885 | |
| 5886 | return rc; |
| 5887 | } |
| 5888 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5889 | static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 5890 | struct ieee80211_key_conf *keyconf, const u8 *addr, |
| 5891 | u32 iv32, u16 *phase1key) |
| 5892 | { |
| 5893 | struct iwl_priv *priv = hw->priv; |
| 5894 | u8 sta_id = IWL_INVALID_STATION; |
| 5895 | unsigned long flags; |
| 5896 | __le16 key_flags = 0; |
| 5897 | int i; |
| 5898 | DECLARE_MAC_BUF(mac); |
| 5899 | |
| 5900 | IWL_DEBUG_MAC80211("enter\n"); |
| 5901 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 5902 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5903 | if (sta_id == IWL_INVALID_STATION) { |
| 5904 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 5905 | print_mac(mac, addr)); |
| 5906 | return; |
| 5907 | } |
| 5908 | |
| 5909 | iwl4965_scan_cancel_timeout(priv, 100); |
| 5910 | |
| 5911 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); |
| 5912 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 5913 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 5914 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 5915 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5916 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 5917 | |
| 5918 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 5919 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5920 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 5921 | priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; |
| 5922 | |
| 5923 | for (i = 0; i < 5; i++) |
| 5924 | priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = |
| 5925 | cpu_to_le16(phase1key[i]); |
| 5926 | |
| 5927 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 5928 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 5929 | |
| 5930 | iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
| 5931 | |
| 5932 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 5933 | |
| 5934 | IWL_DEBUG_MAC80211("leave\n"); |
| 5935 | } |
| 5936 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5937 | 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] | 5938 | const u8 *local_addr, const u8 *addr, |
| 5939 | struct ieee80211_key_conf *key) |
| 5940 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5941 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5942 | DECLARE_MAC_BUF(mac); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5943 | int ret = 0; |
| 5944 | u8 sta_id = IWL_INVALID_STATION; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5945 | u8 is_default_wep_key = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5946 | |
| 5947 | IWL_DEBUG_MAC80211("enter\n"); |
| 5948 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 5949 | if (priv->hw_params.sw_crypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5950 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 5951 | return -EOPNOTSUPP; |
| 5952 | } |
| 5953 | |
| 5954 | if (is_zero_ether_addr(addr)) |
| 5955 | /* only support pairwise keys */ |
| 5956 | return -EOPNOTSUPP; |
| 5957 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 5958 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5959 | if (sta_id == IWL_INVALID_STATION) { |
| 5960 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 5961 | print_mac(mac, addr)); |
| 5962 | return -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5963 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5964 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5965 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5966 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5967 | iwl4965_scan_cancel_timeout(priv, 100); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5968 | mutex_unlock(&priv->mutex); |
| 5969 | |
| 5970 | /* If we are getting WEP group key and we didn't receive any key mapping |
| 5971 | * so far, we are in legacy wep mode (group key only), otherwise we are |
| 5972 | * in 1X mode. |
| 5973 | * In legacy wep mode, we use another host command to the uCode */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 5974 | if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id && |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5975 | priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 5976 | if (cmd == SET_KEY) |
| 5977 | is_default_wep_key = !priv->key_mapping_key; |
| 5978 | else |
| 5979 | is_default_wep_key = priv->default_wep_key; |
| 5980 | } |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5981 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5982 | switch (cmd) { |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5983 | case SET_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5984 | if (is_default_wep_key) |
| 5985 | ret = iwl_set_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5986 | else |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 5987 | ret = iwl_set_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5988 | |
| 5989 | IWL_DEBUG_MAC80211("enable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5990 | break; |
| 5991 | case DISABLE_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5992 | if (is_default_wep_key) |
| 5993 | ret = iwl_remove_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5994 | else |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 5995 | ret = iwl_remove_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5996 | |
| 5997 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5998 | break; |
| 5999 | default: |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 6000 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6001 | } |
| 6002 | |
| 6003 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6004 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 6005 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6006 | } |
| 6007 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 6008 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6009 | const struct ieee80211_tx_queue_params *params) |
| 6010 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6011 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6012 | unsigned long flags; |
| 6013 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6014 | |
| 6015 | IWL_DEBUG_MAC80211("enter\n"); |
| 6016 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6017 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6018 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 6019 | return -EIO; |
| 6020 | } |
| 6021 | |
| 6022 | if (queue >= AC_NUM) { |
| 6023 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 6024 | return 0; |
| 6025 | } |
| 6026 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6027 | if (!priv->qos_data.qos_enable) { |
| 6028 | priv->qos_data.qos_active = 0; |
| 6029 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 6030 | return 0; |
| 6031 | } |
| 6032 | q = AC_NUM - 1 - queue; |
| 6033 | |
| 6034 | spin_lock_irqsave(&priv->lock, flags); |
| 6035 | |
| 6036 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 6037 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 6038 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 6039 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 6040 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6041 | |
| 6042 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 6043 | priv->qos_data.qos_active = 1; |
| 6044 | |
| 6045 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6046 | |
| 6047 | mutex_lock(&priv->mutex); |
| 6048 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6049 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 6050 | else if (priv->assoc_id && iwl_is_associated(priv)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6051 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6052 | |
| 6053 | mutex_unlock(&priv->mutex); |
| 6054 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6055 | IWL_DEBUG_MAC80211("leave\n"); |
| 6056 | return 0; |
| 6057 | } |
| 6058 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6059 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6060 | struct ieee80211_tx_queue_stats *stats) |
| 6061 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6062 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6063 | int i, avail; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6064 | struct iwl4965_tx_queue *txq; |
| 6065 | struct iwl4965_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6066 | unsigned long flags; |
| 6067 | |
| 6068 | IWL_DEBUG_MAC80211("enter\n"); |
| 6069 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6070 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6071 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 6072 | return -EIO; |
| 6073 | } |
| 6074 | |
| 6075 | spin_lock_irqsave(&priv->lock, flags); |
| 6076 | |
| 6077 | for (i = 0; i < AC_NUM; i++) { |
| 6078 | txq = &priv->txq[i]; |
| 6079 | q = &txq->q; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6080 | avail = iwl4965_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6081 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 6082 | stats[i].len = q->n_window - avail; |
| 6083 | stats[i].limit = q->n_window - q->high_mark; |
| 6084 | stats[i].count = q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6085 | |
| 6086 | } |
| 6087 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6088 | |
| 6089 | IWL_DEBUG_MAC80211("leave\n"); |
| 6090 | |
| 6091 | return 0; |
| 6092 | } |
| 6093 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6094 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6095 | struct ieee80211_low_level_stats *stats) |
| 6096 | { |
| 6097 | IWL_DEBUG_MAC80211("enter\n"); |
| 6098 | IWL_DEBUG_MAC80211("leave\n"); |
| 6099 | |
| 6100 | return 0; |
| 6101 | } |
| 6102 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6103 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6104 | { |
| 6105 | IWL_DEBUG_MAC80211("enter\n"); |
| 6106 | IWL_DEBUG_MAC80211("leave\n"); |
| 6107 | |
| 6108 | return 0; |
| 6109 | } |
| 6110 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6111 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6112 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6113 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6114 | unsigned long flags; |
| 6115 | |
| 6116 | mutex_lock(&priv->mutex); |
| 6117 | IWL_DEBUG_MAC80211("enter\n"); |
| 6118 | |
| 6119 | priv->lq_mngr.lq_ready = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6120 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6121 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 6122 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6123 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6124 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6125 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 6126 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6127 | |
| 6128 | cancel_delayed_work(&priv->post_associate); |
| 6129 | |
| 6130 | spin_lock_irqsave(&priv->lock, flags); |
| 6131 | priv->assoc_id = 0; |
| 6132 | priv->assoc_capability = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6133 | priv->assoc_station_added = 0; |
| 6134 | |
| 6135 | /* new association get rid of ibss beacon skb */ |
| 6136 | if (priv->ibss_beacon) |
| 6137 | dev_kfree_skb(priv->ibss_beacon); |
| 6138 | |
| 6139 | priv->ibss_beacon = NULL; |
| 6140 | |
| 6141 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 6142 | priv->timestamp = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6143 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 6144 | priv->beacon_int = 0; |
| 6145 | |
| 6146 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6147 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6148 | if (!iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6149 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 6150 | mutex_unlock(&priv->mutex); |
| 6151 | return; |
| 6152 | } |
| 6153 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6154 | /* we are restarting association process |
| 6155 | * clear RXON_FILTER_ASSOC_MSK bit |
| 6156 | */ |
| 6157 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6158 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6159 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6160 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6161 | } |
| 6162 | |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 6163 | iwl_power_update_mode(priv, 0); |
| 6164 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6165 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 6166 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6167 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6168 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 6169 | mutex_unlock(&priv->mutex); |
| 6170 | return; |
| 6171 | } |
| 6172 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6173 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6174 | |
| 6175 | mutex_unlock(&priv->mutex); |
| 6176 | |
| 6177 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6178 | } |
| 6179 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6180 | 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] | 6181 | struct ieee80211_tx_control *control) |
| 6182 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6183 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6184 | unsigned long flags; |
| 6185 | |
| 6186 | mutex_lock(&priv->mutex); |
| 6187 | IWL_DEBUG_MAC80211("enter\n"); |
| 6188 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6189 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6190 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 6191 | mutex_unlock(&priv->mutex); |
| 6192 | return -EIO; |
| 6193 | } |
| 6194 | |
| 6195 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 6196 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 6197 | mutex_unlock(&priv->mutex); |
| 6198 | return -EIO; |
| 6199 | } |
| 6200 | |
| 6201 | spin_lock_irqsave(&priv->lock, flags); |
| 6202 | |
| 6203 | if (priv->ibss_beacon) |
| 6204 | dev_kfree_skb(priv->ibss_beacon); |
| 6205 | |
| 6206 | priv->ibss_beacon = skb; |
| 6207 | |
| 6208 | priv->assoc_id = 0; |
| 6209 | |
| 6210 | IWL_DEBUG_MAC80211("leave\n"); |
| 6211 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6212 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 6213 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6214 | |
| 6215 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 6216 | |
| 6217 | mutex_unlock(&priv->mutex); |
| 6218 | |
| 6219 | return 0; |
| 6220 | } |
| 6221 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6222 | /***************************************************************************** |
| 6223 | * |
| 6224 | * sysfs attributes |
| 6225 | * |
| 6226 | *****************************************************************************/ |
| 6227 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 6228 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6229 | |
| 6230 | /* |
| 6231 | * The following adds a new attribute to the sysfs representation |
| 6232 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 6233 | * used for controlling the debug level. |
| 6234 | * |
| 6235 | * See the level definitions in iwl for details. |
| 6236 | */ |
| 6237 | |
| 6238 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 6239 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 6240 | return sprintf(buf, "0x%08X\n", iwl_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6241 | } |
| 6242 | static ssize_t store_debug_level(struct device_driver *d, |
| 6243 | const char *buf, size_t count) |
| 6244 | { |
| 6245 | char *p = (char *)buf; |
| 6246 | u32 val; |
| 6247 | |
| 6248 | val = simple_strtoul(p, &p, 0); |
| 6249 | if (p == buf) |
| 6250 | printk(KERN_INFO DRV_NAME |
| 6251 | ": %s is not in hex or decimal form.\n", buf); |
| 6252 | else |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 6253 | iwl_debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6254 | |
| 6255 | return strnlen(buf, count); |
| 6256 | } |
| 6257 | |
| 6258 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 6259 | show_debug_level, store_debug_level); |
| 6260 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 6261 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6262 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6263 | |
| 6264 | static ssize_t show_temperature(struct device *d, |
| 6265 | struct device_attribute *attr, char *buf) |
| 6266 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6267 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6268 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6269 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6270 | return -EAGAIN; |
| 6271 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6272 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6273 | } |
| 6274 | |
| 6275 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 6276 | |
| 6277 | static ssize_t show_rs_window(struct device *d, |
| 6278 | struct device_attribute *attr, |
| 6279 | char *buf) |
| 6280 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6281 | struct iwl_priv *priv = d->driver_data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6282 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6283 | } |
| 6284 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 6285 | |
| 6286 | static ssize_t show_tx_power(struct device *d, |
| 6287 | struct device_attribute *attr, char *buf) |
| 6288 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6289 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6290 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 6291 | } |
| 6292 | |
| 6293 | static ssize_t store_tx_power(struct device *d, |
| 6294 | struct device_attribute *attr, |
| 6295 | const char *buf, size_t count) |
| 6296 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6297 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6298 | char *p = (char *)buf; |
| 6299 | u32 val; |
| 6300 | |
| 6301 | val = simple_strtoul(p, &p, 10); |
| 6302 | if (p == buf) |
| 6303 | printk(KERN_INFO DRV_NAME |
| 6304 | ": %s is not in decimal form.\n", buf); |
| 6305 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6306 | iwl4965_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6307 | |
| 6308 | return count; |
| 6309 | } |
| 6310 | |
| 6311 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 6312 | |
| 6313 | static ssize_t show_flags(struct device *d, |
| 6314 | struct device_attribute *attr, char *buf) |
| 6315 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6316 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6317 | |
| 6318 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 6319 | } |
| 6320 | |
| 6321 | static ssize_t store_flags(struct device *d, |
| 6322 | struct device_attribute *attr, |
| 6323 | const char *buf, size_t count) |
| 6324 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6325 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6326 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 6327 | |
| 6328 | mutex_lock(&priv->mutex); |
| 6329 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 6330 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6331 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6332 | IWL_WARNING("Could not cancel scan.\n"); |
| 6333 | else { |
| 6334 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 6335 | flags); |
| 6336 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6337 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6338 | } |
| 6339 | } |
| 6340 | mutex_unlock(&priv->mutex); |
| 6341 | |
| 6342 | return count; |
| 6343 | } |
| 6344 | |
| 6345 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 6346 | |
| 6347 | static ssize_t show_filter_flags(struct device *d, |
| 6348 | struct device_attribute *attr, char *buf) |
| 6349 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6350 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6351 | |
| 6352 | return sprintf(buf, "0x%04X\n", |
| 6353 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 6354 | } |
| 6355 | |
| 6356 | static ssize_t store_filter_flags(struct device *d, |
| 6357 | struct device_attribute *attr, |
| 6358 | const char *buf, size_t count) |
| 6359 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6360 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6361 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 6362 | |
| 6363 | mutex_lock(&priv->mutex); |
| 6364 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 6365 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6366 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6367 | IWL_WARNING("Could not cancel scan.\n"); |
| 6368 | else { |
| 6369 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 6370 | "0x%04X\n", filter_flags); |
| 6371 | priv->staging_rxon.filter_flags = |
| 6372 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6373 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6374 | } |
| 6375 | } |
| 6376 | mutex_unlock(&priv->mutex); |
| 6377 | |
| 6378 | return count; |
| 6379 | } |
| 6380 | |
| 6381 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 6382 | store_filter_flags); |
| 6383 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6384 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6385 | |
| 6386 | static ssize_t show_measurement(struct device *d, |
| 6387 | struct device_attribute *attr, char *buf) |
| 6388 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6389 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6390 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6391 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 6392 | u8 *data = (u8 *) & measure_report; |
| 6393 | unsigned long flags; |
| 6394 | |
| 6395 | spin_lock_irqsave(&priv->lock, flags); |
| 6396 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 6397 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6398 | return 0; |
| 6399 | } |
| 6400 | memcpy(&measure_report, &priv->measure_report, size); |
| 6401 | priv->measurement_status = 0; |
| 6402 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6403 | |
| 6404 | while (size && (PAGE_SIZE - len)) { |
| 6405 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 6406 | PAGE_SIZE - len, 1); |
| 6407 | len = strlen(buf); |
| 6408 | if (PAGE_SIZE - len) |
| 6409 | buf[len++] = '\n'; |
| 6410 | |
| 6411 | ofs += 16; |
| 6412 | size -= min(size, 16U); |
| 6413 | } |
| 6414 | |
| 6415 | return len; |
| 6416 | } |
| 6417 | |
| 6418 | static ssize_t store_measurement(struct device *d, |
| 6419 | struct device_attribute *attr, |
| 6420 | const char *buf, size_t count) |
| 6421 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6422 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6423 | struct ieee80211_measurement_params params = { |
| 6424 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 6425 | .start_time = cpu_to_le64(priv->last_tsf), |
| 6426 | .duration = cpu_to_le16(1), |
| 6427 | }; |
| 6428 | u8 type = IWL_MEASURE_BASIC; |
| 6429 | u8 buffer[32]; |
| 6430 | u8 channel; |
| 6431 | |
| 6432 | if (count) { |
| 6433 | char *p = buffer; |
| 6434 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 6435 | channel = simple_strtoul(p, NULL, 0); |
| 6436 | if (channel) |
| 6437 | params.channel = channel; |
| 6438 | |
| 6439 | p = buffer; |
| 6440 | while (*p && *p != ' ') |
| 6441 | p++; |
| 6442 | if (*p) |
| 6443 | type = simple_strtoul(p + 1, NULL, 0); |
| 6444 | } |
| 6445 | |
| 6446 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 6447 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6448 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6449 | |
| 6450 | return count; |
| 6451 | } |
| 6452 | |
| 6453 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 6454 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6455 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6456 | |
| 6457 | static ssize_t store_retry_rate(struct device *d, |
| 6458 | struct device_attribute *attr, |
| 6459 | const char *buf, size_t count) |
| 6460 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6461 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6462 | |
| 6463 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 6464 | if (priv->retry_rate <= 0) |
| 6465 | priv->retry_rate = 1; |
| 6466 | |
| 6467 | return count; |
| 6468 | } |
| 6469 | |
| 6470 | static ssize_t show_retry_rate(struct device *d, |
| 6471 | struct device_attribute *attr, char *buf) |
| 6472 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6473 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6474 | return sprintf(buf, "%d", priv->retry_rate); |
| 6475 | } |
| 6476 | |
| 6477 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 6478 | store_retry_rate); |
| 6479 | |
| 6480 | static ssize_t store_power_level(struct device *d, |
| 6481 | struct device_attribute *attr, |
| 6482 | const char *buf, size_t count) |
| 6483 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6484 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6485 | int rc; |
| 6486 | int mode; |
| 6487 | |
| 6488 | mode = simple_strtoul(buf, NULL, 0); |
| 6489 | mutex_lock(&priv->mutex); |
| 6490 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6491 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6492 | rc = -EAGAIN; |
| 6493 | goto out; |
| 6494 | } |
| 6495 | |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 6496 | rc = iwl_power_set_user_mode(priv, mode); |
| 6497 | if (rc) { |
| 6498 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 6499 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6500 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6501 | rc = count; |
| 6502 | |
| 6503 | out: |
| 6504 | mutex_unlock(&priv->mutex); |
| 6505 | return rc; |
| 6506 | } |
| 6507 | |
| 6508 | #define MAX_WX_STRING 80 |
| 6509 | |
| 6510 | /* Values are in microsecond */ |
| 6511 | static const s32 timeout_duration[] = { |
| 6512 | 350000, |
| 6513 | 250000, |
| 6514 | 75000, |
| 6515 | 37000, |
| 6516 | 25000, |
| 6517 | }; |
| 6518 | static const s32 period_duration[] = { |
| 6519 | 400000, |
| 6520 | 700000, |
| 6521 | 1000000, |
| 6522 | 1000000, |
| 6523 | 1000000 |
| 6524 | }; |
| 6525 | |
| 6526 | static ssize_t show_power_level(struct device *d, |
| 6527 | struct device_attribute *attr, char *buf) |
| 6528 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6529 | struct iwl_priv *priv = dev_get_drvdata(d); |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 6530 | int level = priv->power_data.power_mode; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6531 | char *p = buf; |
| 6532 | |
| 6533 | p += sprintf(p, "%d ", level); |
| 6534 | switch (level) { |
| 6535 | case IWL_POWER_MODE_CAM: |
| 6536 | case IWL_POWER_AC: |
| 6537 | p += sprintf(p, "(AC)"); |
| 6538 | break; |
| 6539 | case IWL_POWER_BATTERY: |
| 6540 | p += sprintf(p, "(BATTERY)"); |
| 6541 | break; |
| 6542 | default: |
| 6543 | p += sprintf(p, |
| 6544 | "(Timeout %dms, Period %dms)", |
| 6545 | timeout_duration[level - 1] / 1000, |
| 6546 | period_duration[level - 1] / 1000); |
| 6547 | } |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 6548 | /* |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6549 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 6550 | p += sprintf(p, " OFF\n"); |
| 6551 | else |
| 6552 | p += sprintf(p, " \n"); |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 6553 | */ |
| 6554 | p += sprintf(p, " \n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6555 | return (p - buf + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6556 | } |
| 6557 | |
| 6558 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 6559 | store_power_level); |
| 6560 | |
| 6561 | static ssize_t show_channels(struct device *d, |
| 6562 | struct device_attribute *attr, char *buf) |
| 6563 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6564 | /* all this shit doesn't belong into sysfs anyway */ |
| 6565 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6566 | } |
| 6567 | |
| 6568 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 6569 | |
| 6570 | static ssize_t show_statistics(struct device *d, |
| 6571 | struct device_attribute *attr, char *buf) |
| 6572 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6573 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6574 | u32 size = sizeof(struct iwl4965_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6575 | u32 len = 0, ofs = 0; |
| 6576 | u8 *data = (u8 *) & priv->statistics; |
| 6577 | int rc = 0; |
| 6578 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6579 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6580 | return -EAGAIN; |
| 6581 | |
| 6582 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 6583 | rc = iwl_send_statistics_request(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6584 | mutex_unlock(&priv->mutex); |
| 6585 | |
| 6586 | if (rc) { |
| 6587 | len = sprintf(buf, |
| 6588 | "Error sending statistics request: 0x%08X\n", rc); |
| 6589 | return len; |
| 6590 | } |
| 6591 | |
| 6592 | while (size && (PAGE_SIZE - len)) { |
| 6593 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 6594 | PAGE_SIZE - len, 1); |
| 6595 | len = strlen(buf); |
| 6596 | if (PAGE_SIZE - len) |
| 6597 | buf[len++] = '\n'; |
| 6598 | |
| 6599 | ofs += 16; |
| 6600 | size -= min(size, 16U); |
| 6601 | } |
| 6602 | |
| 6603 | return len; |
| 6604 | } |
| 6605 | |
| 6606 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 6607 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6608 | static ssize_t show_status(struct device *d, |
| 6609 | struct device_attribute *attr, char *buf) |
| 6610 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6611 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6612 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6613 | return -EAGAIN; |
| 6614 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 6615 | } |
| 6616 | |
| 6617 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 6618 | |
| 6619 | static ssize_t dump_error_log(struct device *d, |
| 6620 | struct device_attribute *attr, |
| 6621 | const char *buf, size_t count) |
| 6622 | { |
| 6623 | char *p = (char *)buf; |
| 6624 | |
| 6625 | if (p[0] == '1') |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6626 | iwl4965_dump_nic_error_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6627 | |
| 6628 | return strnlen(buf, count); |
| 6629 | } |
| 6630 | |
| 6631 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 6632 | |
| 6633 | static ssize_t dump_event_log(struct device *d, |
| 6634 | struct device_attribute *attr, |
| 6635 | const char *buf, size_t count) |
| 6636 | { |
| 6637 | char *p = (char *)buf; |
| 6638 | |
| 6639 | if (p[0] == '1') |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6640 | iwl4965_dump_nic_event_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6641 | |
| 6642 | return strnlen(buf, count); |
| 6643 | } |
| 6644 | |
| 6645 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 6646 | |
| 6647 | /***************************************************************************** |
| 6648 | * |
| 6649 | * driver setup and teardown |
| 6650 | * |
| 6651 | *****************************************************************************/ |
| 6652 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6653 | static void iwl4965_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6654 | { |
| 6655 | priv->workqueue = create_workqueue(DRV_NAME); |
| 6656 | |
| 6657 | init_waitqueue_head(&priv->wait_command_queue); |
| 6658 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6659 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 6660 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 6661 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
| 6662 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); |
| 6663 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); |
| 6664 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); |
| 6665 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 6666 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
| 6667 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
| 6668 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start); |
| 6669 | INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start); |
| 6670 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6671 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6672 | iwl4965_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6673 | |
| 6674 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6675 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6676 | } |
| 6677 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6678 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6679 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6680 | iwl4965_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6681 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 6682 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6683 | cancel_delayed_work(&priv->scan_check); |
| 6684 | cancel_delayed_work(&priv->alive_start); |
| 6685 | cancel_delayed_work(&priv->post_associate); |
| 6686 | cancel_work_sync(&priv->beacon_update); |
| 6687 | } |
| 6688 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6689 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6690 | &dev_attr_channels.attr, |
| 6691 | &dev_attr_dump_errors.attr, |
| 6692 | &dev_attr_dump_events.attr, |
| 6693 | &dev_attr_flags.attr, |
| 6694 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6695 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6696 | &dev_attr_measurement.attr, |
| 6697 | #endif |
| 6698 | &dev_attr_power_level.attr, |
| 6699 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6700 | &dev_attr_rs_window.attr, |
| 6701 | &dev_attr_statistics.attr, |
| 6702 | &dev_attr_status.attr, |
| 6703 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6704 | &dev_attr_tx_power.attr, |
| 6705 | |
| 6706 | NULL |
| 6707 | }; |
| 6708 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6709 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6710 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6711 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6712 | }; |
| 6713 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6714 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 6715 | .tx = iwl4965_mac_tx, |
| 6716 | .start = iwl4965_mac_start, |
| 6717 | .stop = iwl4965_mac_stop, |
| 6718 | .add_interface = iwl4965_mac_add_interface, |
| 6719 | .remove_interface = iwl4965_mac_remove_interface, |
| 6720 | .config = iwl4965_mac_config, |
| 6721 | .config_interface = iwl4965_mac_config_interface, |
| 6722 | .configure_filter = iwl4965_configure_filter, |
| 6723 | .set_key = iwl4965_mac_set_key, |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 6724 | .update_tkip_key = iwl4965_mac_update_tkip_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6725 | .get_stats = iwl4965_mac_get_stats, |
| 6726 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 6727 | .conf_tx = iwl4965_mac_conf_tx, |
| 6728 | .get_tsf = iwl4965_mac_get_tsf, |
| 6729 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 6730 | .beacon_update = iwl4965_mac_beacon_update, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 6731 | .bss_info_changed = iwl4965_bss_info_changed, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6732 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | 9ab4617 | 2007-12-25 17:00:38 +0200 | [diff] [blame] | 6733 | .ampdu_action = iwl4965_mac_ampdu_action, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6734 | #endif /* CONFIG_IWL4965_HT */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6735 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6736 | }; |
| 6737 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6738 | 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] | 6739 | { |
| 6740 | int err = 0; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6741 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6742 | struct ieee80211_hw *hw; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 6743 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6744 | unsigned long flags; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6745 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6746 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6747 | /************************ |
| 6748 | * 1. Allocating HW data |
| 6749 | ************************/ |
| 6750 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 6751 | /* Disabling hardware scan means that mac80211 will perform scans |
| 6752 | * "the hard way", rather than using device's scan. */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 6753 | if (cfg->mod_params->disable_hw_scan) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6754 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6755 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6756 | } |
| 6757 | |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 6758 | hw = iwl_alloc_all(cfg, &iwl4965_hw_ops); |
| 6759 | if (!hw) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6760 | err = -ENOMEM; |
| 6761 | goto out; |
| 6762 | } |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 6763 | priv = hw->priv; |
| 6764 | /* At this point both hw and priv are allocated. */ |
| 6765 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6766 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 6767 | |
| 6768 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 6769 | priv->cfg = cfg; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6770 | priv->pci_dev = pdev; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6771 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 6772 | #ifdef CONFIG_IWLWIFI_DEBUG |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 6773 | iwl_debug_level = priv->cfg->mod_params->debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6774 | atomic_set(&priv->restrict_refcnt, 0); |
| 6775 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6776 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6777 | /************************** |
| 6778 | * 2. Initializing PCI bus |
| 6779 | **************************/ |
| 6780 | if (pci_enable_device(pdev)) { |
| 6781 | err = -ENODEV; |
| 6782 | goto out_ieee80211_free_hw; |
| 6783 | } |
| 6784 | |
| 6785 | pci_set_master(pdev); |
| 6786 | |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 6787 | err = pci_set_dma_mask(pdev, DMA_64BIT_MASK); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6788 | if (!err) |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 6789 | err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); |
| 6790 | if (err) { |
| 6791 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 6792 | if (!err) |
| 6793 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 6794 | /* both attempts failed: */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6795 | if (err) { |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 6796 | printk(KERN_WARNING "%s: No suitable DMA available.\n", |
| 6797 | DRV_NAME); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6798 | goto out_pci_disable_device; |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 6799 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6800 | } |
| 6801 | |
| 6802 | err = pci_request_regions(pdev, DRV_NAME); |
| 6803 | if (err) |
| 6804 | goto out_pci_disable_device; |
| 6805 | |
| 6806 | pci_set_drvdata(pdev, priv); |
| 6807 | |
| 6808 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 6809 | * PCI Tx retries from interfering with C3 CPU state */ |
| 6810 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 6811 | |
| 6812 | /*********************** |
| 6813 | * 3. Read REV register |
| 6814 | ***********************/ |
| 6815 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 6816 | if (!priv->hw_base) { |
| 6817 | err = -ENODEV; |
| 6818 | goto out_pci_release_regions; |
| 6819 | } |
| 6820 | |
| 6821 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 6822 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 6823 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 6824 | |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 6825 | iwl_hw_detect(priv); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6826 | printk(KERN_INFO DRV_NAME |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 6827 | ": Detected Intel Wireless WiFi Link %s REV=0x%X\n", |
| 6828 | priv->cfg->name, priv->hw_rev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6829 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 6830 | /* amp init */ |
| 6831 | err = priv->cfg->ops->lib->apm_ops.init(priv); |
| 6832 | if (err < 0) { |
| 6833 | IWL_DEBUG_INFO("Failed to init APMG\n"); |
| 6834 | goto out_iounmap; |
| 6835 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6836 | /***************** |
| 6837 | * 4. Read EEPROM |
| 6838 | *****************/ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6839 | /* Read the EEPROM */ |
| 6840 | err = iwl_eeprom_init(priv); |
| 6841 | if (err) { |
| 6842 | IWL_ERROR("Unable to init EEPROM\n"); |
| 6843 | goto out_iounmap; |
| 6844 | } |
Tomas Winkler | 8614f36 | 2008-04-23 17:14:55 -0700 | [diff] [blame] | 6845 | err = iwl_eeprom_check_version(priv); |
| 6846 | if (err) |
| 6847 | goto out_iounmap; |
| 6848 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6849 | /* MAC Address location in EEPROM same for 3945/4965 */ |
| 6850 | iwl_eeprom_get_mac(priv, priv->mac_addr); |
| 6851 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); |
| 6852 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 6853 | |
| 6854 | /************************ |
| 6855 | * 5. Setup HW constants |
| 6856 | ************************/ |
| 6857 | /* Device-specific setup */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 6858 | if (priv->cfg->ops->lib->set_hw_params(priv)) { |
| 6859 | IWL_ERROR("failed to set hw parameters\n"); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 6860 | goto out_free_eeprom; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6861 | } |
| 6862 | |
| 6863 | /******************* |
| 6864 | * 6. Setup hw/priv |
| 6865 | *******************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6866 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6867 | err = iwl_setup(priv); |
| 6868 | if (err) |
Ron Rindjunsky | 399f4900 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 6869 | goto out_free_eeprom; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6870 | /* At this point both hw and priv are initialized. */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6871 | |
| 6872 | /********************************** |
| 6873 | * 7. Initialize module parameters |
| 6874 | **********************************/ |
| 6875 | |
| 6876 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 6877 | if (priv->cfg->mod_params->disable) { |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6878 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 6879 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 6880 | } |
| 6881 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 6882 | if (priv->cfg->mod_params->enable_qos) |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6883 | priv->qos_data.qos_enable = 1; |
| 6884 | |
| 6885 | /******************** |
| 6886 | * 8. Setup services |
| 6887 | ********************/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6888 | spin_lock_irqsave(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6889 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6890 | spin_unlock_irqrestore(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6891 | |
| 6892 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
| 6893 | if (err) { |
| 6894 | IWL_ERROR("failed to create sysfs device attributes\n"); |
Ron Rindjunsky | 399f4900 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 6895 | goto out_free_eeprom; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6896 | } |
| 6897 | |
| 6898 | err = iwl_dbgfs_register(priv, DRV_NAME); |
| 6899 | if (err) { |
| 6900 | IWL_ERROR("failed to create debugfs files\n"); |
| 6901 | goto out_remove_sysfs; |
| 6902 | } |
| 6903 | |
| 6904 | iwl4965_setup_deferred_work(priv); |
| 6905 | iwl4965_setup_rx_handlers(priv); |
| 6906 | |
| 6907 | /******************** |
| 6908 | * 9. Conclude |
| 6909 | ********************/ |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6910 | pci_save_state(pdev); |
| 6911 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6912 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 6913 | /* notify iwlcore to init */ |
| 6914 | iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6915 | return 0; |
| 6916 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6917 | out_remove_sysfs: |
| 6918 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 6919 | out_free_eeprom: |
| 6920 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6921 | out_iounmap: |
| 6922 | pci_iounmap(pdev, priv->hw_base); |
| 6923 | out_pci_release_regions: |
| 6924 | pci_release_regions(pdev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6925 | pci_set_drvdata(pdev, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6926 | out_pci_disable_device: |
| 6927 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6928 | out_ieee80211_free_hw: |
| 6929 | ieee80211_free_hw(priv->hw); |
| 6930 | out: |
| 6931 | return err; |
| 6932 | } |
| 6933 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 6934 | static void __devexit iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6935 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6936 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6937 | struct list_head *p, *q; |
| 6938 | int i; |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6939 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6940 | |
| 6941 | if (!priv) |
| 6942 | return; |
| 6943 | |
| 6944 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 6945 | |
Ron Rindjunsky | c4f5523 | 2008-03-28 16:21:10 -0700 | [diff] [blame] | 6946 | if (priv->mac80211_registered) { |
| 6947 | ieee80211_unregister_hw(priv->hw); |
| 6948 | priv->mac80211_registered = 0; |
| 6949 | } |
| 6950 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6951 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 6952 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6953 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6954 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6955 | /* make sure we flush any pending irq or |
| 6956 | * tasklet for the driver |
| 6957 | */ |
| 6958 | spin_lock_irqsave(&priv->lock, flags); |
| 6959 | iwl4965_disable_interrupts(priv); |
| 6960 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6961 | |
| 6962 | iwl_synchronize_irq(priv); |
| 6963 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6964 | /* Free MAC hash list for ADHOC */ |
| 6965 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 6966 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 6967 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6968 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6969 | } |
| 6970 | } |
| 6971 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 6972 | iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 6973 | iwl_dbgfs_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6974 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6975 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6976 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6977 | |
| 6978 | if (priv->rxq.bd) |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 6979 | iwl_rx_queue_free(priv, &priv->rxq); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6980 | iwl4965_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6981 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6982 | iwlcore_clear_stations_table(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 6983 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6984 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6985 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 6986 | /*netif_stop_queue(dev); */ |
| 6987 | flush_workqueue(priv->workqueue); |
| 6988 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6989 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6990 | * priv->workqueue... so we can't take down the workqueue |
| 6991 | * until now... */ |
| 6992 | destroy_workqueue(priv->workqueue); |
| 6993 | priv->workqueue = NULL; |
| 6994 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6995 | pci_iounmap(pdev, priv->hw_base); |
| 6996 | pci_release_regions(pdev); |
| 6997 | pci_disable_device(pdev); |
| 6998 | pci_set_drvdata(pdev, NULL); |
| 6999 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 7000 | iwl_free_channel_map(priv); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 7001 | iwlcore_free_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7002 | |
| 7003 | if (priv->ibss_beacon) |
| 7004 | dev_kfree_skb(priv->ibss_beacon); |
| 7005 | |
| 7006 | ieee80211_free_hw(priv->hw); |
| 7007 | } |
| 7008 | |
| 7009 | #ifdef CONFIG_PM |
| 7010 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7011 | 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] | 7012 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7013 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7014 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7015 | if (priv->is_open) { |
| 7016 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 7017 | iwl4965_mac_stop(priv->hw); |
| 7018 | priv->is_open = 1; |
| 7019 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7020 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7021 | pci_set_power_state(pdev, PCI_D3hot); |
| 7022 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7023 | return 0; |
| 7024 | } |
| 7025 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7026 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7027 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7028 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7029 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7030 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7031 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7032 | if (priv->is_open) |
| 7033 | iwl4965_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7034 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7035 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7036 | return 0; |
| 7037 | } |
| 7038 | |
| 7039 | #endif /* CONFIG_PM */ |
| 7040 | |
| 7041 | /***************************************************************************** |
| 7042 | * |
| 7043 | * driver and module entry point |
| 7044 | * |
| 7045 | *****************************************************************************/ |
| 7046 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7047 | /* Hardware specific file defines the PCI IDs table for that hardware module */ |
| 7048 | static struct pci_device_id iwl_hw_card_ids[] = { |
| 7049 | {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)}, |
| 7050 | {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)}, |
Tomas Winkler | 5a6a256 | 2008-04-24 11:55:23 -0700 | [diff] [blame] | 7051 | #ifdef CONFIG_IWL5000 |
| 7052 | {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)}, |
| 7053 | {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)}, |
| 7054 | {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)}, |
| 7055 | #endif /* CONFIG_IWL5000 */ |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7056 | {0} |
| 7057 | }; |
| 7058 | MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); |
| 7059 | |
| 7060 | static struct pci_driver iwl_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7061 | .name = DRV_NAME, |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7062 | .id_table = iwl_hw_card_ids, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7063 | .probe = iwl4965_pci_probe, |
| 7064 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7065 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7066 | .suspend = iwl4965_pci_suspend, |
| 7067 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7068 | #endif |
| 7069 | }; |
| 7070 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7071 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7072 | { |
| 7073 | |
| 7074 | int ret; |
| 7075 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 7076 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7077 | |
| 7078 | ret = iwl4965_rate_control_register(); |
| 7079 | if (ret) { |
| 7080 | IWL_ERROR("Unable to register rate control algorithm: %d\n", ret); |
| 7081 | return ret; |
| 7082 | } |
| 7083 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7084 | ret = pci_register_driver(&iwl_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7085 | if (ret) { |
| 7086 | IWL_ERROR("Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7087 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7088 | } |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 7089 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7090 | ret = driver_create_file(&iwl_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7091 | if (ret) { |
| 7092 | IWL_ERROR("Unable to create driver sysfs file\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7093 | goto error_debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7094 | } |
| 7095 | #endif |
| 7096 | |
| 7097 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7098 | |
| 7099 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 7100 | error_debug: |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7101 | pci_unregister_driver(&iwl_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7102 | #endif |
| 7103 | error_register: |
| 7104 | iwl4965_rate_control_unregister(); |
| 7105 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7106 | } |
| 7107 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7108 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7109 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 7110 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7111 | driver_remove_file(&iwl_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7112 | #endif |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7113 | pci_unregister_driver(&iwl_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7114 | iwl4965_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7115 | } |
| 7116 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7117 | module_exit(iwl4965_exit); |
| 7118 | module_init(iwl4965_init); |