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" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 49 | #include "iwl-4965.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 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 102 | static const struct ieee80211_supported_band *iwl4965_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; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 436 | struct iwl4965_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 | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 882 | void iwl4965_update_chain_flags(struct iwl_priv *priv) |
| 883 | { |
| 884 | |
| 885 | iwl4965_set_rxon_chain(priv); |
| 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 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1076 | static u8 iwl4965_rate_get_lowest_plcp(int rate_mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1077 | { |
| 1078 | u8 i; |
| 1079 | |
| 1080 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1081 | i = iwl4965_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1082 | if (rate_mask & (1 << i)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1083 | return iwl4965_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | return IWL_RATE_INVALID; |
| 1087 | } |
| 1088 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1089 | static int iwl4965_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1090 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1091 | struct iwl4965_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1092 | unsigned int frame_size; |
| 1093 | int rc; |
| 1094 | u8 rate; |
| 1095 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1096 | frame = iwl4965_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1097 | |
| 1098 | if (!frame) { |
| 1099 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 1100 | "command.\n"); |
| 1101 | return -ENOMEM; |
| 1102 | } |
| 1103 | |
| 1104 | if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1105 | rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1106 | 0xFF0); |
| 1107 | if (rate == IWL_INVALID_RATE) |
| 1108 | rate = IWL_RATE_6M_PLCP; |
| 1109 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1110 | rate = iwl4965_rate_get_lowest_plcp(priv->active_rate_basic & 0xF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1111 | if (rate == IWL_INVALID_RATE) |
| 1112 | rate = IWL_RATE_1M_PLCP; |
| 1113 | } |
| 1114 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1115 | frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1116 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1117 | rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1118 | &frame->u.cmd[0]); |
| 1119 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1120 | iwl4965_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1121 | |
| 1122 | return rc; |
| 1123 | } |
| 1124 | |
| 1125 | /****************************************************************************** |
| 1126 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1127 | * Misc. internal state and helper functions |
| 1128 | * |
| 1129 | ******************************************************************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1130 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1131 | static void iwl4965_unset_hw_params(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1132 | { |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 1133 | if (priv->shared_virt) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1134 | pci_free_consistent(priv->pci_dev, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1135 | sizeof(struct iwl4965_shared), |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 1136 | priv->shared_virt, |
| 1137 | priv->shared_phys); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1141 | * 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] | 1142 | * |
| 1143 | * return : set the bit for each supported rate insert in ie |
| 1144 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1145 | static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1146 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1147 | { |
| 1148 | u16 ret_rates = 0, bit; |
| 1149 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1150 | u8 *cnt = ie; |
| 1151 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1152 | |
| 1153 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1154 | if (bit & supported_rate) { |
| 1155 | ret_rates |= bit; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1156 | rates[*cnt] = iwl4965_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1157 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1158 | (*cnt)++; |
| 1159 | (*left)--; |
| 1160 | if ((*left <= 0) || |
| 1161 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1162 | break; |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | return ret_rates; |
| 1167 | } |
| 1168 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1169 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1170 | * 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] | 1171 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1172 | static u16 iwl4965_fill_probe_req(struct iwl_priv *priv, |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1173 | enum ieee80211_band band, |
| 1174 | struct ieee80211_mgmt *frame, |
| 1175 | int left, int is_direct) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1176 | { |
| 1177 | int len = 0; |
| 1178 | u8 *pos = NULL; |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1179 | u16 active_rates, ret_rates, cck_rates, active_rate_basic; |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1180 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1181 | const struct ieee80211_supported_band *sband = |
| 1182 | iwl4965_get_hw_mode(priv, band); |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1183 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1184 | |
| 1185 | /* Make sure there is enough space for the probe request, |
| 1186 | * two mandatory IEs and the data */ |
| 1187 | left -= 24; |
| 1188 | if (left < 0) |
| 1189 | return 0; |
| 1190 | len += 24; |
| 1191 | |
| 1192 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1193 | memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1194 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1195 | memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1196 | frame->seq_ctrl = 0; |
| 1197 | |
| 1198 | /* fill in our indirect SSID IE */ |
| 1199 | /* ...next IE... */ |
| 1200 | |
| 1201 | left -= 2; |
| 1202 | if (left < 0) |
| 1203 | return 0; |
| 1204 | len += 2; |
| 1205 | pos = &(frame->u.probe_req.variable[0]); |
| 1206 | *pos++ = WLAN_EID_SSID; |
| 1207 | *pos++ = 0; |
| 1208 | |
| 1209 | /* fill in our direct SSID IE... */ |
| 1210 | if (is_direct) { |
| 1211 | /* ...next IE... */ |
| 1212 | left -= 2 + priv->essid_len; |
| 1213 | if (left < 0) |
| 1214 | return 0; |
| 1215 | /* ... fill it in... */ |
| 1216 | *pos++ = WLAN_EID_SSID; |
| 1217 | *pos++ = priv->essid_len; |
| 1218 | memcpy(pos, priv->essid, priv->essid_len); |
| 1219 | pos += priv->essid_len; |
| 1220 | len += 2 + priv->essid_len; |
| 1221 | } |
| 1222 | |
| 1223 | /* fill in supported rate */ |
| 1224 | /* ...next IE... */ |
| 1225 | left -= 2; |
| 1226 | if (left < 0) |
| 1227 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1228 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1229 | /* ... fill it in... */ |
| 1230 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1231 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1232 | |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1233 | /* exclude 60M rate */ |
| 1234 | active_rates = priv->rates_mask; |
| 1235 | active_rates &= ~IWL_RATE_60M_MASK; |
| 1236 | |
| 1237 | active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1238 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1239 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1240 | ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1241 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1242 | active_rates &= ~ret_rates; |
| 1243 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1244 | ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1245 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1246 | active_rates &= ~ret_rates; |
| 1247 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1248 | len += 2 + *pos; |
| 1249 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1250 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1251 | goto fill_end; |
| 1252 | |
| 1253 | /* fill in supported extended rate */ |
| 1254 | /* ...next IE... */ |
| 1255 | left -= 2; |
| 1256 | if (left < 0) |
| 1257 | return 0; |
| 1258 | /* ... fill it in... */ |
| 1259 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1260 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1261 | iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1262 | active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1263 | if (*pos > 0) |
| 1264 | len += 2 + *pos; |
| 1265 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1266 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1267 | if (sband && sband->ht_info.ht_supported) { |
| 1268 | struct ieee80211_ht_cap *ht_cap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1269 | pos += (*pos) + 1; |
| 1270 | *pos++ = WLAN_EID_HT_CAPABILITY; |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1271 | *pos++ = sizeof(struct ieee80211_ht_cap); |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1272 | ht_cap = (struct ieee80211_ht_cap *)pos; |
| 1273 | ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap); |
| 1274 | memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16); |
| 1275 | ht_cap->ampdu_params_info =(sband->ht_info.ampdu_factor & |
| 1276 | IEEE80211_HT_CAP_AMPDU_FACTOR) | |
| 1277 | ((sband->ht_info.ampdu_density << 2) & |
| 1278 | IEEE80211_HT_CAP_AMPDU_DENSITY); |
Ron Rindjunsky | 8fb8803 | 2007-11-26 16:14:38 +0200 | [diff] [blame] | 1279 | len += 2 + sizeof(struct ieee80211_ht_cap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1280 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1281 | #endif /*CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1282 | |
| 1283 | fill_end: |
| 1284 | return (u16)len; |
| 1285 | } |
| 1286 | |
| 1287 | /* |
| 1288 | * QoS support |
| 1289 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1290 | static int iwl4965_send_qos_params_command(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1291 | struct iwl4965_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1292 | { |
| 1293 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1294 | return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1295 | sizeof(struct iwl4965_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1298 | static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1299 | { |
| 1300 | unsigned long flags; |
| 1301 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1302 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 1303 | return; |
| 1304 | |
| 1305 | if (!priv->qos_data.qos_enable) |
| 1306 | return; |
| 1307 | |
| 1308 | spin_lock_irqsave(&priv->lock, flags); |
| 1309 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 1310 | |
| 1311 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 1312 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 1313 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1314 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1315 | if (priv->qos_data.qos_active) |
| 1316 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1317 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 1318 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1319 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 1320 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1321 | 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] | 1322 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1323 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1324 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1325 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1326 | if (force || iwl_is_associated(priv)) { |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1327 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 1328 | priv->qos_data.qos_active, |
| 1329 | priv->qos_data.def_qos_parm.qos_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1330 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1331 | iwl4965_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1332 | &(priv->qos_data.def_qos_parm)); |
| 1333 | } |
| 1334 | } |
| 1335 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1336 | 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] | 1337 | { |
| 1338 | /* Filter incoming packets to determine if they are targeted toward |
| 1339 | * this network, discarding packets coming from ourselves */ |
| 1340 | switch (priv->iw_mode) { |
| 1341 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 1342 | /* packets from our adapter are dropped (echo) */ |
| 1343 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 1344 | return 0; |
| 1345 | /* {broad,multi}cast packets to our IBSS go through */ |
| 1346 | if (is_multicast_ether_addr(header->addr1)) |
| 1347 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 1348 | /* packets to our adapter go through */ |
| 1349 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 1350 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 1351 | /* packets from our adapter are dropped (echo) */ |
| 1352 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 1353 | return 0; |
| 1354 | /* {broad,multi}cast packets to our BSS go through */ |
| 1355 | if (is_multicast_ether_addr(header->addr1)) |
| 1356 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 1357 | /* packets to our adapter go through */ |
| 1358 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1359 | default: |
| 1360 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | return 1; |
| 1364 | } |
| 1365 | |
| 1366 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 1367 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1368 | static const char *iwl4965_get_tx_fail_reason(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1369 | { |
| 1370 | switch (status & TX_STATUS_MSK) { |
| 1371 | case TX_STATUS_SUCCESS: |
| 1372 | return "SUCCESS"; |
| 1373 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 1374 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 1375 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 1376 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 1377 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 1378 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 1379 | TX_STATUS_ENTRY(DEST_PS); |
| 1380 | TX_STATUS_ENTRY(ABORTED); |
| 1381 | TX_STATUS_ENTRY(BT_RETRY); |
| 1382 | TX_STATUS_ENTRY(STA_INVALID); |
| 1383 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 1384 | TX_STATUS_ENTRY(TID_DISABLE); |
| 1385 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 1386 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 1387 | TX_STATUS_ENTRY(TX_LOCKED); |
| 1388 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 1389 | } |
| 1390 | |
| 1391 | return "UNKNOWN"; |
| 1392 | } |
| 1393 | |
| 1394 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1395 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1396 | * |
| 1397 | * NOTE: priv->mutex is not required before calling this function |
| 1398 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1399 | static int iwl4965_scan_cancel(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1400 | { |
| 1401 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1402 | clear_bit(STATUS_SCANNING, &priv->status); |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
| 1406 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1407 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1408 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 1409 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1410 | queue_work(priv->workqueue, &priv->abort_scan); |
| 1411 | |
| 1412 | } else |
| 1413 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 1414 | |
| 1415 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1416 | } |
| 1417 | |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
| 1421 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1422 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1423 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 1424 | * |
| 1425 | * NOTE: priv->mutex must be held before calling this function |
| 1426 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1427 | 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] | 1428 | { |
| 1429 | unsigned long now = jiffies; |
| 1430 | int ret; |
| 1431 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1432 | ret = iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1433 | if (ret && ms) { |
| 1434 | mutex_unlock(&priv->mutex); |
| 1435 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 1436 | test_bit(STATUS_SCANNING, &priv->status)) |
| 1437 | msleep(1); |
| 1438 | mutex_lock(&priv->mutex); |
| 1439 | |
| 1440 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1441 | } |
| 1442 | |
| 1443 | return ret; |
| 1444 | } |
| 1445 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1446 | static void iwl4965_sequence_reset(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1447 | { |
| 1448 | /* Reset ieee stats */ |
| 1449 | |
| 1450 | /* We don't reset the net_device_stats (ieee->stats) on |
| 1451 | * re-association */ |
| 1452 | |
| 1453 | priv->last_seq_num = -1; |
| 1454 | priv->last_frag_num = -1; |
| 1455 | priv->last_packet_time = 0; |
| 1456 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1457 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 1461 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 1462 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1463 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1464 | { |
| 1465 | u16 new_val = 0; |
| 1466 | u16 beacon_factor = 0; |
| 1467 | |
| 1468 | beacon_factor = |
| 1469 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 1470 | / MAX_UCODE_BEACON_INTERVAL; |
| 1471 | new_val = beacon_val / beacon_factor; |
| 1472 | |
| 1473 | return cpu_to_le16(new_val); |
| 1474 | } |
| 1475 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1476 | static void iwl4965_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1477 | { |
| 1478 | u64 interval_tm_unit; |
| 1479 | u64 tsf, result; |
| 1480 | unsigned long flags; |
| 1481 | struct ieee80211_conf *conf = NULL; |
| 1482 | u16 beacon_int = 0; |
| 1483 | |
| 1484 | conf = ieee80211_get_hw_conf(priv->hw); |
| 1485 | |
| 1486 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1487 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32); |
| 1488 | priv->rxon_timing.timestamp.dw[0] = |
| 1489 | cpu_to_le32(priv->timestamp & 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1490 | |
| 1491 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 1492 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1493 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1494 | |
| 1495 | beacon_int = priv->beacon_int; |
| 1496 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1497 | |
| 1498 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 1499 | if (beacon_int == 0) { |
| 1500 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 1501 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 1502 | } else { |
| 1503 | priv->rxon_timing.beacon_interval = |
| 1504 | cpu_to_le16(beacon_int); |
| 1505 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1506 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1507 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1508 | } |
| 1509 | |
| 1510 | priv->rxon_timing.atim_window = 0; |
| 1511 | } else { |
| 1512 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1513 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1514 | /* TODO: we need to get atim_window from upper stack |
| 1515 | * for now we set to 0 */ |
| 1516 | priv->rxon_timing.atim_window = 0; |
| 1517 | } |
| 1518 | |
| 1519 | interval_tm_unit = |
| 1520 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 1521 | result = do_div(tsf, interval_tm_unit); |
| 1522 | priv->rxon_timing.beacon_init_val = |
| 1523 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 1524 | |
| 1525 | IWL_DEBUG_ASSOC |
| 1526 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 1527 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 1528 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 1529 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 1530 | } |
| 1531 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1532 | static int iwl4965_scan_initiate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1533 | { |
| 1534 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 1535 | IWL_ERROR("APs don't scan.\n"); |
| 1536 | return 0; |
| 1537 | } |
| 1538 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1539 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1540 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 1541 | return -EIO; |
| 1542 | } |
| 1543 | |
| 1544 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1545 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 1546 | return -EAGAIN; |
| 1547 | } |
| 1548 | |
| 1549 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1550 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 1551 | "Queuing.\n"); |
| 1552 | return -EAGAIN; |
| 1553 | } |
| 1554 | |
| 1555 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 1556 | priv->scan_bands = 2; |
| 1557 | set_bit(STATUS_SCANNING, &priv->status); |
| 1558 | priv->scan_start = jiffies; |
| 1559 | priv->scan_pass_start = priv->scan_start; |
| 1560 | |
| 1561 | queue_work(priv->workqueue, &priv->request_scan); |
| 1562 | |
| 1563 | return 0; |
| 1564 | } |
| 1565 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1566 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1567 | static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1568 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1569 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1570 | if (band == IEEE80211_BAND_5GHZ) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1571 | priv->staging_rxon.flags &= |
| 1572 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 1573 | | RXON_FLG_CCK_MSK); |
| 1574 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1575 | } else { |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 1576 | /* Copied from iwl4965_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1577 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 1578 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1579 | else |
| 1580 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1581 | |
| 1582 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 1583 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1584 | |
| 1585 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 1586 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 1587 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1592 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1593 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1594 | static void iwl4965_connection_init_rx_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1595 | { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1596 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1597 | |
| 1598 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 1599 | |
| 1600 | switch (priv->iw_mode) { |
| 1601 | case IEEE80211_IF_TYPE_AP: |
| 1602 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 1603 | break; |
| 1604 | |
| 1605 | case IEEE80211_IF_TYPE_STA: |
| 1606 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 1607 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 1608 | break; |
| 1609 | |
| 1610 | case IEEE80211_IF_TYPE_IBSS: |
| 1611 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 1612 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1613 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 1614 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1615 | break; |
| 1616 | |
| 1617 | case IEEE80211_IF_TYPE_MNTR: |
| 1618 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 1619 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 1620 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1621 | break; |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1622 | default: |
| 1623 | IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode); |
| 1624 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | #if 0 |
| 1628 | /* TODO: Figure out when short_preamble would be set and cache from |
| 1629 | * that */ |
| 1630 | if (!hw_to_local(priv->hw)->short_preamble) |
| 1631 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1632 | else |
| 1633 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1634 | #endif |
| 1635 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1636 | ch_info = iwl_get_channel_info(priv, priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1637 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1638 | |
| 1639 | if (!ch_info) |
| 1640 | ch_info = &priv->channel_info[0]; |
| 1641 | |
| 1642 | /* |
| 1643 | * in some case A channels are all non IBSS |
| 1644 | * in this case force B/G channel |
| 1645 | */ |
| 1646 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 1647 | !(is_channel_ibss(ch_info))) |
| 1648 | ch_info = &priv->channel_info[0]; |
| 1649 | |
| 1650 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1651 | priv->band = ch_info->band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1652 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1653 | iwl4965_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1654 | |
| 1655 | priv->staging_rxon.ofdm_basic_rates = |
| 1656 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1657 | priv->staging_rxon.cck_basic_rates = |
| 1658 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1659 | |
| 1660 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 1661 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 1662 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1663 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 1664 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 1665 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
| 1666 | iwl4965_set_rxon_chain(priv); |
| 1667 | } |
| 1668 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1669 | static int iwl4965_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1670 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1671 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1672 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1673 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1674 | ch_info = iwl_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1675 | priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1676 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1677 | |
| 1678 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 1679 | IWL_ERROR("channel %d not IBSS channel\n", |
| 1680 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1681 | return -EINVAL; |
| 1682 | } |
| 1683 | } |
| 1684 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1685 | priv->iw_mode = mode; |
| 1686 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1687 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1688 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1689 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1690 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1691 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1692 | /* dont commit rxon if rf-kill is on*/ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1693 | if (!iwl_is_ready_rf(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1694 | return -EAGAIN; |
| 1695 | |
| 1696 | cancel_delayed_work(&priv->scan_check); |
| 1697 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
| 1698 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 1699 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 1700 | return -EAGAIN; |
| 1701 | } |
| 1702 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1703 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1704 | |
| 1705 | return 0; |
| 1706 | } |
| 1707 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1708 | static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1709 | struct ieee80211_tx_control *ctl, |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1710 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1711 | struct sk_buff *skb_frag, |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 1712 | int sta_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1713 | { |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 1714 | struct iwl4965_hw_key *keyinfo = &priv->stations[sta_id].keyinfo; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1715 | struct iwl_wep_key *wepkey; |
| 1716 | int keyidx = 0; |
| 1717 | |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 1718 | BUG_ON(ctl->hw_key->hw_key_idx > 3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1719 | |
| 1720 | switch (keyinfo->alg) { |
| 1721 | case ALG_CCMP: |
| 1722 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM; |
| 1723 | memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen); |
Max Stepanov | 8236e18 | 2008-03-12 16:58:48 -0700 | [diff] [blame] | 1724 | if (ctl->flags & IEEE80211_TXCTL_AMPDU) |
| 1725 | cmd->cmd.tx.tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1726 | IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n"); |
| 1727 | break; |
| 1728 | |
| 1729 | case ALG_TKIP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1730 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP; |
Emmanuel Grumbach | 2bc7508 | 2008-03-19 16:41:45 -0700 | [diff] [blame] | 1731 | ieee80211_get_tkip_key(keyinfo->conf, skb_frag, |
| 1732 | IEEE80211_TKIP_P2_KEY, cmd->cmd.tx.key); |
| 1733 | IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1734 | break; |
| 1735 | |
| 1736 | case ALG_WEP: |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 1737 | wepkey = &priv->wep_keys[ctl->hw_key->hw_key_idx]; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1738 | cmd->cmd.tx.sec_ctl = 0; |
| 1739 | if (priv->default_wep_key) { |
| 1740 | /* the WEP key was sent as static */ |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 1741 | keyidx = ctl->hw_key->hw_key_idx; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1742 | memcpy(&cmd->cmd.tx.key[3], wepkey->key, |
| 1743 | wepkey->key_size); |
| 1744 | if (wepkey->key_size == WEP_KEY_LEN_128) |
| 1745 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
| 1746 | } else { |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 1747 | /* the WEP key was sent as dynamic */ |
| 1748 | keyidx = keyinfo->keyidx; |
| 1749 | memcpy(&cmd->cmd.tx.key[3], keyinfo->key, |
| 1750 | keyinfo->keylen); |
| 1751 | if (keyinfo->keylen == WEP_KEY_LEN_128) |
| 1752 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1753 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1754 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1755 | cmd->cmd.tx.sec_ctl |= (TX_CMD_SEC_WEP | |
| 1756 | (keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1757 | |
| 1758 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1759 | "with key %d\n", keyidx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1760 | break; |
| 1761 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1762 | default: |
| 1763 | printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg); |
| 1764 | break; |
| 1765 | } |
| 1766 | } |
| 1767 | |
| 1768 | /* |
| 1769 | * handle build REPLY_TX command notification. |
| 1770 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1771 | static void iwl4965_build_tx_cmd_basic(struct iwl_priv *priv, |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1772 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1773 | struct ieee80211_tx_control *ctrl, |
| 1774 | struct ieee80211_hdr *hdr, |
| 1775 | int is_unicast, u8 std_id) |
| 1776 | { |
| 1777 | __le16 *qc; |
| 1778 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 1779 | __le32 tx_flags = cmd->cmd.tx.tx_flags; |
| 1780 | |
| 1781 | cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 1782 | if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) { |
| 1783 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
| 1784 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 1785 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1786 | if (ieee80211_is_probe_response(fc) && |
| 1787 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 1788 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 1789 | } else { |
| 1790 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 1791 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1792 | } |
| 1793 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 1794 | if (ieee80211_is_back_request(fc)) |
| 1795 | tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK; |
| 1796 | |
| 1797 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1798 | cmd->cmd.tx.sta_id = std_id; |
| 1799 | if (ieee80211_get_morefrag(hdr)) |
| 1800 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 1801 | |
| 1802 | qc = ieee80211_get_qos_ctrl(hdr); |
| 1803 | if (qc) { |
| 1804 | cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf); |
| 1805 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
| 1806 | } else |
| 1807 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1808 | |
| 1809 | if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) { |
| 1810 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 1811 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
| 1812 | } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { |
| 1813 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 1814 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 1815 | } |
| 1816 | |
| 1817 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 1818 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 1819 | |
| 1820 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
| 1821 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { |
| 1822 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || |
| 1823 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1824 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1825 | else |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1826 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 1827 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1828 | cmd->cmd.tx.timeout.pm_frame_timeout = 0; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 1829 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1830 | |
| 1831 | cmd->cmd.tx.driver_txop = 0; |
| 1832 | cmd->cmd.tx.tx_flags = tx_flags; |
| 1833 | cmd->cmd.tx.next_frame_len = 0; |
| 1834 | } |
Tomas Winkler | 19758be | 2008-03-12 16:58:51 -0700 | [diff] [blame] | 1835 | static void iwl_update_tx_stats(struct iwl_priv *priv, u16 fc, u16 len) |
| 1836 | { |
| 1837 | /* 0 - mgmt, 1 - cnt, 2 - data */ |
| 1838 | int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2; |
| 1839 | priv->tx_stats[idx].cnt++; |
| 1840 | priv->tx_stats[idx].bytes += len; |
| 1841 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1842 | /** |
| 1843 | * iwl4965_get_sta_id - Find station's index within station table |
| 1844 | * |
| 1845 | * If new IBSS station, create new entry in station table |
| 1846 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1847 | static int iwl4965_get_sta_id(struct iwl_priv *priv, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1848 | struct ieee80211_hdr *hdr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1849 | { |
| 1850 | int sta_id; |
| 1851 | u16 fc = le16_to_cpu(hdr->frame_control); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1852 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1853 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1854 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1855 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 1856 | is_multicast_ether_addr(hdr->addr1)) |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1857 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1858 | |
| 1859 | switch (priv->iw_mode) { |
| 1860 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1861 | /* If we are a client station in a BSS network, use the special |
| 1862 | * AP station entry (that's the only station we communicate with) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1863 | case IEEE80211_IF_TYPE_STA: |
| 1864 | return IWL_AP_ID; |
| 1865 | |
| 1866 | /* If we are an AP, then find the station, or use BCAST */ |
| 1867 | case IEEE80211_IF_TYPE_AP: |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 1868 | sta_id = iwl_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1869 | if (sta_id != IWL_INVALID_STATION) |
| 1870 | return sta_id; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1871 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1872 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1873 | /* If this frame is going out to an IBSS network, find the station, |
| 1874 | * or create a new station table entry */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1875 | case IEEE80211_IF_TYPE_IBSS: |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 1876 | sta_id = iwl_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1877 | if (sta_id != IWL_INVALID_STATION) |
| 1878 | return sta_id; |
| 1879 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1880 | /* Create new station table entry */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 1881 | sta_id = iwl4965_add_station_flags(priv, hdr->addr1, |
| 1882 | 0, CMD_ASYNC, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1883 | |
| 1884 | if (sta_id != IWL_INVALID_STATION) |
| 1885 | return sta_id; |
| 1886 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1887 | IWL_DEBUG_DROP("Station %s not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1888 | "Defaulting to broadcast...\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1889 | print_mac(mac, hdr->addr1)); |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1890 | iwl_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1891 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1892 | |
| 1893 | default: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1894 | IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1895 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1896 | } |
| 1897 | } |
| 1898 | |
| 1899 | /* |
| 1900 | * start REPLY_TX command process |
| 1901 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1902 | static int iwl4965_tx_skb(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1903 | struct sk_buff *skb, struct ieee80211_tx_control *ctl) |
| 1904 | { |
| 1905 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1906 | struct iwl4965_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1907 | u32 *control_flags; |
| 1908 | int txq_id = ctl->queue; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1909 | struct iwl4965_tx_queue *txq = NULL; |
| 1910 | struct iwl4965_queue *q = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1911 | dma_addr_t phys_addr; |
| 1912 | dma_addr_t txcmd_phys; |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 1913 | dma_addr_t scratch_phys; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1914 | struct iwl_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1915 | u16 len, idx, len_org; |
| 1916 | u8 id, hdr_len, unicast; |
| 1917 | u8 sta_id; |
| 1918 | u16 seq_number = 0; |
| 1919 | u16 fc; |
| 1920 | __le16 *qc; |
| 1921 | u8 wait_write_ptr = 0; |
| 1922 | unsigned long flags; |
| 1923 | int rc; |
| 1924 | |
| 1925 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1926 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1927 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 1928 | goto drop_unlock; |
| 1929 | } |
| 1930 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 1931 | if (!priv->vif) { |
| 1932 | IWL_DEBUG_DROP("Dropping - !priv->vif\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1933 | goto drop_unlock; |
| 1934 | } |
| 1935 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1936 | if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1937 | IWL_ERROR("ERROR: No TX rate available.\n"); |
| 1938 | goto drop_unlock; |
| 1939 | } |
| 1940 | |
| 1941 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 1942 | id = 0; |
| 1943 | |
| 1944 | fc = le16_to_cpu(hdr->frame_control); |
| 1945 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1946 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1947 | if (ieee80211_is_auth(fc)) |
| 1948 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
| 1949 | else if (ieee80211_is_assoc_request(fc)) |
| 1950 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
| 1951 | else if (ieee80211_is_reassoc_request(fc)) |
| 1952 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 1953 | #endif |
| 1954 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 1955 | /* drop all data frame if we are not associated */ |
Gregory Greenman | 76f3915 | 2008-01-23 10:15:21 -0800 | [diff] [blame] | 1956 | if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) && |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1957 | (!iwl_is_associated(priv) || |
Reinette Chatre | a647724 | 2008-02-14 10:40:28 -0800 | [diff] [blame] | 1958 | ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id) || |
Gregory Greenman | 76f3915 | 2008-01-23 10:15:21 -0800 | [diff] [blame] | 1959 | !priv->assoc_station_added)) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1960 | IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1961 | goto drop_unlock; |
| 1962 | } |
| 1963 | |
| 1964 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1965 | |
| 1966 | hdr_len = ieee80211_get_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1967 | |
| 1968 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1969 | sta_id = iwl4965_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1970 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1971 | DECLARE_MAC_BUF(mac); |
| 1972 | |
| 1973 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n", |
| 1974 | print_mac(mac, hdr->addr1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1975 | goto drop; |
| 1976 | } |
| 1977 | |
| 1978 | IWL_DEBUG_RATE("station Id %d\n", sta_id); |
| 1979 | |
| 1980 | qc = ieee80211_get_qos_ctrl(hdr); |
| 1981 | if (qc) { |
| 1982 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 1983 | seq_number = priv->stations[sta_id].tid[tid].seq_number & |
| 1984 | IEEE80211_SCTL_SEQ; |
| 1985 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 1986 | (hdr->seq_ctrl & |
| 1987 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 1988 | seq_number += 0x10; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1989 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1990 | /* aggregation is on for this <sta,tid> */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1991 | if (ctl->flags & IEEE80211_TXCTL_AMPDU) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1992 | txq_id = priv->stations[sta_id].tid[tid].agg.txq_id; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1993 | priv->stations[sta_id].tid[tid].tfds_in_queue++; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1994 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1995 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1996 | |
| 1997 | /* Descriptor for chosen Tx queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1998 | txq = &priv->txq[txq_id]; |
| 1999 | q = &txq->q; |
| 2000 | |
| 2001 | spin_lock_irqsave(&priv->lock, flags); |
| 2002 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2003 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2004 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2005 | memset(tfd, 0, sizeof(*tfd)); |
| 2006 | control_flags = (u32 *) tfd; |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2007 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2008 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2009 | /* Set up driver data for this TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2010 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl4965_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2011 | txq->txb[q->write_ptr].skb[0] = skb; |
| 2012 | memcpy(&(txq->txb[q->write_ptr].status.control), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2013 | ctl, sizeof(struct ieee80211_tx_control)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2014 | |
| 2015 | /* 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] | 2016 | out_cmd = &txq->cmd[idx]; |
| 2017 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 2018 | memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2019 | |
| 2020 | /* |
| 2021 | * Set up the Tx-command (not MAC!) header. |
| 2022 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 2023 | * after Tx, uCode's Tx response will return this value so driver can |
| 2024 | * locate the frame within the tx queue and do post-tx processing. |
| 2025 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2026 | out_cmd->hdr.cmd = REPLY_TX; |
| 2027 | 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] | 2028 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2029 | |
| 2030 | /* Copy MAC header from skb into command buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2031 | memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); |
| 2032 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2033 | /* |
| 2034 | * Use the first empty entry in this queue's command buffer array |
| 2035 | * to contain the Tx command and MAC header concatenated together |
| 2036 | * (payload data will be in another buffer). |
| 2037 | * Size of this varies, due to varying MAC header length. |
| 2038 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 2039 | * of the MAC header (device reads on dword boundaries). |
| 2040 | * We'll tell device about this padding later. |
| 2041 | */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 2042 | len = priv->hw_params.tx_cmd_len + |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2043 | sizeof(struct iwl_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2044 | |
| 2045 | len_org = len; |
| 2046 | len = (len + 3) & ~3; |
| 2047 | |
| 2048 | if (len_org != len) |
| 2049 | len_org = 1; |
| 2050 | else |
| 2051 | len_org = 0; |
| 2052 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2053 | /* Physical address of this Tx command's header (not MAC header!), |
| 2054 | * within command buffer array. */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2055 | txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx + |
| 2056 | offsetof(struct iwl_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2057 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2058 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 2059 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2060 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2061 | |
| 2062 | if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 2063 | iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2064 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2065 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 2066 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2067 | len = skb->len - hdr_len; |
| 2068 | if (len) { |
| 2069 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 2070 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2071 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2074 | /* Tell 4965 about any 2-byte padding after MAC header */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2075 | if (len_org) |
| 2076 | out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK; |
| 2077 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2078 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2079 | len = (u16)skb->len; |
| 2080 | out_cmd->cmd.tx.len = cpu_to_le16(len); |
| 2081 | |
| 2082 | /* TODO need this for burst mode later on */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2083 | 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] | 2084 | |
| 2085 | /* set is_hcca to 0; it probably will never be implemented */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2086 | 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] | 2087 | |
Tomas Winkler | 19758be | 2008-03-12 16:58:51 -0700 | [diff] [blame] | 2088 | iwl_update_tx_stats(priv, fc, len); |
| 2089 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2090 | scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) + |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2091 | offsetof(struct iwl4965_tx_cmd, scratch); |
| 2092 | out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys); |
| 2093 | out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys); |
| 2094 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2095 | if (!ieee80211_get_morefrag(hdr)) { |
| 2096 | txq->need_update = 1; |
| 2097 | if (qc) { |
| 2098 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2099 | priv->stations[sta_id].tid[tid].seq_number = seq_number; |
| 2100 | } |
| 2101 | } else { |
| 2102 | wait_write_ptr = 1; |
| 2103 | txq->need_update = 0; |
| 2104 | } |
| 2105 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2106 | iwl_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2107 | sizeof(out_cmd->cmd.tx)); |
| 2108 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2109 | 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] | 2110 | ieee80211_get_hdrlen(fc)); |
| 2111 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2112 | /* Set up entry for this TFD in Tx byte-count array */ |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 2113 | priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2114 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2115 | /* Tell device the write index *just past* this latest filled TFD */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2116 | 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] | 2117 | rc = iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2118 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2119 | |
| 2120 | if (rc) |
| 2121 | return rc; |
| 2122 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2123 | if ((iwl4965_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2124 | && priv->mac80211_registered) { |
| 2125 | if (wait_write_ptr) { |
| 2126 | spin_lock_irqsave(&priv->lock, flags); |
| 2127 | txq->need_update = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2128 | iwl4965_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2129 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2130 | } |
| 2131 | |
| 2132 | ieee80211_stop_queue(priv->hw, ctl->queue); |
| 2133 | } |
| 2134 | |
| 2135 | return 0; |
| 2136 | |
| 2137 | drop_unlock: |
| 2138 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2139 | drop: |
| 2140 | return -1; |
| 2141 | } |
| 2142 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2143 | static void iwl4965_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2144 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2145 | const struct ieee80211_supported_band *hw = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2146 | struct ieee80211_rate *rate; |
| 2147 | int i; |
| 2148 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2149 | hw = iwl4965_get_hw_mode(priv, priv->band); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 2150 | if (!hw) { |
| 2151 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 2152 | return; |
| 2153 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2154 | |
| 2155 | priv->active_rate = 0; |
| 2156 | priv->active_rate_basic = 0; |
| 2157 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2158 | for (i = 0; i < hw->n_bitrates; i++) { |
| 2159 | rate = &(hw->bitrates[i]); |
| 2160 | if (rate->hw_value < IWL_RATE_COUNT) |
| 2161 | priv->active_rate |= (1 << rate->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 2165 | priv->active_rate, priv->active_rate_basic); |
| 2166 | |
| 2167 | /* |
| 2168 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 2169 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 2170 | * OFDM |
| 2171 | */ |
| 2172 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 2173 | priv->staging_rxon.cck_basic_rates = |
| 2174 | ((priv->active_rate_basic & |
| 2175 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2176 | else |
| 2177 | priv->staging_rxon.cck_basic_rates = |
| 2178 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2179 | |
| 2180 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 2181 | priv->staging_rxon.ofdm_basic_rates = |
| 2182 | ((priv->active_rate_basic & |
| 2183 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 2184 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2185 | else |
| 2186 | priv->staging_rxon.ofdm_basic_rates = |
| 2187 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2188 | } |
| 2189 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2190 | void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2191 | { |
| 2192 | unsigned long flags; |
| 2193 | |
| 2194 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 2195 | return; |
| 2196 | |
| 2197 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 2198 | disable_radio ? "OFF" : "ON"); |
| 2199 | |
| 2200 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2201 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2202 | /* FIXME: This is a workaround for AP */ |
| 2203 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 2204 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2205 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2206 | CSR_UCODE_SW_BIT_RFKILL); |
| 2207 | spin_unlock_irqrestore(&priv->lock, flags); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2208 | /* call the host command only if no hw rf-kill set */ |
Mohamed Abbas | 5900383 | 2008-04-15 16:01:46 -0700 | [diff] [blame] | 2209 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status) && |
| 2210 | iwl_is_ready(priv)) |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2211 | iwl4965_send_card_state(priv, |
| 2212 | CARD_STATE_CMD_DISABLE, |
| 2213 | 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2214 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2215 | |
| 2216 | /* make sure mac80211 stop sending Tx frame */ |
| 2217 | if (priv->mac80211_registered) |
| 2218 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2219 | } |
| 2220 | return; |
| 2221 | } |
| 2222 | |
| 2223 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2224 | 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] | 2225 | |
| 2226 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2227 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2228 | |
| 2229 | /* wake up ucode */ |
| 2230 | msleep(10); |
| 2231 | |
| 2232 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2233 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 2234 | if (!iwl_grab_nic_access(priv)) |
| 2235 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2236 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2237 | |
| 2238 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 2239 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 2240 | "disabled by HW switch\n"); |
| 2241 | return; |
| 2242 | } |
| 2243 | |
| 2244 | queue_work(priv->workqueue, &priv->restart); |
| 2245 | return; |
| 2246 | } |
| 2247 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2248 | #define IWL_PACKET_RETRY_TIME HZ |
| 2249 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2250 | 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] | 2251 | { |
| 2252 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 2253 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 2254 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 2255 | u16 *last_seq, *last_frag; |
| 2256 | unsigned long *last_time; |
| 2257 | |
| 2258 | switch (priv->iw_mode) { |
| 2259 | case IEEE80211_IF_TYPE_IBSS:{ |
| 2260 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2261 | struct iwl4965_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2262 | u8 *mac = header->addr2; |
| 2263 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 2264 | |
| 2265 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2266 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2267 | if (!compare_ether_addr(entry->mac, mac)) |
| 2268 | break; |
| 2269 | } |
| 2270 | if (p == &priv->ibss_mac_hash[index]) { |
| 2271 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 2272 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2273 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2274 | return 0; |
| 2275 | } |
| 2276 | memcpy(entry->mac, mac, ETH_ALEN); |
| 2277 | entry->seq_num = seq; |
| 2278 | entry->frag_num = frag; |
| 2279 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2280 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2281 | return 0; |
| 2282 | } |
| 2283 | last_seq = &entry->seq_num; |
| 2284 | last_frag = &entry->frag_num; |
| 2285 | last_time = &entry->packet_time; |
| 2286 | break; |
| 2287 | } |
| 2288 | case IEEE80211_IF_TYPE_STA: |
| 2289 | last_seq = &priv->last_seq_num; |
| 2290 | last_frag = &priv->last_frag_num; |
| 2291 | last_time = &priv->last_packet_time; |
| 2292 | break; |
| 2293 | default: |
| 2294 | return 0; |
| 2295 | } |
| 2296 | if ((*last_seq == seq) && |
| 2297 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 2298 | if (*last_frag == frag) |
| 2299 | goto drop; |
| 2300 | if (*last_frag + 1 != frag) |
| 2301 | /* out-of-order fragment */ |
| 2302 | goto drop; |
| 2303 | } else |
| 2304 | *last_seq = seq; |
| 2305 | |
| 2306 | *last_frag = frag; |
| 2307 | *last_time = jiffies; |
| 2308 | return 0; |
| 2309 | |
| 2310 | drop: |
| 2311 | return 1; |
| 2312 | } |
| 2313 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2314 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2315 | |
| 2316 | #include "iwl-spectrum.h" |
| 2317 | |
| 2318 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 2319 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 2320 | #define TIME_UNIT 1024 |
| 2321 | |
| 2322 | /* |
| 2323 | * extended beacon time format |
| 2324 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 2325 | * the high 1 byte is the beacon counts |
| 2326 | * the lower 3 bytes is the time in usec within one beacon interval |
| 2327 | */ |
| 2328 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2329 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2330 | { |
| 2331 | u32 quot; |
| 2332 | u32 rem; |
| 2333 | u32 interval = beacon_interval * 1024; |
| 2334 | |
| 2335 | if (!interval || !usec) |
| 2336 | return 0; |
| 2337 | |
| 2338 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 2339 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 2340 | |
| 2341 | return (quot << 24) + rem; |
| 2342 | } |
| 2343 | |
| 2344 | /* base is usually what we get from ucode with each received frame, |
| 2345 | * the same as HW timer counter counting down |
| 2346 | */ |
| 2347 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2348 | 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] | 2349 | { |
| 2350 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 2351 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 2352 | u32 interval = beacon_interval * TIME_UNIT; |
| 2353 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 2354 | (addon & BEACON_TIME_MASK_HIGH); |
| 2355 | |
| 2356 | if (base_low > addon_low) |
| 2357 | res += base_low - addon_low; |
| 2358 | else if (base_low < addon_low) { |
| 2359 | res += interval + base_low - addon_low; |
| 2360 | res += (1 << 24); |
| 2361 | } else |
| 2362 | res += (1 << 24); |
| 2363 | |
| 2364 | return cpu_to_le32(res); |
| 2365 | } |
| 2366 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2367 | static int iwl4965_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2368 | struct ieee80211_measurement_params *params, |
| 2369 | u8 type) |
| 2370 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2371 | struct iwl4965_spectrum_cmd spectrum; |
| 2372 | struct iwl4965_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2373 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2374 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 2375 | .data = (void *)&spectrum, |
| 2376 | .meta.flags = CMD_WANT_SKB, |
| 2377 | }; |
| 2378 | u32 add_time = le64_to_cpu(params->start_time); |
| 2379 | int rc; |
| 2380 | int spectrum_resp_status; |
| 2381 | int duration = le16_to_cpu(params->duration); |
| 2382 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2383 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2384 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2385 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2386 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 2387 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2388 | |
| 2389 | memset(&spectrum, 0, sizeof(spectrum)); |
| 2390 | |
| 2391 | spectrum.channel_count = cpu_to_le16(1); |
| 2392 | spectrum.flags = |
| 2393 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 2394 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 2395 | cmd.len = sizeof(spectrum); |
| 2396 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 2397 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2398 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2399 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2400 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2401 | add_time, |
| 2402 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2403 | else |
| 2404 | spectrum.start_time = 0; |
| 2405 | |
| 2406 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 2407 | spectrum.channels[0].channel = params->channel; |
| 2408 | spectrum.channels[0].type = type; |
| 2409 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 2410 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 2411 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 2412 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2413 | rc = iwl_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2414 | if (rc) |
| 2415 | return rc; |
| 2416 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2417 | res = (struct iwl4965_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2418 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 2419 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 2420 | rc = -EIO; |
| 2421 | } |
| 2422 | |
| 2423 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 2424 | switch (spectrum_resp_status) { |
| 2425 | case 0: /* Command will be handled */ |
| 2426 | if (res->u.spectrum.id != 0xff) { |
| 2427 | IWL_DEBUG_INFO |
| 2428 | ("Replaced existing measurement: %d\n", |
| 2429 | res->u.spectrum.id); |
| 2430 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 2431 | } |
| 2432 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 2433 | rc = 0; |
| 2434 | break; |
| 2435 | |
| 2436 | case 1: /* Command will not be handled */ |
| 2437 | rc = -EAGAIN; |
| 2438 | break; |
| 2439 | } |
| 2440 | |
| 2441 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 2442 | |
| 2443 | return rc; |
| 2444 | } |
| 2445 | #endif |
| 2446 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2447 | static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2448 | struct iwl4965_tx_info *tx_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2449 | { |
| 2450 | |
| 2451 | tx_sta->status.ack_signal = 0; |
| 2452 | tx_sta->status.excessive_retries = 0; |
| 2453 | tx_sta->status.queue_length = 0; |
| 2454 | tx_sta->status.queue_number = 0; |
| 2455 | |
| 2456 | if (in_interrupt()) |
| 2457 | ieee80211_tx_status_irqsafe(priv->hw, |
| 2458 | tx_sta->skb[0], &(tx_sta->status)); |
| 2459 | else |
| 2460 | ieee80211_tx_status(priv->hw, |
| 2461 | tx_sta->skb[0], &(tx_sta->status)); |
| 2462 | |
| 2463 | tx_sta->skb[0] = NULL; |
| 2464 | } |
| 2465 | |
| 2466 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2467 | * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2468 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2469 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 2470 | * need to be reclaimed. As result, some free space forms. If there is |
| 2471 | * enough free space (> low mark), wake the stack that feeds us. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2472 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2473 | 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] | 2474 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2475 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
| 2476 | struct iwl4965_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2477 | int nfreed = 0; |
| 2478 | |
| 2479 | if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) { |
| 2480 | IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " |
| 2481 | "is out of range [0-%d] %d %d.\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2482 | index, q->n_bd, q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2483 | return 0; |
| 2484 | } |
| 2485 | |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2486 | for (index = iwl_queue_inc_wrap(index, q->n_bd); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2487 | q->read_ptr != index; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2488 | 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] | 2489 | if (txq_id != IWL_CMD_QUEUE_NUM) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2490 | iwl4965_txstatus_to_ieee(priv, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2491 | &(txq->txb[txq->q.read_ptr])); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2492 | iwl4965_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2493 | } else if (nfreed > 1) { |
| 2494 | IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2495 | q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2496 | queue_work(priv->workqueue, &priv->restart); |
| 2497 | } |
| 2498 | nfreed++; |
| 2499 | } |
| 2500 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2501 | /* if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2502 | (txq_id != IWL_CMD_QUEUE_NUM) && |
| 2503 | priv->mac80211_registered) |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2504 | ieee80211_wake_queue(priv->hw, txq_id); */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2505 | |
| 2506 | |
| 2507 | return nfreed; |
| 2508 | } |
| 2509 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2510 | static int iwl4965_is_tx_success(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2511 | { |
| 2512 | status &= TX_STATUS_MSK; |
| 2513 | return (status == TX_STATUS_SUCCESS) |
| 2514 | || (status == TX_STATUS_DIRECT_DONE); |
| 2515 | } |
| 2516 | |
| 2517 | /****************************************************************************** |
| 2518 | * |
| 2519 | * Generic RX handler implementations |
| 2520 | * |
| 2521 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2522 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2523 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2524 | static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2525 | struct ieee80211_hdr *hdr) |
| 2526 | { |
| 2527 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) |
| 2528 | return IWL_AP_ID; |
| 2529 | else { |
| 2530 | u8 *da = ieee80211_get_DA(hdr); |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 2531 | return iwl_find_station(priv, da); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2532 | } |
| 2533 | } |
| 2534 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2535 | static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr( |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2536 | struct iwl_priv *priv, int txq_id, int idx) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2537 | { |
| 2538 | if (priv->txq[txq_id].txb[idx].skb[0]) |
| 2539 | return (struct ieee80211_hdr *)priv->txq[txq_id]. |
| 2540 | txb[idx].skb[0]->data; |
| 2541 | return NULL; |
| 2542 | } |
| 2543 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2544 | 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] | 2545 | { |
| 2546 | __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + |
| 2547 | tx_resp->frame_count); |
| 2548 | return le32_to_cpu(*scd_ssn) & MAX_SN; |
| 2549 | |
| 2550 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2551 | |
| 2552 | /** |
| 2553 | * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue |
| 2554 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2555 | static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2556 | struct iwl4965_ht_agg *agg, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2557 | struct iwl4965_tx_resp_agg *tx_resp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2558 | u16 start_idx) |
| 2559 | { |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2560 | u16 status; |
| 2561 | struct agg_tx_status *frame_status = &tx_resp->status; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2562 | struct ieee80211_tx_status *tx_status = NULL; |
| 2563 | struct ieee80211_hdr *hdr = NULL; |
| 2564 | int i, sh; |
| 2565 | int txq_id, idx; |
| 2566 | u16 seq; |
| 2567 | |
| 2568 | if (agg->wait_for_ba) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2569 | IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2570 | |
| 2571 | agg->frame_count = tx_resp->frame_count; |
| 2572 | agg->start_idx = start_idx; |
| 2573 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2574 | agg->bitmap = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2575 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2576 | /* # frames attempted by Tx command */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2577 | if (agg->frame_count == 1) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2578 | /* Only one frame was attempted; no block-ack will arrive */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2579 | status = le16_to_cpu(frame_status[0].status); |
| 2580 | seq = le16_to_cpu(frame_status[0].sequence); |
| 2581 | idx = SEQ_TO_INDEX(seq); |
| 2582 | txq_id = SEQ_TO_QUEUE(seq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2583 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2584 | /* FIXME: code repetition */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2585 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n", |
| 2586 | agg->frame_count, agg->start_idx, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2587 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2588 | tx_status = &(priv->txq[txq_id].txb[idx].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2589 | tx_status->retry_count = tx_resp->failure_frame; |
| 2590 | tx_status->queue_number = status & 0xff; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2591 | tx_status->queue_length = tx_resp->failure_rts; |
| 2592 | tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2593 | tx_status->flags = iwl4965_is_tx_success(status)? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2594 | IEEE80211_TX_STATUS_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 2595 | iwl4965_hwrate_to_tx_control(priv, |
| 2596 | le32_to_cpu(tx_resp->rate_n_flags), |
| 2597 | &tx_status->control); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2598 | /* FIXME: code repetition end */ |
| 2599 | |
| 2600 | IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", |
| 2601 | status & 0xff, tx_resp->failure_frame); |
| 2602 | IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2603 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2604 | |
| 2605 | agg->wait_for_ba = 0; |
| 2606 | } else { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2607 | /* Two or more frames were attempted; expect block-ack */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2608 | u64 bitmap = 0; |
| 2609 | int start = agg->start_idx; |
| 2610 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2611 | /* Construct bit-map of pending frames within Tx window */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2612 | for (i = 0; i < agg->frame_count; i++) { |
| 2613 | u16 sc; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2614 | status = le16_to_cpu(frame_status[i].status); |
| 2615 | seq = le16_to_cpu(frame_status[i].sequence); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2616 | idx = SEQ_TO_INDEX(seq); |
| 2617 | txq_id = SEQ_TO_QUEUE(seq); |
| 2618 | |
| 2619 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 2620 | AGG_TX_STATE_ABORT_MSK)) |
| 2621 | continue; |
| 2622 | |
| 2623 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
| 2624 | agg->frame_count, txq_id, idx); |
| 2625 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2626 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2627 | |
| 2628 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 2629 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
| 2630 | IWL_ERROR("BUG_ON idx doesn't match seq control" |
| 2631 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 2632 | idx, SEQ_TO_SN(sc), |
| 2633 | hdr->seq_ctrl); |
| 2634 | return -1; |
| 2635 | } |
| 2636 | |
| 2637 | IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
| 2638 | i, idx, SEQ_TO_SN(sc)); |
| 2639 | |
| 2640 | sh = idx - start; |
| 2641 | if (sh > 64) { |
| 2642 | sh = (start - idx) + 0xff; |
| 2643 | bitmap = bitmap << sh; |
| 2644 | sh = 0; |
| 2645 | start = idx; |
| 2646 | } else if (sh < -64) |
| 2647 | sh = 0xff - (start - idx); |
| 2648 | else if (sh < 0) { |
| 2649 | sh = start - idx; |
| 2650 | start = idx; |
| 2651 | bitmap = bitmap << sh; |
| 2652 | sh = 0; |
| 2653 | } |
| 2654 | bitmap |= (1 << sh); |
| 2655 | IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n", |
| 2656 | start, (u32)(bitmap & 0xFFFFFFFF)); |
| 2657 | } |
| 2658 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2659 | agg->bitmap = bitmap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2660 | agg->start_idx = start; |
| 2661 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2662 | 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] | 2663 | agg->frame_count, agg->start_idx, |
John W. Linville | 06501d2 | 2008-04-01 17:38:47 -0400 | [diff] [blame] | 2664 | (unsigned long long)agg->bitmap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2665 | |
| 2666 | if (bitmap) |
| 2667 | agg->wait_for_ba = 1; |
| 2668 | } |
| 2669 | return 0; |
| 2670 | } |
| 2671 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2672 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2673 | /** |
| 2674 | * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response |
| 2675 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2676 | static void iwl4965_rx_reply_tx(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2677 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2678 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2679 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2680 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 2681 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 2682 | int index = SEQ_TO_INDEX(sequence); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2683 | struct iwl4965_tx_queue *txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2684 | struct ieee80211_tx_status *tx_status; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2685 | struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2686 | u32 status = le32_to_cpu(tx_resp->status); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2687 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2688 | int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION; |
| 2689 | struct ieee80211_hdr *hdr; |
| 2690 | __le16 *qc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2691 | #endif |
| 2692 | |
| 2693 | if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) { |
| 2694 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 2695 | "is out of range [0-%d] %d %d\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2696 | index, txq->q.n_bd, txq->q.write_ptr, |
| 2697 | txq->q.read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2698 | return; |
| 2699 | } |
| 2700 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2701 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2702 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index); |
| 2703 | qc = ieee80211_get_qos_ctrl(hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2704 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2705 | if (qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2706 | tid = le16_to_cpu(*qc) & 0xf; |
| 2707 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2708 | sta_id = iwl4965_get_ra_sta_id(priv, hdr); |
| 2709 | if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) { |
| 2710 | IWL_ERROR("Station not known\n"); |
| 2711 | return; |
| 2712 | } |
| 2713 | |
| 2714 | if (txq->sched_retry) { |
| 2715 | const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp); |
| 2716 | struct iwl4965_ht_agg *agg = NULL; |
| 2717 | |
| 2718 | if (!qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2719 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2720 | |
| 2721 | agg = &priv->stations[sta_id].tid[tid].agg; |
| 2722 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2723 | iwl4965_tx_status_reply_tx(priv, agg, |
| 2724 | (struct iwl4965_tx_resp_agg *)tx_resp, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2725 | |
| 2726 | if ((tx_resp->frame_count == 1) && |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2727 | !iwl4965_is_tx_success(status)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2728 | /* TODO: send BAR */ |
| 2729 | } |
| 2730 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2731 | if (txq->q.read_ptr != (scd_ssn & 0xff)) { |
| 2732 | int freed; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2733 | index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2734 | IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " |
| 2735 | "%d index %d\n", scd_ssn , index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2736 | freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
| 2737 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 2738 | |
| 2739 | if (iwl4965_queue_space(&txq->q) > txq->q.low_mark && |
| 2740 | txq_id >= 0 && priv->mac80211_registered && |
| 2741 | agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) |
| 2742 | ieee80211_wake_queue(priv->hw, txq_id); |
| 2743 | |
| 2744 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2745 | } |
| 2746 | } else { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2747 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2748 | tx_status = &(txq->txb[txq->q.read_ptr].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2749 | |
| 2750 | tx_status->retry_count = tx_resp->failure_frame; |
| 2751 | tx_status->queue_number = status; |
| 2752 | tx_status->queue_length = tx_resp->bt_kill_count; |
| 2753 | tx_status->queue_length |= tx_resp->failure_rts; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2754 | tx_status->flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2755 | iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 2756 | iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags), |
| 2757 | &tx_status->control); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2758 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2759 | 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] | 2760 | "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2761 | status, le32_to_cpu(tx_resp->rate_n_flags), |
| 2762 | tx_resp->failure_frame); |
| 2763 | |
| 2764 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2765 | if (index != -1) { |
| 2766 | int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2767 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2768 | if (tid != MAX_TID_COUNT) |
| 2769 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 2770 | if (iwl4965_queue_space(&txq->q) > txq->q.low_mark && |
| 2771 | (txq_id >= 0) && |
| 2772 | priv->mac80211_registered) |
| 2773 | ieee80211_wake_queue(priv->hw, txq_id); |
| 2774 | if (tid != MAX_TID_COUNT) |
| 2775 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
| 2776 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2777 | } |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2778 | #ifdef CONFIG_IWL4965_HT |
| 2779 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2780 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2781 | |
| 2782 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 2783 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 2784 | } |
| 2785 | |
| 2786 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2787 | static void iwl4965_rx_reply_alive(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2788 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2789 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2790 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 2791 | struct iwl4965_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2792 | struct delayed_work *pwork; |
| 2793 | |
| 2794 | palive = &pkt->u.alive_frame; |
| 2795 | |
| 2796 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 2797 | "0x%01X 0x%01X\n", |
| 2798 | palive->is_valid, palive->ver_type, |
| 2799 | palive->ver_subtype); |
| 2800 | |
| 2801 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 2802 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 2803 | memcpy(&priv->card_alive_init, |
| 2804 | &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2805 | sizeof(struct iwl4965_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2806 | pwork = &priv->init_alive_start; |
| 2807 | } else { |
| 2808 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 2809 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2810 | sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2811 | pwork = &priv->alive_start; |
| 2812 | } |
| 2813 | |
| 2814 | /* We delay the ALIVE response by 5ms to |
| 2815 | * give the HW RF Kill time to activate... */ |
| 2816 | if (palive->is_valid == UCODE_VALID_OK) |
| 2817 | queue_delayed_work(priv->workqueue, pwork, |
| 2818 | msecs_to_jiffies(5)); |
| 2819 | else |
| 2820 | IWL_WARNING("uCode did not respond OK.\n"); |
| 2821 | } |
| 2822 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2823 | static void iwl4965_rx_reply_add_sta(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2824 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2825 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2826 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2827 | |
| 2828 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 2829 | return; |
| 2830 | } |
| 2831 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2832 | static void iwl4965_rx_reply_error(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2833 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2834 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2835 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2836 | |
| 2837 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 2838 | "seq 0x%04X ser 0x%08X\n", |
| 2839 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 2840 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 2841 | pkt->u.err_resp.cmd_id, |
| 2842 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 2843 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 2844 | } |
| 2845 | |
| 2846 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2847 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2848 | static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2849 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2850 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 2851 | struct iwl4965_rxon_cmd *rxon = (void *)&priv->active_rxon; |
| 2852 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2853 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 2854 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 2855 | rxon->channel = csa->channel; |
| 2856 | priv->staging_rxon.channel = csa->channel; |
| 2857 | } |
| 2858 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2859 | static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2860 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2861 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2862 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2863 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 2864 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2865 | |
| 2866 | if (!report->state) { |
| 2867 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 2868 | "Spectrum Measure Notification: Start\n"); |
| 2869 | return; |
| 2870 | } |
| 2871 | |
| 2872 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 2873 | priv->measurement_status |= MEASUREMENT_READY; |
| 2874 | #endif |
| 2875 | } |
| 2876 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2877 | static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2878 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2879 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2880 | #ifdef CONFIG_IWLWIFI_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2881 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 2882 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2883 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 2884 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 2885 | #endif |
| 2886 | } |
| 2887 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2888 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2889 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2890 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2891 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2892 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 2893 | "notification for %s:\n", |
| 2894 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2895 | 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] | 2896 | } |
| 2897 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2898 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2899 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2900 | struct iwl_priv *priv = |
| 2901 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2902 | struct sk_buff *beacon; |
| 2903 | |
| 2904 | /* 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] | 2905 | beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2906 | |
| 2907 | if (!beacon) { |
| 2908 | IWL_ERROR("update beacon failed\n"); |
| 2909 | return; |
| 2910 | } |
| 2911 | |
| 2912 | mutex_lock(&priv->mutex); |
| 2913 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 2914 | if (priv->ibss_beacon) |
| 2915 | dev_kfree_skb(priv->ibss_beacon); |
| 2916 | |
| 2917 | priv->ibss_beacon = beacon; |
| 2918 | mutex_unlock(&priv->mutex); |
| 2919 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2920 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2921 | } |
| 2922 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2923 | static void iwl4965_rx_beacon_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2924 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2925 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2926 | #ifdef CONFIG_IWLWIFI_DEBUG |
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_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 2929 | 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] | 2930 | |
| 2931 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 2932 | "tsf %d %d rate %d\n", |
| 2933 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 2934 | beacon->beacon_notify_hdr.failure_frame, |
| 2935 | le32_to_cpu(beacon->ibss_mgr_status), |
| 2936 | le32_to_cpu(beacon->high_tsf), |
| 2937 | le32_to_cpu(beacon->low_tsf), rate); |
| 2938 | #endif |
| 2939 | |
| 2940 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 2941 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 2942 | queue_work(priv->workqueue, &priv->beacon_update); |
| 2943 | } |
| 2944 | |
| 2945 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2946 | static void iwl4965_rx_reply_scan(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2947 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2948 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2949 | #ifdef CONFIG_IWLWIFI_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2950 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 2951 | struct iwl4965_scanreq_notification *notif = |
| 2952 | (struct iwl4965_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2953 | |
| 2954 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 2955 | #endif |
| 2956 | } |
| 2957 | |
| 2958 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2959 | static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2960 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2961 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2962 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 2963 | struct iwl4965_scanstart_notification *notif = |
| 2964 | (struct iwl4965_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2965 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 2966 | IWL_DEBUG_SCAN("Scan start: " |
| 2967 | "%d [802.11%s] " |
| 2968 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 2969 | notif->channel, |
| 2970 | notif->band ? "bg" : "a", |
| 2971 | notif->tsf_high, |
| 2972 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 2973 | } |
| 2974 | |
| 2975 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2976 | static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2977 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2978 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2979 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 2980 | struct iwl4965_scanresults_notification *notif = |
| 2981 | (struct iwl4965_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2982 | |
| 2983 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 2984 | "%d [802.11%s] " |
| 2985 | "(TSF: 0x%08X:%08X) - %d " |
| 2986 | "elapsed=%lu usec (%dms since last)\n", |
| 2987 | notif->channel, |
| 2988 | notif->band ? "bg" : "a", |
| 2989 | le32_to_cpu(notif->tsf_high), |
| 2990 | le32_to_cpu(notif->tsf_low), |
| 2991 | le32_to_cpu(notif->statistics[0]), |
| 2992 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 2993 | jiffies_to_msecs(elapsed_jiffies |
| 2994 | (priv->last_scan_jiffies, jiffies))); |
| 2995 | |
| 2996 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2997 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3001 | static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3002 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3003 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3004 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3005 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3006 | |
| 3007 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 3008 | scan_notif->scanned_channels, |
| 3009 | scan_notif->tsf_low, |
| 3010 | scan_notif->tsf_high, scan_notif->status); |
| 3011 | |
| 3012 | /* The HW is no longer scanning */ |
| 3013 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 3014 | |
| 3015 | /* The scan completion notification came in, so kill that timer... */ |
| 3016 | cancel_delayed_work(&priv->scan_check); |
| 3017 | |
| 3018 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 3019 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 3020 | jiffies_to_msecs(elapsed_jiffies |
| 3021 | (priv->scan_pass_start, jiffies))); |
| 3022 | |
| 3023 | /* Remove this scanned band from the list |
| 3024 | * of pending bands to scan */ |
| 3025 | priv->scan_bands--; |
| 3026 | |
| 3027 | /* If a request to abort was given, or the scan did not succeed |
| 3028 | * then we reset the scan state machine and terminate, |
| 3029 | * re-queuing another scan if one has been requested */ |
| 3030 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 3031 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 3032 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 3033 | } else { |
| 3034 | /* If there are more bands on this scan pass reschedule */ |
| 3035 | if (priv->scan_bands > 0) |
| 3036 | goto reschedule; |
| 3037 | } |
| 3038 | |
| 3039 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3040 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3041 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 3042 | |
| 3043 | clear_bit(STATUS_SCANNING, &priv->status); |
| 3044 | |
| 3045 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 3046 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 3047 | |
| 3048 | queue_work(priv->workqueue, &priv->scan_completed); |
| 3049 | |
| 3050 | return; |
| 3051 | |
| 3052 | reschedule: |
| 3053 | priv->scan_pass_start = jiffies; |
| 3054 | queue_work(priv->workqueue, &priv->request_scan); |
| 3055 | } |
| 3056 | |
| 3057 | /* Handle notification from uCode that card's power state is changing |
| 3058 | * due to software, hardware, or critical temperature RFKILL */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3059 | static void iwl4965_rx_card_state_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3060 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3061 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3062 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3063 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 3064 | unsigned long status = priv->status; |
| 3065 | |
| 3066 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 3067 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 3068 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 3069 | |
| 3070 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 3071 | RF_CARD_DISABLED)) { |
| 3072 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3073 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3074 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 3075 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3076 | if (!iwl_grab_nic_access(priv)) { |
| 3077 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3078 | priv, HBUS_TARG_MBX_C, |
| 3079 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 3080 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3081 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3082 | } |
| 3083 | |
| 3084 | if (!(flags & RXON_CARD_DISABLED)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3085 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3086 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3087 | if (!iwl_grab_nic_access(priv)) { |
| 3088 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3089 | priv, HBUS_TARG_MBX_C, |
| 3090 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 3091 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3092 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3093 | } |
| 3094 | } |
| 3095 | |
| 3096 | if (flags & RF_CARD_DISABLED) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3097 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3098 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3099 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 3100 | if (!iwl_grab_nic_access(priv)) |
| 3101 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3102 | } |
| 3103 | } |
| 3104 | |
| 3105 | if (flags & HW_CARD_DISABLED) |
| 3106 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3107 | else |
| 3108 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3109 | |
| 3110 | |
| 3111 | if (flags & SW_CARD_DISABLED) |
| 3112 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3113 | else |
| 3114 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3115 | |
| 3116 | if (!(flags & RXON_CARD_DISABLED)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3117 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3118 | |
| 3119 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 3120 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 3121 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 3122 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 3123 | queue_work(priv->workqueue, &priv->rf_kill); |
| 3124 | else |
| 3125 | wake_up_interruptible(&priv->wait_command_queue); |
| 3126 | } |
| 3127 | |
| 3128 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3129 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3130 | * |
| 3131 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 3132 | * to the host. |
| 3133 | * |
| 3134 | * This function chains into the hardware specific files for them to setup |
| 3135 | * any hardware specific handlers as well. |
| 3136 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3137 | static void iwl4965_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3138 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3139 | priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive; |
| 3140 | priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta; |
| 3141 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 3142 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3143 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3144 | iwl4965_rx_spectrum_measure_notif; |
| 3145 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3146 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3147 | iwl4965_rx_pm_debug_statistics_notif; |
| 3148 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3149 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3150 | /* |
| 3151 | * The same handler is used for both the REPLY to a discrete |
| 3152 | * statistics request from the host as well as for the periodic |
| 3153 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3154 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3155 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
| 3156 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3157 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3158 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
| 3159 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3160 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3161 | iwl4965_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3162 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3163 | iwl4965_rx_scan_complete_notif; |
| 3164 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
| 3165 | priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3166 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3167 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3168 | iwl4965_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3169 | } |
| 3170 | |
| 3171 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3172 | * 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] | 3173 | * @rxb: Rx buffer to reclaim |
| 3174 | * |
| 3175 | * If an Rx buffer has an async callback associated with it the callback |
| 3176 | * will be executed. The attached skb (if present) will only be freed |
| 3177 | * if the callback returns 1 |
| 3178 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3179 | static void iwl4965_tx_cmd_complete(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3180 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3181 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3182 | struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3183 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3184 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3185 | int index = SEQ_TO_INDEX(sequence); |
| 3186 | int huge = sequence & SEQ_HUGE_FRAME; |
| 3187 | int cmd_index; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3188 | struct iwl_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3189 | |
| 3190 | /* If a Tx command is being handled and it isn't in the actual |
| 3191 | * command queue then there a command routing bug has been introduced |
| 3192 | * in the queue management code. */ |
| 3193 | if (txq_id != IWL_CMD_QUEUE_NUM) |
| 3194 | IWL_ERROR("Error wrong command queue %d command id 0x%X\n", |
| 3195 | txq_id, pkt->hdr.cmd); |
| 3196 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 3197 | |
| 3198 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 3199 | cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
| 3200 | |
| 3201 | /* Input error checking is done when commands are added to queue. */ |
| 3202 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 3203 | cmd->meta.source->u.skb = rxb->skb; |
| 3204 | rxb->skb = NULL; |
| 3205 | } else if (cmd->meta.u.callback && |
| 3206 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 3207 | rxb->skb = NULL; |
| 3208 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3209 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3210 | |
| 3211 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 3212 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3213 | wake_up_interruptible(&priv->wait_command_queue); |
| 3214 | } |
| 3215 | } |
| 3216 | |
| 3217 | /************************** RX-FUNCTIONS ****************************/ |
| 3218 | /* |
| 3219 | * Rx theory of operation |
| 3220 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3221 | * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs), |
| 3222 | * each of which point to Receive Buffers to be filled by 4965. These get |
| 3223 | * used not only for Rx frames, but for any command response or notification |
| 3224 | * from the 4965. The driver and 4965 manage the Rx buffers by means |
| 3225 | * of indexes into the circular buffer. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3226 | * |
| 3227 | * Rx Queue Indexes |
| 3228 | * The host/firmware share two index registers for managing the Rx buffers. |
| 3229 | * |
| 3230 | * The READ index maps to the first position that the firmware may be writing |
| 3231 | * to -- the driver can read up to (but not including) this position and get |
| 3232 | * good data. |
| 3233 | * The READ index is managed by the firmware once the card is enabled. |
| 3234 | * |
| 3235 | * The WRITE index maps to the last position the driver has read from -- the |
| 3236 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 3237 | * |
| 3238 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 3239 | * WRITE = READ. |
| 3240 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3241 | * During initialization, the host sets up the READ queue position to the first |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3242 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 3243 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3244 | * When the firmware places a packet in a buffer, it will advance the READ index |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3245 | * and fire the RX interrupt. The driver can then query the READ index and |
| 3246 | * process as many packets as possible, moving the WRITE index forward as it |
| 3247 | * resets the Rx queue buffers with new memory. |
| 3248 | * |
| 3249 | * The management in the driver is as follows: |
| 3250 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 3251 | * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3252 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3253 | * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3254 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 3255 | * 'processed' and 'read' driver indexes as well) |
| 3256 | * + A received packet is processed and handed to the kernel network stack, |
| 3257 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 3258 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 3259 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 3260 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 3261 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 3262 | * |
| 3263 | * |
| 3264 | * Driver sequence: |
| 3265 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3266 | * iwl4965_rx_queue_alloc() Allocates rx_free |
| 3267 | * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3268 | * iwl4965_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3269 | * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3270 | * queue, updates firmware pointers, and updates |
| 3271 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3272 | * are available, schedules iwl4965_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3273 | * |
| 3274 | * -- enable interrupts -- |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3275 | * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3276 | * READ INDEX, detaching the SKB from the pool. |
| 3277 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3278 | * Calls iwl4965_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3279 | * slots. |
| 3280 | * ... |
| 3281 | * |
| 3282 | */ |
| 3283 | |
| 3284 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3285 | * iwl4965_rx_queue_space - Return number of free slots available in queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3286 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3287 | static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3288 | { |
| 3289 | int s = q->read - q->write; |
| 3290 | if (s <= 0) |
| 3291 | s += RX_QUEUE_SIZE; |
| 3292 | /* keep some buffer to not confuse full and empty queue */ |
| 3293 | s -= 2; |
| 3294 | if (s < 0) |
| 3295 | s = 0; |
| 3296 | return s; |
| 3297 | } |
| 3298 | |
| 3299 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3300 | * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3301 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3302 | int iwl4965_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl4965_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3303 | { |
| 3304 | u32 reg = 0; |
| 3305 | int rc = 0; |
| 3306 | unsigned long flags; |
| 3307 | |
| 3308 | spin_lock_irqsave(&q->lock, flags); |
| 3309 | |
| 3310 | if (q->need_update == 0) |
| 3311 | goto exit_unlock; |
| 3312 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3313 | /* If power-saving is in use, make sure device is awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3314 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3315 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3316 | |
| 3317 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3318 | iwl_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3319 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 3320 | goto exit_unlock; |
| 3321 | } |
| 3322 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3323 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3324 | if (rc) |
| 3325 | goto exit_unlock; |
| 3326 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3327 | /* Device expects a multiple of 8 */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3328 | iwl_write_direct32(priv, FH_RSCSR_CHNL0_WPTR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3329 | q->write & ~0x7); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3330 | iwl_release_nic_access(priv); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3331 | |
| 3332 | /* Else device is assumed to be awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3333 | } else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3334 | /* Device expects a multiple of 8 */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3335 | iwl_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3336 | |
| 3337 | |
| 3338 | q->need_update = 0; |
| 3339 | |
| 3340 | exit_unlock: |
| 3341 | spin_unlock_irqrestore(&q->lock, flags); |
| 3342 | return rc; |
| 3343 | } |
| 3344 | |
| 3345 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3346 | * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3347 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3348 | static inline __le32 iwl4965_dma_addr2rbd_ptr(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3349 | dma_addr_t dma_addr) |
| 3350 | { |
| 3351 | return cpu_to_le32((u32)(dma_addr >> 8)); |
| 3352 | } |
| 3353 | |
| 3354 | |
| 3355 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3356 | * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3357 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3358 | * If there are slots in the RX queue that need to be restocked, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3359 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3360 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3361 | * |
| 3362 | * This moves the 'write' index forward to catch up with 'processed', and |
| 3363 | * also updates the memory address in the firmware to reference the new |
| 3364 | * target buffer. |
| 3365 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3366 | static int iwl4965_rx_queue_restock(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3367 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3368 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3369 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3370 | struct iwl4965_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3371 | unsigned long flags; |
| 3372 | int write, rc; |
| 3373 | |
| 3374 | spin_lock_irqsave(&rxq->lock, flags); |
| 3375 | write = rxq->write & ~0x7; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3376 | while ((iwl4965_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3377 | /* Get next free Rx buffer, remove from free list */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3378 | element = rxq->rx_free.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3379 | rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3380 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3381 | |
| 3382 | /* Point to Rx buffer via next RBD in circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3383 | rxq->bd[rxq->write] = iwl4965_dma_addr2rbd_ptr(priv, rxb->dma_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3384 | rxq->queue[rxq->write] = rxb; |
| 3385 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 3386 | rxq->free_count--; |
| 3387 | } |
| 3388 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3389 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 3390 | * refill it */ |
| 3391 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 3392 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 3393 | |
| 3394 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3395 | /* If we've added more space for the firmware to place data, tell it. |
| 3396 | * Increment device's write pointer in multiples of 8. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3397 | if ((write != (rxq->write & ~0x7)) |
| 3398 | || (abs(rxq->write - rxq->read) > 7)) { |
| 3399 | spin_lock_irqsave(&rxq->lock, flags); |
| 3400 | rxq->need_update = 1; |
| 3401 | spin_unlock_irqrestore(&rxq->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3402 | rc = iwl4965_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3403 | if (rc) |
| 3404 | return rc; |
| 3405 | } |
| 3406 | |
| 3407 | return 0; |
| 3408 | } |
| 3409 | |
| 3410 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3411 | * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3412 | * |
| 3413 | * When moving to rx_free an SKB is allocated for the slot. |
| 3414 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3415 | * Also restock the Rx queue via iwl4965_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3416 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3417 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3418 | static void iwl4965_rx_allocate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3419 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3420 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3421 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3422 | struct iwl4965_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3423 | unsigned long flags; |
| 3424 | spin_lock_irqsave(&rxq->lock, flags); |
| 3425 | while (!list_empty(&rxq->rx_used)) { |
| 3426 | element = rxq->rx_used.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3427 | rxb = list_entry(element, struct iwl4965_rx_mem_buffer, list); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3428 | |
| 3429 | /* Alloc a new receive buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3430 | rxb->skb = |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3431 | alloc_skb(priv->hw_params.rx_buf_size, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 3432 | __GFP_NOWARN | GFP_ATOMIC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3433 | if (!rxb->skb) { |
| 3434 | if (net_ratelimit()) |
| 3435 | printk(KERN_CRIT DRV_NAME |
| 3436 | ": Can not allocate SKB buffers\n"); |
| 3437 | /* We don't reschedule replenish work here -- we will |
| 3438 | * call the restock method and if it still needs |
| 3439 | * more buffers it will schedule replenish */ |
| 3440 | break; |
| 3441 | } |
| 3442 | priv->alloc_rxb_skb++; |
| 3443 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3444 | |
| 3445 | /* Get physical address of RB/SKB */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3446 | rxb->dma_addr = |
| 3447 | pci_map_single(priv->pci_dev, rxb->skb->data, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3448 | priv->hw_params.rx_buf_size, PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3449 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 3450 | rxq->free_count++; |
| 3451 | } |
| 3452 | spin_unlock_irqrestore(&rxq->lock, flags); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | /* |
| 3456 | * this should be called while priv->lock is locked |
| 3457 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 3458 | static void __iwl4965_rx_replenish(void *data) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3459 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3460 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3461 | |
| 3462 | iwl4965_rx_allocate(priv); |
| 3463 | iwl4965_rx_queue_restock(priv); |
| 3464 | } |
| 3465 | |
| 3466 | |
| 3467 | void iwl4965_rx_replenish(void *data) |
| 3468 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3469 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3470 | unsigned long flags; |
| 3471 | |
| 3472 | iwl4965_rx_allocate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3473 | |
| 3474 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3475 | iwl4965_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3476 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3477 | } |
| 3478 | |
| 3479 | /* Assumes that the skb field of the buffers in 'pool' is kept accurate. |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3480 | * If an SKB has been detached, the POOL needs to have its SKB set to NULL |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3481 | * This free routine walks the list of POOL entries and if SKB is set to |
| 3482 | * non NULL it is unmapped and freed |
| 3483 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3484 | static void iwl4965_rx_queue_free(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3485 | { |
| 3486 | int i; |
| 3487 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 3488 | if (rxq->pool[i].skb != NULL) { |
| 3489 | pci_unmap_single(priv->pci_dev, |
| 3490 | rxq->pool[i].dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3491 | priv->hw_params.rx_buf_size, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 3492 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3493 | dev_kfree_skb(rxq->pool[i].skb); |
| 3494 | } |
| 3495 | } |
| 3496 | |
| 3497 | pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd, |
| 3498 | rxq->dma_addr); |
| 3499 | rxq->bd = NULL; |
| 3500 | } |
| 3501 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3502 | int iwl4965_rx_queue_alloc(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3503 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3504 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3505 | struct pci_dev *dev = priv->pci_dev; |
| 3506 | int i; |
| 3507 | |
| 3508 | spin_lock_init(&rxq->lock); |
| 3509 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3510 | INIT_LIST_HEAD(&rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3511 | |
| 3512 | /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3513 | rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr); |
| 3514 | if (!rxq->bd) |
| 3515 | return -ENOMEM; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3516 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3517 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3518 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
| 3519 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3520 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3521 | /* Set us so that we have processed and used all buffers, but have |
| 3522 | * not restocked the Rx queue with fresh buffers */ |
| 3523 | rxq->read = rxq->write = 0; |
| 3524 | rxq->free_count = 0; |
| 3525 | rxq->need_update = 0; |
| 3526 | return 0; |
| 3527 | } |
| 3528 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3529 | void iwl4965_rx_queue_reset(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3530 | { |
| 3531 | unsigned long flags; |
| 3532 | int i; |
| 3533 | spin_lock_irqsave(&rxq->lock, flags); |
| 3534 | INIT_LIST_HEAD(&rxq->rx_free); |
| 3535 | INIT_LIST_HEAD(&rxq->rx_used); |
| 3536 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 3537 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 3538 | /* In the reset function, these buffers may have been allocated |
| 3539 | * to an SKB, so we need to unmap and free potential storage */ |
| 3540 | if (rxq->pool[i].skb != NULL) { |
| 3541 | pci_unmap_single(priv->pci_dev, |
| 3542 | rxq->pool[i].dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3543 | priv->hw_params.rx_buf_size, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 3544 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3545 | priv->alloc_rxb_skb--; |
| 3546 | dev_kfree_skb(rxq->pool[i].skb); |
| 3547 | rxq->pool[i].skb = NULL; |
| 3548 | } |
| 3549 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 3550 | } |
| 3551 | |
| 3552 | /* Set us so that we have processed and used all buffers, but have |
| 3553 | * not restocked the Rx queue with fresh buffers */ |
| 3554 | rxq->read = rxq->write = 0; |
| 3555 | rxq->free_count = 0; |
| 3556 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3557 | } |
| 3558 | |
| 3559 | /* Convert linear signal-to-noise ratio into dB */ |
| 3560 | static u8 ratio2dB[100] = { |
| 3561 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 3562 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 3563 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 3564 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 3565 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 3566 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 3567 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 3568 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 3569 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 3570 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 3571 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 3572 | }; |
| 3573 | |
| 3574 | /* Calculates a relative dB value from a ratio of linear |
| 3575 | * (i.e. not dB) signal levels. |
| 3576 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3577 | int iwl4965_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3578 | { |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 3579 | /* 1000:1 or higher just report as 60 dB */ |
| 3580 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3581 | return 60; |
| 3582 | |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 3583 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3584 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | c899a57 | 2007-10-14 19:51:15 +0200 | [diff] [blame] | 3585 | if (sig_ratio >= 100) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3586 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 3587 | |
| 3588 | /* We shouldn't see this */ |
| 3589 | if (sig_ratio < 1) |
| 3590 | return 0; |
| 3591 | |
| 3592 | /* Use table for ratios 1:1 - 99:1 */ |
| 3593 | return (int)ratio2dB[sig_ratio]; |
| 3594 | } |
| 3595 | |
| 3596 | #define PERFECT_RSSI (-20) /* dBm */ |
| 3597 | #define WORST_RSSI (-95) /* dBm */ |
| 3598 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 3599 | |
| 3600 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 3601 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 3602 | * about formulas used below. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3603 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3604 | { |
| 3605 | int sig_qual; |
| 3606 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 3607 | |
| 3608 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 3609 | * as indicator; formula is (signal dbm - noise dbm). |
| 3610 | * SNR at or above 40 is a great signal (100%). |
| 3611 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 3612 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 3613 | if (noise_dbm) { |
| 3614 | if (rssi_dbm - noise_dbm >= 40) |
| 3615 | return 100; |
| 3616 | else if (rssi_dbm < noise_dbm) |
| 3617 | return 0; |
| 3618 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 3619 | |
| 3620 | /* Else use just the signal level. |
| 3621 | * This formula is a least squares fit of data points collected and |
| 3622 | * compared with a reference system that had a percentage (%) display |
| 3623 | * for signal quality. */ |
| 3624 | } else |
| 3625 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 3626 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 3627 | (RSSI_RANGE * RSSI_RANGE); |
| 3628 | |
| 3629 | if (sig_qual > 100) |
| 3630 | sig_qual = 100; |
| 3631 | else if (sig_qual < 1) |
| 3632 | sig_qual = 0; |
| 3633 | |
| 3634 | return sig_qual; |
| 3635 | } |
| 3636 | |
| 3637 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3638 | * iwl4965_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3639 | * |
| 3640 | * Uses the priv->rx_handlers callback function array to invoke |
| 3641 | * the appropriate handlers, including command responses, |
| 3642 | * frame-received notifications, and other notifications. |
| 3643 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3644 | static void iwl4965_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3645 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3646 | struct iwl4965_rx_mem_buffer *rxb; |
| 3647 | struct iwl4965_rx_packet *pkt; |
| 3648 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3649 | u32 r, i; |
| 3650 | int reclaim; |
| 3651 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3652 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 3653 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3654 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3655 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 3656 | * buffer that the driver may process (last buffer filled by ucode). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3657 | r = iwl4965_hw_get_rx_read(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3658 | i = rxq->read; |
| 3659 | |
| 3660 | /* Rx interrupt, but nothing sent from uCode */ |
| 3661 | if (i == r) |
| 3662 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 3663 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3664 | if (iwl4965_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
| 3665 | fill_rx = 1; |
| 3666 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3667 | while (i != r) { |
| 3668 | rxb = rxq->queue[i]; |
| 3669 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3670 | /* 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] | 3671 | * then a bug has been introduced in the queue refilling |
| 3672 | * routines -- catch it here */ |
| 3673 | BUG_ON(rxb == NULL); |
| 3674 | |
| 3675 | rxq->queue[i] = NULL; |
| 3676 | |
| 3677 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3678 | priv->hw_params.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3679 | PCI_DMA_FROMDEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3680 | pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3681 | |
| 3682 | /* Reclaim a command buffer only if this packet is a response |
| 3683 | * to a (driver-originated) command. |
| 3684 | * If the packet (e.g. Rx frame) originated from uCode, |
| 3685 | * there is no command buffer to reclaim. |
| 3686 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 3687 | * but apparently a few don't get set; catch them here. */ |
| 3688 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 3689 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3690 | (pkt->hdr.cmd != REPLY_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 3691 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3692 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 3693 | (pkt->hdr.cmd != REPLY_TX); |
| 3694 | |
| 3695 | /* Based on type of command response or notification, |
| 3696 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3697 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3698 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
| 3699 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 3700 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 3701 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 3702 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 3703 | } else { |
| 3704 | /* No handling needed */ |
| 3705 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 3706 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 3707 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 3708 | pkt->hdr.cmd); |
| 3709 | } |
| 3710 | |
| 3711 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3712 | /* Invoke any callbacks, transfer the skb to caller, and |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3713 | * fire off the (possibly) blocking iwl_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3714 | * as we reclaim the driver command queue */ |
| 3715 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3716 | iwl4965_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3717 | else |
| 3718 | IWL_WARNING("Claim null rxb?\n"); |
| 3719 | } |
| 3720 | |
| 3721 | /* For now we just don't re-use anything. We can tweak this |
| 3722 | * later to try and re-use notification packets and SKBs that |
| 3723 | * fail to Rx correctly */ |
| 3724 | if (rxb->skb != NULL) { |
| 3725 | priv->alloc_rxb_skb--; |
| 3726 | dev_kfree_skb_any(rxb->skb); |
| 3727 | rxb->skb = NULL; |
| 3728 | } |
| 3729 | |
| 3730 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3731 | priv->hw_params.rx_buf_size, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 3732 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3733 | spin_lock_irqsave(&rxq->lock, flags); |
| 3734 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 3735 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3736 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3737 | /* If there are a lot of unused frames, |
| 3738 | * restock the Rx queue so ucode wont assert. */ |
| 3739 | if (fill_rx) { |
| 3740 | count++; |
| 3741 | if (count >= 8) { |
| 3742 | priv->rxq.read = i; |
| 3743 | __iwl4965_rx_replenish(priv); |
| 3744 | count = 0; |
| 3745 | } |
| 3746 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | /* Backtrack one entry */ |
| 3750 | priv->rxq.read = i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3751 | iwl4965_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3752 | } |
| 3753 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3754 | /** |
| 3755 | * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware |
| 3756 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3757 | static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3758 | struct iwl4965_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3759 | { |
| 3760 | u32 reg = 0; |
| 3761 | int rc = 0; |
| 3762 | int txq_id = txq->q.id; |
| 3763 | |
| 3764 | if (txq->need_update == 0) |
| 3765 | return rc; |
| 3766 | |
| 3767 | /* if we're trying to save power */ |
| 3768 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 3769 | /* wake up nic if it's powered down ... |
| 3770 | * uCode will wake up, and interrupt us again, so next |
| 3771 | * time we'll skip this part. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3772 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3773 | |
| 3774 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 3775 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3776 | iwl_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3777 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 3778 | return rc; |
| 3779 | } |
| 3780 | |
| 3781 | /* restore this queue's parameters in nic hardware. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3782 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3783 | if (rc) |
| 3784 | return rc; |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3785 | iwl_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3786 | txq->q.write_ptr | (txq_id << 8)); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3787 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3788 | |
| 3789 | /* else not in power-save mode, uCode will never sleep when we're |
| 3790 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 3791 | } else |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3792 | iwl_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3793 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3794 | |
| 3795 | txq->need_update = 0; |
| 3796 | |
| 3797 | return rc; |
| 3798 | } |
| 3799 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3800 | #ifdef CONFIG_IWLWIFI_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3801 | static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3802 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3803 | DECLARE_MAC_BUF(mac); |
| 3804 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3805 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3806 | iwl_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3807 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 3808 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 3809 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 3810 | le32_to_cpu(rxon->filter_flags)); |
| 3811 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 3812 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 3813 | rxon->ofdm_basic_rates); |
| 3814 | 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] | 3815 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 3816 | print_mac(mac, rxon->node_addr)); |
| 3817 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 3818 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3819 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 3820 | } |
| 3821 | #endif |
| 3822 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3823 | static void iwl4965_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3824 | { |
| 3825 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 3826 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3827 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3828 | } |
| 3829 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3830 | /* call this function to flush any scheduled tasklet */ |
| 3831 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
| 3832 | { |
| 3833 | /* wait to make sure we flush pedding tasklet*/ |
| 3834 | synchronize_irq(priv->pci_dev->irq); |
| 3835 | tasklet_kill(&priv->irq_tasklet); |
| 3836 | } |
| 3837 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3838 | static inline void iwl4965_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3839 | { |
| 3840 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 3841 | |
| 3842 | /* disable interrupts from uCode/NIC to host */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3843 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3844 | |
| 3845 | /* acknowledge/clear/reset any interrupts still pending |
| 3846 | * from uCode or flow handler (Rx/Tx DMA) */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3847 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 3848 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3849 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 3850 | } |
| 3851 | |
| 3852 | static const char *desc_lookup(int i) |
| 3853 | { |
| 3854 | switch (i) { |
| 3855 | case 1: |
| 3856 | return "FAIL"; |
| 3857 | case 2: |
| 3858 | return "BAD_PARAM"; |
| 3859 | case 3: |
| 3860 | return "BAD_CHECKSUM"; |
| 3861 | case 4: |
| 3862 | return "NMI_INTERRUPT"; |
| 3863 | case 5: |
| 3864 | return "SYSASSERT"; |
| 3865 | case 6: |
| 3866 | return "FATAL_ERROR"; |
| 3867 | } |
| 3868 | |
| 3869 | return "UNKNOWN"; |
| 3870 | } |
| 3871 | |
| 3872 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 3873 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 3874 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3875 | static void iwl4965_dump_nic_error_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3876 | { |
| 3877 | u32 data2, line; |
| 3878 | u32 desc, time, count, base, data1; |
| 3879 | u32 blink1, blink2, ilink1, ilink2; |
| 3880 | int rc; |
| 3881 | |
| 3882 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 3883 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3884 | if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3885 | IWL_ERROR("Not valid error log pointer 0x%08X\n", base); |
| 3886 | return; |
| 3887 | } |
| 3888 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3889 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3890 | if (rc) { |
| 3891 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 3892 | return; |
| 3893 | } |
| 3894 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3895 | count = iwl_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3896 | |
| 3897 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
| 3898 | IWL_ERROR("Start IWL Error Log Dump:\n"); |
Tomas Winkler | 2acae16 | 2008-03-02 01:25:59 +0200 | [diff] [blame] | 3899 | IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3900 | } |
| 3901 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3902 | desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32)); |
| 3903 | blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32)); |
| 3904 | blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32)); |
| 3905 | ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32)); |
| 3906 | ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32)); |
| 3907 | data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32)); |
| 3908 | data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32)); |
| 3909 | line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32)); |
| 3910 | time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3911 | |
| 3912 | IWL_ERROR("Desc Time " |
| 3913 | "data1 data2 line\n"); |
| 3914 | IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n", |
| 3915 | desc_lookup(desc), desc, time, data1, data2, line); |
| 3916 | IWL_ERROR("blink1 blink2 ilink1 ilink2\n"); |
| 3917 | IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2, |
| 3918 | ilink1, ilink2); |
| 3919 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3920 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | #define EVENT_START_OFFSET (4 * sizeof(u32)) |
| 3924 | |
| 3925 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3926 | * iwl4965_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3927 | * |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3928 | * NOTE: Must be called with iwl_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3929 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3930 | 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] | 3931 | u32 num_events, u32 mode) |
| 3932 | { |
| 3933 | u32 i; |
| 3934 | u32 base; /* SRAM byte address of event log header */ |
| 3935 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 3936 | u32 ptr; /* SRAM byte address of log data */ |
| 3937 | u32 ev, time, data; /* event log data */ |
| 3938 | |
| 3939 | if (num_events == 0) |
| 3940 | return; |
| 3941 | |
| 3942 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 3943 | |
| 3944 | if (mode == 0) |
| 3945 | event_size = 2 * sizeof(u32); |
| 3946 | else |
| 3947 | event_size = 3 * sizeof(u32); |
| 3948 | |
| 3949 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 3950 | |
| 3951 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 3952 | * place event id # at far right for easier visual parsing. */ |
| 3953 | for (i = 0; i < num_events; i++) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3954 | ev = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3955 | ptr += sizeof(u32); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3956 | time = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3957 | ptr += sizeof(u32); |
| 3958 | if (mode == 0) |
| 3959 | IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */ |
| 3960 | else { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3961 | data = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3962 | ptr += sizeof(u32); |
| 3963 | IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev); |
| 3964 | } |
| 3965 | } |
| 3966 | } |
| 3967 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3968 | static void iwl4965_dump_nic_event_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3969 | { |
| 3970 | int rc; |
| 3971 | u32 base; /* SRAM byte address of event log header */ |
| 3972 | u32 capacity; /* event log capacity in # entries */ |
| 3973 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 3974 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 3975 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 3976 | u32 size; /* # entries that we'll print */ |
| 3977 | |
| 3978 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3979 | if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3980 | IWL_ERROR("Invalid event log pointer 0x%08X\n", base); |
| 3981 | return; |
| 3982 | } |
| 3983 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3984 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3985 | if (rc) { |
| 3986 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 3987 | return; |
| 3988 | } |
| 3989 | |
| 3990 | /* event log header */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3991 | capacity = iwl_read_targ_mem(priv, base); |
| 3992 | mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 3993 | num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 3994 | next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3995 | |
| 3996 | size = num_wraps ? capacity : next_entry; |
| 3997 | |
| 3998 | /* bail out if nothing in log */ |
| 3999 | if (size == 0) { |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 4000 | IWL_ERROR("Start IWL Event Log Dump: nothing in log\n"); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4001 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4002 | return; |
| 4003 | } |
| 4004 | |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 4005 | 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] | 4006 | size, num_wraps); |
| 4007 | |
| 4008 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 4009 | * i.e the next one that uCode would fill. */ |
| 4010 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4011 | iwl4965_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4012 | capacity - next_entry, mode); |
| 4013 | |
| 4014 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4015 | iwl4965_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4016 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4017 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4018 | } |
| 4019 | |
| 4020 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4021 | * 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] | 4022 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4023 | static void iwl4965_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4024 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4025 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4026 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 4027 | |
| 4028 | /* Cancel currently queued command. */ |
| 4029 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 4030 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4031 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 4032 | if (iwl_debug_level & IWL_DL_FW_ERRORS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4033 | iwl4965_dump_nic_error_log(priv); |
| 4034 | iwl4965_dump_nic_event_log(priv); |
| 4035 | iwl4965_print_rx_config_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4036 | } |
| 4037 | #endif |
| 4038 | |
| 4039 | wake_up_interruptible(&priv->wait_command_queue); |
| 4040 | |
| 4041 | /* Keep the restart process from trying to send host |
| 4042 | * commands by clearing the INIT status bit */ |
| 4043 | clear_bit(STATUS_READY, &priv->status); |
| 4044 | |
| 4045 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 4046 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 4047 | "Restarting adapter due to uCode error.\n"); |
| 4048 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4049 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4050 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 4051 | sizeof(priv->recovery_rxon)); |
| 4052 | priv->error_recovering = 1; |
| 4053 | } |
| 4054 | queue_work(priv->workqueue, &priv->restart); |
| 4055 | } |
| 4056 | } |
| 4057 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4058 | static void iwl4965_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4059 | { |
| 4060 | unsigned long flags; |
| 4061 | |
| 4062 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 4063 | sizeof(priv->staging_rxon)); |
| 4064 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4065 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4066 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4067 | iwl4965_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4068 | |
| 4069 | spin_lock_irqsave(&priv->lock, flags); |
| 4070 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 4071 | priv->error_recovering = 0; |
| 4072 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4073 | } |
| 4074 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4075 | static void iwl4965_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4076 | { |
| 4077 | u32 inta, handled = 0; |
| 4078 | u32 inta_fh; |
| 4079 | unsigned long flags; |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4080 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4081 | u32 inta_mask; |
| 4082 | #endif |
| 4083 | |
| 4084 | spin_lock_irqsave(&priv->lock, flags); |
| 4085 | |
| 4086 | /* Ack/clear/reset pending uCode interrupts. |
| 4087 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 4088 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4089 | inta = iwl_read32(priv, CSR_INT); |
| 4090 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4091 | |
| 4092 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 4093 | * Any new interrupts that happen after this, either while we're |
| 4094 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4095 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 4096 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4097 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4098 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 4099 | if (iwl_debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4100 | /* just for debug */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4101 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4102 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4103 | inta, inta_mask, inta_fh); |
| 4104 | } |
| 4105 | #endif |
| 4106 | |
| 4107 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 4108 | * atomic, make sure that inta covers all the interrupts that |
| 4109 | * we've discovered, even if FH interrupt came in just after |
| 4110 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 4111 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4112 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 4113 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4114 | inta |= CSR_INT_BIT_FH_TX; |
| 4115 | |
| 4116 | /* Now service all interrupt bits discovered above. */ |
| 4117 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 4118 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 4119 | |
| 4120 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4121 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4122 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4123 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4124 | |
| 4125 | handled |= CSR_INT_BIT_HW_ERR; |
| 4126 | |
| 4127 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4128 | |
| 4129 | return; |
| 4130 | } |
| 4131 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4132 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 4133 | if (iwl_debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4134 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4135 | if (inta & CSR_INT_BIT_SCD) |
| 4136 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 4137 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4138 | |
| 4139 | /* Alive notification via Rx interrupt will do the real work */ |
| 4140 | if (inta & CSR_INT_BIT_ALIVE) |
| 4141 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 4142 | } |
| 4143 | #endif |
| 4144 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4145 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4146 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4147 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4148 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 4149 | int hw_rf_kill = 0; |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4150 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4151 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 4152 | hw_rf_kill = 1; |
| 4153 | |
| 4154 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR, |
| 4155 | "RF_KILL bit toggled to %s.\n", |
| 4156 | hw_rf_kill ? "disable radio":"enable radio"); |
| 4157 | |
| 4158 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 4159 | * when we loaded driver, and is now set to "enable". |
| 4160 | * After we're Alive, RF_KILL gets handled by |
Reinette Chatre | 3230455 | 2008-02-15 14:34:37 -0800 | [diff] [blame] | 4161 | * iwl4965_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 4162 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 4163 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4164 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 4165 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4166 | |
| 4167 | handled |= CSR_INT_BIT_RF_KILL; |
| 4168 | } |
| 4169 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4170 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4171 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 4172 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 4173 | handled |= CSR_INT_BIT_CT_KILL; |
| 4174 | } |
| 4175 | |
| 4176 | /* Error detected by uCode */ |
| 4177 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 4178 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 4179 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4180 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4181 | handled |= CSR_INT_BIT_SW_ERR; |
| 4182 | } |
| 4183 | |
| 4184 | /* uCode wakes up after power-down sleep */ |
| 4185 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 4186 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4187 | iwl4965_rx_queue_update_write_ptr(priv, &priv->rxq); |
| 4188 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[0]); |
| 4189 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[1]); |
| 4190 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[2]); |
| 4191 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[3]); |
| 4192 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[4]); |
| 4193 | iwl4965_tx_queue_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4194 | |
| 4195 | handled |= CSR_INT_BIT_WAKEUP; |
| 4196 | } |
| 4197 | |
| 4198 | /* All uCode command responses, including Tx command responses, |
| 4199 | * Rx "responses" (frame-received notification), and other |
| 4200 | * notifications from uCode come through here*/ |
| 4201 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4202 | iwl4965_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4203 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 4204 | } |
| 4205 | |
| 4206 | if (inta & CSR_INT_BIT_FH_TX) { |
| 4207 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 4208 | handled |= CSR_INT_BIT_FH_TX; |
| 4209 | } |
| 4210 | |
| 4211 | if (inta & ~handled) |
| 4212 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 4213 | |
| 4214 | if (inta & ~CSR_INI_SET_MASK) { |
| 4215 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 4216 | inta & ~CSR_INI_SET_MASK); |
| 4217 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 4218 | } |
| 4219 | |
| 4220 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4221 | /* only Re-enable if diabled by irq */ |
| 4222 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 4223 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4224 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4225 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 4226 | if (iwl_debug_level & (IWL_DL_ISR)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4227 | inta = iwl_read32(priv, CSR_INT); |
| 4228 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 4229 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4230 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 4231 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 4232 | } |
| 4233 | #endif |
| 4234 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4235 | } |
| 4236 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4237 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4238 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4239 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4240 | u32 inta, inta_mask; |
| 4241 | u32 inta_fh; |
| 4242 | if (!priv) |
| 4243 | return IRQ_NONE; |
| 4244 | |
| 4245 | spin_lock(&priv->lock); |
| 4246 | |
| 4247 | /* Disable (but don't clear!) interrupts here to avoid |
| 4248 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 4249 | * If we have something to service, the tasklet will re-enable ints. |
| 4250 | * 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] | 4251 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 4252 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4253 | |
| 4254 | /* Discover which interrupts are active/pending */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4255 | inta = iwl_read32(priv, CSR_INT); |
| 4256 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4257 | |
| 4258 | /* Ignore interrupt if there's nothing in NIC to service. |
| 4259 | * This may be due to IRQ shared with another device, |
| 4260 | * or due to sporadic interrupts thrown from our NIC. */ |
| 4261 | if (!inta && !inta_fh) { |
| 4262 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 4263 | goto none; |
| 4264 | } |
| 4265 | |
| 4266 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 4267 | /* Hardware disappeared. It might have already raised |
| 4268 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4269 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 4270 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4274 | inta, inta_mask, inta_fh); |
| 4275 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4276 | inta &= ~CSR_INT_BIT_SCD; |
| 4277 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4278 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4279 | if (likely(inta || inta_fh)) |
| 4280 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4281 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 4282 | unplugged: |
| 4283 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4284 | return IRQ_HANDLED; |
| 4285 | |
| 4286 | none: |
| 4287 | /* re-enable interrupts here since we don't have anything to service. */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4288 | /* only Re-enable if diabled by irq */ |
| 4289 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 4290 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4291 | spin_unlock(&priv->lock); |
| 4292 | return IRQ_NONE; |
| 4293 | } |
| 4294 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4295 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 4296 | * sending probe req. This should be set long enough to hear probe responses |
| 4297 | * from more than one AP. */ |
| 4298 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 4299 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 4300 | |
| 4301 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 4302 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 4303 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 4304 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 4305 | * no other traffic). |
| 4306 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 4307 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 4308 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 4309 | |
| 4310 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 4311 | * Must be set longer than active dwell time. |
| 4312 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 4313 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 4314 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 4315 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 4316 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 4317 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4318 | static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4319 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4320 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4321 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4322 | return IWL_ACTIVE_DWELL_TIME_52; |
| 4323 | else |
| 4324 | return IWL_ACTIVE_DWELL_TIME_24; |
| 4325 | } |
| 4326 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4327 | static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4328 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4329 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4330 | u16 active = iwl4965_get_active_dwell_time(priv, band); |
| 4331 | u16 passive = (band != IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4332 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 4333 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 4334 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4335 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4336 | /* If we're associated, we clamp the maximum passive |
| 4337 | * dwell time to be 98% of the beacon interval (minus |
| 4338 | * 2 * channel tune time) */ |
| 4339 | passive = priv->beacon_int; |
| 4340 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 4341 | passive = IWL_PASSIVE_DWELL_BASE; |
| 4342 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 4343 | } |
| 4344 | |
| 4345 | if (passive <= active) |
| 4346 | passive = active + 1; |
| 4347 | |
| 4348 | return passive; |
| 4349 | } |
| 4350 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4351 | static int iwl4965_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4352 | enum ieee80211_band band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4353 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4354 | struct iwl4965_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4355 | { |
| 4356 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4357 | const struct ieee80211_supported_band *sband; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4358 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4359 | u16 passive_dwell = 0; |
| 4360 | u16 active_dwell = 0; |
| 4361 | int added, i; |
| 4362 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4363 | sband = iwl4965_get_hw_mode(priv, band); |
| 4364 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4365 | return 0; |
| 4366 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4367 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4368 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4369 | active_dwell = iwl4965_get_active_dwell_time(priv, band); |
| 4370 | passive_dwell = iwl4965_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4371 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4372 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 4373 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 4374 | continue; |
| 4375 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4376 | scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4377 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 4378 | ch_info = iwl_get_channel_info(priv, band, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4379 | scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4380 | if (!is_channel_valid(ch_info)) { |
| 4381 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 4382 | scan_ch->channel); |
| 4383 | continue; |
| 4384 | } |
| 4385 | |
| 4386 | if (!is_active || is_channel_passive(ch_info) || |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4387 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4388 | scan_ch->type = 0; /* passive */ |
| 4389 | else |
| 4390 | scan_ch->type = 1; /* active */ |
| 4391 | |
| 4392 | if (scan_ch->type & 1) |
| 4393 | scan_ch->type |= (direct_mask << 1); |
| 4394 | |
| 4395 | if (is_channel_narrow(ch_info)) |
| 4396 | scan_ch->type |= (1 << 7); |
| 4397 | |
| 4398 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 4399 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 4400 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4401 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4402 | scan_ch->tpc.dsp_atten = 110; |
| 4403 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 4404 | |
| 4405 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4406 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4407 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 4408 | else { |
| 4409 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 4410 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4411 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 4412 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4413 | */ |
| 4414 | } |
| 4415 | |
| 4416 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 4417 | scan_ch->channel, |
| 4418 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 4419 | (scan_ch->type & 1) ? |
| 4420 | active_dwell : passive_dwell); |
| 4421 | |
| 4422 | scan_ch++; |
| 4423 | added++; |
| 4424 | } |
| 4425 | |
| 4426 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 4427 | return added; |
| 4428 | } |
| 4429 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4430 | static void iwl4965_init_hw_rates(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4431 | struct ieee80211_rate *rates) |
| 4432 | { |
| 4433 | int i; |
| 4434 | |
| 4435 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4436 | rates[i].bitrate = iwl4965_rates[i].ieee * 5; |
| 4437 | rates[i].hw_value = i; /* Rate scaling will work on indexes */ |
| 4438 | rates[i].hw_value_short = i; |
| 4439 | rates[i].flags = 0; |
| 4440 | if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4441 | /* |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4442 | * If CCK != 1M then set short preamble rate flag. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4443 | */ |
Tomas Winkler | 35cdeaf | 2008-03-11 16:17:20 -0700 | [diff] [blame] | 4444 | rates[i].flags |= |
| 4445 | (iwl4965_rates[i].plcp == IWL_RATE_1M_PLCP) ? |
| 4446 | 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4447 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4448 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4449 | } |
| 4450 | |
| 4451 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4452 | * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4453 | */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4454 | int iwl4965_init_geos(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4455 | { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4456 | struct iwl_channel_info *ch; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4457 | struct ieee80211_supported_band *sband; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4458 | struct ieee80211_channel *channels; |
| 4459 | struct ieee80211_channel *geo_ch; |
| 4460 | struct ieee80211_rate *rates; |
| 4461 | int i = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4462 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4463 | if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates || |
| 4464 | priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4465 | IWL_DEBUG_INFO("Geography modes already initialized.\n"); |
| 4466 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4467 | return 0; |
| 4468 | } |
| 4469 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4470 | channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 4471 | priv->channel_count, GFP_KERNEL); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4472 | if (!channels) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4473 | return -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4474 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4475 | rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4476 | GFP_KERNEL); |
| 4477 | if (!rates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4478 | kfree(channels); |
| 4479 | return -ENOMEM; |
| 4480 | } |
| 4481 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4482 | /* 5.2GHz channels start after the 2.4GHz channels */ |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4483 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4484 | sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)]; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4485 | /* just OFDM */ |
| 4486 | sband->bitrates = &rates[IWL_FIRST_OFDM_RATE]; |
| 4487 | sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4488 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 4489 | iwl4965_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_5GHZ); |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 4490 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4491 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 4492 | sband->channels = channels; |
| 4493 | /* OFDM & CCK */ |
| 4494 | sband->bitrates = rates; |
| 4495 | sband->n_bitrates = IWL_RATE_COUNT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4496 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 4497 | iwl4965_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_2GHZ); |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 4498 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4499 | priv->ieee_channels = channels; |
| 4500 | priv->ieee_rates = rates; |
| 4501 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4502 | iwl4965_init_hw_rates(priv, rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4503 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4504 | for (i = 0; i < priv->channel_count; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4505 | ch = &priv->channel_info[i]; |
| 4506 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4507 | /* FIXME: might be removed if scan is OK */ |
| 4508 | if (!is_channel_valid(ch)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4509 | continue; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4510 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4511 | if (is_channel_a_band(ch)) |
| 4512 | sband = &priv->bands[IEEE80211_BAND_5GHZ]; |
| 4513 | else |
| 4514 | sband = &priv->bands[IEEE80211_BAND_2GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4515 | |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4516 | geo_ch = &sband->channels[sband->n_channels++]; |
| 4517 | |
| 4518 | geo_ch->center_freq = ieee80211_channel_to_frequency(ch->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4519 | geo_ch->max_power = ch->max_power_avg; |
| 4520 | geo_ch->max_antenna_gain = 0xff; |
Mohamed Abbas | 7b72304 | 2008-01-31 21:46:40 -0800 | [diff] [blame] | 4521 | geo_ch->hw_value = ch->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4522 | |
| 4523 | if (is_channel_valid(ch)) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4524 | if (!(ch->flags & EEPROM_CHANNEL_IBSS)) |
| 4525 | geo_ch->flags |= IEEE80211_CHAN_NO_IBSS; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4526 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4527 | if (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) |
| 4528 | geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4529 | |
| 4530 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4531 | geo_ch->flags |= IEEE80211_CHAN_RADAR; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4532 | |
| 4533 | if (ch->max_power_avg > priv->max_channel_txpower_limit) |
| 4534 | priv->max_channel_txpower_limit = |
| 4535 | ch->max_power_avg; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4536 | } else { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4537 | geo_ch->flags |= IEEE80211_CHAN_DISABLED; |
Tomas Winkler | 8211ef7 | 2008-03-02 01:36:04 +0200 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | /* Save flags for reg domain usage */ |
| 4541 | geo_ch->orig_flags = geo_ch->flags; |
| 4542 | |
| 4543 | IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n", |
| 4544 | ch->channel, geo_ch->center_freq, |
| 4545 | is_channel_a_band(ch) ? "5.2" : "2.4", |
| 4546 | geo_ch->flags & IEEE80211_CHAN_DISABLED ? |
| 4547 | "restricted" : "valid", |
| 4548 | geo_ch->flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4549 | } |
| 4550 | |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4551 | if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && |
| 4552 | priv->cfg->sku & IWL_SKU_A) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4553 | printk(KERN_INFO DRV_NAME |
| 4554 | ": Incorrectly detected BG card as ABG. Please send " |
| 4555 | "your PCI ID 0x%04X:0x%04X to maintainer.\n", |
| 4556 | priv->pci_dev->device, priv->pci_dev->subsystem_device); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4557 | priv->cfg->sku &= ~IWL_SKU_A; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4558 | } |
| 4559 | |
| 4560 | printk(KERN_INFO DRV_NAME |
| 4561 | ": Tunable channels: %d 802.11bg, %d 802.11a channels\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4562 | priv->bands[IEEE80211_BAND_2GHZ].n_channels, |
| 4563 | priv->bands[IEEE80211_BAND_5GHZ].n_channels); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4564 | |
John W. Linville | e0e0a67 | 2008-03-25 15:58:40 -0400 | [diff] [blame] | 4565 | if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 4566 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 4567 | &priv->bands[IEEE80211_BAND_2GHZ]; |
| 4568 | if (priv->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 4569 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 4570 | &priv->bands[IEEE80211_BAND_5GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4571 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4572 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4573 | |
| 4574 | return 0; |
| 4575 | } |
| 4576 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4577 | /* |
| 4578 | * iwl4965_free_geos - undo allocations in iwl4965_init_geos |
| 4579 | */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4580 | void iwl4965_free_geos(struct iwl_priv *priv) |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4581 | { |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4582 | kfree(priv->ieee_channels); |
| 4583 | kfree(priv->ieee_rates); |
| 4584 | clear_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 4585 | } |
| 4586 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4587 | /****************************************************************************** |
| 4588 | * |
| 4589 | * uCode download functions |
| 4590 | * |
| 4591 | ******************************************************************************/ |
| 4592 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4593 | static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4594 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4595 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 4596 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 4597 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 4598 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 4599 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 4600 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4601 | } |
| 4602 | |
| 4603 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4604 | * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4605 | * looking at all data. |
| 4606 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4607 | static int iwl4965_verify_inst_full(struct iwl_priv *priv, __le32 *image, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4608 | u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4609 | { |
| 4610 | u32 val; |
| 4611 | u32 save_len = len; |
| 4612 | int rc = 0; |
| 4613 | u32 errcnt; |
| 4614 | |
| 4615 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 4616 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4617 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4618 | if (rc) |
| 4619 | return rc; |
| 4620 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4621 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4622 | |
| 4623 | errcnt = 0; |
| 4624 | for (; len > 0; len -= sizeof(u32), image++) { |
| 4625 | /* read data comes through single port, auto-incr addr */ |
| 4626 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 4627 | * if IWL_DL_IO is set */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4628 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4629 | if (val != le32_to_cpu(*image)) { |
| 4630 | IWL_ERROR("uCode INST section is invalid at " |
| 4631 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 4632 | save_len - len, val, le32_to_cpu(*image)); |
| 4633 | rc = -EIO; |
| 4634 | errcnt++; |
| 4635 | if (errcnt >= 20) |
| 4636 | break; |
| 4637 | } |
| 4638 | } |
| 4639 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4640 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4641 | |
| 4642 | if (!errcnt) |
| 4643 | IWL_DEBUG_INFO |
| 4644 | ("ucode image in INSTRUCTION memory is good\n"); |
| 4645 | |
| 4646 | return rc; |
| 4647 | } |
| 4648 | |
| 4649 | |
| 4650 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4651 | * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4652 | * using sample data 100 bytes apart. If these sample points are good, |
| 4653 | * it's a pretty good bet that everything between them is good, too. |
| 4654 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4655 | static int iwl4965_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4656 | { |
| 4657 | u32 val; |
| 4658 | int rc = 0; |
| 4659 | u32 errcnt = 0; |
| 4660 | u32 i; |
| 4661 | |
| 4662 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 4663 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4664 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4665 | if (rc) |
| 4666 | return rc; |
| 4667 | |
| 4668 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 4669 | /* read data comes through single port, auto-incr addr */ |
| 4670 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 4671 | * if IWL_DL_IO is set */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4672 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4673 | i + RTC_INST_LOWER_BOUND); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4674 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4675 | if (val != le32_to_cpu(*image)) { |
| 4676 | #if 0 /* Enable this if you want to see details */ |
| 4677 | IWL_ERROR("uCode INST section is invalid at " |
| 4678 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 4679 | i, val, *image); |
| 4680 | #endif |
| 4681 | rc = -EIO; |
| 4682 | errcnt++; |
| 4683 | if (errcnt >= 3) |
| 4684 | break; |
| 4685 | } |
| 4686 | } |
| 4687 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4688 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4689 | |
| 4690 | return rc; |
| 4691 | } |
| 4692 | |
| 4693 | |
| 4694 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4695 | * iwl4965_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4696 | * and verify its contents |
| 4697 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4698 | static int iwl4965_verify_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4699 | { |
| 4700 | __le32 *image; |
| 4701 | u32 len; |
| 4702 | int rc = 0; |
| 4703 | |
| 4704 | /* Try bootstrap */ |
| 4705 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 4706 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4707 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4708 | if (rc == 0) { |
| 4709 | IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); |
| 4710 | return 0; |
| 4711 | } |
| 4712 | |
| 4713 | /* Try initialize */ |
| 4714 | image = (__le32 *)priv->ucode_init.v_addr; |
| 4715 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4716 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4717 | if (rc == 0) { |
| 4718 | IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); |
| 4719 | return 0; |
| 4720 | } |
| 4721 | |
| 4722 | /* Try runtime/protocol */ |
| 4723 | image = (__le32 *)priv->ucode_code.v_addr; |
| 4724 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4725 | rc = iwl4965_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4726 | if (rc == 0) { |
| 4727 | IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); |
| 4728 | return 0; |
| 4729 | } |
| 4730 | |
| 4731 | IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
| 4732 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4733 | /* Since nothing seems to match, show first several data entries in |
| 4734 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 4735 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4736 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 4737 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4738 | rc = iwl4965_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4739 | |
| 4740 | return rc; |
| 4741 | } |
| 4742 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4743 | static void iwl4965_nic_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4744 | { |
| 4745 | /* Remove all resets to allow NIC to operate */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4746 | iwl_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4747 | } |
| 4748 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4749 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4750 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4751 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4752 | * |
| 4753 | * Copy into buffers for card to fetch via bus-mastering |
| 4754 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4755 | static int iwl4965_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4756 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4757 | struct iwl4965_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4758 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4759 | const struct firmware *ucode_raw; |
Tomas Winkler | 4bf775c | 2008-03-04 18:09:31 -0800 | [diff] [blame] | 4760 | const char *name = priv->cfg->fw_name; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4761 | u8 *src; |
| 4762 | size_t len; |
| 4763 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 4764 | |
| 4765 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 4766 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4767 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 4768 | if (ret < 0) { |
| 4769 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 4770 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4771 | goto error; |
| 4772 | } |
| 4773 | |
| 4774 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 4775 | name, ucode_raw->size); |
| 4776 | |
| 4777 | /* Make sure that we got at least our header! */ |
| 4778 | if (ucode_raw->size < sizeof(*ucode)) { |
| 4779 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4780 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4781 | goto err_release; |
| 4782 | } |
| 4783 | |
| 4784 | /* Data from ucode file: header followed by uCode images */ |
| 4785 | ucode = (void *)ucode_raw->data; |
| 4786 | |
| 4787 | ver = le32_to_cpu(ucode->ver); |
| 4788 | inst_size = le32_to_cpu(ucode->inst_size); |
| 4789 | data_size = le32_to_cpu(ucode->data_size); |
| 4790 | init_size = le32_to_cpu(ucode->init_size); |
| 4791 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 4792 | boot_size = le32_to_cpu(ucode->boot_size); |
| 4793 | |
| 4794 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 4795 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 4796 | inst_size); |
| 4797 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 4798 | data_size); |
| 4799 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 4800 | init_size); |
| 4801 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 4802 | init_data_size); |
| 4803 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 4804 | boot_size); |
| 4805 | |
| 4806 | /* Verify size of file vs. image size info in file's header */ |
| 4807 | if (ucode_raw->size < sizeof(*ucode) + |
| 4808 | inst_size + data_size + init_size + |
| 4809 | init_data_size + boot_size) { |
| 4810 | |
| 4811 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 4812 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4813 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4814 | goto err_release; |
| 4815 | } |
| 4816 | |
| 4817 | /* Verify that uCode images will fit in card's SRAM */ |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4818 | if (inst_size > priv->hw_params.max_inst_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4819 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 4820 | inst_size); |
| 4821 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4822 | goto err_release; |
| 4823 | } |
| 4824 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4825 | if (data_size > priv->hw_params.max_data_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4826 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 4827 | data_size); |
| 4828 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4829 | goto err_release; |
| 4830 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4831 | if (init_size > priv->hw_params.max_inst_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4832 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4833 | ("uCode init instr len %d too large to fit in\n", |
| 4834 | init_size); |
| 4835 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4836 | goto err_release; |
| 4837 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4838 | if (init_data_size > priv->hw_params.max_data_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4839 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4840 | ("uCode init data len %d too large to fit in\n", |
| 4841 | init_data_size); |
| 4842 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4843 | goto err_release; |
| 4844 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4845 | if (boot_size > priv->hw_params.max_bsm_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4846 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4847 | ("uCode boot instr len %d too large to fit in\n", |
| 4848 | boot_size); |
| 4849 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4850 | goto err_release; |
| 4851 | } |
| 4852 | |
| 4853 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 4854 | |
| 4855 | /* Runtime instructions and 2 copies of data: |
| 4856 | * 1) unmodified from disk |
| 4857 | * 2) backup cache for save/restore during power-downs */ |
| 4858 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4859 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4860 | |
| 4861 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4862 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4863 | |
| 4864 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4865 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4866 | |
| 4867 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4868 | if (init_size && init_data_size) { |
| 4869 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4870 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4871 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4872 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4873 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4874 | |
| 4875 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 4876 | goto err_pci_alloc; |
| 4877 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4878 | |
| 4879 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4880 | if (boot_size) { |
| 4881 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4882 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4883 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4884 | if (!priv->ucode_boot.v_addr) |
| 4885 | goto err_pci_alloc; |
| 4886 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4887 | |
| 4888 | /* Copy images into buffers for card's bus-master reads ... */ |
| 4889 | |
| 4890 | /* Runtime instructions (first block of data in file) */ |
| 4891 | src = &ucode->data[0]; |
| 4892 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4893 | 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] | 4894 | memcpy(priv->ucode_code.v_addr, src, len); |
| 4895 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 4896 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 4897 | |
| 4898 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4899 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4900 | src = &ucode->data[inst_size]; |
| 4901 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4902 | 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] | 4903 | memcpy(priv->ucode_data.v_addr, src, len); |
| 4904 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 4905 | |
| 4906 | /* Initialization instructions (3rd block) */ |
| 4907 | if (init_size) { |
| 4908 | src = &ucode->data[inst_size + data_size]; |
| 4909 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4910 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 4911 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4912 | memcpy(priv->ucode_init.v_addr, src, len); |
| 4913 | } |
| 4914 | |
| 4915 | /* Initialization data (4th block) */ |
| 4916 | if (init_data_size) { |
| 4917 | src = &ucode->data[inst_size + data_size + init_size]; |
| 4918 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4919 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 4920 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4921 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 4922 | } |
| 4923 | |
| 4924 | /* Bootstrap instructions (5th block) */ |
| 4925 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 4926 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4927 | 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] | 4928 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 4929 | |
| 4930 | /* We have our copies now, allow OS release its copies */ |
| 4931 | release_firmware(ucode_raw); |
| 4932 | return 0; |
| 4933 | |
| 4934 | err_pci_alloc: |
| 4935 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4936 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4937 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4938 | |
| 4939 | err_release: |
| 4940 | release_firmware(ucode_raw); |
| 4941 | |
| 4942 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4943 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4944 | } |
| 4945 | |
| 4946 | |
| 4947 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4948 | * iwl4965_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4949 | * |
| 4950 | * Tell initialization uCode where to find runtime uCode. |
| 4951 | * |
| 4952 | * BSM registers initially contain pointers to initialization uCode. |
| 4953 | * We need to replace them to load runtime uCode inst and data, |
| 4954 | * and to save runtime data when powering down. |
| 4955 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4956 | static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4957 | { |
| 4958 | dma_addr_t pinst; |
| 4959 | dma_addr_t pdata; |
| 4960 | int rc = 0; |
| 4961 | unsigned long flags; |
| 4962 | |
| 4963 | /* bits 35:4 for 4965 */ |
| 4964 | pinst = priv->ucode_code.p_addr >> 4; |
| 4965 | pdata = priv->ucode_data_backup.p_addr >> 4; |
| 4966 | |
| 4967 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4968 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4969 | if (rc) { |
| 4970 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4971 | return rc; |
| 4972 | } |
| 4973 | |
| 4974 | /* Tell bootstrap uCode where to find image to load */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4975 | iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 4976 | iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 4977 | iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4978 | priv->ucode_data.len); |
| 4979 | |
| 4980 | /* Inst bytecount must be last to set up, bit 31 signals uCode |
| 4981 | * that all new ptr/size info is in place */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4982 | iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4983 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 4984 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4985 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4986 | |
| 4987 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4988 | |
| 4989 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 4990 | |
| 4991 | return rc; |
| 4992 | } |
| 4993 | |
| 4994 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4995 | * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4996 | * |
| 4997 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 4998 | * |
| 4999 | * The 4965 "initialize" ALIVE reply contains calibration data for: |
| 5000 | * Voltage, temperature, and MIMO tx gain correction, now stored in priv |
| 5001 | * (3945 does not contain this data). |
| 5002 | * |
| 5003 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
| 5004 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5005 | static void iwl4965_init_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5006 | { |
| 5007 | /* Check alive response for "valid" sign from uCode */ |
| 5008 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 5009 | /* We had an error bringing up the hardware, so take it |
| 5010 | * all the way back down so we can try again */ |
| 5011 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 5012 | goto restart; |
| 5013 | } |
| 5014 | |
| 5015 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 5016 | * This is a paranoid check, because we would not have gotten the |
| 5017 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5018 | if (iwl4965_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5019 | /* Runtime instruction load was bad; |
| 5020 | * take it all the way back down so we can try again */ |
| 5021 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 5022 | goto restart; |
| 5023 | } |
| 5024 | |
| 5025 | /* Calculate temperature */ |
| 5026 | priv->temperature = iwl4965_get_temperature(priv); |
| 5027 | |
| 5028 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 5029 | * load and launch runtime uCode, which will send us another "Alive" |
| 5030 | * notification. */ |
| 5031 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5032 | if (iwl4965_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5033 | /* Runtime instruction load won't happen; |
| 5034 | * take it all the way back down so we can try again */ |
| 5035 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 5036 | goto restart; |
| 5037 | } |
| 5038 | return; |
| 5039 | |
| 5040 | restart: |
| 5041 | queue_work(priv->workqueue, &priv->restart); |
| 5042 | } |
| 5043 | |
| 5044 | |
| 5045 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5046 | * iwl4965_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5047 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5048 | * Alive gets handled by iwl4965_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5049 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5050 | static void iwl4965_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5051 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 5052 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5053 | |
| 5054 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 5055 | |
| 5056 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 5057 | /* We had an error bringing up the hardware, so take it |
| 5058 | * all the way back down so we can try again */ |
| 5059 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 5060 | goto restart; |
| 5061 | } |
| 5062 | |
| 5063 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 5064 | * This is a paranoid check, because we would not have gotten the |
| 5065 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5066 | if (iwl4965_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5067 | /* Runtime instruction load was bad; |
| 5068 | * take it all the way back down so we can try again */ |
| 5069 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 5070 | goto restart; |
| 5071 | } |
| 5072 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5073 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5074 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 5075 | ret = priv->cfg->ops->lib->alive_notify(priv); |
| 5076 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5077 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 5078 | ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5079 | goto restart; |
| 5080 | } |
| 5081 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5082 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5083 | set_bit(STATUS_ALIVE, &priv->status); |
| 5084 | |
| 5085 | /* Clear out the uCode error bit if it is set */ |
| 5086 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 5087 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5088 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5089 | return; |
| 5090 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5091 | ieee80211_start_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5092 | |
| 5093 | priv->active_rate = priv->rates_mask; |
| 5094 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 5095 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5096 | if (iwl_is_associated(priv)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5097 | struct iwl4965_rxon_cmd *active_rxon = |
| 5098 | (struct iwl4965_rxon_cmd *)(&priv->active_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5099 | |
| 5100 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 5101 | sizeof(priv->staging_rxon)); |
| 5102 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 5103 | } else { |
| 5104 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5105 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5106 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 5107 | } |
| 5108 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5109 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5110 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5111 | |
| 5112 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5113 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5114 | |
| 5115 | /* At this point, the NIC is initialized and operational */ |
| 5116 | priv->notif_missed_beacons = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5117 | |
| 5118 | iwl4965_rf_kill_ct_config(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5119 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 5120 | iwl_leds_register(priv); |
| 5121 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5122 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 5123 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5124 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5125 | |
| 5126 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5127 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5128 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 5129 | iwlcore_low_level_notify(priv, IWLCORE_START_EVT); |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 5130 | ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5131 | return; |
| 5132 | |
| 5133 | restart: |
| 5134 | queue_work(priv->workqueue, &priv->restart); |
| 5135 | } |
| 5136 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5137 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5138 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5139 | static void __iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5140 | { |
| 5141 | unsigned long flags; |
| 5142 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5143 | struct ieee80211_conf *conf = NULL; |
| 5144 | |
| 5145 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 5146 | |
| 5147 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5148 | |
| 5149 | if (!exit_pending) |
| 5150 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5151 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 5152 | iwl_leds_unregister(priv); |
| 5153 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 5154 | iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT); |
| 5155 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5156 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5157 | |
| 5158 | /* Unblock any waiting calls */ |
| 5159 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 5160 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5161 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 5162 | * exiting the module */ |
| 5163 | if (!exit_pending) |
| 5164 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 5165 | |
| 5166 | /* stop and reset the on-board processor */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 5167 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5168 | |
| 5169 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5170 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5171 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5172 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5173 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5174 | |
| 5175 | if (priv->mac80211_registered) |
| 5176 | ieee80211_stop_queues(priv->hw); |
| 5177 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5178 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5179 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5180 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5181 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 5182 | STATUS_RF_KILL_HW | |
| 5183 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 5184 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 5185 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 5186 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5187 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 5188 | STATUS_IN_SUSPEND; |
| 5189 | goto exit; |
| 5190 | } |
| 5191 | |
| 5192 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 5193 | * SUSPEND bits and continue taking the NIC down. */ |
| 5194 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 5195 | STATUS_RF_KILL_HW | |
| 5196 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 5197 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 5198 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 5199 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5200 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 5201 | STATUS_IN_SUSPEND | |
| 5202 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 5203 | STATUS_FW_ERROR; |
| 5204 | |
| 5205 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 5206 | iwl_clear_bit(priv, CSR_GP_CNTRL, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5207 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5208 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5209 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5210 | iwl4965_hw_txq_ctx_stop(priv); |
| 5211 | iwl4965_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5212 | |
| 5213 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 5214 | if (!iwl_grab_nic_access(priv)) { |
| 5215 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5216 | APMG_CLK_VAL_DMA_CLK_RQT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 5217 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5218 | } |
| 5219 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5220 | |
| 5221 | udelay(5); |
| 5222 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5223 | iwl4965_hw_nic_stop_master(priv); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 5224 | iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5225 | iwl4965_hw_nic_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5226 | |
| 5227 | exit: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5228 | memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5229 | |
| 5230 | if (priv->ibss_beacon) |
| 5231 | dev_kfree_skb(priv->ibss_beacon); |
| 5232 | priv->ibss_beacon = NULL; |
| 5233 | |
| 5234 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5235 | iwl4965_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5236 | } |
| 5237 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5238 | static void iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5239 | { |
| 5240 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5241 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5242 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 5243 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5244 | iwl4965_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5245 | } |
| 5246 | |
| 5247 | #define MAX_HW_RESTARTS 5 |
| 5248 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5249 | static int __iwl4965_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5250 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 5251 | int i; |
| 5252 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5253 | |
| 5254 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 5255 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 5256 | return -EIO; |
| 5257 | } |
| 5258 | |
| 5259 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 5260 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 5261 | "parameter)\n"); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 5262 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5263 | return -ENODEV; |
| 5264 | } |
| 5265 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 5266 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 5267 | IWL_ERROR("ucode not available for device bringup\n"); |
| 5268 | return -EIO; |
| 5269 | } |
| 5270 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5271 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 5272 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5273 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 5274 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5275 | else { |
| 5276 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 5277 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 5278 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5279 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 5280 | return -ENODEV; |
| 5281 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5282 | } |
| 5283 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 5284 | iwl_rfkill_set_hw_state(priv); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 5285 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5286 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 5287 | ret = priv->cfg->ops->lib->hw_nic_init(priv); |
| 5288 | if (ret) { |
| 5289 | IWL_ERROR("Unable to init nic\n"); |
| 5290 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5291 | } |
| 5292 | |
| 5293 | /* make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 5294 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 5295 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5296 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 5297 | |
| 5298 | /* clear (again), then enable host interrupts */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 5299 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5300 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5301 | |
| 5302 | /* really make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 5303 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 5304 | 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] | 5305 | |
| 5306 | /* Copy original ucode data image from disk into backup cache. |
| 5307 | * This will be used to initialize the on-board processor's |
| 5308 | * data SRAM for a clean start when the runtime program first loads. */ |
| 5309 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5310 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5311 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5312 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 5313 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5314 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5315 | |
| 5316 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 5317 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5318 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5319 | |
| 5320 | /* load bootstrap state machine, |
| 5321 | * load bootstrap program into processor's memory, |
| 5322 | * prepare to load the "initialize" uCode */ |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 5323 | ret = priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5324 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 5325 | if (ret) { |
| 5326 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5327 | continue; |
| 5328 | } |
| 5329 | |
| 5330 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5331 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5332 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5333 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 5334 | |
| 5335 | return 0; |
| 5336 | } |
| 5337 | |
| 5338 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5339 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5340 | |
| 5341 | /* tried to restart and config the device for as long as our |
| 5342 | * patience could withstand */ |
| 5343 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 5344 | return -EIO; |
| 5345 | } |
| 5346 | |
| 5347 | |
| 5348 | /***************************************************************************** |
| 5349 | * |
| 5350 | * Workqueue callbacks |
| 5351 | * |
| 5352 | *****************************************************************************/ |
| 5353 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5354 | static void iwl4965_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5355 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5356 | struct iwl_priv *priv = |
| 5357 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5358 | |
| 5359 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5360 | return; |
| 5361 | |
| 5362 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5363 | iwl4965_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5364 | mutex_unlock(&priv->mutex); |
| 5365 | } |
| 5366 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5367 | static void iwl4965_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5368 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5369 | struct iwl_priv *priv = |
| 5370 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5371 | |
| 5372 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5373 | return; |
| 5374 | |
| 5375 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5376 | iwl4965_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5377 | mutex_unlock(&priv->mutex); |
| 5378 | } |
| 5379 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5380 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5381 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5382 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5383 | |
| 5384 | wake_up_interruptible(&priv->wait_command_queue); |
| 5385 | |
| 5386 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5387 | return; |
| 5388 | |
| 5389 | mutex_lock(&priv->mutex); |
| 5390 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5391 | if (!iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5392 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 5393 | "HW and/or SW RF Kill no longer active, restarting " |
| 5394 | "device\n"); |
| 5395 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5396 | queue_work(priv->workqueue, &priv->restart); |
| 5397 | } else { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 5398 | /* make sure mac80211 stop sending Tx frame */ |
| 5399 | if (priv->mac80211_registered) |
| 5400 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5401 | |
| 5402 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 5403 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 5404 | "disabled by SW switch\n"); |
| 5405 | else |
| 5406 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 5407 | "Kill switch must be turned off for " |
| 5408 | "wireless networking to work.\n"); |
| 5409 | } |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 5410 | iwl_rfkill_set_hw_state(priv); |
| 5411 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5412 | mutex_unlock(&priv->mutex); |
| 5413 | } |
| 5414 | |
| 5415 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 5416 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5417 | static void iwl4965_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5418 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5419 | struct iwl_priv *priv = |
| 5420 | container_of(data, struct iwl_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5421 | |
| 5422 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5423 | return; |
| 5424 | |
| 5425 | mutex_lock(&priv->mutex); |
| 5426 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 5427 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 5428 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 5429 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 5430 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5431 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5432 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5433 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5434 | } |
| 5435 | mutex_unlock(&priv->mutex); |
| 5436 | } |
| 5437 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5438 | static void iwl4965_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5439 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5440 | struct iwl_priv *priv = |
| 5441 | container_of(data, struct iwl_priv, request_scan); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5442 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5443 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5444 | .len = sizeof(struct iwl4965_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5445 | .meta.flags = CMD_SIZE_HUGE, |
| 5446 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5447 | struct iwl4965_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5448 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5449 | u16 cmd_len; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5450 | enum ieee80211_band band; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5451 | u8 direct_mask; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5452 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5453 | |
| 5454 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5455 | |
| 5456 | mutex_lock(&priv->mutex); |
| 5457 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5458 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5459 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 5460 | goto done; |
| 5461 | } |
| 5462 | |
| 5463 | /* Make sure the scan wasn't cancelled before this queued work |
| 5464 | * was given the chance to run... */ |
| 5465 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 5466 | goto done; |
| 5467 | |
| 5468 | /* This should never be called or scheduled if there is currently |
| 5469 | * a scan active in the hardware. */ |
| 5470 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 5471 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 5472 | "Ignoring second request.\n"); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5473 | ret = -EIO; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5474 | goto done; |
| 5475 | } |
| 5476 | |
| 5477 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 5478 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 5479 | goto done; |
| 5480 | } |
| 5481 | |
| 5482 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 5483 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 5484 | goto done; |
| 5485 | } |
| 5486 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5487 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5488 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 5489 | goto done; |
| 5490 | } |
| 5491 | |
| 5492 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 5493 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 5494 | goto done; |
| 5495 | } |
| 5496 | |
| 5497 | if (!priv->scan_bands) { |
| 5498 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 5499 | goto done; |
| 5500 | } |
| 5501 | |
| 5502 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5503 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5504 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 5505 | if (!priv->scan) { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5506 | ret = -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5507 | goto done; |
| 5508 | } |
| 5509 | } |
| 5510 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5511 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5512 | |
| 5513 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 5514 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 5515 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5516 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5517 | u16 interval = 0; |
| 5518 | u32 extra; |
| 5519 | u32 suspend_time = 100; |
| 5520 | u32 scan_suspend_time = 100; |
| 5521 | unsigned long flags; |
| 5522 | |
| 5523 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 5524 | |
| 5525 | spin_lock_irqsave(&priv->lock, flags); |
| 5526 | interval = priv->beacon_int; |
| 5527 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5528 | |
| 5529 | scan->suspend_time = 0; |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5530 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5531 | if (!interval) |
| 5532 | interval = suspend_time; |
| 5533 | |
| 5534 | extra = (suspend_time / interval) << 22; |
| 5535 | scan_suspend_time = (extra | |
| 5536 | ((suspend_time % interval) * 1024)); |
| 5537 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 5538 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 5539 | scan_suspend_time, interval); |
| 5540 | } |
| 5541 | |
| 5542 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 5543 | if (priv->one_direct_scan) { |
| 5544 | IWL_DEBUG_SCAN |
| 5545 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5546 | iwl4965_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5547 | priv->direct_ssid_len)); |
| 5548 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 5549 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 5550 | memcpy(scan->direct_scan[0].ssid, |
| 5551 | priv->direct_ssid, priv->direct_ssid_len); |
| 5552 | direct_mask = 1; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5553 | } else if (!iwl_is_associated(priv) && priv->essid_len) { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 5554 | IWL_DEBUG_SCAN |
| 5555 | ("Kicking off one direct scan for '%s' when not associated\n", |
| 5556 | iwl4965_escape_essid(priv->essid, priv->essid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5557 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 5558 | scan->direct_scan[0].len = priv->essid_len; |
| 5559 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 5560 | direct_mask = 1; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5561 | } else { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 5562 | IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5563 | direct_mask = 0; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5564 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5565 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5566 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 5567 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5568 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 5569 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5570 | |
| 5571 | switch (priv->scan_bands) { |
| 5572 | case 2: |
| 5573 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 5574 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5575 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5576 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 5577 | |
| 5578 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5579 | band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5580 | break; |
| 5581 | |
| 5582 | case 1: |
| 5583 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5584 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5585 | RATE_MCS_ANT_B_MSK); |
| 5586 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5587 | band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5588 | break; |
| 5589 | |
| 5590 | default: |
| 5591 | IWL_WARNING("Invalid scan band count\n"); |
| 5592 | goto done; |
| 5593 | } |
| 5594 | |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5595 | /* We don't build a direct scan probe request; the uCode will do |
| 5596 | * that based on the direct_mask added to each channel entry */ |
| 5597 | cmd_len = iwl4965_fill_probe_req(priv, band, |
| 5598 | (struct ieee80211_mgmt *)scan->data, |
| 5599 | IWL_MAX_SCAN_SIZE - sizeof(*scan), 0); |
| 5600 | |
| 5601 | scan->tx_cmd.len = cpu_to_le16(cmd_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5602 | /* select Rx chains */ |
| 5603 | |
| 5604 | /* Force use of chains B and C (0x6) for scan Rx. |
| 5605 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 5606 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 5607 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 5608 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 5609 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 5610 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 5611 | |
| 5612 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 5613 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 5614 | |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 5615 | if (direct_mask) |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 5616 | scan->channel_count = |
| 5617 | iwl4965_get_channels_for_scan( |
| 5618 | priv, band, 1, /* active */ |
| 5619 | direct_mask, |
| 5620 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 5621 | else |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 5622 | scan->channel_count = |
| 5623 | iwl4965_get_channels_for_scan( |
| 5624 | priv, band, 0, /* passive */ |
| 5625 | direct_mask, |
| 5626 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5627 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 5628 | scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | |
| 5629 | RXON_FILTER_BCON_AWARE_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5630 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5631 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5632 | cmd.data = scan; |
| 5633 | scan->len = cpu_to_le16(cmd.len); |
| 5634 | |
| 5635 | set_bit(STATUS_SCAN_HW, &priv->status); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5636 | ret = iwl_send_cmd_sync(priv, &cmd); |
| 5637 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5638 | goto done; |
| 5639 | |
| 5640 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 5641 | IWL_SCAN_CHECK_WATCHDOG); |
| 5642 | |
| 5643 | mutex_unlock(&priv->mutex); |
| 5644 | return; |
| 5645 | |
| 5646 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 5647 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5648 | queue_work(priv->workqueue, &priv->scan_completed); |
| 5649 | mutex_unlock(&priv->mutex); |
| 5650 | } |
| 5651 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5652 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5653 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5654 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5655 | |
| 5656 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5657 | return; |
| 5658 | |
| 5659 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5660 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5661 | mutex_unlock(&priv->mutex); |
| 5662 | } |
| 5663 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5664 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5665 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5666 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5667 | |
| 5668 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5669 | return; |
| 5670 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5671 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5672 | queue_work(priv->workqueue, &priv->up); |
| 5673 | } |
| 5674 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5675 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5676 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5677 | struct iwl_priv *priv = |
| 5678 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5679 | |
| 5680 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5681 | return; |
| 5682 | |
| 5683 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5684 | iwl4965_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5685 | mutex_unlock(&priv->mutex); |
| 5686 | } |
| 5687 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5688 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 5689 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5690 | static void iwl4965_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5691 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5692 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5693 | int ret = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5694 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5695 | |
| 5696 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 5697 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 5698 | return; |
| 5699 | } |
| 5700 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5701 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 5702 | priv->assoc_id, |
| 5703 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5704 | |
| 5705 | |
| 5706 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5707 | return; |
| 5708 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5709 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5710 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5711 | return; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5712 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5713 | iwl4965_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5714 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5715 | conf = ieee80211_get_hw_conf(priv->hw); |
| 5716 | |
| 5717 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5718 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5719 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5720 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 5721 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5722 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5723 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5724 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5725 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 5726 | "Attempting to continue.\n"); |
| 5727 | |
| 5728 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 5729 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5730 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 5731 | if (priv->current_ht_config.is_ht) |
| 5732 | iwl4965_set_rxon_ht(priv, &priv->current_ht_config); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5733 | #endif /* CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5734 | iwl4965_set_rxon_chain(priv); |
| 5735 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 5736 | |
| 5737 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 5738 | priv->assoc_id, priv->beacon_int); |
| 5739 | |
| 5740 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 5741 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5742 | else |
| 5743 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5744 | |
| 5745 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 5746 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 5747 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 5748 | else |
| 5749 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 5750 | |
| 5751 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 5752 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 5753 | |
| 5754 | } |
| 5755 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5756 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5757 | |
| 5758 | switch (priv->iw_mode) { |
| 5759 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5760 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5761 | break; |
| 5762 | |
| 5763 | case IEEE80211_IF_TYPE_IBSS: |
| 5764 | |
| 5765 | /* clear out the station table */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5766 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5767 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5768 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
| 5769 | iwl4965_rxon_add_station(priv, priv->bssid, 0); |
| 5770 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
| 5771 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5772 | |
| 5773 | break; |
| 5774 | |
| 5775 | default: |
| 5776 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 5777 | __FUNCTION__, priv->iw_mode); |
| 5778 | break; |
| 5779 | } |
| 5780 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5781 | iwl4965_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5782 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5783 | /* Enable Rx differential gain and sensitivity calibrations */ |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 5784 | iwl_chain_noise_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5785 | priv->start_calib = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5786 | |
| 5787 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 5788 | priv->assoc_station_added = 1; |
| 5789 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5790 | iwl4965_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 5791 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 5792 | iwl_power_update_mode(priv, 0); |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5793 | /* we have just associated, don't start scan too early */ |
| 5794 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5795 | } |
| 5796 | |
| 5797 | |
| 5798 | static void iwl4965_bg_post_associate(struct work_struct *data) |
| 5799 | { |
| 5800 | struct iwl_priv *priv = container_of(data, struct iwl_priv, |
| 5801 | post_associate.work); |
| 5802 | |
| 5803 | mutex_lock(&priv->mutex); |
| 5804 | iwl4965_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5805 | mutex_unlock(&priv->mutex); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5806 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5807 | } |
| 5808 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5809 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5810 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5811 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5812 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5813 | if (!iwl_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5814 | return; |
| 5815 | |
| 5816 | mutex_lock(&priv->mutex); |
| 5817 | |
| 5818 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5819 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5820 | |
| 5821 | mutex_unlock(&priv->mutex); |
| 5822 | } |
| 5823 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5824 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 5825 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5826 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5827 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5828 | struct iwl_priv *priv = |
| 5829 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5830 | |
| 5831 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 5832 | |
| 5833 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 5834 | return; |
| 5835 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 5836 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
| 5837 | iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5838 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5839 | ieee80211_scan_completed(priv->hw); |
| 5840 | |
| 5841 | /* Since setting the TXPOWER may have been deferred while |
| 5842 | * performing the scan, fire one off */ |
| 5843 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5844 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5845 | mutex_unlock(&priv->mutex); |
| 5846 | } |
| 5847 | |
| 5848 | /***************************************************************************** |
| 5849 | * |
| 5850 | * mac80211 entry point functions |
| 5851 | * |
| 5852 | *****************************************************************************/ |
| 5853 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5854 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 5855 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5856 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5857 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5858 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5859 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5860 | |
| 5861 | IWL_DEBUG_MAC80211("enter\n"); |
| 5862 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5863 | if (pci_enable_device(priv->pci_dev)) { |
| 5864 | IWL_ERROR("Fail to pci_enable_device\n"); |
| 5865 | return -ENODEV; |
| 5866 | } |
| 5867 | pci_restore_state(priv->pci_dev); |
| 5868 | pci_enable_msi(priv->pci_dev); |
| 5869 | |
| 5870 | ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, |
| 5871 | DRV_NAME, priv); |
| 5872 | if (ret) { |
| 5873 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 5874 | goto out_disable_msi; |
| 5875 | } |
| 5876 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5877 | /* we should be verifying the device is ready to be opened */ |
| 5878 | mutex_lock(&priv->mutex); |
| 5879 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5880 | memset(&priv->staging_rxon, 0, sizeof(struct iwl4965_rxon_cmd)); |
| 5881 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 5882 | * ucode filename and max sizes are card-specific. */ |
| 5883 | |
| 5884 | if (!priv->ucode_code.len) { |
| 5885 | ret = iwl4965_read_ucode(priv); |
| 5886 | if (ret) { |
| 5887 | IWL_ERROR("Could not read microcode: %d\n", ret); |
| 5888 | mutex_unlock(&priv->mutex); |
| 5889 | goto out_release_irq; |
| 5890 | } |
| 5891 | } |
| 5892 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5893 | ret = __iwl4965_up(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5894 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5895 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5896 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5897 | if (ret) |
| 5898 | goto out_release_irq; |
| 5899 | |
| 5900 | IWL_DEBUG_INFO("Start UP work done.\n"); |
| 5901 | |
| 5902 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 5903 | return 0; |
| 5904 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5905 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 5906 | * mac80211 will not be run successfully. */ |
| 5907 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 5908 | test_bit(STATUS_READY, &priv->status), |
| 5909 | UCODE_READY_TIMEOUT); |
| 5910 | if (!ret) { |
| 5911 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 5912 | IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n", |
| 5913 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 5914 | ret = -ETIMEDOUT; |
| 5915 | goto out_release_irq; |
| 5916 | } |
| 5917 | } |
| 5918 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5919 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5920 | IWL_DEBUG_MAC80211("leave\n"); |
| 5921 | return 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5922 | |
| 5923 | out_release_irq: |
| 5924 | free_irq(priv->pci_dev->irq, priv); |
| 5925 | out_disable_msi: |
| 5926 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5927 | pci_disable_device(priv->pci_dev); |
| 5928 | priv->is_open = 0; |
| 5929 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5930 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5931 | } |
| 5932 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5933 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5934 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5935 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5936 | |
| 5937 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5938 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5939 | if (!priv->is_open) { |
| 5940 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 5941 | return; |
| 5942 | } |
| 5943 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5944 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5945 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5946 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5947 | /* stop mac, cancel any scan request and clear |
| 5948 | * RXON_FILTER_ASSOC_MSK BIT |
| 5949 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5950 | mutex_lock(&priv->mutex); |
| 5951 | iwl4965_scan_cancel_timeout(priv, 100); |
| 5952 | cancel_delayed_work(&priv->post_associate); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5953 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5954 | } |
| 5955 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5956 | iwl4965_down(priv); |
| 5957 | |
| 5958 | flush_workqueue(priv->workqueue); |
| 5959 | free_irq(priv->pci_dev->irq, priv); |
| 5960 | pci_disable_msi(priv->pci_dev); |
| 5961 | pci_save_state(priv->pci_dev); |
| 5962 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5963 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5964 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5965 | } |
| 5966 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5967 | 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] | 5968 | struct ieee80211_tx_control *ctl) |
| 5969 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5970 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5971 | |
| 5972 | IWL_DEBUG_MAC80211("enter\n"); |
| 5973 | |
| 5974 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 5975 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 5976 | return -1; |
| 5977 | } |
| 5978 | |
| 5979 | 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] | 5980 | ctl->tx_rate->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5981 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5982 | if (iwl4965_tx_skb(priv, skb, ctl)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5983 | dev_kfree_skb_any(skb); |
| 5984 | |
| 5985 | IWL_DEBUG_MAC80211("leave\n"); |
| 5986 | return 0; |
| 5987 | } |
| 5988 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5989 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5990 | struct ieee80211_if_init_conf *conf) |
| 5991 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5992 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5993 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5994 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5995 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5996 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5997 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5998 | if (priv->vif) { |
| 5999 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Reinette Chatre | 75849d2 | 2008-01-23 10:15:17 -0800 | [diff] [blame] | 6000 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6001 | } |
| 6002 | |
| 6003 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6004 | priv->vif = conf->vif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6005 | |
| 6006 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6007 | |
| 6008 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6009 | |
| 6010 | if (conf->mac_addr) { |
| 6011 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 6012 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 6013 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6014 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6015 | if (iwl_is_ready(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6016 | iwl4965_set_mode(priv, conf->type); |
| 6017 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6018 | mutex_unlock(&priv->mutex); |
| 6019 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6020 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6021 | return 0; |
| 6022 | } |
| 6023 | |
| 6024 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6025 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6026 | * |
| 6027 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 6028 | * be set inappropriately and the driver currently sets the hardware up to |
| 6029 | * use it whenever needed. |
| 6030 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6031 | 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] | 6032 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6033 | struct iwl_priv *priv = hw->priv; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6034 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6035 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6036 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6037 | |
| 6038 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6039 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6040 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 6041 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
| 6042 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6043 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6044 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6045 | ret = -EIO; |
| 6046 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6047 | } |
| 6048 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 6049 | if (unlikely(!priv->cfg->mod_params->disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6050 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6051 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 6052 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6053 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6054 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6055 | } |
| 6056 | |
| 6057 | spin_lock_irqsave(&priv->lock, flags); |
| 6058 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 6059 | ch_info = iwl_get_channel_info(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6060 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6061 | if (!is_channel_valid(ch_info)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6062 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 6063 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6064 | ret = -EINVAL; |
| 6065 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6066 | } |
| 6067 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6068 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 6069 | /* if we are switching from ht to 2.4 clear flags |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6070 | * from any ht related info since 2.4 does not |
| 6071 | * support ht */ |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 6072 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6073 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 6074 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 6075 | #endif |
| 6076 | ) |
| 6077 | priv->staging_rxon.flags = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6078 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6079 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6080 | iwlcore_set_rxon_channel(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6081 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6082 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6083 | iwl4965_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6084 | |
| 6085 | /* The list of supported rates and rate mask can be different |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6086 | * for each band; since the band may have changed, reset |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6087 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6088 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6089 | |
| 6090 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6091 | |
| 6092 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 6093 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6094 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6095 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6096 | } |
| 6097 | #endif |
| 6098 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 6099 | if (priv->cfg->ops->lib->radio_kill_sw) |
| 6100 | priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6101 | |
| 6102 | if (!conf->radio_enabled) { |
| 6103 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6104 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6105 | } |
| 6106 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6107 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6108 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6109 | ret = -EIO; |
| 6110 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6111 | } |
| 6112 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6113 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6114 | |
| 6115 | if (memcmp(&priv->active_rxon, |
| 6116 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6117 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6118 | else |
| 6119 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 6120 | |
| 6121 | IWL_DEBUG_MAC80211("leave\n"); |
| 6122 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6123 | out: |
| 6124 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6125 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6126 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6127 | } |
| 6128 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6129 | static void iwl4965_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6130 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 6131 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6132 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 6133 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6134 | return; |
| 6135 | |
| 6136 | /* The following should be done only at AP bring up */ |
| 6137 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 6138 | |
| 6139 | /* RXON - unassoc (to set timing command) */ |
| 6140 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6141 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6142 | |
| 6143 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6144 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 6145 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 6146 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6147 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 6148 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6149 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 6150 | "Attempting to continue.\n"); |
| 6151 | |
| 6152 | iwl4965_set_rxon_chain(priv); |
| 6153 | |
| 6154 | /* FIXME: what should be the assoc_id for AP? */ |
| 6155 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 6156 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 6157 | priv->staging_rxon.flags |= |
| 6158 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6159 | else |
| 6160 | priv->staging_rxon.flags &= |
| 6161 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6162 | |
| 6163 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 6164 | if (priv->assoc_capability & |
| 6165 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 6166 | priv->staging_rxon.flags |= |
| 6167 | RXON_FLG_SHORT_SLOT_MSK; |
| 6168 | else |
| 6169 | priv->staging_rxon.flags &= |
| 6170 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 6171 | |
| 6172 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 6173 | priv->staging_rxon.flags &= |
| 6174 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 6175 | } |
| 6176 | /* restore RXON assoc */ |
| 6177 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6178 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6179 | iwl4965_activate_qos(priv, 1); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6180 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 6181 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6182 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6183 | |
| 6184 | /* FIXME - we need to add code here to detect a totally new |
| 6185 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 6186 | * clear sta table, add BCAST sta... */ |
| 6187 | } |
| 6188 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6189 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, |
| 6190 | struct ieee80211_vif *vif, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6191 | struct ieee80211_if_conf *conf) |
| 6192 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6193 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6194 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6195 | unsigned long flags; |
| 6196 | int rc; |
| 6197 | |
| 6198 | if (conf == NULL) |
| 6199 | return -EIO; |
| 6200 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 6201 | if (priv->vif != vif) { |
| 6202 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 6203 | return 0; |
| 6204 | } |
| 6205 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6206 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 6207 | (!conf->beacon || !conf->ssid_len)) { |
| 6208 | IWL_DEBUG_MAC80211 |
| 6209 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 6210 | return 0; |
| 6211 | } |
| 6212 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6213 | if (!iwl_is_alive(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6214 | return -EAGAIN; |
| 6215 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6216 | mutex_lock(&priv->mutex); |
| 6217 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6218 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6219 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 6220 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6221 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6222 | /* |
| 6223 | * very dubious code was here; the probe filtering flag is never set: |
| 6224 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6225 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 6226 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6227 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6228 | |
| 6229 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 6230 | if (!conf->bssid) { |
| 6231 | conf->bssid = priv->mac_addr; |
| 6232 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6233 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 6234 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6235 | } |
| 6236 | if (priv->ibss_beacon) |
| 6237 | dev_kfree_skb(priv->ibss_beacon); |
| 6238 | |
| 6239 | priv->ibss_beacon = conf->beacon; |
| 6240 | } |
| 6241 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6242 | if (iwl_is_rfkill(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6243 | goto done; |
| 6244 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6245 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 6246 | !is_multicast_ether_addr(conf->bssid)) { |
| 6247 | /* If there is currently a HW scan going on in the background |
| 6248 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6249 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6250 | IWL_WARNING("Aborted scan still in progress " |
| 6251 | "after 100ms\n"); |
| 6252 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 6253 | mutex_unlock(&priv->mutex); |
| 6254 | return -EAGAIN; |
| 6255 | } |
| 6256 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 6257 | |
| 6258 | /* TODO: Audit driver for usage of these members and see |
| 6259 | * if mac80211 deprecates them (priv->bssid looks like it |
| 6260 | * shouldn't be there, but I haven't scanned the IBSS code |
| 6261 | * to verify) - jpk */ |
| 6262 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 6263 | |
| 6264 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6265 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6266 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6267 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6268 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6269 | iwl4965_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6270 | priv, priv->active_rxon.bssid_addr, 1); |
| 6271 | } |
| 6272 | |
| 6273 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6274 | iwl4965_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6275 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6276 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6277 | } |
| 6278 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6279 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6280 | spin_lock_irqsave(&priv->lock, flags); |
| 6281 | if (!conf->ssid_len) |
| 6282 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 6283 | else |
| 6284 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 6285 | |
| 6286 | priv->essid_len = conf->ssid_len; |
| 6287 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6288 | |
| 6289 | IWL_DEBUG_MAC80211("leave\n"); |
| 6290 | mutex_unlock(&priv->mutex); |
| 6291 | |
| 6292 | return 0; |
| 6293 | } |
| 6294 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6295 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6296 | unsigned int changed_flags, |
| 6297 | unsigned int *total_flags, |
| 6298 | int mc_count, struct dev_addr_list *mc_list) |
| 6299 | { |
| 6300 | /* |
| 6301 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6302 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 6303 | */ |
| 6304 | *total_flags = 0; |
| 6305 | } |
| 6306 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6307 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6308 | struct ieee80211_if_init_conf *conf) |
| 6309 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6310 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6311 | |
| 6312 | IWL_DEBUG_MAC80211("enter\n"); |
| 6313 | |
| 6314 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 6315 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6316 | if (iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6317 | iwl4965_scan_cancel_timeout(priv, 100); |
| 6318 | cancel_delayed_work(&priv->post_associate); |
| 6319 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 6320 | iwl4965_commit_rxon(priv); |
| 6321 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6322 | if (priv->vif == conf->vif) { |
| 6323 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6324 | memset(priv->bssid, 0, ETH_ALEN); |
| 6325 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 6326 | priv->essid_len = 0; |
| 6327 | } |
| 6328 | mutex_unlock(&priv->mutex); |
| 6329 | |
| 6330 | IWL_DEBUG_MAC80211("leave\n"); |
| 6331 | |
| 6332 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 6333 | |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 6334 | |
| 6335 | #ifdef CONFIG_IWL4965_HT |
| 6336 | static void iwl4965_ht_conf(struct iwl_priv *priv, |
| 6337 | struct ieee80211_bss_conf *bss_conf) |
| 6338 | { |
| 6339 | struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf; |
| 6340 | struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf; |
| 6341 | struct iwl_ht_info *iwl_conf = &priv->current_ht_config; |
| 6342 | |
| 6343 | IWL_DEBUG_MAC80211("enter: \n"); |
| 6344 | |
| 6345 | iwl_conf->is_ht = bss_conf->assoc_ht; |
| 6346 | |
| 6347 | if (!iwl_conf->is_ht) |
| 6348 | return; |
| 6349 | |
| 6350 | priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 6351 | |
| 6352 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) |
| 6353 | iwl_conf->sgf |= 0x1; |
| 6354 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) |
| 6355 | iwl_conf->sgf |= 0x2; |
| 6356 | |
| 6357 | iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); |
| 6358 | iwl_conf->max_amsdu_size = |
| 6359 | !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); |
| 6360 | |
| 6361 | iwl_conf->supported_chan_width = |
| 6362 | !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); |
| 6363 | iwl_conf->extension_chan_offset = |
| 6364 | ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; |
| 6365 | /* If no above or below channel supplied disable FAT channel */ |
| 6366 | if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE && |
| 6367 | iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW) |
| 6368 | iwl_conf->supported_chan_width = 0; |
| 6369 | |
| 6370 | iwl_conf->tx_mimo_ps_mode = |
| 6371 | (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 6372 | memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); |
| 6373 | |
| 6374 | iwl_conf->control_channel = ht_bss_conf->primary_channel; |
| 6375 | iwl_conf->tx_chan_width = |
| 6376 | !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); |
| 6377 | iwl_conf->ht_protection = |
| 6378 | ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; |
| 6379 | iwl_conf->non_GF_STA_present = |
| 6380 | !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT); |
| 6381 | |
| 6382 | IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel); |
| 6383 | IWL_DEBUG_MAC80211("leave\n"); |
| 6384 | } |
| 6385 | #else |
| 6386 | static inline void iwl4965_ht_conf(struct iwl_priv *priv, |
| 6387 | struct ieee80211_bss_conf *bss_conf) |
| 6388 | { |
| 6389 | } |
| 6390 | #endif |
| 6391 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 6392 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 6393 | static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, |
| 6394 | struct ieee80211_vif *vif, |
| 6395 | struct ieee80211_bss_conf *bss_conf, |
| 6396 | u32 changes) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 6397 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6398 | struct iwl_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 6399 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 6400 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
| 6401 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 6402 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 6403 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
| 6404 | bss_conf->use_short_preamble); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 6405 | if (bss_conf->use_short_preamble) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 6406 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6407 | else |
| 6408 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6409 | } |
| 6410 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 6411 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 6412 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6413 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 6414 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 6415 | else |
| 6416 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 6417 | } |
| 6418 | |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 6419 | if (changes & BSS_CHANGED_HT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 6420 | IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 6421 | iwl4965_ht_conf(priv, bss_conf); |
| 6422 | iwl4965_set_rxon_chain(priv); |
| 6423 | } |
| 6424 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 6425 | if (changes & BSS_CHANGED_ASSOC) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 6426 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 6427 | /* This should never happen as this function should |
| 6428 | * never be called from interrupt context. */ |
| 6429 | if (WARN_ON_ONCE(in_interrupt())) |
| 6430 | return; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 6431 | if (bss_conf->assoc) { |
| 6432 | priv->assoc_id = bss_conf->aid; |
| 6433 | priv->beacon_int = bss_conf->beacon_int; |
| 6434 | priv->timestamp = bss_conf->timestamp; |
| 6435 | priv->assoc_capability = bss_conf->assoc_capability; |
| 6436 | priv->next_scan_jiffies = jiffies + |
| 6437 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 6438 | mutex_lock(&priv->mutex); |
| 6439 | iwl4965_post_associate(priv); |
| 6440 | mutex_unlock(&priv->mutex); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 6441 | } else { |
| 6442 | priv->assoc_id = 0; |
| 6443 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); |
| 6444 | } |
| 6445 | } else if (changes && iwl_is_associated(priv) && priv->assoc_id) { |
| 6446 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 6447 | iwl_send_rxon_assoc(priv); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 6448 | } |
| 6449 | |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 6450 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6451 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6452 | 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] | 6453 | { |
| 6454 | int rc = 0; |
| 6455 | unsigned long flags; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6456 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6457 | |
| 6458 | IWL_DEBUG_MAC80211("enter\n"); |
| 6459 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6460 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6461 | spin_lock_irqsave(&priv->lock, flags); |
| 6462 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6463 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6464 | rc = -EIO; |
| 6465 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 6466 | goto out_unlock; |
| 6467 | } |
| 6468 | |
| 6469 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 6470 | rc = -EIO; |
| 6471 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 6472 | goto out_unlock; |
| 6473 | } |
| 6474 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6475 | /* we don't schedule scan within next_scan_jiffies period */ |
| 6476 | if (priv->next_scan_jiffies && |
| 6477 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 6478 | rc = -EAGAIN; |
| 6479 | goto out_unlock; |
| 6480 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6481 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6482 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 6483 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6484 | rc = -EAGAIN; |
| 6485 | goto out_unlock; |
| 6486 | } |
| 6487 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6488 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6489 | iwl4965_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6490 | |
| 6491 | priv->one_direct_scan = 1; |
| 6492 | priv->direct_ssid_len = (u8) |
| 6493 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 6494 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 6495 | } else |
| 6496 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6497 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6498 | rc = iwl4965_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6499 | |
| 6500 | IWL_DEBUG_MAC80211("leave\n"); |
| 6501 | |
| 6502 | out_unlock: |
| 6503 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6504 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6505 | |
| 6506 | return rc; |
| 6507 | } |
| 6508 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 6509 | static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 6510 | struct ieee80211_key_conf *keyconf, const u8 *addr, |
| 6511 | u32 iv32, u16 *phase1key) |
| 6512 | { |
| 6513 | struct iwl_priv *priv = hw->priv; |
| 6514 | u8 sta_id = IWL_INVALID_STATION; |
| 6515 | unsigned long flags; |
| 6516 | __le16 key_flags = 0; |
| 6517 | int i; |
| 6518 | DECLARE_MAC_BUF(mac); |
| 6519 | |
| 6520 | IWL_DEBUG_MAC80211("enter\n"); |
| 6521 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 6522 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 6523 | if (sta_id == IWL_INVALID_STATION) { |
| 6524 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 6525 | print_mac(mac, addr)); |
| 6526 | return; |
| 6527 | } |
| 6528 | |
| 6529 | iwl4965_scan_cancel_timeout(priv, 100); |
| 6530 | |
| 6531 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); |
| 6532 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 6533 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 6534 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 6535 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 6536 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 6537 | |
| 6538 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 6539 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 6540 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 6541 | priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; |
| 6542 | |
| 6543 | for (i = 0; i < 5; i++) |
| 6544 | priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = |
| 6545 | cpu_to_le16(phase1key[i]); |
| 6546 | |
| 6547 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 6548 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 6549 | |
| 6550 | iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
| 6551 | |
| 6552 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 6553 | |
| 6554 | IWL_DEBUG_MAC80211("leave\n"); |
| 6555 | } |
| 6556 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6557 | 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] | 6558 | const u8 *local_addr, const u8 *addr, |
| 6559 | struct ieee80211_key_conf *key) |
| 6560 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6561 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6562 | DECLARE_MAC_BUF(mac); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 6563 | int ret = 0; |
| 6564 | u8 sta_id = IWL_INVALID_STATION; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 6565 | u8 is_default_wep_key = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6566 | |
| 6567 | IWL_DEBUG_MAC80211("enter\n"); |
| 6568 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 6569 | if (priv->hw_params.sw_crypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6570 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 6571 | return -EOPNOTSUPP; |
| 6572 | } |
| 6573 | |
| 6574 | if (is_zero_ether_addr(addr)) |
| 6575 | /* only support pairwise keys */ |
| 6576 | return -EOPNOTSUPP; |
| 6577 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 6578 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 6579 | if (sta_id == IWL_INVALID_STATION) { |
| 6580 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 6581 | print_mac(mac, addr)); |
| 6582 | return -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6583 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 6584 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6585 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 6586 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6587 | iwl4965_scan_cancel_timeout(priv, 100); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 6588 | mutex_unlock(&priv->mutex); |
| 6589 | |
| 6590 | /* If we are getting WEP group key and we didn't receive any key mapping |
| 6591 | * so far, we are in legacy wep mode (group key only), otherwise we are |
| 6592 | * in 1X mode. |
| 6593 | * In legacy wep mode, we use another host command to the uCode */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 6594 | 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] | 6595 | priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 6596 | if (cmd == SET_KEY) |
| 6597 | is_default_wep_key = !priv->key_mapping_key; |
| 6598 | else |
| 6599 | is_default_wep_key = priv->default_wep_key; |
| 6600 | } |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6601 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6602 | switch (cmd) { |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 6603 | case SET_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 6604 | if (is_default_wep_key) |
| 6605 | ret = iwl_set_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 6606 | else |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 6607 | ret = iwl_set_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 6608 | |
| 6609 | IWL_DEBUG_MAC80211("enable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6610 | break; |
| 6611 | case DISABLE_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 6612 | if (is_default_wep_key) |
| 6613 | ret = iwl_remove_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 6614 | else |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 6615 | ret = iwl_remove_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 6616 | |
| 6617 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6618 | break; |
| 6619 | default: |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 6620 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6621 | } |
| 6622 | |
| 6623 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6624 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 6625 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6626 | } |
| 6627 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6628 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, int queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6629 | const struct ieee80211_tx_queue_params *params) |
| 6630 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6631 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6632 | unsigned long flags; |
| 6633 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6634 | |
| 6635 | IWL_DEBUG_MAC80211("enter\n"); |
| 6636 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6637 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6638 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 6639 | return -EIO; |
| 6640 | } |
| 6641 | |
| 6642 | if (queue >= AC_NUM) { |
| 6643 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 6644 | return 0; |
| 6645 | } |
| 6646 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6647 | if (!priv->qos_data.qos_enable) { |
| 6648 | priv->qos_data.qos_active = 0; |
| 6649 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 6650 | return 0; |
| 6651 | } |
| 6652 | q = AC_NUM - 1 - queue; |
| 6653 | |
| 6654 | spin_lock_irqsave(&priv->lock, flags); |
| 6655 | |
| 6656 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 6657 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 6658 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 6659 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 6660 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6661 | |
| 6662 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 6663 | priv->qos_data.qos_active = 1; |
| 6664 | |
| 6665 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6666 | |
| 6667 | mutex_lock(&priv->mutex); |
| 6668 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6669 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 6670 | else if (priv->assoc_id && iwl_is_associated(priv)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6671 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6672 | |
| 6673 | mutex_unlock(&priv->mutex); |
| 6674 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6675 | IWL_DEBUG_MAC80211("leave\n"); |
| 6676 | return 0; |
| 6677 | } |
| 6678 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6679 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6680 | struct ieee80211_tx_queue_stats *stats) |
| 6681 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6682 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6683 | int i, avail; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6684 | struct iwl4965_tx_queue *txq; |
| 6685 | struct iwl4965_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6686 | unsigned long flags; |
| 6687 | |
| 6688 | IWL_DEBUG_MAC80211("enter\n"); |
| 6689 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6690 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6691 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 6692 | return -EIO; |
| 6693 | } |
| 6694 | |
| 6695 | spin_lock_irqsave(&priv->lock, flags); |
| 6696 | |
| 6697 | for (i = 0; i < AC_NUM; i++) { |
| 6698 | txq = &priv->txq[i]; |
| 6699 | q = &txq->q; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6700 | avail = iwl4965_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6701 | |
| 6702 | stats->data[i].len = q->n_window - avail; |
| 6703 | stats->data[i].limit = q->n_window - q->high_mark; |
| 6704 | stats->data[i].count = q->n_window; |
| 6705 | |
| 6706 | } |
| 6707 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6708 | |
| 6709 | IWL_DEBUG_MAC80211("leave\n"); |
| 6710 | |
| 6711 | return 0; |
| 6712 | } |
| 6713 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6714 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6715 | struct ieee80211_low_level_stats *stats) |
| 6716 | { |
| 6717 | IWL_DEBUG_MAC80211("enter\n"); |
| 6718 | IWL_DEBUG_MAC80211("leave\n"); |
| 6719 | |
| 6720 | return 0; |
| 6721 | } |
| 6722 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6723 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6724 | { |
| 6725 | IWL_DEBUG_MAC80211("enter\n"); |
| 6726 | IWL_DEBUG_MAC80211("leave\n"); |
| 6727 | |
| 6728 | return 0; |
| 6729 | } |
| 6730 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6731 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6732 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6733 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6734 | unsigned long flags; |
| 6735 | |
| 6736 | mutex_lock(&priv->mutex); |
| 6737 | IWL_DEBUG_MAC80211("enter\n"); |
| 6738 | |
| 6739 | priv->lq_mngr.lq_ready = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6740 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6741 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 6742 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6743 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6744 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6745 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6746 | iwlcore_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6747 | |
| 6748 | cancel_delayed_work(&priv->post_associate); |
| 6749 | |
| 6750 | spin_lock_irqsave(&priv->lock, flags); |
| 6751 | priv->assoc_id = 0; |
| 6752 | priv->assoc_capability = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6753 | priv->assoc_station_added = 0; |
| 6754 | |
| 6755 | /* new association get rid of ibss beacon skb */ |
| 6756 | if (priv->ibss_beacon) |
| 6757 | dev_kfree_skb(priv->ibss_beacon); |
| 6758 | |
| 6759 | priv->ibss_beacon = NULL; |
| 6760 | |
| 6761 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 6762 | priv->timestamp = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6763 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 6764 | priv->beacon_int = 0; |
| 6765 | |
| 6766 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6767 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6768 | if (!iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6769 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 6770 | mutex_unlock(&priv->mutex); |
| 6771 | return; |
| 6772 | } |
| 6773 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6774 | /* we are restarting association process |
| 6775 | * clear RXON_FILTER_ASSOC_MSK bit |
| 6776 | */ |
| 6777 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6778 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6779 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6780 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6781 | } |
| 6782 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 6783 | iwl_power_update_mode(priv, 0); |
| 6784 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6785 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 6786 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 6787 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6788 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 6789 | mutex_unlock(&priv->mutex); |
| 6790 | return; |
| 6791 | } |
| 6792 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6793 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6794 | |
| 6795 | mutex_unlock(&priv->mutex); |
| 6796 | |
| 6797 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6798 | } |
| 6799 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6800 | 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] | 6801 | struct ieee80211_tx_control *control) |
| 6802 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6803 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6804 | unsigned long flags; |
| 6805 | |
| 6806 | mutex_lock(&priv->mutex); |
| 6807 | IWL_DEBUG_MAC80211("enter\n"); |
| 6808 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6809 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6810 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 6811 | mutex_unlock(&priv->mutex); |
| 6812 | return -EIO; |
| 6813 | } |
| 6814 | |
| 6815 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 6816 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 6817 | mutex_unlock(&priv->mutex); |
| 6818 | return -EIO; |
| 6819 | } |
| 6820 | |
| 6821 | spin_lock_irqsave(&priv->lock, flags); |
| 6822 | |
| 6823 | if (priv->ibss_beacon) |
| 6824 | dev_kfree_skb(priv->ibss_beacon); |
| 6825 | |
| 6826 | priv->ibss_beacon = skb; |
| 6827 | |
| 6828 | priv->assoc_id = 0; |
| 6829 | |
| 6830 | IWL_DEBUG_MAC80211("leave\n"); |
| 6831 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6832 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6833 | iwlcore_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6834 | |
| 6835 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 6836 | |
| 6837 | mutex_unlock(&priv->mutex); |
| 6838 | |
| 6839 | return 0; |
| 6840 | } |
| 6841 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6842 | /***************************************************************************** |
| 6843 | * |
| 6844 | * sysfs attributes |
| 6845 | * |
| 6846 | *****************************************************************************/ |
| 6847 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 6848 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6849 | |
| 6850 | /* |
| 6851 | * The following adds a new attribute to the sysfs representation |
| 6852 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 6853 | * used for controlling the debug level. |
| 6854 | * |
| 6855 | * See the level definitions in iwl for details. |
| 6856 | */ |
| 6857 | |
| 6858 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 6859 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 6860 | return sprintf(buf, "0x%08X\n", iwl_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6861 | } |
| 6862 | static ssize_t store_debug_level(struct device_driver *d, |
| 6863 | const char *buf, size_t count) |
| 6864 | { |
| 6865 | char *p = (char *)buf; |
| 6866 | u32 val; |
| 6867 | |
| 6868 | val = simple_strtoul(p, &p, 0); |
| 6869 | if (p == buf) |
| 6870 | printk(KERN_INFO DRV_NAME |
| 6871 | ": %s is not in hex or decimal form.\n", buf); |
| 6872 | else |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 6873 | iwl_debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6874 | |
| 6875 | return strnlen(buf, count); |
| 6876 | } |
| 6877 | |
| 6878 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 6879 | show_debug_level, store_debug_level); |
| 6880 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 6881 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6882 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6883 | |
| 6884 | static ssize_t show_temperature(struct device *d, |
| 6885 | struct device_attribute *attr, char *buf) |
| 6886 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6887 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6888 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6889 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6890 | return -EAGAIN; |
| 6891 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6892 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6893 | } |
| 6894 | |
| 6895 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 6896 | |
| 6897 | static ssize_t show_rs_window(struct device *d, |
| 6898 | struct device_attribute *attr, |
| 6899 | char *buf) |
| 6900 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6901 | struct iwl_priv *priv = d->driver_data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6902 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6903 | } |
| 6904 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 6905 | |
| 6906 | static ssize_t show_tx_power(struct device *d, |
| 6907 | struct device_attribute *attr, char *buf) |
| 6908 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6909 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6910 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 6911 | } |
| 6912 | |
| 6913 | static ssize_t store_tx_power(struct device *d, |
| 6914 | struct device_attribute *attr, |
| 6915 | const char *buf, size_t count) |
| 6916 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6917 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6918 | char *p = (char *)buf; |
| 6919 | u32 val; |
| 6920 | |
| 6921 | val = simple_strtoul(p, &p, 10); |
| 6922 | if (p == buf) |
| 6923 | printk(KERN_INFO DRV_NAME |
| 6924 | ": %s is not in decimal form.\n", buf); |
| 6925 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6926 | iwl4965_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6927 | |
| 6928 | return count; |
| 6929 | } |
| 6930 | |
| 6931 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 6932 | |
| 6933 | static ssize_t show_flags(struct device *d, |
| 6934 | struct device_attribute *attr, char *buf) |
| 6935 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6936 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6937 | |
| 6938 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 6939 | } |
| 6940 | |
| 6941 | static ssize_t store_flags(struct device *d, |
| 6942 | struct device_attribute *attr, |
| 6943 | const char *buf, size_t count) |
| 6944 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6945 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6946 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 6947 | |
| 6948 | mutex_lock(&priv->mutex); |
| 6949 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 6950 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6951 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6952 | IWL_WARNING("Could not cancel scan.\n"); |
| 6953 | else { |
| 6954 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 6955 | flags); |
| 6956 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6957 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6958 | } |
| 6959 | } |
| 6960 | mutex_unlock(&priv->mutex); |
| 6961 | |
| 6962 | return count; |
| 6963 | } |
| 6964 | |
| 6965 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 6966 | |
| 6967 | static ssize_t show_filter_flags(struct device *d, |
| 6968 | struct device_attribute *attr, char *buf) |
| 6969 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6970 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6971 | |
| 6972 | return sprintf(buf, "0x%04X\n", |
| 6973 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 6974 | } |
| 6975 | |
| 6976 | static ssize_t store_filter_flags(struct device *d, |
| 6977 | struct device_attribute *attr, |
| 6978 | const char *buf, size_t count) |
| 6979 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6980 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6981 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 6982 | |
| 6983 | mutex_lock(&priv->mutex); |
| 6984 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 6985 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6986 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6987 | IWL_WARNING("Could not cancel scan.\n"); |
| 6988 | else { |
| 6989 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 6990 | "0x%04X\n", filter_flags); |
| 6991 | priv->staging_rxon.filter_flags = |
| 6992 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6993 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6994 | } |
| 6995 | } |
| 6996 | mutex_unlock(&priv->mutex); |
| 6997 | |
| 6998 | return count; |
| 6999 | } |
| 7000 | |
| 7001 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 7002 | store_filter_flags); |
| 7003 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7004 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7005 | |
| 7006 | static ssize_t show_measurement(struct device *d, |
| 7007 | struct device_attribute *attr, char *buf) |
| 7008 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7009 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7010 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7011 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 7012 | u8 *data = (u8 *) & measure_report; |
| 7013 | unsigned long flags; |
| 7014 | |
| 7015 | spin_lock_irqsave(&priv->lock, flags); |
| 7016 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 7017 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7018 | return 0; |
| 7019 | } |
| 7020 | memcpy(&measure_report, &priv->measure_report, size); |
| 7021 | priv->measurement_status = 0; |
| 7022 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7023 | |
| 7024 | while (size && (PAGE_SIZE - len)) { |
| 7025 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 7026 | PAGE_SIZE - len, 1); |
| 7027 | len = strlen(buf); |
| 7028 | if (PAGE_SIZE - len) |
| 7029 | buf[len++] = '\n'; |
| 7030 | |
| 7031 | ofs += 16; |
| 7032 | size -= min(size, 16U); |
| 7033 | } |
| 7034 | |
| 7035 | return len; |
| 7036 | } |
| 7037 | |
| 7038 | static ssize_t store_measurement(struct device *d, |
| 7039 | struct device_attribute *attr, |
| 7040 | const char *buf, size_t count) |
| 7041 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7042 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7043 | struct ieee80211_measurement_params params = { |
| 7044 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 7045 | .start_time = cpu_to_le64(priv->last_tsf), |
| 7046 | .duration = cpu_to_le16(1), |
| 7047 | }; |
| 7048 | u8 type = IWL_MEASURE_BASIC; |
| 7049 | u8 buffer[32]; |
| 7050 | u8 channel; |
| 7051 | |
| 7052 | if (count) { |
| 7053 | char *p = buffer; |
| 7054 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 7055 | channel = simple_strtoul(p, NULL, 0); |
| 7056 | if (channel) |
| 7057 | params.channel = channel; |
| 7058 | |
| 7059 | p = buffer; |
| 7060 | while (*p && *p != ' ') |
| 7061 | p++; |
| 7062 | if (*p) |
| 7063 | type = simple_strtoul(p + 1, NULL, 0); |
| 7064 | } |
| 7065 | |
| 7066 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 7067 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7068 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7069 | |
| 7070 | return count; |
| 7071 | } |
| 7072 | |
| 7073 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 7074 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7075 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7076 | |
| 7077 | static ssize_t store_retry_rate(struct device *d, |
| 7078 | struct device_attribute *attr, |
| 7079 | const char *buf, size_t count) |
| 7080 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7081 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7082 | |
| 7083 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 7084 | if (priv->retry_rate <= 0) |
| 7085 | priv->retry_rate = 1; |
| 7086 | |
| 7087 | return count; |
| 7088 | } |
| 7089 | |
| 7090 | static ssize_t show_retry_rate(struct device *d, |
| 7091 | struct device_attribute *attr, char *buf) |
| 7092 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7093 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7094 | return sprintf(buf, "%d", priv->retry_rate); |
| 7095 | } |
| 7096 | |
| 7097 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 7098 | store_retry_rate); |
| 7099 | |
| 7100 | static ssize_t store_power_level(struct device *d, |
| 7101 | struct device_attribute *attr, |
| 7102 | const char *buf, size_t count) |
| 7103 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7104 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7105 | int rc; |
| 7106 | int mode; |
| 7107 | |
| 7108 | mode = simple_strtoul(buf, NULL, 0); |
| 7109 | mutex_lock(&priv->mutex); |
| 7110 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 7111 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7112 | rc = -EAGAIN; |
| 7113 | goto out; |
| 7114 | } |
| 7115 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 7116 | rc = iwl_power_set_user_mode(priv, mode); |
| 7117 | if (rc) { |
| 7118 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 7119 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7120 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7121 | rc = count; |
| 7122 | |
| 7123 | out: |
| 7124 | mutex_unlock(&priv->mutex); |
| 7125 | return rc; |
| 7126 | } |
| 7127 | |
| 7128 | #define MAX_WX_STRING 80 |
| 7129 | |
| 7130 | /* Values are in microsecond */ |
| 7131 | static const s32 timeout_duration[] = { |
| 7132 | 350000, |
| 7133 | 250000, |
| 7134 | 75000, |
| 7135 | 37000, |
| 7136 | 25000, |
| 7137 | }; |
| 7138 | static const s32 period_duration[] = { |
| 7139 | 400000, |
| 7140 | 700000, |
| 7141 | 1000000, |
| 7142 | 1000000, |
| 7143 | 1000000 |
| 7144 | }; |
| 7145 | |
| 7146 | static ssize_t show_power_level(struct device *d, |
| 7147 | struct device_attribute *attr, char *buf) |
| 7148 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7149 | struct iwl_priv *priv = dev_get_drvdata(d); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 7150 | int level = priv->power_data.power_mode; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7151 | char *p = buf; |
| 7152 | |
| 7153 | p += sprintf(p, "%d ", level); |
| 7154 | switch (level) { |
| 7155 | case IWL_POWER_MODE_CAM: |
| 7156 | case IWL_POWER_AC: |
| 7157 | p += sprintf(p, "(AC)"); |
| 7158 | break; |
| 7159 | case IWL_POWER_BATTERY: |
| 7160 | p += sprintf(p, "(BATTERY)"); |
| 7161 | break; |
| 7162 | default: |
| 7163 | p += sprintf(p, |
| 7164 | "(Timeout %dms, Period %dms)", |
| 7165 | timeout_duration[level - 1] / 1000, |
| 7166 | period_duration[level - 1] / 1000); |
| 7167 | } |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 7168 | /* |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7169 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 7170 | p += sprintf(p, " OFF\n"); |
| 7171 | else |
| 7172 | p += sprintf(p, " \n"); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 7173 | */ |
| 7174 | p += sprintf(p, " \n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7175 | return (p - buf + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7176 | } |
| 7177 | |
| 7178 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 7179 | store_power_level); |
| 7180 | |
| 7181 | static ssize_t show_channels(struct device *d, |
| 7182 | struct device_attribute *attr, char *buf) |
| 7183 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7184 | /* all this shit doesn't belong into sysfs anyway */ |
| 7185 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7186 | } |
| 7187 | |
| 7188 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 7189 | |
| 7190 | static ssize_t show_statistics(struct device *d, |
| 7191 | struct device_attribute *attr, char *buf) |
| 7192 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7193 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7194 | u32 size = sizeof(struct iwl4965_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7195 | u32 len = 0, ofs = 0; |
| 7196 | u8 *data = (u8 *) & priv->statistics; |
| 7197 | int rc = 0; |
| 7198 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 7199 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7200 | return -EAGAIN; |
| 7201 | |
| 7202 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 7203 | rc = iwl_send_statistics_request(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7204 | mutex_unlock(&priv->mutex); |
| 7205 | |
| 7206 | if (rc) { |
| 7207 | len = sprintf(buf, |
| 7208 | "Error sending statistics request: 0x%08X\n", rc); |
| 7209 | return len; |
| 7210 | } |
| 7211 | |
| 7212 | while (size && (PAGE_SIZE - len)) { |
| 7213 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 7214 | PAGE_SIZE - len, 1); |
| 7215 | len = strlen(buf); |
| 7216 | if (PAGE_SIZE - len) |
| 7217 | buf[len++] = '\n'; |
| 7218 | |
| 7219 | ofs += 16; |
| 7220 | size -= min(size, 16U); |
| 7221 | } |
| 7222 | |
| 7223 | return len; |
| 7224 | } |
| 7225 | |
| 7226 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 7227 | |
| 7228 | static ssize_t show_antenna(struct device *d, |
| 7229 | struct device_attribute *attr, char *buf) |
| 7230 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7231 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7232 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 7233 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7234 | return -EAGAIN; |
| 7235 | |
| 7236 | return sprintf(buf, "%d\n", priv->antenna); |
| 7237 | } |
| 7238 | |
| 7239 | static ssize_t store_antenna(struct device *d, |
| 7240 | struct device_attribute *attr, |
| 7241 | const char *buf, size_t count) |
| 7242 | { |
| 7243 | int ant; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7244 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7245 | |
| 7246 | if (count == 0) |
| 7247 | return 0; |
| 7248 | |
| 7249 | if (sscanf(buf, "%1i", &ant) != 1) { |
| 7250 | IWL_DEBUG_INFO("not in hex or decimal form.\n"); |
| 7251 | return count; |
| 7252 | } |
| 7253 | |
| 7254 | if ((ant >= 0) && (ant <= 2)) { |
| 7255 | IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7256 | priv->antenna = (enum iwl4965_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7257 | } else |
| 7258 | IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); |
| 7259 | |
| 7260 | |
| 7261 | return count; |
| 7262 | } |
| 7263 | |
| 7264 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 7265 | |
| 7266 | static ssize_t show_status(struct device *d, |
| 7267 | struct device_attribute *attr, char *buf) |
| 7268 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7269 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 7270 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7271 | return -EAGAIN; |
| 7272 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 7273 | } |
| 7274 | |
| 7275 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 7276 | |
| 7277 | static ssize_t dump_error_log(struct device *d, |
| 7278 | struct device_attribute *attr, |
| 7279 | const char *buf, size_t count) |
| 7280 | { |
| 7281 | char *p = (char *)buf; |
| 7282 | |
| 7283 | if (p[0] == '1') |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7284 | iwl4965_dump_nic_error_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7285 | |
| 7286 | return strnlen(buf, count); |
| 7287 | } |
| 7288 | |
| 7289 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 7290 | |
| 7291 | static ssize_t dump_event_log(struct device *d, |
| 7292 | struct device_attribute *attr, |
| 7293 | const char *buf, size_t count) |
| 7294 | { |
| 7295 | char *p = (char *)buf; |
| 7296 | |
| 7297 | if (p[0] == '1') |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7298 | iwl4965_dump_nic_event_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7299 | |
| 7300 | return strnlen(buf, count); |
| 7301 | } |
| 7302 | |
| 7303 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 7304 | |
| 7305 | /***************************************************************************** |
| 7306 | * |
| 7307 | * driver setup and teardown |
| 7308 | * |
| 7309 | *****************************************************************************/ |
| 7310 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7311 | static void iwl4965_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7312 | { |
| 7313 | priv->workqueue = create_workqueue(DRV_NAME); |
| 7314 | |
| 7315 | init_waitqueue_head(&priv->wait_command_queue); |
| 7316 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7317 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 7318 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 7319 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
| 7320 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); |
| 7321 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); |
| 7322 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); |
| 7323 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 7324 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
| 7325 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
| 7326 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start); |
| 7327 | INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start); |
| 7328 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7329 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7330 | iwl4965_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7331 | |
| 7332 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7333 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7334 | } |
| 7335 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7336 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7337 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7338 | iwl4965_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7339 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 7340 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7341 | cancel_delayed_work(&priv->scan_check); |
| 7342 | cancel_delayed_work(&priv->alive_start); |
| 7343 | cancel_delayed_work(&priv->post_associate); |
| 7344 | cancel_work_sync(&priv->beacon_update); |
| 7345 | } |
| 7346 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7347 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7348 | &dev_attr_antenna.attr, |
| 7349 | &dev_attr_channels.attr, |
| 7350 | &dev_attr_dump_errors.attr, |
| 7351 | &dev_attr_dump_events.attr, |
| 7352 | &dev_attr_flags.attr, |
| 7353 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7354 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7355 | &dev_attr_measurement.attr, |
| 7356 | #endif |
| 7357 | &dev_attr_power_level.attr, |
| 7358 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7359 | &dev_attr_rs_window.attr, |
| 7360 | &dev_attr_statistics.attr, |
| 7361 | &dev_attr_status.attr, |
| 7362 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7363 | &dev_attr_tx_power.attr, |
| 7364 | |
| 7365 | NULL |
| 7366 | }; |
| 7367 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7368 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7369 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7370 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7371 | }; |
| 7372 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7373 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 7374 | .tx = iwl4965_mac_tx, |
| 7375 | .start = iwl4965_mac_start, |
| 7376 | .stop = iwl4965_mac_stop, |
| 7377 | .add_interface = iwl4965_mac_add_interface, |
| 7378 | .remove_interface = iwl4965_mac_remove_interface, |
| 7379 | .config = iwl4965_mac_config, |
| 7380 | .config_interface = iwl4965_mac_config_interface, |
| 7381 | .configure_filter = iwl4965_configure_filter, |
| 7382 | .set_key = iwl4965_mac_set_key, |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 7383 | .update_tkip_key = iwl4965_mac_update_tkip_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7384 | .get_stats = iwl4965_mac_get_stats, |
| 7385 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 7386 | .conf_tx = iwl4965_mac_conf_tx, |
| 7387 | .get_tsf = iwl4965_mac_get_tsf, |
| 7388 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 7389 | .beacon_update = iwl4965_mac_beacon_update, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 7390 | .bss_info_changed = iwl4965_bss_info_changed, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7391 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | 9ab4617 | 2007-12-25 17:00:38 +0200 | [diff] [blame] | 7392 | .ampdu_action = iwl4965_mac_ampdu_action, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7393 | #endif /* CONFIG_IWL4965_HT */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7394 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7395 | }; |
| 7396 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7397 | 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] | 7398 | { |
| 7399 | int err = 0; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7400 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7401 | struct ieee80211_hw *hw; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 7402 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7403 | unsigned long flags; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7404 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7405 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 7406 | /************************ |
| 7407 | * 1. Allocating HW data |
| 7408 | ************************/ |
| 7409 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 7410 | /* Disabling hardware scan means that mac80211 will perform scans |
| 7411 | * "the hard way", rather than using device's scan. */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 7412 | if (cfg->mod_params->disable_hw_scan) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7413 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7414 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7415 | } |
| 7416 | |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 7417 | hw = iwl_alloc_all(cfg, &iwl4965_hw_ops); |
| 7418 | if (!hw) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7419 | err = -ENOMEM; |
| 7420 | goto out; |
| 7421 | } |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 7422 | priv = hw->priv; |
| 7423 | /* At this point both hw and priv are allocated. */ |
| 7424 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7425 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 7426 | |
| 7427 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 7428 | priv->cfg = cfg; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7429 | priv->pci_dev = pdev; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 7430 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 7431 | #ifdef CONFIG_IWLWIFI_DEBUG |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 7432 | iwl_debug_level = priv->cfg->mod_params->debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7433 | atomic_set(&priv->restrict_refcnt, 0); |
| 7434 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7435 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 7436 | /************************** |
| 7437 | * 2. Initializing PCI bus |
| 7438 | **************************/ |
| 7439 | if (pci_enable_device(pdev)) { |
| 7440 | err = -ENODEV; |
| 7441 | goto out_ieee80211_free_hw; |
| 7442 | } |
| 7443 | |
| 7444 | pci_set_master(pdev); |
| 7445 | |
| 7446 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 7447 | if (!err) |
| 7448 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 7449 | if (err) { |
| 7450 | printk(KERN_WARNING DRV_NAME |
| 7451 | ": No suitable DMA available.\n"); |
| 7452 | goto out_pci_disable_device; |
| 7453 | } |
| 7454 | |
| 7455 | err = pci_request_regions(pdev, DRV_NAME); |
| 7456 | if (err) |
| 7457 | goto out_pci_disable_device; |
| 7458 | |
| 7459 | pci_set_drvdata(pdev, priv); |
| 7460 | |
| 7461 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 7462 | * PCI Tx retries from interfering with C3 CPU state */ |
| 7463 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 7464 | |
| 7465 | /*********************** |
| 7466 | * 3. Read REV register |
| 7467 | ***********************/ |
| 7468 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 7469 | if (!priv->hw_base) { |
| 7470 | err = -ENODEV; |
| 7471 | goto out_pci_release_regions; |
| 7472 | } |
| 7473 | |
| 7474 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 7475 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 7476 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 7477 | |
| 7478 | printk(KERN_INFO DRV_NAME |
| 7479 | ": Detected Intel Wireless WiFi Link %s\n", priv->cfg->name); |
| 7480 | |
| 7481 | /***************** |
| 7482 | * 4. Read EEPROM |
| 7483 | *****************/ |
| 7484 | /* nic init */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 7485 | iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS, |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 7486 | CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); |
| 7487 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 7488 | iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); |
| 7489 | err = iwl_poll_bit(priv, CSR_GP_CNTRL, |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 7490 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, |
| 7491 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); |
| 7492 | if (err < 0) { |
| 7493 | IWL_DEBUG_INFO("Failed to init the card\n"); |
| 7494 | goto out_iounmap; |
| 7495 | } |
| 7496 | /* Read the EEPROM */ |
| 7497 | err = iwl_eeprom_init(priv); |
| 7498 | if (err) { |
| 7499 | IWL_ERROR("Unable to init EEPROM\n"); |
| 7500 | goto out_iounmap; |
| 7501 | } |
| 7502 | /* MAC Address location in EEPROM same for 3945/4965 */ |
| 7503 | iwl_eeprom_get_mac(priv, priv->mac_addr); |
| 7504 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); |
| 7505 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 7506 | |
| 7507 | /************************ |
| 7508 | * 5. Setup HW constants |
| 7509 | ************************/ |
| 7510 | /* Device-specific setup */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 7511 | if (priv->cfg->ops->lib->set_hw_params(priv)) { |
| 7512 | IWL_ERROR("failed to set hw parameters\n"); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 7513 | goto out_free_eeprom; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 7514 | } |
| 7515 | |
| 7516 | /******************* |
| 7517 | * 6. Setup hw/priv |
| 7518 | *******************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7519 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 7520 | err = iwl_setup(priv); |
| 7521 | if (err) |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 7522 | goto out_unset_hw_params; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 7523 | /* At this point both hw and priv are initialized. */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 7524 | |
| 7525 | /********************************** |
| 7526 | * 7. Initialize module parameters |
| 7527 | **********************************/ |
| 7528 | |
| 7529 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 7530 | if (priv->cfg->mod_params->disable) { |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 7531 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 7532 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 7533 | } |
| 7534 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 7535 | if (priv->cfg->mod_params->enable_qos) |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 7536 | priv->qos_data.qos_enable = 1; |
| 7537 | |
| 7538 | /******************** |
| 7539 | * 8. Setup services |
| 7540 | ********************/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7541 | spin_lock_irqsave(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 7542 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7543 | spin_unlock_irqrestore(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 7544 | |
| 7545 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
| 7546 | if (err) { |
| 7547 | IWL_ERROR("failed to create sysfs device attributes\n"); |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 7548 | goto out_unset_hw_params; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 7549 | } |
| 7550 | |
| 7551 | err = iwl_dbgfs_register(priv, DRV_NAME); |
| 7552 | if (err) { |
| 7553 | IWL_ERROR("failed to create debugfs files\n"); |
| 7554 | goto out_remove_sysfs; |
| 7555 | } |
| 7556 | |
| 7557 | iwl4965_setup_deferred_work(priv); |
| 7558 | iwl4965_setup_rx_handlers(priv); |
| 7559 | |
| 7560 | /******************** |
| 7561 | * 9. Conclude |
| 7562 | ********************/ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7563 | pci_save_state(pdev); |
| 7564 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7565 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 7566 | /* notify iwlcore to init */ |
| 7567 | iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7568 | return 0; |
| 7569 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 7570 | out_remove_sysfs: |
| 7571 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 7572 | out_unset_hw_params: |
| 7573 | iwl4965_unset_hw_params(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 7574 | out_free_eeprom: |
| 7575 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7576 | out_iounmap: |
| 7577 | pci_iounmap(pdev, priv->hw_base); |
| 7578 | out_pci_release_regions: |
| 7579 | pci_release_regions(pdev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 7580 | pci_set_drvdata(pdev, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7581 | out_pci_disable_device: |
| 7582 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7583 | out_ieee80211_free_hw: |
| 7584 | ieee80211_free_hw(priv->hw); |
| 7585 | out: |
| 7586 | return err; |
| 7587 | } |
| 7588 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 7589 | static void __devexit iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7590 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7591 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7592 | struct list_head *p, *q; |
| 7593 | int i; |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7594 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7595 | |
| 7596 | if (!priv) |
| 7597 | return; |
| 7598 | |
| 7599 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 7600 | |
Ron Rindjunsky | c4f5523 | 2008-03-28 16:21:10 -0700 | [diff] [blame] | 7601 | if (priv->mac80211_registered) { |
| 7602 | ieee80211_unregister_hw(priv->hw); |
| 7603 | priv->mac80211_registered = 0; |
| 7604 | } |
| 7605 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7606 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 7607 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7608 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7609 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 7610 | /* make sure we flush any pending irq or |
| 7611 | * tasklet for the driver |
| 7612 | */ |
| 7613 | spin_lock_irqsave(&priv->lock, flags); |
| 7614 | iwl4965_disable_interrupts(priv); |
| 7615 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7616 | |
| 7617 | iwl_synchronize_irq(priv); |
| 7618 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7619 | /* Free MAC hash list for ADHOC */ |
| 7620 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 7621 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 7622 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7623 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7624 | } |
| 7625 | } |
| 7626 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 7627 | iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 7628 | iwl_dbgfs_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7629 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7630 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7631 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7632 | |
| 7633 | if (priv->rxq.bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7634 | iwl4965_rx_queue_free(priv, &priv->rxq); |
| 7635 | iwl4965_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7636 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 7637 | iwl4965_unset_hw_params(priv); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 7638 | iwlcore_clear_stations_table(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 7639 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7640 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7641 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 7642 | /*netif_stop_queue(dev); */ |
| 7643 | flush_workqueue(priv->workqueue); |
| 7644 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7645 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7646 | * priv->workqueue... so we can't take down the workqueue |
| 7647 | * until now... */ |
| 7648 | destroy_workqueue(priv->workqueue); |
| 7649 | priv->workqueue = NULL; |
| 7650 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7651 | pci_iounmap(pdev, priv->hw_base); |
| 7652 | pci_release_regions(pdev); |
| 7653 | pci_disable_device(pdev); |
| 7654 | pci_set_drvdata(pdev, NULL); |
| 7655 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 7656 | iwl_free_channel_map(priv); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 7657 | iwl4965_free_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7658 | |
| 7659 | if (priv->ibss_beacon) |
| 7660 | dev_kfree_skb(priv->ibss_beacon); |
| 7661 | |
| 7662 | ieee80211_free_hw(priv->hw); |
| 7663 | } |
| 7664 | |
| 7665 | #ifdef CONFIG_PM |
| 7666 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7667 | 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] | 7668 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7669 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7670 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7671 | if (priv->is_open) { |
| 7672 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 7673 | iwl4965_mac_stop(priv->hw); |
| 7674 | priv->is_open = 1; |
| 7675 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7676 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7677 | pci_set_power_state(pdev, PCI_D3hot); |
| 7678 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7679 | return 0; |
| 7680 | } |
| 7681 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7682 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7683 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 7684 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7685 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7686 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7687 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7688 | if (priv->is_open) |
| 7689 | iwl4965_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7690 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 7691 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7692 | return 0; |
| 7693 | } |
| 7694 | |
| 7695 | #endif /* CONFIG_PM */ |
| 7696 | |
| 7697 | /***************************************************************************** |
| 7698 | * |
| 7699 | * driver and module entry point |
| 7700 | * |
| 7701 | *****************************************************************************/ |
| 7702 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7703 | /* Hardware specific file defines the PCI IDs table for that hardware module */ |
| 7704 | static struct pci_device_id iwl_hw_card_ids[] = { |
| 7705 | {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)}, |
| 7706 | {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)}, |
| 7707 | {0} |
| 7708 | }; |
| 7709 | MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); |
| 7710 | |
| 7711 | static struct pci_driver iwl_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7712 | .name = DRV_NAME, |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7713 | .id_table = iwl_hw_card_ids, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7714 | .probe = iwl4965_pci_probe, |
| 7715 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7716 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7717 | .suspend = iwl4965_pci_suspend, |
| 7718 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7719 | #endif |
| 7720 | }; |
| 7721 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7722 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7723 | { |
| 7724 | |
| 7725 | int ret; |
| 7726 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 7727 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7728 | |
| 7729 | ret = iwl4965_rate_control_register(); |
| 7730 | if (ret) { |
| 7731 | IWL_ERROR("Unable to register rate control algorithm: %d\n", ret); |
| 7732 | return ret; |
| 7733 | } |
| 7734 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7735 | ret = pci_register_driver(&iwl_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7736 | if (ret) { |
| 7737 | IWL_ERROR("Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7738 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7739 | } |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 7740 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7741 | ret = driver_create_file(&iwl_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7742 | if (ret) { |
| 7743 | IWL_ERROR("Unable to create driver sysfs file\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7744 | goto error_debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7745 | } |
| 7746 | #endif |
| 7747 | |
| 7748 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7749 | |
| 7750 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 7751 | error_debug: |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7752 | pci_unregister_driver(&iwl_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7753 | #endif |
| 7754 | error_register: |
| 7755 | iwl4965_rate_control_unregister(); |
| 7756 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7757 | } |
| 7758 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7759 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7760 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 7761 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7762 | driver_remove_file(&iwl_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7763 | #endif |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 7764 | pci_unregister_driver(&iwl_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 7765 | iwl4965_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7766 | } |
| 7767 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7768 | module_exit(iwl4965_exit); |
| 7769 | module_init(iwl4965_init); |