Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved. |
| 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
| 25 | * James P. Ketrenos <ipw2100-admin@linux.intel.com> |
| 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/version.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/dma-mapping.h> |
| 36 | #include <linux/delay.h> |
| 37 | #include <linux/skbuff.h> |
| 38 | #include <linux/netdevice.h> |
| 39 | #include <linux/wireless.h> |
| 40 | #include <linux/firmware.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 41 | #include <linux/etherdevice.h> |
| 42 | #include <linux/if_arp.h> |
| 43 | |
| 44 | #include <net/ieee80211_radiotap.h> |
| 45 | #include <net/mac80211.h> |
| 46 | |
| 47 | #include <asm/div64.h> |
| 48 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 49 | #include "iwl-3945.h" |
| 50 | #include "iwl-helpers.h" |
| 51 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 52 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 53 | u32 iwl3945_debug_level; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 54 | #endif |
| 55 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 56 | static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv *priv, |
| 57 | struct iwl3945_tx_queue *txq); |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 58 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 59 | /****************************************************************************** |
| 60 | * |
| 61 | * module boiler plate |
| 62 | * |
| 63 | ******************************************************************************/ |
| 64 | |
| 65 | /* module parameters */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 66 | static int iwl3945_param_disable_hw_scan; /* def: 0 = use 3945's h/w scan */ |
| 67 | static int iwl3945_param_debug; /* def: 0 = minimal debug log messages */ |
| 68 | static int iwl3945_param_disable; /* def: 0 = enable radio */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 69 | static int iwl3945_param_antenna; /* def: 0 = both antennas (use diversity) */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 70 | int iwl3945_param_hwcrypto; /* def: 0 = use software encryption */ |
| 71 | static int iwl3945_param_qos_enable = 1; /* def: 1 = use quality of service */ |
| 72 | int iwl3945_param_queues_num = IWL_MAX_NUM_QUEUES; /* def: 8 Tx queues */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * module name, copyright, version, etc. |
| 76 | * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk |
| 77 | */ |
| 78 | |
| 79 | #define DRV_DESCRIPTION \ |
| 80 | "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux" |
| 81 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 82 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 83 | #define VD "d" |
| 84 | #else |
| 85 | #define VD |
| 86 | #endif |
| 87 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 88 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 89 | #define VS "s" |
| 90 | #else |
| 91 | #define VS |
| 92 | #endif |
| 93 | |
Reinette Chatre | b9e0b44 | 2008-02-08 16:39:11 -0800 | [diff] [blame] | 94 | #define IWLWIFI_VERSION "1.2.26k" VD VS |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 95 | #define DRV_COPYRIGHT "Copyright(c) 2003-2007 Intel Corporation" |
| 96 | #define DRV_VERSION IWLWIFI_VERSION |
| 97 | |
| 98 | /* Change firmware file name, using "-" and incrementing number, |
| 99 | * *only* when uCode interface or architecture changes so that it |
| 100 | * is not compatible with earlier drivers. |
| 101 | * This number will also appear in << 8 position of 1st dword of uCode file */ |
| 102 | #define IWL3945_UCODE_API "-1" |
| 103 | |
| 104 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 105 | MODULE_VERSION(DRV_VERSION); |
| 106 | MODULE_AUTHOR(DRV_COPYRIGHT); |
| 107 | MODULE_LICENSE("GPL"); |
| 108 | |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 109 | static __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 110 | { |
| 111 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 112 | int hdr_len = ieee80211_get_hdrlen(fc); |
| 113 | |
| 114 | if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA)) |
| 115 | return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN); |
| 116 | return NULL; |
| 117 | } |
| 118 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 119 | static const struct ieee80211_supported_band *iwl3945_get_band( |
| 120 | struct iwl3945_priv *priv, enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 121 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 122 | return priv->hw->wiphy->bands[band]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 125 | static int iwl3945_is_empty_essid(const char *essid, int essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 126 | { |
| 127 | /* Single white space is for Linksys APs */ |
| 128 | if (essid_len == 1 && essid[0] == ' ') |
| 129 | return 1; |
| 130 | |
| 131 | /* Otherwise, if the entire essid is 0, we assume it is hidden */ |
| 132 | while (essid_len) { |
| 133 | essid_len--; |
| 134 | if (essid[essid_len] != '\0') |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | return 1; |
| 139 | } |
| 140 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 141 | static const char *iwl3945_escape_essid(const char *essid, u8 essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 142 | { |
| 143 | static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
| 144 | const char *s = essid; |
| 145 | char *d = escaped; |
| 146 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 147 | if (iwl3945_is_empty_essid(essid, essid_len)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 148 | memcpy(escaped, "<hidden>", sizeof("<hidden>")); |
| 149 | return escaped; |
| 150 | } |
| 151 | |
| 152 | essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE); |
| 153 | while (essid_len--) { |
| 154 | if (*s == '\0') { |
| 155 | *d++ = '\\'; |
| 156 | *d++ = '0'; |
| 157 | s++; |
| 158 | } else |
| 159 | *d++ = *s++; |
| 160 | } |
| 161 | *d = '\0'; |
| 162 | return escaped; |
| 163 | } |
| 164 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 165 | static void iwl3945_print_hex_dump(int level, void *p, u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 166 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 167 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 168 | if (!(iwl3945_debug_level & level)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 169 | return; |
| 170 | |
| 171 | print_hex_dump(KERN_DEBUG, "iwl data: ", DUMP_PREFIX_OFFSET, 16, 1, |
| 172 | p, len, 1); |
| 173 | #endif |
| 174 | } |
| 175 | |
| 176 | /*************** DMA-QUEUE-GENERAL-FUNCTIONS ***** |
| 177 | * DMA services |
| 178 | * |
| 179 | * Theory of operation |
| 180 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 181 | * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer |
| 182 | * of buffer descriptors, each of which points to one or more data buffers for |
| 183 | * the device to read from or fill. Driver and device exchange status of each |
| 184 | * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty |
| 185 | * entries in each circular buffer, to protect against confusing empty and full |
| 186 | * queue states. |
| 187 | * |
| 188 | * The device reads or writes the data in the queues via the device's several |
| 189 | * DMA/FIFO channels. Each queue is mapped to a single DMA channel. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 190 | * |
| 191 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 192 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 193 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 194 | * Tx queue resumed. |
| 195 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 196 | * The 3945 operates with six queues: One receive queue, one transmit queue |
| 197 | * (#4) for sending commands to the device firmware, and four transmit queues |
| 198 | * (#0-3) for data tx via EDCA. An additional 2 HCCA queues are unused. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 199 | ***************************************************/ |
| 200 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 201 | static int iwl3945_queue_space(const struct iwl3945_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 202 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 203 | int s = q->read_ptr - q->write_ptr; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 204 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 205 | if (q->read_ptr > q->write_ptr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 206 | s -= q->n_bd; |
| 207 | |
| 208 | if (s <= 0) |
| 209 | s += q->n_window; |
| 210 | /* keep some reserve to not confuse empty and full situations */ |
| 211 | s -= 2; |
| 212 | if (s < 0) |
| 213 | s = 0; |
| 214 | return s; |
| 215 | } |
| 216 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 217 | /** |
| 218 | * iwl3945_queue_inc_wrap - increment queue index, wrap back to beginning |
| 219 | * @index -- current index |
| 220 | * @n_bd -- total number of entries in queue (must be power of 2) |
| 221 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 222 | static inline int iwl3945_queue_inc_wrap(int index, int n_bd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 223 | { |
| 224 | return ++index & (n_bd - 1); |
| 225 | } |
| 226 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 227 | /** |
| 228 | * iwl3945_queue_dec_wrap - increment queue index, wrap back to end |
| 229 | * @index -- current index |
| 230 | * @n_bd -- total number of entries in queue (must be power of 2) |
| 231 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 232 | static inline int iwl3945_queue_dec_wrap(int index, int n_bd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 233 | { |
| 234 | return --index & (n_bd - 1); |
| 235 | } |
| 236 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 237 | static inline int x2_queue_used(const struct iwl3945_queue *q, int i) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 238 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 239 | return q->write_ptr > q->read_ptr ? |
| 240 | (i >= q->read_ptr && i < q->write_ptr) : |
| 241 | !(i < q->read_ptr && i >= q->write_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 244 | static inline u8 get_cmd_index(struct iwl3945_queue *q, u32 index, int is_huge) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 245 | { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 246 | /* 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] | 247 | if (is_huge) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 248 | return q->n_window; /* must be power of 2 */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 249 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 250 | /* Otherwise, use normal size buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 251 | return index & (q->n_window - 1); |
| 252 | } |
| 253 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 254 | /** |
| 255 | * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes |
| 256 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 257 | static int iwl3945_queue_init(struct iwl3945_priv *priv, struct iwl3945_queue *q, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 258 | int count, int slots_num, u32 id) |
| 259 | { |
| 260 | q->n_bd = count; |
| 261 | q->n_window = slots_num; |
| 262 | q->id = id; |
| 263 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 264 | /* count must be power-of-two size, otherwise iwl3945_queue_inc_wrap |
| 265 | * and iwl3945_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 266 | BUG_ON(!is_power_of_2(count)); |
| 267 | |
| 268 | /* slots_num must be power-of-two size, otherwise |
| 269 | * get_cmd_index is broken. */ |
| 270 | BUG_ON(!is_power_of_2(slots_num)); |
| 271 | |
| 272 | q->low_mark = q->n_window / 4; |
| 273 | if (q->low_mark < 4) |
| 274 | q->low_mark = 4; |
| 275 | |
| 276 | q->high_mark = q->n_window / 8; |
| 277 | if (q->high_mark < 2) |
| 278 | q->high_mark = 2; |
| 279 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 280 | q->write_ptr = q->read_ptr = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 285 | /** |
| 286 | * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue |
| 287 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 288 | static int iwl3945_tx_queue_alloc(struct iwl3945_priv *priv, |
| 289 | struct iwl3945_tx_queue *txq, u32 id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 290 | { |
| 291 | struct pci_dev *dev = priv->pci_dev; |
| 292 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 293 | /* Driver private data, only for Tx (not command) queues, |
| 294 | * not shared with device. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 295 | if (id != IWL_CMD_QUEUE_NUM) { |
| 296 | txq->txb = kmalloc(sizeof(txq->txb[0]) * |
| 297 | TFD_QUEUE_SIZE_MAX, GFP_KERNEL); |
| 298 | if (!txq->txb) { |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 299 | IWL_ERROR("kmalloc for auxiliary BD " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 300 | "structures failed\n"); |
| 301 | goto error; |
| 302 | } |
| 303 | } else |
| 304 | txq->txb = NULL; |
| 305 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 306 | /* Circular buffer of transmit frame descriptors (TFDs), |
| 307 | * shared with device */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 308 | txq->bd = pci_alloc_consistent(dev, |
| 309 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX, |
| 310 | &txq->q.dma_addr); |
| 311 | |
| 312 | if (!txq->bd) { |
| 313 | IWL_ERROR("pci_alloc_consistent(%zd) failed\n", |
| 314 | sizeof(txq->bd[0]) * TFD_QUEUE_SIZE_MAX); |
| 315 | goto error; |
| 316 | } |
| 317 | txq->q.id = id; |
| 318 | |
| 319 | return 0; |
| 320 | |
| 321 | error: |
| 322 | if (txq->txb) { |
| 323 | kfree(txq->txb); |
| 324 | txq->txb = NULL; |
| 325 | } |
| 326 | |
| 327 | return -ENOMEM; |
| 328 | } |
| 329 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 330 | /** |
| 331 | * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue |
| 332 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 333 | int iwl3945_tx_queue_init(struct iwl3945_priv *priv, |
| 334 | struct iwl3945_tx_queue *txq, int slots_num, u32 txq_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 335 | { |
| 336 | struct pci_dev *dev = priv->pci_dev; |
| 337 | int len; |
| 338 | int rc = 0; |
| 339 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 340 | /* |
| 341 | * Alloc buffer array for commands (Tx or other types of commands). |
| 342 | * For the command queue (#4), allocate command space + one big |
| 343 | * command for scan, since scan command is very huge; the system will |
| 344 | * not have two scans at the same time, so only one is needed. |
| 345 | * For data Tx queues (all other queues), no super-size command |
| 346 | * space is needed. |
| 347 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 348 | len = sizeof(struct iwl3945_cmd) * slots_num; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 349 | if (txq_id == IWL_CMD_QUEUE_NUM) |
| 350 | len += IWL_MAX_SCAN_SIZE; |
| 351 | txq->cmd = pci_alloc_consistent(dev, len, &txq->dma_addr_cmd); |
| 352 | if (!txq->cmd) |
| 353 | return -ENOMEM; |
| 354 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 355 | /* Alloc driver data array and TFD circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 356 | rc = iwl3945_tx_queue_alloc(priv, txq, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 357 | if (rc) { |
| 358 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 359 | |
| 360 | return -ENOMEM; |
| 361 | } |
| 362 | txq->need_update = 0; |
| 363 | |
| 364 | /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 365 | * iwl3945_queue_inc_wrap and iwl3945_queue_dec_wrap are broken. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 366 | BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 367 | |
| 368 | /* Initialize queue high/low-water, head/tail indexes */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 369 | iwl3945_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] | 370 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 371 | /* Tell device where to find queue, enable DMA channel. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 372 | iwl3945_hw_tx_queue_init(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 378 | * iwl3945_tx_queue_free - Deallocate DMA queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 379 | * @txq: Transmit queue to deallocate. |
| 380 | * |
| 381 | * Empty queue by removing and destroying all BD's. |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 382 | * Free all buffers. |
| 383 | * 0-fill, but do not free "txq" descriptor structure. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 384 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 385 | void iwl3945_tx_queue_free(struct iwl3945_priv *priv, struct iwl3945_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 386 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 387 | struct iwl3945_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 388 | struct pci_dev *dev = priv->pci_dev; |
| 389 | int len; |
| 390 | |
| 391 | if (q->n_bd == 0) |
| 392 | return; |
| 393 | |
| 394 | /* first, empty all BD's */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 395 | for (; q->write_ptr != q->read_ptr; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 396 | q->read_ptr = iwl3945_queue_inc_wrap(q->read_ptr, q->n_bd)) |
| 397 | iwl3945_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 398 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 399 | len = sizeof(struct iwl3945_cmd) * q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 400 | if (q->id == IWL_CMD_QUEUE_NUM) |
| 401 | len += IWL_MAX_SCAN_SIZE; |
| 402 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 403 | /* De-alloc array of command/tx buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 404 | pci_free_consistent(dev, len, txq->cmd, txq->dma_addr_cmd); |
| 405 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 406 | /* De-alloc circular buffer of TFDs */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 407 | if (txq->q.n_bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 408 | pci_free_consistent(dev, sizeof(struct iwl3945_tfd_frame) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 409 | txq->q.n_bd, txq->bd, txq->q.dma_addr); |
| 410 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 411 | /* De-alloc array of per-TFD driver data */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 412 | if (txq->txb) { |
| 413 | kfree(txq->txb); |
| 414 | txq->txb = NULL; |
| 415 | } |
| 416 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 417 | /* 0-fill queue descriptor structure */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 418 | memset(txq, 0, sizeof(*txq)); |
| 419 | } |
| 420 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 421 | const u8 iwl3945_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 422 | |
| 423 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 424 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 425 | * the functionality provided here |
| 426 | */ |
| 427 | |
| 428 | /**************************************************************/ |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 429 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 430 | /** |
| 431 | * iwl3945_remove_station - Remove driver's knowledge of station. |
| 432 | * |
| 433 | * NOTE: This does not remove station from device's station table. |
| 434 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 435 | static u8 iwl3945_remove_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 436 | { |
| 437 | int index = IWL_INVALID_STATION; |
| 438 | int i; |
| 439 | unsigned long flags; |
| 440 | |
| 441 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 442 | |
| 443 | if (is_ap) |
| 444 | index = IWL_AP_ID; |
| 445 | else if (is_broadcast_ether_addr(addr)) |
| 446 | index = priv->hw_setting.bcast_sta_id; |
| 447 | else |
| 448 | for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) |
| 449 | if (priv->stations[i].used && |
| 450 | !compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 451 | addr)) { |
| 452 | index = i; |
| 453 | break; |
| 454 | } |
| 455 | |
| 456 | if (unlikely(index == IWL_INVALID_STATION)) |
| 457 | goto out; |
| 458 | |
| 459 | if (priv->stations[index].used) { |
| 460 | priv->stations[index].used = 0; |
| 461 | priv->num_stations--; |
| 462 | } |
| 463 | |
| 464 | BUG_ON(priv->num_stations < 0); |
| 465 | |
| 466 | out: |
| 467 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 468 | return 0; |
| 469 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 470 | #endif |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 471 | |
| 472 | /** |
| 473 | * iwl3945_clear_stations_table - Clear the driver's station table |
| 474 | * |
| 475 | * NOTE: This does not clear or otherwise alter the device's station table. |
| 476 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 477 | static void iwl3945_clear_stations_table(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 478 | { |
| 479 | unsigned long flags; |
| 480 | |
| 481 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 482 | |
| 483 | priv->num_stations = 0; |
| 484 | memset(priv->stations, 0, sizeof(priv->stations)); |
| 485 | |
| 486 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 487 | } |
| 488 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 489 | /** |
| 490 | * iwl3945_add_station - Add station to station tables in driver and device |
| 491 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 492 | u8 iwl3945_add_station(struct iwl3945_priv *priv, const u8 *addr, int is_ap, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 493 | { |
| 494 | int i; |
| 495 | int index = IWL_INVALID_STATION; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 496 | struct iwl3945_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 497 | unsigned long flags_spin; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 498 | DECLARE_MAC_BUF(mac); |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 499 | u8 rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 500 | |
| 501 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 502 | if (is_ap) |
| 503 | index = IWL_AP_ID; |
| 504 | else if (is_broadcast_ether_addr(addr)) |
| 505 | index = priv->hw_setting.bcast_sta_id; |
| 506 | else |
| 507 | for (i = IWL_STA_ID; i < priv->hw_setting.max_stations; i++) { |
| 508 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 509 | addr)) { |
| 510 | index = i; |
| 511 | break; |
| 512 | } |
| 513 | |
| 514 | if (!priv->stations[i].used && |
| 515 | index == IWL_INVALID_STATION) |
| 516 | index = i; |
| 517 | } |
| 518 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 519 | /* These two conditions has the same outcome but keep them separate |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 520 | since they have different meaning */ |
| 521 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 522 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 523 | return index; |
| 524 | } |
| 525 | |
| 526 | if (priv->stations[index].used && |
| 527 | !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) { |
| 528 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 529 | return index; |
| 530 | } |
| 531 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 532 | 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] | 533 | station = &priv->stations[index]; |
| 534 | station->used = 1; |
| 535 | priv->num_stations++; |
| 536 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 537 | /* Set up the REPLY_ADD_STA command to send to device */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 538 | memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 539 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 540 | station->sta.mode = 0; |
| 541 | station->sta.sta.sta_id = index; |
| 542 | station->sta.station_flags = 0; |
| 543 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 544 | if (priv->band == IEEE80211_BAND_5GHZ) |
Tomas Winkler | 6994633 | 2007-10-25 17:15:27 +0800 | [diff] [blame] | 545 | rate = IWL_RATE_6M_PLCP; |
| 546 | else |
| 547 | rate = IWL_RATE_1M_PLCP; |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 548 | |
| 549 | /* Turn on both antennas for the station... */ |
| 550 | station->sta.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 551 | iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK); |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 552 | station->current_rate.rate_n_flags = |
| 553 | le16_to_cpu(station->sta.rate_n_flags); |
| 554 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 555 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 556 | |
| 557 | /* Add station to device's station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 558 | iwl3945_send_add_station(priv, &station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 559 | return index; |
| 560 | |
| 561 | } |
| 562 | |
| 563 | /*************** DRIVER STATUS FUNCTIONS *****/ |
| 564 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 565 | static inline int iwl3945_is_ready(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 566 | { |
| 567 | /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are |
| 568 | * set but EXIT_PENDING is not */ |
| 569 | return test_bit(STATUS_READY, &priv->status) && |
| 570 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) && |
| 571 | !test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 572 | } |
| 573 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 574 | static inline int iwl3945_is_alive(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 575 | { |
| 576 | return test_bit(STATUS_ALIVE, &priv->status); |
| 577 | } |
| 578 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 579 | static inline int iwl3945_is_init(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 580 | { |
| 581 | return test_bit(STATUS_INIT, &priv->status); |
| 582 | } |
| 583 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 584 | static inline int iwl3945_is_rfkill(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 585 | { |
| 586 | return test_bit(STATUS_RF_KILL_HW, &priv->status) || |
| 587 | test_bit(STATUS_RF_KILL_SW, &priv->status); |
| 588 | } |
| 589 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 590 | static inline int iwl3945_is_ready_rf(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 591 | { |
| 592 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 593 | if (iwl3945_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 594 | return 0; |
| 595 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 596 | return iwl3945_is_ready(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 600 | |
| 601 | #define IWL_CMD(x) case x : return #x |
| 602 | |
| 603 | static const char *get_cmd_string(u8 cmd) |
| 604 | { |
| 605 | switch (cmd) { |
| 606 | IWL_CMD(REPLY_ALIVE); |
| 607 | IWL_CMD(REPLY_ERROR); |
| 608 | IWL_CMD(REPLY_RXON); |
| 609 | IWL_CMD(REPLY_RXON_ASSOC); |
| 610 | IWL_CMD(REPLY_QOS_PARAM); |
| 611 | IWL_CMD(REPLY_RXON_TIMING); |
| 612 | IWL_CMD(REPLY_ADD_STA); |
| 613 | IWL_CMD(REPLY_REMOVE_STA); |
| 614 | IWL_CMD(REPLY_REMOVE_ALL_STA); |
| 615 | IWL_CMD(REPLY_3945_RX); |
| 616 | IWL_CMD(REPLY_TX); |
| 617 | IWL_CMD(REPLY_RATE_SCALE); |
| 618 | IWL_CMD(REPLY_LEDS_CMD); |
| 619 | IWL_CMD(REPLY_TX_LINK_QUALITY_CMD); |
| 620 | IWL_CMD(RADAR_NOTIFICATION); |
| 621 | IWL_CMD(REPLY_QUIET_CMD); |
| 622 | IWL_CMD(REPLY_CHANNEL_SWITCH); |
| 623 | IWL_CMD(CHANNEL_SWITCH_NOTIFICATION); |
| 624 | IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD); |
| 625 | IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION); |
| 626 | IWL_CMD(POWER_TABLE_CMD); |
| 627 | IWL_CMD(PM_SLEEP_NOTIFICATION); |
| 628 | IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC); |
| 629 | IWL_CMD(REPLY_SCAN_CMD); |
| 630 | IWL_CMD(REPLY_SCAN_ABORT_CMD); |
| 631 | IWL_CMD(SCAN_START_NOTIFICATION); |
| 632 | IWL_CMD(SCAN_RESULTS_NOTIFICATION); |
| 633 | IWL_CMD(SCAN_COMPLETE_NOTIFICATION); |
| 634 | IWL_CMD(BEACON_NOTIFICATION); |
| 635 | IWL_CMD(REPLY_TX_BEACON); |
| 636 | IWL_CMD(WHO_IS_AWAKE_NOTIFICATION); |
| 637 | IWL_CMD(QUIET_NOTIFICATION); |
| 638 | IWL_CMD(REPLY_TX_PWR_TABLE_CMD); |
| 639 | IWL_CMD(MEASURE_ABORT_NOTIFICATION); |
| 640 | IWL_CMD(REPLY_BT_CONFIG); |
| 641 | IWL_CMD(REPLY_STATISTICS_CMD); |
| 642 | IWL_CMD(STATISTICS_NOTIFICATION); |
| 643 | IWL_CMD(REPLY_CARD_STATE_CMD); |
| 644 | IWL_CMD(CARD_STATE_NOTIFICATION); |
| 645 | IWL_CMD(MISSED_BEACONS_NOTIFICATION); |
| 646 | default: |
| 647 | return "UNKNOWN"; |
| 648 | |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | #define HOST_COMPLETE_TIMEOUT (HZ / 2) |
| 653 | |
| 654 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 655 | * iwl3945_enqueue_hcmd - enqueue a uCode command |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 656 | * @priv: device private data point |
| 657 | * @cmd: a point to the ucode command structure |
| 658 | * |
| 659 | * The function returns < 0 values to indicate the operation is |
| 660 | * failed. On success, it turns the index (> 0) of command in the |
| 661 | * command queue. |
| 662 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 663 | static int iwl3945_enqueue_hcmd(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 664 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 665 | struct iwl3945_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
| 666 | struct iwl3945_queue *q = &txq->q; |
| 667 | struct iwl3945_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 668 | u32 *control_flags; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 669 | struct iwl3945_cmd *out_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 670 | u32 idx; |
| 671 | u16 fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 672 | dma_addr_t phys_addr; |
| 673 | int pad; |
| 674 | u16 count; |
| 675 | int ret; |
| 676 | unsigned long flags; |
| 677 | |
| 678 | /* If any of the command structures end up being larger than |
| 679 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
| 680 | * we will need to increase the size of the TFD entries */ |
| 681 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
| 682 | !(cmd->meta.flags & CMD_SIZE_HUGE)); |
| 683 | |
Gregory Greenman | c342a1b | 2008-02-06 11:20:40 -0800 | [diff] [blame] | 684 | |
| 685 | if (iwl3945_is_rfkill(priv)) { |
| 686 | IWL_DEBUG_INFO("Not sending command - RF KILL"); |
| 687 | return -EIO; |
| 688 | } |
| 689 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 690 | if (iwl3945_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 691 | IWL_ERROR("No space for Tx\n"); |
| 692 | return -ENOSPC; |
| 693 | } |
| 694 | |
| 695 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 696 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 697 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 698 | memset(tfd, 0, sizeof(*tfd)); |
| 699 | |
| 700 | control_flags = (u32 *) tfd; |
| 701 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 702 | 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] | 703 | out_cmd = &txq->cmd[idx]; |
| 704 | |
| 705 | out_cmd->hdr.cmd = cmd->id; |
| 706 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 707 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 708 | |
| 709 | /* At this point, the out_cmd now has all of the incoming cmd |
| 710 | * information */ |
| 711 | |
| 712 | out_cmd->hdr.flags = 0; |
| 713 | 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] | 714 | INDEX_TO_SEQ(q->write_ptr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 715 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
| 716 | out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME); |
| 717 | |
| 718 | phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 719 | offsetof(struct iwl3945_cmd, hdr); |
| 720 | iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 721 | |
| 722 | pad = U32_PAD(cmd->len); |
| 723 | count = TFD_CTL_COUNT_GET(*control_flags); |
| 724 | *control_flags = TFD_CTL_COUNT_SET(count) | TFD_CTL_PAD_SET(pad); |
| 725 | |
| 726 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 727 | "%d bytes at %d[%d]:%d\n", |
| 728 | get_cmd_string(out_cmd->hdr.cmd), |
| 729 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 730 | fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 731 | |
| 732 | txq->need_update = 1; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 733 | |
| 734 | /* Increment and update queue's write index */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 735 | q->write_ptr = iwl3945_queue_inc_wrap(q->write_ptr, q->n_bd); |
| 736 | ret = iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 737 | |
| 738 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 739 | return ret ? ret : idx; |
| 740 | } |
| 741 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 742 | static int iwl3945_send_cmd_async(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 743 | { |
| 744 | int ret; |
| 745 | |
| 746 | BUG_ON(!(cmd->meta.flags & CMD_ASYNC)); |
| 747 | |
| 748 | /* An asynchronous command can not expect an SKB to be set. */ |
| 749 | BUG_ON(cmd->meta.flags & CMD_WANT_SKB); |
| 750 | |
| 751 | /* An asynchronous command MUST have a callback. */ |
| 752 | BUG_ON(!cmd->meta.u.callback); |
| 753 | |
| 754 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 755 | return -EBUSY; |
| 756 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 757 | ret = iwl3945_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 758 | if (ret < 0) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 759 | IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 760 | get_cmd_string(cmd->id), ret); |
| 761 | return ret; |
| 762 | } |
| 763 | return 0; |
| 764 | } |
| 765 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 766 | static int iwl3945_send_cmd_sync(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 767 | { |
| 768 | int cmd_idx; |
| 769 | int ret; |
| 770 | static atomic_t entry = ATOMIC_INIT(0); /* reentrance protection */ |
| 771 | |
| 772 | BUG_ON(cmd->meta.flags & CMD_ASYNC); |
| 773 | |
| 774 | /* A synchronous command can not have a callback set. */ |
| 775 | BUG_ON(cmd->meta.u.callback != NULL); |
| 776 | |
| 777 | if (atomic_xchg(&entry, 1)) { |
| 778 | IWL_ERROR("Error sending %s: Already sending a host command\n", |
| 779 | get_cmd_string(cmd->id)); |
| 780 | return -EBUSY; |
| 781 | } |
| 782 | |
| 783 | set_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 784 | |
| 785 | if (cmd->meta.flags & CMD_WANT_SKB) |
| 786 | cmd->meta.source = &cmd->meta; |
| 787 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 788 | cmd_idx = iwl3945_enqueue_hcmd(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 789 | if (cmd_idx < 0) { |
| 790 | ret = cmd_idx; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 791 | IWL_ERROR("Error sending %s: iwl3945_enqueue_hcmd failed: %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 792 | get_cmd_string(cmd->id), ret); |
| 793 | goto out; |
| 794 | } |
| 795 | |
| 796 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 797 | !test_bit(STATUS_HCMD_ACTIVE, &priv->status), |
| 798 | HOST_COMPLETE_TIMEOUT); |
| 799 | if (!ret) { |
| 800 | if (test_bit(STATUS_HCMD_ACTIVE, &priv->status)) { |
| 801 | IWL_ERROR("Error sending %s: time out after %dms.\n", |
| 802 | get_cmd_string(cmd->id), |
| 803 | jiffies_to_msecs(HOST_COMPLETE_TIMEOUT)); |
| 804 | |
| 805 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 806 | ret = -ETIMEDOUT; |
| 807 | goto cancel; |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 812 | IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n", |
| 813 | get_cmd_string(cmd->id)); |
| 814 | ret = -ECANCELED; |
| 815 | goto fail; |
| 816 | } |
| 817 | if (test_bit(STATUS_FW_ERROR, &priv->status)) { |
| 818 | IWL_DEBUG_INFO("Command %s failed: FW Error\n", |
| 819 | get_cmd_string(cmd->id)); |
| 820 | ret = -EIO; |
| 821 | goto fail; |
| 822 | } |
| 823 | if ((cmd->meta.flags & CMD_WANT_SKB) && !cmd->meta.u.skb) { |
| 824 | IWL_ERROR("Error: Response NULL in '%s'\n", |
| 825 | get_cmd_string(cmd->id)); |
| 826 | ret = -EIO; |
| 827 | goto out; |
| 828 | } |
| 829 | |
| 830 | ret = 0; |
| 831 | goto out; |
| 832 | |
| 833 | cancel: |
| 834 | if (cmd->meta.flags & CMD_WANT_SKB) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 835 | struct iwl3945_cmd *qcmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 836 | |
| 837 | /* Cancel the CMD_WANT_SKB flag for the cmd in the |
| 838 | * TX cmd queue. Otherwise in case the cmd comes |
| 839 | * in later, it will possibly set an invalid |
| 840 | * address (cmd->meta.source). */ |
| 841 | qcmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_idx]; |
| 842 | qcmd->meta.flags &= ~CMD_WANT_SKB; |
| 843 | } |
| 844 | fail: |
| 845 | if (cmd->meta.u.skb) { |
| 846 | dev_kfree_skb_any(cmd->meta.u.skb); |
| 847 | cmd->meta.u.skb = NULL; |
| 848 | } |
| 849 | out: |
| 850 | atomic_set(&entry, 0); |
| 851 | return ret; |
| 852 | } |
| 853 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 854 | int iwl3945_send_cmd(struct iwl3945_priv *priv, struct iwl3945_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 855 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 856 | if (cmd->meta.flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 857 | return iwl3945_send_cmd_async(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 858 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 859 | return iwl3945_send_cmd_sync(priv, cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 860 | } |
| 861 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 862 | int iwl3945_send_cmd_pdu(struct iwl3945_priv *priv, u8 id, u16 len, const void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 863 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 864 | struct iwl3945_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 865 | .id = id, |
| 866 | .len = len, |
| 867 | .data = data, |
| 868 | }; |
| 869 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 870 | return iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 871 | } |
| 872 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 873 | static int __must_check iwl3945_send_cmd_u32(struct iwl3945_priv *priv, u8 id, u32 val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 874 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 875 | struct iwl3945_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 876 | .id = id, |
| 877 | .len = sizeof(val), |
| 878 | .data = &val, |
| 879 | }; |
| 880 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 881 | return iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 882 | } |
| 883 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 884 | int iwl3945_send_statistics_request(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 885 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 886 | return iwl3945_send_cmd_u32(priv, REPLY_STATISTICS_CMD, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 890 | * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 891 | * @band: 2.4 or 5 GHz band |
| 892 | * @channel: Any channel valid for the requested band |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 893 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 894 | * In addition to setting the staging RXON, priv->band is also set. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 895 | * |
| 896 | * NOTE: Does not commit to the hardware; it sets appropriate bit fields |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 897 | * in the staging RXON flag structure based on the band |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 898 | */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 899 | static int iwl3945_set_rxon_channel(struct iwl3945_priv *priv, |
| 900 | enum ieee80211_band band, |
| 901 | u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 902 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 903 | if (!iwl3945_get_channel_info(priv, band, channel)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 904 | IWL_DEBUG_INFO("Could not set channel to %d [%d]\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 905 | channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 906 | return -EINVAL; |
| 907 | } |
| 908 | |
| 909 | if ((le16_to_cpu(priv->staging_rxon.channel) == channel) && |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 910 | (priv->band == band)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 911 | return 0; |
| 912 | |
| 913 | priv->staging_rxon.channel = cpu_to_le16(channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 914 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 915 | priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; |
| 916 | else |
| 917 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 918 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 919 | priv->band = band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 920 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 921 | IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 922 | |
| 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 927 | * iwl3945_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 928 | * |
| 929 | * NOTE: This is really only useful during development and can eventually |
| 930 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 931 | * making changes |
| 932 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 933 | static int iwl3945_check_rxon_cmd(struct iwl3945_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 934 | { |
| 935 | int error = 0; |
| 936 | int counter = 1; |
| 937 | |
| 938 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 939 | error |= le32_to_cpu(rxon->flags & |
| 940 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 941 | RXON_FLG_RADAR_DETECT_MSK)); |
| 942 | if (error) |
| 943 | IWL_WARNING("check 24G fields %d | %d\n", |
| 944 | counter++, error); |
| 945 | } else { |
| 946 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 947 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 948 | if (error) |
| 949 | IWL_WARNING("check 52 fields %d | %d\n", |
| 950 | counter++, error); |
| 951 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 952 | if (error) |
| 953 | IWL_WARNING("check 52 CCK %d | %d\n", |
| 954 | counter++, error); |
| 955 | } |
| 956 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 957 | if (error) |
| 958 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); |
| 959 | |
| 960 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 961 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 962 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 963 | if (error) |
| 964 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); |
| 965 | |
| 966 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 967 | if (error) |
| 968 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); |
| 969 | |
| 970 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 971 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 972 | if (error) |
| 973 | IWL_WARNING("check CCK and short slot %d | %d\n", |
| 974 | counter++, error); |
| 975 | |
| 976 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 977 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 978 | if (error) |
| 979 | IWL_WARNING("check CCK & auto detect %d | %d\n", |
| 980 | counter++, error); |
| 981 | |
| 982 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 983 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 984 | if (error) |
| 985 | IWL_WARNING("check TGG and auto detect %d | %d\n", |
| 986 | counter++, error); |
| 987 | |
| 988 | if ((rxon->flags & RXON_FLG_DIS_DIV_MSK)) |
| 989 | error |= ((rxon->flags & (RXON_FLG_ANT_B_MSK | |
| 990 | RXON_FLG_ANT_A_MSK)) == 0); |
| 991 | if (error) |
| 992 | IWL_WARNING("check antenna %d %d\n", counter++, error); |
| 993 | |
| 994 | if (error) |
| 995 | IWL_WARNING("Tuning to channel %d\n", |
| 996 | le16_to_cpu(rxon->channel)); |
| 997 | |
| 998 | if (error) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 999 | IWL_ERROR("Not a valid iwl3945_rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1000 | return -1; |
| 1001 | } |
| 1002 | return 0; |
| 1003 | } |
| 1004 | |
| 1005 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1006 | * iwl3945_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] | 1007 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1008 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1009 | * If the RXON structure is changing enough to require a new tune, |
| 1010 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 1011 | * 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] | 1012 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1013 | static int iwl3945_full_rxon_required(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1014 | { |
| 1015 | |
| 1016 | /* These items are only settable from the full RXON command */ |
| 1017 | if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || |
| 1018 | compare_ether_addr(priv->staging_rxon.bssid_addr, |
| 1019 | priv->active_rxon.bssid_addr) || |
| 1020 | compare_ether_addr(priv->staging_rxon.node_addr, |
| 1021 | priv->active_rxon.node_addr) || |
| 1022 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, |
| 1023 | priv->active_rxon.wlap_bssid_addr) || |
| 1024 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || |
| 1025 | (priv->staging_rxon.channel != priv->active_rxon.channel) || |
| 1026 | (priv->staging_rxon.air_propagation != |
| 1027 | priv->active_rxon.air_propagation) || |
| 1028 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) |
| 1029 | return 1; |
| 1030 | |
| 1031 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 1032 | * be updated with the RXON_ASSOC command -- however only some |
| 1033 | * flag transitions are allowed using RXON_ASSOC */ |
| 1034 | |
| 1035 | /* Check if we are not switching bands */ |
| 1036 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 1037 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
| 1038 | return 1; |
| 1039 | |
| 1040 | /* Check if we are switching association toggle */ |
| 1041 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 1042 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
| 1043 | return 1; |
| 1044 | |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1048 | static int iwl3945_send_rxon_assoc(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1049 | { |
| 1050 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1051 | struct iwl3945_rx_packet *res = NULL; |
| 1052 | struct iwl3945_rxon_assoc_cmd rxon_assoc; |
| 1053 | struct iwl3945_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1054 | .id = REPLY_RXON_ASSOC, |
| 1055 | .len = sizeof(rxon_assoc), |
| 1056 | .meta.flags = CMD_WANT_SKB, |
| 1057 | .data = &rxon_assoc, |
| 1058 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1059 | const struct iwl3945_rxon_cmd *rxon1 = &priv->staging_rxon; |
| 1060 | const struct iwl3945_rxon_cmd *rxon2 = &priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1061 | |
| 1062 | if ((rxon1->flags == rxon2->flags) && |
| 1063 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 1064 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 1065 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 1066 | IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n"); |
| 1067 | return 0; |
| 1068 | } |
| 1069 | |
| 1070 | rxon_assoc.flags = priv->staging_rxon.flags; |
| 1071 | rxon_assoc.filter_flags = priv->staging_rxon.filter_flags; |
| 1072 | rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates; |
| 1073 | rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates; |
| 1074 | rxon_assoc.reserved = 0; |
| 1075 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1076 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1077 | if (rc) |
| 1078 | return rc; |
| 1079 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1080 | res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1081 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1082 | IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n"); |
| 1083 | rc = -EIO; |
| 1084 | } |
| 1085 | |
| 1086 | priv->alloc_rxb_skb--; |
| 1087 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1088 | |
| 1089 | return rc; |
| 1090 | } |
| 1091 | |
| 1092 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1093 | * iwl3945_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1094 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1095 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1096 | * the active_rxon structure is updated with the new data. This |
| 1097 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 1098 | * a HW tune is required based on the RXON structure changes. |
| 1099 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1100 | static int iwl3945_commit_rxon(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1101 | { |
| 1102 | /* cast away the const for active_rxon in this function */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1103 | struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1104 | int rc = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1105 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1106 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1107 | if (!iwl3945_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1108 | return -1; |
| 1109 | |
| 1110 | /* always get timestamp with Rx frame */ |
| 1111 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
| 1112 | |
| 1113 | /* select antenna */ |
| 1114 | priv->staging_rxon.flags &= |
| 1115 | ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK); |
| 1116 | priv->staging_rxon.flags |= iwl3945_get_antenna_flags(priv); |
| 1117 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1118 | rc = iwl3945_check_rxon_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1119 | if (rc) { |
| 1120 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); |
| 1121 | return -EINVAL; |
| 1122 | } |
| 1123 | |
| 1124 | /* If we don't need to send a full RXON, we can use |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1125 | * iwl3945_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1126 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1127 | if (!iwl3945_full_rxon_required(priv)) { |
| 1128 | rc = iwl3945_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1129 | if (rc) { |
| 1130 | IWL_ERROR("Error setting RXON_ASSOC " |
| 1131 | "configuration (%d).\n", rc); |
| 1132 | return rc; |
| 1133 | } |
| 1134 | |
| 1135 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 1136 | |
| 1137 | return 0; |
| 1138 | } |
| 1139 | |
| 1140 | /* If we are currently associated and the new config requires |
| 1141 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 1142 | * we must clear the associated from the active configuration |
| 1143 | * before we apply the new config */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1144 | if (iwl3945_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1145 | (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
| 1146 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 1147 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 1148 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1149 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON, |
| 1150 | sizeof(struct iwl3945_rxon_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1151 | &priv->active_rxon); |
| 1152 | |
| 1153 | /* If the mask clearing failed then we set |
| 1154 | * active_rxon back to what it was previously */ |
| 1155 | if (rc) { |
| 1156 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 1157 | IWL_ERROR("Error clearing ASSOC_MSK on current " |
| 1158 | "configuration (%d).\n", rc); |
| 1159 | return rc; |
| 1160 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | IWL_DEBUG_INFO("Sending RXON\n" |
| 1164 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 1165 | "* channel = %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1166 | "* bssid = %s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1167 | ((priv->staging_rxon.filter_flags & |
| 1168 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
| 1169 | le16_to_cpu(priv->staging_rxon.channel), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1170 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1171 | |
| 1172 | /* Apply the new configuration */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1173 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON, |
| 1174 | sizeof(struct iwl3945_rxon_cmd), &priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1175 | if (rc) { |
| 1176 | IWL_ERROR("Error setting new configuration (%d).\n", rc); |
| 1177 | return rc; |
| 1178 | } |
| 1179 | |
| 1180 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 1181 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1182 | iwl3945_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 1183 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1184 | /* If we issue a new RXON command which required a tune then we must |
| 1185 | * 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] | 1186 | rc = iwl3945_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1187 | if (rc) { |
| 1188 | IWL_ERROR("Error setting Tx power (%d).\n", rc); |
| 1189 | return rc; |
| 1190 | } |
| 1191 | |
| 1192 | /* Add the broadcast address so we can send broadcast frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1193 | if (iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1194 | IWL_INVALID_STATION) { |
| 1195 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); |
| 1196 | return -EIO; |
| 1197 | } |
| 1198 | |
| 1199 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 1200 | * add the IWL_AP_ID to the station rate table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1201 | if (iwl3945_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1202 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1203 | if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr, 1, 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1204 | == IWL_INVALID_STATION) { |
| 1205 | IWL_ERROR("Error adding AP address for transmit.\n"); |
| 1206 | return -EIO; |
| 1207 | } |
| 1208 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1209 | /* Init the hardware's rate fallback order based on the band */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1210 | rc = iwl3945_init_hw_rate_table(priv); |
| 1211 | if (rc) { |
| 1212 | IWL_ERROR("Error setting HW rate table: %02X\n", rc); |
| 1213 | return -EIO; |
| 1214 | } |
| 1215 | |
| 1216 | return 0; |
| 1217 | } |
| 1218 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1219 | static int iwl3945_send_bt_config(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1220 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1221 | struct iwl3945_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1222 | .flags = 3, |
| 1223 | .lead_time = 0xAA, |
| 1224 | .max_kill = 1, |
| 1225 | .kill_ack_mask = 0, |
| 1226 | .kill_cts_mask = 0, |
| 1227 | }; |
| 1228 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1229 | return iwl3945_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
| 1230 | sizeof(struct iwl3945_bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1233 | static int iwl3945_send_scan_abort(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1234 | { |
| 1235 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1236 | struct iwl3945_rx_packet *res; |
| 1237 | struct iwl3945_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1238 | .id = REPLY_SCAN_ABORT_CMD, |
| 1239 | .meta.flags = CMD_WANT_SKB, |
| 1240 | }; |
| 1241 | |
| 1242 | /* If there isn't a scan actively going on in the hardware |
| 1243 | * then we are in between scan bands and not actually |
| 1244 | * actively scanning, so don't send the abort command */ |
| 1245 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1246 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1247 | return 0; |
| 1248 | } |
| 1249 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1250 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1251 | if (rc) { |
| 1252 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1253 | return rc; |
| 1254 | } |
| 1255 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1256 | res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1257 | if (res->u.status != CAN_ABORT_STATUS) { |
| 1258 | /* The scan abort will return 1 for success or |
| 1259 | * 2 for "failure". A failure condition can be |
| 1260 | * due to simply not being in an active scan which |
| 1261 | * can occur if we send the scan abort before we |
| 1262 | * the microcode has notified us that a scan is |
| 1263 | * completed. */ |
| 1264 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 1265 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1266 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 1267 | } |
| 1268 | |
| 1269 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1270 | |
| 1271 | return rc; |
| 1272 | } |
| 1273 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1274 | static int iwl3945_card_state_sync_callback(struct iwl3945_priv *priv, |
| 1275 | struct iwl3945_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1276 | struct sk_buff *skb) |
| 1277 | { |
| 1278 | return 1; |
| 1279 | } |
| 1280 | |
| 1281 | /* |
| 1282 | * CARD_STATE_CMD |
| 1283 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1284 | * 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] | 1285 | * |
| 1286 | * When in the 'enable' state the card operates as normal. |
| 1287 | * When in the 'disable' state, the card enters into a low power mode. |
| 1288 | * When in the 'halt' state, the card is shut down and must be fully |
| 1289 | * restarted to come back on. |
| 1290 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1291 | static int iwl3945_send_card_state(struct iwl3945_priv *priv, u32 flags, u8 meta_flag) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1292 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1293 | struct iwl3945_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1294 | .id = REPLY_CARD_STATE_CMD, |
| 1295 | .len = sizeof(u32), |
| 1296 | .data = &flags, |
| 1297 | .meta.flags = meta_flag, |
| 1298 | }; |
| 1299 | |
| 1300 | if (meta_flag & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1301 | cmd.meta.u.callback = iwl3945_card_state_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1302 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1303 | return iwl3945_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1304 | } |
| 1305 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1306 | static int iwl3945_add_sta_sync_callback(struct iwl3945_priv *priv, |
| 1307 | struct iwl3945_cmd *cmd, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1308 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1309 | struct iwl3945_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1310 | |
| 1311 | if (!skb) { |
| 1312 | IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n"); |
| 1313 | return 1; |
| 1314 | } |
| 1315 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1316 | res = (struct iwl3945_rx_packet *)skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1317 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1318 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 1319 | res->hdr.flags); |
| 1320 | return 1; |
| 1321 | } |
| 1322 | |
| 1323 | switch (res->u.add_sta.status) { |
| 1324 | case ADD_STA_SUCCESS_MSK: |
| 1325 | break; |
| 1326 | default: |
| 1327 | break; |
| 1328 | } |
| 1329 | |
| 1330 | /* We didn't cache the SKB; let the caller free it */ |
| 1331 | return 1; |
| 1332 | } |
| 1333 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1334 | int iwl3945_send_add_station(struct iwl3945_priv *priv, |
| 1335 | struct iwl3945_addsta_cmd *sta, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1336 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1337 | struct iwl3945_rx_packet *res = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1338 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1339 | struct iwl3945_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1340 | .id = REPLY_ADD_STA, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1341 | .len = sizeof(struct iwl3945_addsta_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1342 | .meta.flags = flags, |
| 1343 | .data = sta, |
| 1344 | }; |
| 1345 | |
| 1346 | if (flags & CMD_ASYNC) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1347 | cmd.meta.u.callback = iwl3945_add_sta_sync_callback; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1348 | else |
| 1349 | cmd.meta.flags |= CMD_WANT_SKB; |
| 1350 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1351 | rc = iwl3945_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1352 | |
| 1353 | if (rc || (flags & CMD_ASYNC)) |
| 1354 | return rc; |
| 1355 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1356 | res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1357 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1358 | IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 1359 | res->hdr.flags); |
| 1360 | rc = -EIO; |
| 1361 | } |
| 1362 | |
| 1363 | if (rc == 0) { |
| 1364 | switch (res->u.add_sta.status) { |
| 1365 | case ADD_STA_SUCCESS_MSK: |
| 1366 | IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n"); |
| 1367 | break; |
| 1368 | default: |
| 1369 | rc = -EIO; |
| 1370 | IWL_WARNING("REPLY_ADD_STA failed\n"); |
| 1371 | break; |
| 1372 | } |
| 1373 | } |
| 1374 | |
| 1375 | priv->alloc_rxb_skb--; |
| 1376 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1377 | |
| 1378 | return rc; |
| 1379 | } |
| 1380 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1381 | static int iwl3945_update_sta_key_info(struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1382 | struct ieee80211_key_conf *keyconf, |
| 1383 | u8 sta_id) |
| 1384 | { |
| 1385 | unsigned long flags; |
| 1386 | __le16 key_flags = 0; |
| 1387 | |
| 1388 | switch (keyconf->alg) { |
| 1389 | case ALG_CCMP: |
| 1390 | key_flags |= STA_KEY_FLG_CCMP; |
| 1391 | key_flags |= cpu_to_le16( |
| 1392 | keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 1393 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 1394 | break; |
| 1395 | case ALG_TKIP: |
| 1396 | case ALG_WEP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1397 | default: |
| 1398 | return -EINVAL; |
| 1399 | } |
| 1400 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 1401 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 1402 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 1403 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, |
| 1404 | keyconf->keylen); |
| 1405 | |
| 1406 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, |
| 1407 | keyconf->keylen); |
| 1408 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 1409 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1410 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1411 | |
| 1412 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1413 | |
| 1414 | IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1415 | iwl3945_send_add_station(priv, &priv->stations[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1416 | return 0; |
| 1417 | } |
| 1418 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1419 | static int iwl3945_clear_sta_key_info(struct iwl3945_priv *priv, u8 sta_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1420 | { |
| 1421 | unsigned long flags; |
| 1422 | |
| 1423 | spin_lock_irqsave(&priv->sta_lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1424 | memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key)); |
| 1425 | memset(&priv->stations[sta_id].sta.key, 0, sizeof(struct iwl3945_keyinfo)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1426 | priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; |
| 1427 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 1428 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 1429 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 1430 | |
| 1431 | IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1432 | iwl3945_send_add_station(priv, &priv->stations[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1433 | return 0; |
| 1434 | } |
| 1435 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1436 | static void iwl3945_clear_free_frames(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1437 | { |
| 1438 | struct list_head *element; |
| 1439 | |
| 1440 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 1441 | priv->frames_count); |
| 1442 | |
| 1443 | while (!list_empty(&priv->free_frames)) { |
| 1444 | element = priv->free_frames.next; |
| 1445 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1446 | kfree(list_entry(element, struct iwl3945_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1447 | priv->frames_count--; |
| 1448 | } |
| 1449 | |
| 1450 | if (priv->frames_count) { |
| 1451 | IWL_WARNING("%d frames still in use. Did we lose one?\n", |
| 1452 | priv->frames_count); |
| 1453 | priv->frames_count = 0; |
| 1454 | } |
| 1455 | } |
| 1456 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1457 | static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1458 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1459 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1460 | struct list_head *element; |
| 1461 | if (list_empty(&priv->free_frames)) { |
| 1462 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 1463 | if (!frame) { |
| 1464 | IWL_ERROR("Could not allocate frame!\n"); |
| 1465 | return NULL; |
| 1466 | } |
| 1467 | |
| 1468 | priv->frames_count++; |
| 1469 | return frame; |
| 1470 | } |
| 1471 | |
| 1472 | element = priv->free_frames.next; |
| 1473 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1474 | return list_entry(element, struct iwl3945_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1475 | } |
| 1476 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1477 | static void iwl3945_free_frame(struct iwl3945_priv *priv, struct iwl3945_frame *frame) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1478 | { |
| 1479 | memset(frame, 0, sizeof(*frame)); |
| 1480 | list_add(&frame->list, &priv->free_frames); |
| 1481 | } |
| 1482 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1483 | unsigned int iwl3945_fill_beacon_frame(struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1484 | struct ieee80211_hdr *hdr, |
| 1485 | const u8 *dest, int left) |
| 1486 | { |
| 1487 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1488 | if (!iwl3945_is_associated(priv) || !priv->ibss_beacon || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1489 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
| 1490 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) |
| 1491 | return 0; |
| 1492 | |
| 1493 | if (priv->ibss_beacon->len > left) |
| 1494 | return 0; |
| 1495 | |
| 1496 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 1497 | |
| 1498 | return priv->ibss_beacon->len; |
| 1499 | } |
| 1500 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1501 | static u8 iwl3945_rate_get_lowest_plcp(int rate_mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1502 | { |
| 1503 | u8 i; |
| 1504 | |
| 1505 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1506 | i = iwl3945_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1507 | if (rate_mask & (1 << i)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1508 | return iwl3945_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | return IWL_RATE_INVALID; |
| 1512 | } |
| 1513 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1514 | static int iwl3945_send_beacon_cmd(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1515 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1516 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1517 | unsigned int frame_size; |
| 1518 | int rc; |
| 1519 | u8 rate; |
| 1520 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1521 | frame = iwl3945_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1522 | |
| 1523 | if (!frame) { |
| 1524 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 1525 | "command.\n"); |
| 1526 | return -ENOMEM; |
| 1527 | } |
| 1528 | |
| 1529 | if (!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1530 | rate = iwl3945_rate_get_lowest_plcp(priv->active_rate_basic & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1531 | 0xFF0); |
| 1532 | if (rate == IWL_INVALID_RATE) |
| 1533 | rate = IWL_RATE_6M_PLCP; |
| 1534 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1535 | rate = iwl3945_rate_get_lowest_plcp(priv->active_rate_basic & 0xF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1536 | if (rate == IWL_INVALID_RATE) |
| 1537 | rate = IWL_RATE_1M_PLCP; |
| 1538 | } |
| 1539 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1540 | frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1541 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1542 | rc = iwl3945_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1543 | &frame->u.cmd[0]); |
| 1544 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1545 | iwl3945_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1546 | |
| 1547 | return rc; |
| 1548 | } |
| 1549 | |
| 1550 | /****************************************************************************** |
| 1551 | * |
| 1552 | * EEPROM related functions |
| 1553 | * |
| 1554 | ******************************************************************************/ |
| 1555 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1556 | static void get_eeprom_mac(struct iwl3945_priv *priv, u8 *mac) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1557 | { |
| 1558 | memcpy(mac, priv->eeprom.mac_address, 6); |
| 1559 | } |
| 1560 | |
Reinette Chatre | 74a3a25 | 2008-01-23 10:15:19 -0800 | [diff] [blame] | 1561 | /* |
| 1562 | * Clear the OWNER_MSK, to establish driver (instead of uCode running on |
| 1563 | * embedded controller) as EEPROM reader; each read is a series of pulses |
| 1564 | * to/from the EEPROM chip, not a single event, so even reads could conflict |
| 1565 | * if they weren't arbitrated by some ownership mechanism. Here, the driver |
| 1566 | * simply claims ownership, which should be safe when this function is called |
| 1567 | * (i.e. before loading uCode!). |
| 1568 | */ |
| 1569 | static inline int iwl3945_eeprom_acquire_semaphore(struct iwl3945_priv *priv) |
| 1570 | { |
| 1571 | _iwl3945_clear_bit(priv, CSR_EEPROM_GP, CSR_EEPROM_GP_IF_OWNER_MSK); |
| 1572 | return 0; |
| 1573 | } |
| 1574 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1575 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1576 | * iwl3945_eeprom_init - read EEPROM contents |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1577 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1578 | * Load the EEPROM contents from adapter into priv->eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1579 | * |
| 1580 | * NOTE: This routine uses the non-debug IO access functions. |
| 1581 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1582 | int iwl3945_eeprom_init(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1583 | { |
Tomas Winkler | 58ff6d4 | 2008-02-13 02:47:54 +0200 | [diff] [blame] | 1584 | u16 *e = (u16 *)&priv->eeprom; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1585 | u32 gp = iwl3945_read32(priv, CSR_EEPROM_GP); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1586 | u32 r; |
| 1587 | int sz = sizeof(priv->eeprom); |
| 1588 | int rc; |
| 1589 | int i; |
| 1590 | u16 addr; |
| 1591 | |
| 1592 | /* The EEPROM structure has several padding buffers within it |
| 1593 | * and when adding new EEPROM maps is subject to programmer errors |
| 1594 | * which may be very difficult to identify without explicitly |
| 1595 | * checking the resulting size of the eeprom map. */ |
| 1596 | BUILD_BUG_ON(sizeof(priv->eeprom) != IWL_EEPROM_IMAGE_SIZE); |
| 1597 | |
| 1598 | if ((gp & CSR_EEPROM_GP_VALID_MSK) == CSR_EEPROM_GP_BAD_SIGNATURE) { |
| 1599 | IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp); |
| 1600 | return -ENOENT; |
| 1601 | } |
| 1602 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1603 | /* Make sure driver (instead of uCode) is allowed to read EEPROM */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1604 | rc = iwl3945_eeprom_acquire_semaphore(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1605 | if (rc < 0) { |
Ian Schram | 91e1747 | 2007-10-25 17:15:23 +0800 | [diff] [blame] | 1606 | IWL_ERROR("Failed to acquire EEPROM semaphore.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1607 | return -ENOENT; |
| 1608 | } |
| 1609 | |
| 1610 | /* eeprom is an array of 16bit values */ |
| 1611 | for (addr = 0; addr < sz; addr += sizeof(u16)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1612 | _iwl3945_write32(priv, CSR_EEPROM_REG, addr << 1); |
| 1613 | _iwl3945_clear_bit(priv, CSR_EEPROM_REG, CSR_EEPROM_REG_BIT_CMD); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1614 | |
| 1615 | for (i = 0; i < IWL_EEPROM_ACCESS_TIMEOUT; |
| 1616 | i += IWL_EEPROM_ACCESS_DELAY) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1617 | r = _iwl3945_read_direct32(priv, CSR_EEPROM_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1618 | if (r & CSR_EEPROM_REG_READ_VALID_MSK) |
| 1619 | break; |
| 1620 | udelay(IWL_EEPROM_ACCESS_DELAY); |
| 1621 | } |
| 1622 | |
| 1623 | if (!(r & CSR_EEPROM_REG_READ_VALID_MSK)) { |
| 1624 | IWL_ERROR("Time out reading EEPROM[%d]", addr); |
| 1625 | return -ETIMEDOUT; |
| 1626 | } |
Tomas Winkler | 58ff6d4 | 2008-02-13 02:47:54 +0200 | [diff] [blame] | 1627 | e[addr / 2] = le16_to_cpu((__force __le16)(r >> 16)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | return 0; |
| 1631 | } |
| 1632 | |
| 1633 | /****************************************************************************** |
| 1634 | * |
| 1635 | * Misc. internal state and helper functions |
| 1636 | * |
| 1637 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1638 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1639 | |
| 1640 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1641 | * iwl3945_report_frame - dump frame to syslog during debug sessions |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1642 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1643 | * You may hack this function to show different aspects of received frames, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1644 | * including selective frame dumps. |
| 1645 | * group100 parameter selects whether to show 1 out of 100 good frames. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1646 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1647 | void iwl3945_report_frame(struct iwl3945_priv *priv, |
| 1648 | struct iwl3945_rx_packet *pkt, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1649 | struct ieee80211_hdr *header, int group100) |
| 1650 | { |
| 1651 | u32 to_us; |
| 1652 | u32 print_summary = 0; |
| 1653 | u32 print_dump = 0; /* set to 1 to dump all frames' contents */ |
| 1654 | u32 hundred = 0; |
| 1655 | u32 dataframe = 0; |
| 1656 | u16 fc; |
| 1657 | u16 seq_ctl; |
| 1658 | u16 channel; |
| 1659 | u16 phy_flags; |
| 1660 | int rate_sym; |
| 1661 | u16 length; |
| 1662 | u16 status; |
| 1663 | u16 bcn_tmr; |
| 1664 | u32 tsf_low; |
| 1665 | u64 tsf; |
| 1666 | u8 rssi; |
| 1667 | u8 agc; |
| 1668 | u16 sig_avg; |
| 1669 | u16 noise_diff; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1670 | struct iwl3945_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); |
| 1671 | struct iwl3945_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); |
| 1672 | struct iwl3945_rx_frame_end *rx_end = IWL_RX_END(pkt); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1673 | u8 *data = IWL_RX_DATA(pkt); |
| 1674 | |
| 1675 | /* MAC header */ |
| 1676 | fc = le16_to_cpu(header->frame_control); |
| 1677 | seq_ctl = le16_to_cpu(header->seq_ctrl); |
| 1678 | |
| 1679 | /* metadata */ |
| 1680 | channel = le16_to_cpu(rx_hdr->channel); |
| 1681 | phy_flags = le16_to_cpu(rx_hdr->phy_flags); |
| 1682 | rate_sym = rx_hdr->rate; |
| 1683 | length = le16_to_cpu(rx_hdr->len); |
| 1684 | |
| 1685 | /* end-of-frame status and timestamp */ |
| 1686 | status = le32_to_cpu(rx_end->status); |
| 1687 | bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp); |
| 1688 | tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff; |
| 1689 | tsf = le64_to_cpu(rx_end->timestamp); |
| 1690 | |
| 1691 | /* signal statistics */ |
| 1692 | rssi = rx_stats->rssi; |
| 1693 | agc = rx_stats->agc; |
| 1694 | sig_avg = le16_to_cpu(rx_stats->sig_avg); |
| 1695 | noise_diff = le16_to_cpu(rx_stats->noise_diff); |
| 1696 | |
| 1697 | to_us = !compare_ether_addr(header->addr1, priv->mac_addr); |
| 1698 | |
| 1699 | /* if data frame is to us and all is good, |
| 1700 | * (optionally) print summary for only 1 out of every 100 */ |
| 1701 | if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) == |
| 1702 | (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) { |
| 1703 | dataframe = 1; |
| 1704 | if (!group100) |
| 1705 | print_summary = 1; /* print each frame */ |
| 1706 | else if (priv->framecnt_to_us < 100) { |
| 1707 | priv->framecnt_to_us++; |
| 1708 | print_summary = 0; |
| 1709 | } else { |
| 1710 | priv->framecnt_to_us = 0; |
| 1711 | print_summary = 1; |
| 1712 | hundred = 1; |
| 1713 | } |
| 1714 | } else { |
| 1715 | /* print summary for all other frames */ |
| 1716 | print_summary = 1; |
| 1717 | } |
| 1718 | |
| 1719 | if (print_summary) { |
| 1720 | char *title; |
| 1721 | u32 rate; |
| 1722 | |
| 1723 | if (hundred) |
| 1724 | title = "100Frames"; |
| 1725 | else if (fc & IEEE80211_FCTL_RETRY) |
| 1726 | title = "Retry"; |
| 1727 | else if (ieee80211_is_assoc_response(fc)) |
| 1728 | title = "AscRsp"; |
| 1729 | else if (ieee80211_is_reassoc_response(fc)) |
| 1730 | title = "RasRsp"; |
| 1731 | else if (ieee80211_is_probe_response(fc)) { |
| 1732 | title = "PrbRsp"; |
| 1733 | print_dump = 1; /* dump frame contents */ |
| 1734 | } else if (ieee80211_is_beacon(fc)) { |
| 1735 | title = "Beacon"; |
| 1736 | print_dump = 1; /* dump frame contents */ |
| 1737 | } else if (ieee80211_is_atim(fc)) |
| 1738 | title = "ATIM"; |
| 1739 | else if (ieee80211_is_auth(fc)) |
| 1740 | title = "Auth"; |
| 1741 | else if (ieee80211_is_deauth(fc)) |
| 1742 | title = "DeAuth"; |
| 1743 | else if (ieee80211_is_disassoc(fc)) |
| 1744 | title = "DisAssoc"; |
| 1745 | else |
| 1746 | title = "Frame"; |
| 1747 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1748 | rate = iwl3945_rate_index_from_plcp(rate_sym); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1749 | if (rate == -1) |
| 1750 | rate = 0; |
| 1751 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1752 | rate = iwl3945_rates[rate].ieee / 2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1753 | |
| 1754 | /* print frame summary. |
| 1755 | * MAC addresses show just the last byte (for brevity), |
| 1756 | * but you can hack it to show more, if you'd like to. */ |
| 1757 | if (dataframe) |
| 1758 | IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, " |
| 1759 | "len=%u, rssi=%d, chnl=%d, rate=%u, \n", |
| 1760 | title, fc, header->addr1[5], |
| 1761 | length, rssi, channel, rate); |
| 1762 | else { |
| 1763 | /* src/dst addresses assume managed mode */ |
| 1764 | IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, " |
| 1765 | "src=0x%02x, rssi=%u, tim=%lu usec, " |
| 1766 | "phy=0x%02x, chnl=%d\n", |
| 1767 | title, fc, header->addr1[5], |
| 1768 | header->addr3[5], rssi, |
| 1769 | tsf_low - priv->scan_start_tsf, |
| 1770 | phy_flags, channel); |
| 1771 | } |
| 1772 | } |
| 1773 | if (print_dump) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1774 | iwl3945_print_hex_dump(IWL_DL_RX, data, length); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1775 | } |
| 1776 | #endif |
| 1777 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1778 | static void iwl3945_unset_hw_setting(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1779 | { |
| 1780 | if (priv->hw_setting.shared_virt) |
| 1781 | pci_free_consistent(priv->pci_dev, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1782 | sizeof(struct iwl3945_shared), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1783 | priv->hw_setting.shared_virt, |
| 1784 | priv->hw_setting.shared_phys); |
| 1785 | } |
| 1786 | |
| 1787 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1788 | * iwl3945_supported_rate_to_ie - fill in the supported rate in IE field |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1789 | * |
| 1790 | * return : set the bit for each supported rate insert in ie |
| 1791 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1792 | static u16 iwl3945_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1793 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1794 | { |
| 1795 | u16 ret_rates = 0, bit; |
| 1796 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1797 | u8 *cnt = ie; |
| 1798 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1799 | |
| 1800 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 1801 | if (bit & supported_rate) { |
| 1802 | ret_rates |= bit; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1803 | rates[*cnt] = iwl3945_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1804 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 1805 | (*cnt)++; |
| 1806 | (*left)--; |
| 1807 | if ((*left <= 0) || |
| 1808 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1809 | break; |
| 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | return ret_rates; |
| 1814 | } |
| 1815 | |
| 1816 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1817 | * iwl3945_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] | 1818 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1819 | static u16 iwl3945_fill_probe_req(struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1820 | struct ieee80211_mgmt *frame, |
| 1821 | int left, int is_direct) |
| 1822 | { |
| 1823 | int len = 0; |
| 1824 | u8 *pos = NULL; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1825 | u16 active_rates, ret_rates, cck_rates; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1826 | |
| 1827 | /* Make sure there is enough space for the probe request, |
| 1828 | * two mandatory IEs and the data */ |
| 1829 | left -= 24; |
| 1830 | if (left < 0) |
| 1831 | return 0; |
| 1832 | len += 24; |
| 1833 | |
| 1834 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1835 | memcpy(frame->da, iwl3945_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1836 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1837 | memcpy(frame->bssid, iwl3945_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1838 | frame->seq_ctrl = 0; |
| 1839 | |
| 1840 | /* fill in our indirect SSID IE */ |
| 1841 | /* ...next IE... */ |
| 1842 | |
| 1843 | left -= 2; |
| 1844 | if (left < 0) |
| 1845 | return 0; |
| 1846 | len += 2; |
| 1847 | pos = &(frame->u.probe_req.variable[0]); |
| 1848 | *pos++ = WLAN_EID_SSID; |
| 1849 | *pos++ = 0; |
| 1850 | |
| 1851 | /* fill in our direct SSID IE... */ |
| 1852 | if (is_direct) { |
| 1853 | /* ...next IE... */ |
| 1854 | left -= 2 + priv->essid_len; |
| 1855 | if (left < 0) |
| 1856 | return 0; |
| 1857 | /* ... fill it in... */ |
| 1858 | *pos++ = WLAN_EID_SSID; |
| 1859 | *pos++ = priv->essid_len; |
| 1860 | memcpy(pos, priv->essid, priv->essid_len); |
| 1861 | pos += priv->essid_len; |
| 1862 | len += 2 + priv->essid_len; |
| 1863 | } |
| 1864 | |
| 1865 | /* fill in supported rate */ |
| 1866 | /* ...next IE... */ |
| 1867 | left -= 2; |
| 1868 | if (left < 0) |
| 1869 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1870 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1871 | /* ... fill it in... */ |
| 1872 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1873 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1874 | |
| 1875 | priv->active_rate = priv->rates_mask; |
| 1876 | active_rates = priv->active_rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1877 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 1878 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1879 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1880 | ret_rates = iwl3945_supported_rate_to_ie(pos, cck_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1881 | priv->active_rate_basic, &left); |
| 1882 | active_rates &= ~ret_rates; |
| 1883 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1884 | ret_rates = iwl3945_supported_rate_to_ie(pos, active_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1885 | priv->active_rate_basic, &left); |
| 1886 | active_rates &= ~ret_rates; |
| 1887 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1888 | len += 2 + *pos; |
| 1889 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1890 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1891 | goto fill_end; |
| 1892 | |
| 1893 | /* fill in supported extended rate */ |
| 1894 | /* ...next IE... */ |
| 1895 | left -= 2; |
| 1896 | if (left < 0) |
| 1897 | return 0; |
| 1898 | /* ... fill it in... */ |
| 1899 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1900 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1901 | iwl3945_supported_rate_to_ie(pos, active_rates, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1902 | priv->active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1903 | if (*pos > 0) |
| 1904 | len += 2 + *pos; |
| 1905 | |
| 1906 | fill_end: |
| 1907 | return (u16)len; |
| 1908 | } |
| 1909 | |
| 1910 | /* |
| 1911 | * QoS support |
| 1912 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1913 | static int iwl3945_send_qos_params_command(struct iwl3945_priv *priv, |
| 1914 | struct iwl3945_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1915 | { |
| 1916 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1917 | return iwl3945_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
| 1918 | sizeof(struct iwl3945_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1921 | static void iwl3945_reset_qos(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1922 | { |
| 1923 | u16 cw_min = 15; |
| 1924 | u16 cw_max = 1023; |
| 1925 | u8 aifs = 2; |
| 1926 | u8 is_legacy = 0; |
| 1927 | unsigned long flags; |
| 1928 | int i; |
| 1929 | |
| 1930 | spin_lock_irqsave(&priv->lock, flags); |
| 1931 | priv->qos_data.qos_active = 0; |
| 1932 | |
| 1933 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) { |
| 1934 | if (priv->qos_data.qos_enable) |
| 1935 | priv->qos_data.qos_active = 1; |
| 1936 | if (!(priv->active_rate & 0xfff0)) { |
| 1937 | cw_min = 31; |
| 1938 | is_legacy = 1; |
| 1939 | } |
| 1940 | } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 1941 | if (priv->qos_data.qos_enable) |
| 1942 | priv->qos_data.qos_active = 1; |
| 1943 | } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) { |
| 1944 | cw_min = 31; |
| 1945 | is_legacy = 1; |
| 1946 | } |
| 1947 | |
| 1948 | if (priv->qos_data.qos_active) |
| 1949 | aifs = 3; |
| 1950 | |
| 1951 | priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min); |
| 1952 | priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max); |
| 1953 | priv->qos_data.def_qos_parm.ac[0].aifsn = aifs; |
| 1954 | priv->qos_data.def_qos_parm.ac[0].edca_txop = 0; |
| 1955 | priv->qos_data.def_qos_parm.ac[0].reserved1 = 0; |
| 1956 | |
| 1957 | if (priv->qos_data.qos_active) { |
| 1958 | i = 1; |
| 1959 | priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min); |
| 1960 | priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max); |
| 1961 | priv->qos_data.def_qos_parm.ac[i].aifsn = 7; |
| 1962 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 1963 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1964 | |
| 1965 | i = 2; |
| 1966 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 1967 | cpu_to_le16((cw_min + 1) / 2 - 1); |
| 1968 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 1969 | cpu_to_le16(cw_max); |
| 1970 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 1971 | if (is_legacy) |
| 1972 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1973 | cpu_to_le16(6016); |
| 1974 | else |
| 1975 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1976 | cpu_to_le16(3008); |
| 1977 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1978 | |
| 1979 | i = 3; |
| 1980 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 1981 | cpu_to_le16((cw_min + 1) / 4 - 1); |
| 1982 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 1983 | cpu_to_le16((cw_max + 1) / 2 - 1); |
| 1984 | priv->qos_data.def_qos_parm.ac[i].aifsn = 2; |
| 1985 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 1986 | if (is_legacy) |
| 1987 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1988 | cpu_to_le16(3264); |
| 1989 | else |
| 1990 | priv->qos_data.def_qos_parm.ac[i].edca_txop = |
| 1991 | cpu_to_le16(1504); |
| 1992 | } else { |
| 1993 | for (i = 1; i < 4; i++) { |
| 1994 | priv->qos_data.def_qos_parm.ac[i].cw_min = |
| 1995 | cpu_to_le16(cw_min); |
| 1996 | priv->qos_data.def_qos_parm.ac[i].cw_max = |
| 1997 | cpu_to_le16(cw_max); |
| 1998 | priv->qos_data.def_qos_parm.ac[i].aifsn = aifs; |
| 1999 | priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; |
| 2000 | priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; |
| 2001 | } |
| 2002 | } |
| 2003 | IWL_DEBUG_QOS("set QoS to default \n"); |
| 2004 | |
| 2005 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2006 | } |
| 2007 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2008 | static void iwl3945_activate_qos(struct iwl3945_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2009 | { |
| 2010 | unsigned long flags; |
| 2011 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2012 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2013 | return; |
| 2014 | |
| 2015 | if (!priv->qos_data.qos_enable) |
| 2016 | return; |
| 2017 | |
| 2018 | spin_lock_irqsave(&priv->lock, flags); |
| 2019 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 2020 | |
| 2021 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 2022 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 2023 | priv->qos_data.def_qos_parm.qos_flags |= |
| 2024 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
| 2025 | |
| 2026 | if (priv->qos_data.qos_active) |
| 2027 | priv->qos_data.def_qos_parm.qos_flags |= |
| 2028 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 2029 | |
| 2030 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2031 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2032 | if (force || iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2033 | IWL_DEBUG_QOS("send QoS cmd with Qos active %d \n", |
| 2034 | priv->qos_data.qos_active); |
| 2035 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2036 | iwl3945_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2037 | &(priv->qos_data.def_qos_parm)); |
| 2038 | } |
| 2039 | } |
| 2040 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2041 | /* |
| 2042 | * Power management (not Tx power!) functions |
| 2043 | */ |
| 2044 | #define MSEC_TO_USEC 1024 |
| 2045 | |
| 2046 | #define NOSLP __constant_cpu_to_le32(0) |
| 2047 | #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK |
| 2048 | #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC) |
| 2049 | #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \ |
| 2050 | __constant_cpu_to_le32(X1), \ |
| 2051 | __constant_cpu_to_le32(X2), \ |
| 2052 | __constant_cpu_to_le32(X3), \ |
| 2053 | __constant_cpu_to_le32(X4)} |
| 2054 | |
| 2055 | |
| 2056 | /* default power management (not Tx power) table values */ |
| 2057 | /* for tim 0-10 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2058 | static struct iwl3945_power_vec_entry range_0[IWL_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2059 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 2060 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 2061 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0}, |
| 2062 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0}, |
| 2063 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1}, |
| 2064 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1} |
| 2065 | }; |
| 2066 | |
| 2067 | /* for tim > 10 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2068 | static struct iwl3945_power_vec_entry range_1[IWL_POWER_AC] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2069 | {{NOSLP, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 2070 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(500), |
| 2071 | SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 2072 | {{SLP, SLP_TIMEOUT(200), SLP_TIMEOUT(300), |
| 2073 | SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 2074 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(100), |
| 2075 | SLP_VEC(2, 6, 9, 9, 0xFF)}, 0}, |
| 2076 | {{SLP, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 2077 | {{SLP, SLP_TIMEOUT(25), SLP_TIMEOUT(25), |
| 2078 | SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 2079 | }; |
| 2080 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2081 | int iwl3945_power_init_handle(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2082 | { |
| 2083 | int rc = 0, i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2084 | struct iwl3945_power_mgr *pow_data; |
| 2085 | int size = sizeof(struct iwl3945_power_vec_entry) * IWL_POWER_AC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2086 | u16 pci_pm; |
| 2087 | |
| 2088 | IWL_DEBUG_POWER("Initialize power \n"); |
| 2089 | |
| 2090 | pow_data = &(priv->power_data); |
| 2091 | |
| 2092 | memset(pow_data, 0, sizeof(*pow_data)); |
| 2093 | |
| 2094 | pow_data->active_index = IWL_POWER_RANGE_0; |
| 2095 | pow_data->dtim_val = 0xffff; |
| 2096 | |
| 2097 | memcpy(&pow_data->pwr_range_0[0], &range_0[0], size); |
| 2098 | memcpy(&pow_data->pwr_range_1[0], &range_1[0], size); |
| 2099 | |
| 2100 | rc = pci_read_config_word(priv->pci_dev, PCI_LINK_CTRL, &pci_pm); |
| 2101 | if (rc != 0) |
| 2102 | return 0; |
| 2103 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2104 | struct iwl3945_powertable_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2105 | |
| 2106 | IWL_DEBUG_POWER("adjust power command flags\n"); |
| 2107 | |
| 2108 | for (i = 0; i < IWL_POWER_AC; i++) { |
| 2109 | cmd = &pow_data->pwr_range_0[i].cmd; |
| 2110 | |
| 2111 | if (pci_pm & 0x1) |
| 2112 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 2113 | else |
| 2114 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
| 2115 | } |
| 2116 | } |
| 2117 | return rc; |
| 2118 | } |
| 2119 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2120 | static int iwl3945_update_power_cmd(struct iwl3945_priv *priv, |
| 2121 | struct iwl3945_powertable_cmd *cmd, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2122 | { |
| 2123 | int rc = 0, i; |
| 2124 | u8 skip; |
| 2125 | u32 max_sleep = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2126 | struct iwl3945_power_vec_entry *range; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2127 | u8 period = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2128 | struct iwl3945_power_mgr *pow_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2129 | |
| 2130 | if (mode > IWL_POWER_INDEX_5) { |
| 2131 | IWL_DEBUG_POWER("Error invalid power mode \n"); |
| 2132 | return -1; |
| 2133 | } |
| 2134 | pow_data = &(priv->power_data); |
| 2135 | |
| 2136 | if (pow_data->active_index == IWL_POWER_RANGE_0) |
| 2137 | range = &pow_data->pwr_range_0[0]; |
| 2138 | else |
| 2139 | range = &pow_data->pwr_range_1[1]; |
| 2140 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2141 | memcpy(cmd, &range[mode].cmd, sizeof(struct iwl3945_powertable_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2142 | |
| 2143 | #ifdef IWL_MAC80211_DISABLE |
| 2144 | if (priv->assoc_network != NULL) { |
| 2145 | unsigned long flags; |
| 2146 | |
| 2147 | period = priv->assoc_network->tim.tim_period; |
| 2148 | } |
| 2149 | #endif /*IWL_MAC80211_DISABLE */ |
| 2150 | skip = range[mode].no_dtim; |
| 2151 | |
| 2152 | if (period == 0) { |
| 2153 | period = 1; |
| 2154 | skip = 0; |
| 2155 | } |
| 2156 | |
| 2157 | if (skip == 0) { |
| 2158 | max_sleep = period; |
| 2159 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 2160 | } else { |
| 2161 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 2162 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 2163 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
| 2164 | } |
| 2165 | |
| 2166 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) { |
| 2167 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 2168 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
| 2169 | } |
| 2170 | |
| 2171 | IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags); |
| 2172 | IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 2173 | IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 2174 | IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
| 2175 | le32_to_cpu(cmd->sleep_interval[0]), |
| 2176 | le32_to_cpu(cmd->sleep_interval[1]), |
| 2177 | le32_to_cpu(cmd->sleep_interval[2]), |
| 2178 | le32_to_cpu(cmd->sleep_interval[3]), |
| 2179 | le32_to_cpu(cmd->sleep_interval[4])); |
| 2180 | |
| 2181 | return rc; |
| 2182 | } |
| 2183 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2184 | static int iwl3945_send_power_mode(struct iwl3945_priv *priv, u32 mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2185 | { |
John W. Linville | 9a62f73 | 2007-11-15 16:27:36 -0500 | [diff] [blame] | 2186 | u32 uninitialized_var(final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2187 | int rc; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2188 | struct iwl3945_powertable_cmd cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2189 | |
| 2190 | /* If on battery, set to 3, |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2191 | * if plugged into AC power, set to CAM ("continuously aware mode"), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2192 | * else user level */ |
| 2193 | switch (mode) { |
| 2194 | case IWL_POWER_BATTERY: |
| 2195 | final_mode = IWL_POWER_INDEX_3; |
| 2196 | break; |
| 2197 | case IWL_POWER_AC: |
| 2198 | final_mode = IWL_POWER_MODE_CAM; |
| 2199 | break; |
| 2200 | default: |
| 2201 | final_mode = mode; |
| 2202 | break; |
| 2203 | } |
| 2204 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2205 | iwl3945_update_power_cmd(priv, &cmd, final_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2206 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2207 | rc = iwl3945_send_cmd_pdu(priv, POWER_TABLE_CMD, sizeof(cmd), &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2208 | |
| 2209 | if (final_mode == IWL_POWER_MODE_CAM) |
| 2210 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 2211 | else |
| 2212 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 2213 | |
| 2214 | return rc; |
| 2215 | } |
| 2216 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2217 | int iwl3945_is_network_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2218 | { |
| 2219 | /* Filter incoming packets to determine if they are targeted toward |
| 2220 | * this network, discarding packets coming from ourselves */ |
| 2221 | switch (priv->iw_mode) { |
| 2222 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 2223 | /* packets from our adapter are dropped (echo) */ |
| 2224 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 2225 | return 0; |
| 2226 | /* {broad,multi}cast packets to our IBSS go through */ |
| 2227 | if (is_multicast_ether_addr(header->addr1)) |
| 2228 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 2229 | /* packets to our adapter go through */ |
| 2230 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2231 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 2232 | /* packets from our adapter are dropped (echo) */ |
| 2233 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 2234 | return 0; |
| 2235 | /* {broad,multi}cast packets to our BSS go through */ |
| 2236 | if (is_multicast_ether_addr(header->addr1)) |
| 2237 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 2238 | /* packets to our adapter go through */ |
| 2239 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2240 | } |
| 2241 | |
| 2242 | return 1; |
| 2243 | } |
| 2244 | |
| 2245 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2246 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2247 | static const char *iwl3945_get_tx_fail_reason(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2248 | { |
| 2249 | switch (status & TX_STATUS_MSK) { |
| 2250 | case TX_STATUS_SUCCESS: |
| 2251 | return "SUCCESS"; |
| 2252 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 2253 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 2254 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 2255 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 2256 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 2257 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 2258 | TX_STATUS_ENTRY(DEST_PS); |
| 2259 | TX_STATUS_ENTRY(ABORTED); |
| 2260 | TX_STATUS_ENTRY(BT_RETRY); |
| 2261 | TX_STATUS_ENTRY(STA_INVALID); |
| 2262 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 2263 | TX_STATUS_ENTRY(TID_DISABLE); |
| 2264 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 2265 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 2266 | TX_STATUS_ENTRY(TX_LOCKED); |
| 2267 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 2268 | } |
| 2269 | |
| 2270 | return "UNKNOWN"; |
| 2271 | } |
| 2272 | |
| 2273 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2274 | * iwl3945_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2275 | * |
| 2276 | * NOTE: priv->mutex is not required before calling this function |
| 2277 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2278 | static int iwl3945_scan_cancel(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2279 | { |
| 2280 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 2281 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2282 | return 0; |
| 2283 | } |
| 2284 | |
| 2285 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2286 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2287 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 2288 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2289 | queue_work(priv->workqueue, &priv->abort_scan); |
| 2290 | |
| 2291 | } else |
| 2292 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 2293 | |
| 2294 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2295 | } |
| 2296 | |
| 2297 | return 0; |
| 2298 | } |
| 2299 | |
| 2300 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2301 | * iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2302 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 2303 | * |
| 2304 | * NOTE: priv->mutex must be held before calling this function |
| 2305 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2306 | static int iwl3945_scan_cancel_timeout(struct iwl3945_priv *priv, unsigned long ms) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2307 | { |
| 2308 | unsigned long now = jiffies; |
| 2309 | int ret; |
| 2310 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2311 | ret = iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2312 | if (ret && ms) { |
| 2313 | mutex_unlock(&priv->mutex); |
| 2314 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 2315 | test_bit(STATUS_SCANNING, &priv->status)) |
| 2316 | msleep(1); |
| 2317 | mutex_lock(&priv->mutex); |
| 2318 | |
| 2319 | return test_bit(STATUS_SCANNING, &priv->status); |
| 2320 | } |
| 2321 | |
| 2322 | return ret; |
| 2323 | } |
| 2324 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2325 | static void iwl3945_sequence_reset(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2326 | { |
| 2327 | /* Reset ieee stats */ |
| 2328 | |
| 2329 | /* We don't reset the net_device_stats (ieee->stats) on |
| 2330 | * re-association */ |
| 2331 | |
| 2332 | priv->last_seq_num = -1; |
| 2333 | priv->last_frag_num = -1; |
| 2334 | priv->last_packet_time = 0; |
| 2335 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2336 | iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2337 | } |
| 2338 | |
| 2339 | #define MAX_UCODE_BEACON_INTERVAL 1024 |
| 2340 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 2341 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2342 | static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2343 | { |
| 2344 | u16 new_val = 0; |
| 2345 | u16 beacon_factor = 0; |
| 2346 | |
| 2347 | beacon_factor = |
| 2348 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 2349 | / MAX_UCODE_BEACON_INTERVAL; |
| 2350 | new_val = beacon_val / beacon_factor; |
| 2351 | |
| 2352 | return cpu_to_le16(new_val); |
| 2353 | } |
| 2354 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2355 | static void iwl3945_setup_rxon_timing(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2356 | { |
| 2357 | u64 interval_tm_unit; |
| 2358 | u64 tsf, result; |
| 2359 | unsigned long flags; |
| 2360 | struct ieee80211_conf *conf = NULL; |
| 2361 | u16 beacon_int = 0; |
| 2362 | |
| 2363 | conf = ieee80211_get_hw_conf(priv->hw); |
| 2364 | |
| 2365 | spin_lock_irqsave(&priv->lock, flags); |
| 2366 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp1); |
| 2367 | priv->rxon_timing.timestamp.dw[0] = cpu_to_le32(priv->timestamp0); |
| 2368 | |
| 2369 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 2370 | |
| 2371 | tsf = priv->timestamp1; |
| 2372 | tsf = ((tsf << 32) | priv->timestamp0); |
| 2373 | |
| 2374 | beacon_int = priv->beacon_int; |
| 2375 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2376 | |
| 2377 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 2378 | if (beacon_int == 0) { |
| 2379 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 2380 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 2381 | } else { |
| 2382 | priv->rxon_timing.beacon_interval = |
| 2383 | cpu_to_le16(beacon_int); |
| 2384 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2385 | iwl3945_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2386 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2387 | } |
| 2388 | |
| 2389 | priv->rxon_timing.atim_window = 0; |
| 2390 | } else { |
| 2391 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2392 | iwl3945_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2393 | /* TODO: we need to get atim_window from upper stack |
| 2394 | * for now we set to 0 */ |
| 2395 | priv->rxon_timing.atim_window = 0; |
| 2396 | } |
| 2397 | |
| 2398 | interval_tm_unit = |
| 2399 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 2400 | result = do_div(tsf, interval_tm_unit); |
| 2401 | priv->rxon_timing.beacon_init_val = |
| 2402 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 2403 | |
| 2404 | IWL_DEBUG_ASSOC |
| 2405 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 2406 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 2407 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 2408 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 2409 | } |
| 2410 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2411 | static int iwl3945_scan_initiate(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2412 | { |
| 2413 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 2414 | IWL_ERROR("APs don't scan.\n"); |
| 2415 | return 0; |
| 2416 | } |
| 2417 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2418 | if (!iwl3945_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2419 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 2420 | return -EIO; |
| 2421 | } |
| 2422 | |
| 2423 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2424 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 2425 | return -EAGAIN; |
| 2426 | } |
| 2427 | |
| 2428 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2429 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 2430 | "Queuing.\n"); |
| 2431 | return -EAGAIN; |
| 2432 | } |
| 2433 | |
| 2434 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 2435 | priv->scan_bands = 2; |
| 2436 | set_bit(STATUS_SCANNING, &priv->status); |
| 2437 | priv->scan_start = jiffies; |
| 2438 | priv->scan_pass_start = priv->scan_start; |
| 2439 | |
| 2440 | queue_work(priv->workqueue, &priv->request_scan); |
| 2441 | |
| 2442 | return 0; |
| 2443 | } |
| 2444 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2445 | static int iwl3945_set_rxon_hwcrypto(struct iwl3945_priv *priv, int hw_decrypt) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2446 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2447 | struct iwl3945_rxon_cmd *rxon = &priv->staging_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2448 | |
| 2449 | if (hw_decrypt) |
| 2450 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 2451 | else |
| 2452 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 2453 | |
| 2454 | return 0; |
| 2455 | } |
| 2456 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2457 | static void iwl3945_set_flags_for_phymode(struct iwl3945_priv *priv, |
| 2458 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2459 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2460 | if (band == IEEE80211_BAND_5GHZ) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2461 | priv->staging_rxon.flags &= |
| 2462 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 2463 | | RXON_FLG_CCK_MSK); |
| 2464 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2465 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2466 | /* Copied from iwl3945_bg_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2467 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 2468 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2469 | else |
| 2470 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2471 | |
| 2472 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 2473 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2474 | |
| 2475 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 2476 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 2477 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2482 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2483 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2484 | static void iwl3945_connection_init_rx_config(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2485 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2486 | const struct iwl3945_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2487 | |
| 2488 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 2489 | |
| 2490 | switch (priv->iw_mode) { |
| 2491 | case IEEE80211_IF_TYPE_AP: |
| 2492 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 2493 | break; |
| 2494 | |
| 2495 | case IEEE80211_IF_TYPE_STA: |
| 2496 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 2497 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 2498 | break; |
| 2499 | |
| 2500 | case IEEE80211_IF_TYPE_IBSS: |
| 2501 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 2502 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2503 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 2504 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2505 | break; |
| 2506 | |
| 2507 | case IEEE80211_IF_TYPE_MNTR: |
| 2508 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 2509 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 2510 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 2511 | break; |
| 2512 | } |
| 2513 | |
| 2514 | #if 0 |
| 2515 | /* TODO: Figure out when short_preamble would be set and cache from |
| 2516 | * that */ |
| 2517 | if (!hw_to_local(priv->hw)->short_preamble) |
| 2518 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2519 | else |
| 2520 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2521 | #endif |
| 2522 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2523 | ch_info = iwl3945_get_channel_info(priv, priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2524 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2525 | |
| 2526 | if (!ch_info) |
| 2527 | ch_info = &priv->channel_info[0]; |
| 2528 | |
| 2529 | /* |
| 2530 | * in some case A channels are all non IBSS |
| 2531 | * in this case force B/G channel |
| 2532 | */ |
| 2533 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 2534 | !(is_channel_ibss(ch_info))) |
| 2535 | ch_info = &priv->channel_info[0]; |
| 2536 | |
| 2537 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
| 2538 | if (is_channel_a_band(ch_info)) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2539 | priv->band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2540 | else |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2541 | priv->band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2542 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2543 | iwl3945_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2544 | |
| 2545 | priv->staging_rxon.ofdm_basic_rates = |
| 2546 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2547 | priv->staging_rxon.cck_basic_rates = |
| 2548 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2549 | } |
| 2550 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2551 | static int iwl3945_set_mode(struct iwl3945_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2552 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2553 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2554 | const struct iwl3945_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2555 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2556 | ch_info = iwl3945_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2557 | priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2558 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2559 | |
| 2560 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 2561 | IWL_ERROR("channel %d not IBSS channel\n", |
| 2562 | le16_to_cpu(priv->staging_rxon.channel)); |
| 2563 | return -EINVAL; |
| 2564 | } |
| 2565 | } |
| 2566 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2567 | priv->iw_mode = mode; |
| 2568 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2569 | iwl3945_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2570 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2571 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2572 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2573 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2574 | /* dont commit rxon if rf-kill is on*/ |
| 2575 | if (!iwl3945_is_ready_rf(priv)) |
| 2576 | return -EAGAIN; |
| 2577 | |
| 2578 | cancel_delayed_work(&priv->scan_check); |
| 2579 | if (iwl3945_scan_cancel_timeout(priv, 100)) { |
| 2580 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 2581 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 2582 | return -EAGAIN; |
| 2583 | } |
| 2584 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2585 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2586 | |
| 2587 | return 0; |
| 2588 | } |
| 2589 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2590 | static void iwl3945_build_tx_cmd_hwcrypto(struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2591 | struct ieee80211_tx_control *ctl, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2592 | struct iwl3945_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2593 | struct sk_buff *skb_frag, |
| 2594 | int last_frag) |
| 2595 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2596 | struct iwl3945_hw_key *keyinfo = &priv->stations[ctl->key_idx].keyinfo; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2597 | |
| 2598 | switch (keyinfo->alg) { |
| 2599 | case ALG_CCMP: |
| 2600 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM; |
| 2601 | memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen); |
| 2602 | IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n"); |
| 2603 | break; |
| 2604 | |
| 2605 | case ALG_TKIP: |
| 2606 | #if 0 |
| 2607 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP; |
| 2608 | |
| 2609 | if (last_frag) |
| 2610 | memcpy(cmd->cmd.tx.tkip_mic.byte, skb_frag->tail - 8, |
| 2611 | 8); |
| 2612 | else |
| 2613 | memset(cmd->cmd.tx.tkip_mic.byte, 0, 8); |
| 2614 | #endif |
| 2615 | break; |
| 2616 | |
| 2617 | case ALG_WEP: |
| 2618 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_WEP | |
| 2619 | (ctl->key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT; |
| 2620 | |
| 2621 | if (keyinfo->keylen == 13) |
| 2622 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
| 2623 | |
| 2624 | memcpy(&cmd->cmd.tx.key[3], keyinfo->key, keyinfo->keylen); |
| 2625 | |
| 2626 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
| 2627 | "with key %d\n", ctl->key_idx); |
| 2628 | break; |
| 2629 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2630 | default: |
| 2631 | printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg); |
| 2632 | break; |
| 2633 | } |
| 2634 | } |
| 2635 | |
| 2636 | /* |
| 2637 | * handle build REPLY_TX command notification. |
| 2638 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2639 | static void iwl3945_build_tx_cmd_basic(struct iwl3945_priv *priv, |
| 2640 | struct iwl3945_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2641 | struct ieee80211_tx_control *ctrl, |
| 2642 | struct ieee80211_hdr *hdr, |
| 2643 | int is_unicast, u8 std_id) |
| 2644 | { |
| 2645 | __le16 *qc; |
| 2646 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2647 | __le32 tx_flags = cmd->cmd.tx.tx_flags; |
| 2648 | |
| 2649 | cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 2650 | if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) { |
| 2651 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
| 2652 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 2653 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2654 | if (ieee80211_is_probe_response(fc) && |
| 2655 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 2656 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 2657 | } else { |
| 2658 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 2659 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2660 | } |
| 2661 | |
| 2662 | cmd->cmd.tx.sta_id = std_id; |
| 2663 | if (ieee80211_get_morefrag(hdr)) |
| 2664 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 2665 | |
| 2666 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2667 | if (qc) { |
| 2668 | cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf); |
| 2669 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
| 2670 | } else |
| 2671 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 2672 | |
| 2673 | if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) { |
| 2674 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 2675 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
| 2676 | } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { |
| 2677 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 2678 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 2679 | } |
| 2680 | |
| 2681 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 2682 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 2683 | |
| 2684 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
| 2685 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { |
| 2686 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || |
| 2687 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2688 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2689 | else |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2690 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2691 | } else |
| 2692 | cmd->cmd.tx.timeout.pm_frame_timeout = 0; |
| 2693 | |
| 2694 | cmd->cmd.tx.driver_txop = 0; |
| 2695 | cmd->cmd.tx.tx_flags = tx_flags; |
| 2696 | cmd->cmd.tx.next_frame_len = 0; |
| 2697 | } |
| 2698 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2699 | /** |
| 2700 | * iwl3945_get_sta_id - Find station's index within station table |
| 2701 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2702 | static int iwl3945_get_sta_id(struct iwl3945_priv *priv, struct ieee80211_hdr *hdr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2703 | { |
| 2704 | int sta_id; |
| 2705 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2706 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2707 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2708 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 2709 | is_multicast_ether_addr(hdr->addr1)) |
| 2710 | return priv->hw_setting.bcast_sta_id; |
| 2711 | |
| 2712 | switch (priv->iw_mode) { |
| 2713 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2714 | /* If we are a client station in a BSS network, use the special |
| 2715 | * AP station entry (that's the only station we communicate with) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2716 | case IEEE80211_IF_TYPE_STA: |
| 2717 | return IWL_AP_ID; |
| 2718 | |
| 2719 | /* If we are an AP, then find the station, or use BCAST */ |
| 2720 | case IEEE80211_IF_TYPE_AP: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2721 | sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2722 | if (sta_id != IWL_INVALID_STATION) |
| 2723 | return sta_id; |
| 2724 | return priv->hw_setting.bcast_sta_id; |
| 2725 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2726 | /* If this frame is going out to an IBSS network, find the station, |
| 2727 | * or create a new station table entry */ |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2728 | case IEEE80211_IF_TYPE_IBSS: { |
| 2729 | DECLARE_MAC_BUF(mac); |
| 2730 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2731 | /* Create new station table entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2732 | sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2733 | if (sta_id != IWL_INVALID_STATION) |
| 2734 | return sta_id; |
| 2735 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2736 | sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2737 | |
| 2738 | if (sta_id != IWL_INVALID_STATION) |
| 2739 | return sta_id; |
| 2740 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2741 | IWL_DEBUG_DROP("Station %s not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2742 | "Defaulting to broadcast...\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2743 | print_mac(mac, hdr->addr1)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2744 | iwl3945_print_hex_dump(IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2745 | return priv->hw_setting.bcast_sta_id; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2746 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2747 | default: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2748 | IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2749 | return priv->hw_setting.bcast_sta_id; |
| 2750 | } |
| 2751 | } |
| 2752 | |
| 2753 | /* |
| 2754 | * start REPLY_TX command process |
| 2755 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2756 | static int iwl3945_tx_skb(struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2757 | struct sk_buff *skb, struct ieee80211_tx_control *ctl) |
| 2758 | { |
| 2759 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2760 | struct iwl3945_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2761 | u32 *control_flags; |
| 2762 | int txq_id = ctl->queue; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2763 | struct iwl3945_tx_queue *txq = NULL; |
| 2764 | struct iwl3945_queue *q = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2765 | dma_addr_t phys_addr; |
| 2766 | dma_addr_t txcmd_phys; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2767 | struct iwl3945_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2768 | u16 len, idx, len_org; |
| 2769 | u8 id, hdr_len, unicast; |
| 2770 | u8 sta_id; |
| 2771 | u16 seq_number = 0; |
| 2772 | u16 fc; |
| 2773 | __le16 *qc; |
| 2774 | u8 wait_write_ptr = 0; |
| 2775 | unsigned long flags; |
| 2776 | int rc; |
| 2777 | |
| 2778 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2779 | if (iwl3945_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2780 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 2781 | goto drop_unlock; |
| 2782 | } |
| 2783 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 2784 | if (!priv->vif) { |
| 2785 | IWL_DEBUG_DROP("Dropping - !priv->vif\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2786 | goto drop_unlock; |
| 2787 | } |
| 2788 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2789 | if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2790 | IWL_ERROR("ERROR: No TX rate available.\n"); |
| 2791 | goto drop_unlock; |
| 2792 | } |
| 2793 | |
| 2794 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 2795 | id = 0; |
| 2796 | |
| 2797 | fc = le16_to_cpu(hdr->frame_control); |
| 2798 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2799 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2800 | if (ieee80211_is_auth(fc)) |
| 2801 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
| 2802 | else if (ieee80211_is_assoc_request(fc)) |
| 2803 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
| 2804 | else if (ieee80211_is_reassoc_request(fc)) |
| 2805 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 2806 | #endif |
| 2807 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2808 | /* drop all data frame if we are not associated */ |
Reinette Chatre | a647724 | 2008-02-14 10:40:28 -0800 | [diff] [blame] | 2809 | if ((!iwl3945_is_associated(priv) || |
| 2810 | ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id)) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2811 | ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2812 | IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2813 | goto drop_unlock; |
| 2814 | } |
| 2815 | |
| 2816 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2817 | |
| 2818 | hdr_len = ieee80211_get_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2819 | |
| 2820 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2821 | sta_id = iwl3945_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2822 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2823 | DECLARE_MAC_BUF(mac); |
| 2824 | |
| 2825 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n", |
| 2826 | print_mac(mac, hdr->addr1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2827 | goto drop; |
| 2828 | } |
| 2829 | |
| 2830 | IWL_DEBUG_RATE("station Id %d\n", sta_id); |
| 2831 | |
| 2832 | qc = ieee80211_get_qos_ctrl(hdr); |
| 2833 | if (qc) { |
| 2834 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2835 | seq_number = priv->stations[sta_id].tid[tid].seq_number & |
| 2836 | IEEE80211_SCTL_SEQ; |
| 2837 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 2838 | (hdr->seq_ctrl & |
| 2839 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 2840 | seq_number += 0x10; |
| 2841 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2842 | |
| 2843 | /* Descriptor for chosen Tx queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2844 | txq = &priv->txq[txq_id]; |
| 2845 | q = &txq->q; |
| 2846 | |
| 2847 | spin_lock_irqsave(&priv->lock, flags); |
| 2848 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2849 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2850 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2851 | memset(tfd, 0, sizeof(*tfd)); |
| 2852 | control_flags = (u32 *) tfd; |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2853 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2854 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2855 | /* Set up driver data for this TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2856 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl3945_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2857 | txq->txb[q->write_ptr].skb[0] = skb; |
| 2858 | memcpy(&(txq->txb[q->write_ptr].status.control), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2859 | ctl, sizeof(struct ieee80211_tx_control)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2860 | |
| 2861 | /* Init first empty entry in queue's array of Tx/cmd buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2862 | out_cmd = &txq->cmd[idx]; |
| 2863 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 2864 | memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2865 | |
| 2866 | /* |
| 2867 | * Set up the Tx-command (not MAC!) header. |
| 2868 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 2869 | * after Tx, uCode's Tx response will return this value so driver can |
| 2870 | * locate the frame within the tx queue and do post-tx processing. |
| 2871 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2872 | out_cmd->hdr.cmd = REPLY_TX; |
| 2873 | 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] | 2874 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2875 | |
| 2876 | /* Copy MAC header from skb into command buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2877 | memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); |
| 2878 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2879 | /* |
| 2880 | * Use the first empty entry in this queue's command buffer array |
| 2881 | * to contain the Tx command and MAC header concatenated together |
| 2882 | * (payload data will be in another buffer). |
| 2883 | * Size of this varies, due to varying MAC header length. |
| 2884 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 2885 | * of the MAC header (device reads on dword boundaries). |
| 2886 | * We'll tell device about this padding later. |
| 2887 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2888 | len = priv->hw_setting.tx_cmd_len + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2889 | sizeof(struct iwl3945_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2890 | |
| 2891 | len_org = len; |
| 2892 | len = (len + 3) & ~3; |
| 2893 | |
| 2894 | if (len_org != len) |
| 2895 | len_org = 1; |
| 2896 | else |
| 2897 | len_org = 0; |
| 2898 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2899 | /* Physical address of this Tx command's header (not MAC header!), |
| 2900 | * within command buffer array. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2901 | txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl3945_cmd) * idx + |
| 2902 | offsetof(struct iwl3945_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2903 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2904 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 2905 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2906 | iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2907 | |
| 2908 | if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2909 | iwl3945_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2910 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2911 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 2912 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2913 | len = skb->len - hdr_len; |
| 2914 | if (len) { |
| 2915 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 2916 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2917 | iwl3945_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2918 | } |
| 2919 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2920 | if (!len) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2921 | /* If there is no payload, then we use only one Tx buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2922 | *control_flags = TFD_CTL_COUNT_SET(1); |
| 2923 | else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2924 | /* Else use 2 buffers. |
| 2925 | * Tell 3945 about any padding after MAC header */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2926 | *control_flags = TFD_CTL_COUNT_SET(2) | |
| 2927 | TFD_CTL_PAD_SET(U32_PAD(len)); |
| 2928 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2929 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2930 | len = (u16)skb->len; |
| 2931 | out_cmd->cmd.tx.len = cpu_to_le16(len); |
| 2932 | |
| 2933 | /* TODO need this for burst mode later on */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2934 | iwl3945_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2935 | |
| 2936 | /* set is_hcca to 0; it probably will never be implemented */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2937 | iwl3945_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] | 2938 | |
| 2939 | out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_A_MSK; |
| 2940 | out_cmd->cmd.tx.tx_flags &= ~TX_CMD_FLG_ANT_B_MSK; |
| 2941 | |
| 2942 | if (!ieee80211_get_morefrag(hdr)) { |
| 2943 | txq->need_update = 1; |
| 2944 | if (qc) { |
| 2945 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 2946 | priv->stations[sta_id].tid[tid].seq_number = seq_number; |
| 2947 | } |
| 2948 | } else { |
| 2949 | wait_write_ptr = 1; |
| 2950 | txq->need_update = 0; |
| 2951 | } |
| 2952 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2953 | iwl3945_print_hex_dump(IWL_DL_TX, out_cmd->cmd.payload, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2954 | sizeof(out_cmd->cmd.tx)); |
| 2955 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2956 | iwl3945_print_hex_dump(IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2957 | ieee80211_get_hdrlen(fc)); |
| 2958 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2959 | /* Tell device the write index *just past* this latest filled TFD */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2960 | q->write_ptr = iwl3945_queue_inc_wrap(q->write_ptr, q->n_bd); |
| 2961 | rc = iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2962 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2963 | |
| 2964 | if (rc) |
| 2965 | return rc; |
| 2966 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2967 | if ((iwl3945_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2968 | && priv->mac80211_registered) { |
| 2969 | if (wait_write_ptr) { |
| 2970 | spin_lock_irqsave(&priv->lock, flags); |
| 2971 | txq->need_update = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2972 | iwl3945_tx_queue_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2973 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2974 | } |
| 2975 | |
| 2976 | ieee80211_stop_queue(priv->hw, ctl->queue); |
| 2977 | } |
| 2978 | |
| 2979 | return 0; |
| 2980 | |
| 2981 | drop_unlock: |
| 2982 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2983 | drop: |
| 2984 | return -1; |
| 2985 | } |
| 2986 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2987 | static void iwl3945_set_rate(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2988 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2989 | const struct ieee80211_supported_band *sband = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2990 | struct ieee80211_rate *rate; |
| 2991 | int i; |
| 2992 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2993 | sband = iwl3945_get_band(priv, priv->band); |
| 2994 | if (!sband) { |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 2995 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 2996 | return; |
| 2997 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2998 | |
| 2999 | priv->active_rate = 0; |
| 3000 | priv->active_rate_basic = 0; |
| 3001 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3002 | IWL_DEBUG_RATE("Setting rates for %s GHz\n", |
| 3003 | sband->band == IEEE80211_BAND_2GHZ ? "2.4" : "5"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3004 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3005 | for (i = 0; i < sband->n_bitrates; i++) { |
| 3006 | rate = &sband->bitrates[i]; |
| 3007 | if ((rate->hw_value < IWL_RATE_COUNT) && |
| 3008 | !(rate->flags & IEEE80211_CHAN_DISABLED)) { |
| 3009 | IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n", |
| 3010 | rate->hw_value, iwl3945_rates[rate->hw_value].plcp); |
| 3011 | priv->active_rate |= (1 << rate->hw_value); |
| 3012 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 3016 | priv->active_rate, priv->active_rate_basic); |
| 3017 | |
| 3018 | /* |
| 3019 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 3020 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 3021 | * OFDM |
| 3022 | */ |
| 3023 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 3024 | priv->staging_rxon.cck_basic_rates = |
| 3025 | ((priv->active_rate_basic & |
| 3026 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 3027 | else |
| 3028 | priv->staging_rxon.cck_basic_rates = |
| 3029 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 3030 | |
| 3031 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 3032 | priv->staging_rxon.ofdm_basic_rates = |
| 3033 | ((priv->active_rate_basic & |
| 3034 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 3035 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 3036 | else |
| 3037 | priv->staging_rxon.ofdm_basic_rates = |
| 3038 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 3039 | } |
| 3040 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3041 | static void iwl3945_radio_kill_sw(struct iwl3945_priv *priv, int disable_radio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3042 | { |
| 3043 | unsigned long flags; |
| 3044 | |
| 3045 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 3046 | return; |
| 3047 | |
| 3048 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 3049 | disable_radio ? "OFF" : "ON"); |
| 3050 | |
| 3051 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3052 | iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3053 | /* FIXME: This is a workaround for AP */ |
| 3054 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 3055 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3056 | iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3057 | CSR_UCODE_SW_BIT_RFKILL); |
| 3058 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3059 | iwl3945_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3060 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3061 | } |
| 3062 | return; |
| 3063 | } |
| 3064 | |
| 3065 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3066 | iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3067 | |
| 3068 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3069 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3070 | |
| 3071 | /* wake up ucode */ |
| 3072 | msleep(10); |
| 3073 | |
| 3074 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3075 | iwl3945_read32(priv, CSR_UCODE_DRV_GP1); |
| 3076 | if (!iwl3945_grab_nic_access(priv)) |
| 3077 | iwl3945_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3078 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3079 | |
| 3080 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 3081 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 3082 | "disabled by HW switch\n"); |
| 3083 | return; |
| 3084 | } |
| 3085 | |
| 3086 | queue_work(priv->workqueue, &priv->restart); |
| 3087 | return; |
| 3088 | } |
| 3089 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3090 | void iwl3945_set_decrypted_flag(struct iwl3945_priv *priv, struct sk_buff *skb, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3091 | u32 decrypt_res, struct ieee80211_rx_status *stats) |
| 3092 | { |
| 3093 | u16 fc = |
| 3094 | le16_to_cpu(((struct ieee80211_hdr *)skb->data)->frame_control); |
| 3095 | |
| 3096 | if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
| 3097 | return; |
| 3098 | |
| 3099 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 3100 | return; |
| 3101 | |
| 3102 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 3103 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 3104 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 3105 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 3106 | RX_RES_STATUS_BAD_ICV_MIC) |
| 3107 | stats->flag |= RX_FLAG_MMIC_ERROR; |
| 3108 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 3109 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 3110 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 3111 | RX_RES_STATUS_DECRYPT_OK) { |
| 3112 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 3113 | stats->flag |= RX_FLAG_DECRYPTED; |
| 3114 | } |
| 3115 | break; |
| 3116 | |
| 3117 | default: |
| 3118 | break; |
| 3119 | } |
| 3120 | } |
| 3121 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3122 | #define IWL_PACKET_RETRY_TIME HZ |
| 3123 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3124 | int iwl3945_is_duplicate_packet(struct iwl3945_priv *priv, struct ieee80211_hdr *header) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3125 | { |
| 3126 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 3127 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 3128 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 3129 | u16 *last_seq, *last_frag; |
| 3130 | unsigned long *last_time; |
| 3131 | |
| 3132 | switch (priv->iw_mode) { |
| 3133 | case IEEE80211_IF_TYPE_IBSS:{ |
| 3134 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3135 | struct iwl3945_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3136 | u8 *mac = header->addr2; |
| 3137 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 3138 | |
| 3139 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3140 | entry = list_entry(p, struct iwl3945_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3141 | if (!compare_ether_addr(entry->mac, mac)) |
| 3142 | break; |
| 3143 | } |
| 3144 | if (p == &priv->ibss_mac_hash[index]) { |
| 3145 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 3146 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 3147 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3148 | return 0; |
| 3149 | } |
| 3150 | memcpy(entry->mac, mac, ETH_ALEN); |
| 3151 | entry->seq_num = seq; |
| 3152 | entry->frag_num = frag; |
| 3153 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 3154 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3155 | return 0; |
| 3156 | } |
| 3157 | last_seq = &entry->seq_num; |
| 3158 | last_frag = &entry->frag_num; |
| 3159 | last_time = &entry->packet_time; |
| 3160 | break; |
| 3161 | } |
| 3162 | case IEEE80211_IF_TYPE_STA: |
| 3163 | last_seq = &priv->last_seq_num; |
| 3164 | last_frag = &priv->last_frag_num; |
| 3165 | last_time = &priv->last_packet_time; |
| 3166 | break; |
| 3167 | default: |
| 3168 | return 0; |
| 3169 | } |
| 3170 | if ((*last_seq == seq) && |
| 3171 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 3172 | if (*last_frag == frag) |
| 3173 | goto drop; |
| 3174 | if (*last_frag + 1 != frag) |
| 3175 | /* out-of-order fragment */ |
| 3176 | goto drop; |
| 3177 | } else |
| 3178 | *last_seq = seq; |
| 3179 | |
| 3180 | *last_frag = frag; |
| 3181 | *last_time = jiffies; |
| 3182 | return 0; |
| 3183 | |
| 3184 | drop: |
| 3185 | return 1; |
| 3186 | } |
| 3187 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3188 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3189 | |
| 3190 | #include "iwl-spectrum.h" |
| 3191 | |
| 3192 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 3193 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 3194 | #define TIME_UNIT 1024 |
| 3195 | |
| 3196 | /* |
| 3197 | * extended beacon time format |
| 3198 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 3199 | * the high 1 byte is the beacon counts |
| 3200 | * the lower 3 bytes is the time in usec within one beacon interval |
| 3201 | */ |
| 3202 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3203 | static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3204 | { |
| 3205 | u32 quot; |
| 3206 | u32 rem; |
| 3207 | u32 interval = beacon_interval * 1024; |
| 3208 | |
| 3209 | if (!interval || !usec) |
| 3210 | return 0; |
| 3211 | |
| 3212 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 3213 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 3214 | |
| 3215 | return (quot << 24) + rem; |
| 3216 | } |
| 3217 | |
| 3218 | /* base is usually what we get from ucode with each received frame, |
| 3219 | * the same as HW timer counter counting down |
| 3220 | */ |
| 3221 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3222 | static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3223 | { |
| 3224 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 3225 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 3226 | u32 interval = beacon_interval * TIME_UNIT; |
| 3227 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 3228 | (addon & BEACON_TIME_MASK_HIGH); |
| 3229 | |
| 3230 | if (base_low > addon_low) |
| 3231 | res += base_low - addon_low; |
| 3232 | else if (base_low < addon_low) { |
| 3233 | res += interval + base_low - addon_low; |
| 3234 | res += (1 << 24); |
| 3235 | } else |
| 3236 | res += (1 << 24); |
| 3237 | |
| 3238 | return cpu_to_le32(res); |
| 3239 | } |
| 3240 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3241 | static int iwl3945_get_measurement(struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3242 | struct ieee80211_measurement_params *params, |
| 3243 | u8 type) |
| 3244 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3245 | struct iwl3945_spectrum_cmd spectrum; |
| 3246 | struct iwl3945_rx_packet *res; |
| 3247 | struct iwl3945_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3248 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 3249 | .data = (void *)&spectrum, |
| 3250 | .meta.flags = CMD_WANT_SKB, |
| 3251 | }; |
| 3252 | u32 add_time = le64_to_cpu(params->start_time); |
| 3253 | int rc; |
| 3254 | int spectrum_resp_status; |
| 3255 | int duration = le16_to_cpu(params->duration); |
| 3256 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3257 | if (iwl3945_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3258 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3259 | iwl3945_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3260 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 3261 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3262 | |
| 3263 | memset(&spectrum, 0, sizeof(spectrum)); |
| 3264 | |
| 3265 | spectrum.channel_count = cpu_to_le16(1); |
| 3266 | spectrum.flags = |
| 3267 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 3268 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 3269 | cmd.len = sizeof(spectrum); |
| 3270 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 3271 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3272 | if (iwl3945_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3273 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3274 | iwl3945_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3275 | add_time, |
| 3276 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 3277 | else |
| 3278 | spectrum.start_time = 0; |
| 3279 | |
| 3280 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 3281 | spectrum.channels[0].channel = params->channel; |
| 3282 | spectrum.channels[0].type = type; |
| 3283 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 3284 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 3285 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 3286 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3287 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3288 | if (rc) |
| 3289 | return rc; |
| 3290 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3291 | res = (struct iwl3945_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3292 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 3293 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 3294 | rc = -EIO; |
| 3295 | } |
| 3296 | |
| 3297 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 3298 | switch (spectrum_resp_status) { |
| 3299 | case 0: /* Command will be handled */ |
| 3300 | if (res->u.spectrum.id != 0xff) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 3301 | IWL_DEBUG_INFO("Replaced existing measurement: %d\n", |
| 3302 | res->u.spectrum.id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3303 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 3304 | } |
| 3305 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 3306 | rc = 0; |
| 3307 | break; |
| 3308 | |
| 3309 | case 1: /* Command will not be handled */ |
| 3310 | rc = -EAGAIN; |
| 3311 | break; |
| 3312 | } |
| 3313 | |
| 3314 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 3315 | |
| 3316 | return rc; |
| 3317 | } |
| 3318 | #endif |
| 3319 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3320 | static void iwl3945_txstatus_to_ieee(struct iwl3945_priv *priv, |
| 3321 | struct iwl3945_tx_info *tx_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3322 | { |
| 3323 | |
| 3324 | tx_sta->status.ack_signal = 0; |
| 3325 | tx_sta->status.excessive_retries = 0; |
| 3326 | tx_sta->status.queue_length = 0; |
| 3327 | tx_sta->status.queue_number = 0; |
| 3328 | |
| 3329 | if (in_interrupt()) |
| 3330 | ieee80211_tx_status_irqsafe(priv->hw, |
| 3331 | tx_sta->skb[0], &(tx_sta->status)); |
| 3332 | else |
| 3333 | ieee80211_tx_status(priv->hw, |
| 3334 | tx_sta->skb[0], &(tx_sta->status)); |
| 3335 | |
| 3336 | tx_sta->skb[0] = NULL; |
| 3337 | } |
| 3338 | |
| 3339 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3340 | * iwl3945_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3341 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3342 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 3343 | * need to be reclaimed. As result, some free space forms. If there is |
| 3344 | * enough free space (> low mark), wake the stack that feeds us. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3345 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3346 | static int iwl3945_tx_queue_reclaim(struct iwl3945_priv *priv, int txq_id, int index) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3347 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3348 | struct iwl3945_tx_queue *txq = &priv->txq[txq_id]; |
| 3349 | struct iwl3945_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3350 | int nfreed = 0; |
| 3351 | |
| 3352 | if ((index >= q->n_bd) || (x2_queue_used(q, index) == 0)) { |
| 3353 | IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " |
| 3354 | "is out of range [0-%d] %d %d.\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3355 | index, q->n_bd, q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3356 | return 0; |
| 3357 | } |
| 3358 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3359 | for (index = iwl3945_queue_inc_wrap(index, q->n_bd); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3360 | q->read_ptr != index; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3361 | q->read_ptr = iwl3945_queue_inc_wrap(q->read_ptr, q->n_bd)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3362 | if (txq_id != IWL_CMD_QUEUE_NUM) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3363 | iwl3945_txstatus_to_ieee(priv, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3364 | &(txq->txb[txq->q.read_ptr])); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3365 | iwl3945_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3366 | } else if (nfreed > 1) { |
| 3367 | IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3368 | q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3369 | queue_work(priv->workqueue, &priv->restart); |
| 3370 | } |
| 3371 | nfreed++; |
| 3372 | } |
| 3373 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3374 | if (iwl3945_queue_space(q) > q->low_mark && (txq_id >= 0) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3375 | (txq_id != IWL_CMD_QUEUE_NUM) && |
| 3376 | priv->mac80211_registered) |
| 3377 | ieee80211_wake_queue(priv->hw, txq_id); |
| 3378 | |
| 3379 | |
| 3380 | return nfreed; |
| 3381 | } |
| 3382 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3383 | static int iwl3945_is_tx_success(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3384 | { |
| 3385 | return (status & 0xFF) == 0x1; |
| 3386 | } |
| 3387 | |
| 3388 | /****************************************************************************** |
| 3389 | * |
| 3390 | * Generic RX handler implementations |
| 3391 | * |
| 3392 | ******************************************************************************/ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3393 | /** |
| 3394 | * iwl3945_rx_reply_tx - Handle Tx response |
| 3395 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3396 | static void iwl3945_rx_reply_tx(struct iwl3945_priv *priv, |
| 3397 | struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3398 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3399 | struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3400 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3401 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3402 | int index = SEQ_TO_INDEX(sequence); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3403 | struct iwl3945_tx_queue *txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3404 | struct ieee80211_tx_status *tx_status; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3405 | struct iwl3945_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3406 | u32 status = le32_to_cpu(tx_resp->status); |
| 3407 | |
| 3408 | if ((index >= txq->q.n_bd) || (x2_queue_used(&txq->q, index) == 0)) { |
| 3409 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 3410 | "is out of range [0-%d] %d %d\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3411 | index, txq->q.n_bd, txq->q.write_ptr, |
| 3412 | txq->q.read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3413 | return; |
| 3414 | } |
| 3415 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3416 | tx_status = &(txq->txb[txq->q.read_ptr].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3417 | |
| 3418 | tx_status->retry_count = tx_resp->failure_frame; |
| 3419 | tx_status->queue_number = status; |
| 3420 | tx_status->queue_length = tx_resp->bt_kill_count; |
| 3421 | tx_status->queue_length |= tx_resp->failure_rts; |
| 3422 | |
| 3423 | tx_status->flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3424 | iwl3945_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3425 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3426 | IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3427 | txq_id, iwl3945_get_tx_fail_reason(status), status, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3428 | tx_resp->rate, tx_resp->failure_frame); |
| 3429 | |
| 3430 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
| 3431 | if (index != -1) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3432 | iwl3945_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3433 | |
| 3434 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 3435 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 3436 | } |
| 3437 | |
| 3438 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3439 | static void iwl3945_rx_reply_alive(struct iwl3945_priv *priv, |
| 3440 | struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3441 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3442 | struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; |
| 3443 | struct iwl3945_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3444 | struct delayed_work *pwork; |
| 3445 | |
| 3446 | palive = &pkt->u.alive_frame; |
| 3447 | |
| 3448 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 3449 | "0x%01X 0x%01X\n", |
| 3450 | palive->is_valid, palive->ver_type, |
| 3451 | palive->ver_subtype); |
| 3452 | |
| 3453 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 3454 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 3455 | memcpy(&priv->card_alive_init, |
| 3456 | &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3457 | sizeof(struct iwl3945_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3458 | pwork = &priv->init_alive_start; |
| 3459 | } else { |
| 3460 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 3461 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3462 | sizeof(struct iwl3945_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3463 | pwork = &priv->alive_start; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3464 | iwl3945_disable_events(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3465 | } |
| 3466 | |
| 3467 | /* We delay the ALIVE response by 5ms to |
| 3468 | * give the HW RF Kill time to activate... */ |
| 3469 | if (palive->is_valid == UCODE_VALID_OK) |
| 3470 | queue_delayed_work(priv->workqueue, pwork, |
| 3471 | msecs_to_jiffies(5)); |
| 3472 | else |
| 3473 | IWL_WARNING("uCode did not respond OK.\n"); |
| 3474 | } |
| 3475 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3476 | static void iwl3945_rx_reply_add_sta(struct iwl3945_priv *priv, |
| 3477 | struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3478 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3479 | struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3480 | |
| 3481 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 3482 | return; |
| 3483 | } |
| 3484 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3485 | static void iwl3945_rx_reply_error(struct iwl3945_priv *priv, |
| 3486 | struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3487 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3488 | struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3489 | |
| 3490 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 3491 | "seq 0x%04X ser 0x%08X\n", |
| 3492 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 3493 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 3494 | pkt->u.err_resp.cmd_id, |
| 3495 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 3496 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 3497 | } |
| 3498 | |
| 3499 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 3500 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3501 | static void iwl3945_rx_csa(struct iwl3945_priv *priv, struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3502 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3503 | struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; |
| 3504 | struct iwl3945_rxon_cmd *rxon = (void *)&priv->active_rxon; |
| 3505 | struct iwl3945_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3506 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 3507 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 3508 | rxon->channel = csa->channel; |
| 3509 | priv->staging_rxon.channel = csa->channel; |
| 3510 | } |
| 3511 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3512 | static void iwl3945_rx_spectrum_measure_notif(struct iwl3945_priv *priv, |
| 3513 | struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3514 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3515 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3516 | struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; |
| 3517 | struct iwl3945_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3518 | |
| 3519 | if (!report->state) { |
| 3520 | IWL_DEBUG(IWL_DL_11H | IWL_DL_INFO, |
| 3521 | "Spectrum Measure Notification: Start\n"); |
| 3522 | return; |
| 3523 | } |
| 3524 | |
| 3525 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 3526 | priv->measurement_status |= MEASUREMENT_READY; |
| 3527 | #endif |
| 3528 | } |
| 3529 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3530 | static void iwl3945_rx_pm_sleep_notif(struct iwl3945_priv *priv, |
| 3531 | struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3532 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3533 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3534 | struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; |
| 3535 | struct iwl3945_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3536 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 3537 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 3538 | #endif |
| 3539 | } |
| 3540 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3541 | static void iwl3945_rx_pm_debug_statistics_notif(struct iwl3945_priv *priv, |
| 3542 | struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3543 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3544 | struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3545 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 3546 | "notification for %s:\n", |
| 3547 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3548 | iwl3945_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] | 3549 | } |
| 3550 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3551 | static void iwl3945_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3552 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3553 | struct iwl3945_priv *priv = |
| 3554 | container_of(work, struct iwl3945_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3555 | struct sk_buff *beacon; |
| 3556 | |
| 3557 | /* 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] | 3558 | beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3559 | |
| 3560 | if (!beacon) { |
| 3561 | IWL_ERROR("update beacon failed\n"); |
| 3562 | return; |
| 3563 | } |
| 3564 | |
| 3565 | mutex_lock(&priv->mutex); |
| 3566 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 3567 | if (priv->ibss_beacon) |
| 3568 | dev_kfree_skb(priv->ibss_beacon); |
| 3569 | |
| 3570 | priv->ibss_beacon = beacon; |
| 3571 | mutex_unlock(&priv->mutex); |
| 3572 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3573 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3574 | } |
| 3575 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3576 | static void iwl3945_rx_beacon_notif(struct iwl3945_priv *priv, |
| 3577 | struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3578 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3579 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3580 | struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; |
| 3581 | struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3582 | u8 rate = beacon->beacon_notify_hdr.rate; |
| 3583 | |
| 3584 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 3585 | "tsf %d %d rate %d\n", |
| 3586 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 3587 | beacon->beacon_notify_hdr.failure_frame, |
| 3588 | le32_to_cpu(beacon->ibss_mgr_status), |
| 3589 | le32_to_cpu(beacon->high_tsf), |
| 3590 | le32_to_cpu(beacon->low_tsf), rate); |
| 3591 | #endif |
| 3592 | |
| 3593 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 3594 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 3595 | queue_work(priv->workqueue, &priv->beacon_update); |
| 3596 | } |
| 3597 | |
| 3598 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3599 | static void iwl3945_rx_reply_scan(struct iwl3945_priv *priv, |
| 3600 | struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3601 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3602 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3603 | struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; |
| 3604 | struct iwl3945_scanreq_notification *notif = |
| 3605 | (struct iwl3945_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3606 | |
| 3607 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 3608 | #endif |
| 3609 | } |
| 3610 | |
| 3611 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3612 | static void iwl3945_rx_scan_start_notif(struct iwl3945_priv *priv, |
| 3613 | struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3614 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3615 | struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; |
| 3616 | struct iwl3945_scanstart_notification *notif = |
| 3617 | (struct iwl3945_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3618 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 3619 | IWL_DEBUG_SCAN("Scan start: " |
| 3620 | "%d [802.11%s] " |
| 3621 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 3622 | notif->channel, |
| 3623 | notif->band ? "bg" : "a", |
| 3624 | notif->tsf_high, |
| 3625 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 3626 | } |
| 3627 | |
| 3628 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3629 | static void iwl3945_rx_scan_results_notif(struct iwl3945_priv *priv, |
| 3630 | struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3631 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3632 | struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; |
| 3633 | struct iwl3945_scanresults_notification *notif = |
| 3634 | (struct iwl3945_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3635 | |
| 3636 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 3637 | "%d [802.11%s] " |
| 3638 | "(TSF: 0x%08X:%08X) - %d " |
| 3639 | "elapsed=%lu usec (%dms since last)\n", |
| 3640 | notif->channel, |
| 3641 | notif->band ? "bg" : "a", |
| 3642 | le32_to_cpu(notif->tsf_high), |
| 3643 | le32_to_cpu(notif->tsf_low), |
| 3644 | le32_to_cpu(notif->statistics[0]), |
| 3645 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 3646 | jiffies_to_msecs(elapsed_jiffies |
| 3647 | (priv->last_scan_jiffies, jiffies))); |
| 3648 | |
| 3649 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3650 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3651 | } |
| 3652 | |
| 3653 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3654 | static void iwl3945_rx_scan_complete_notif(struct iwl3945_priv *priv, |
| 3655 | struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3656 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3657 | struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; |
| 3658 | struct iwl3945_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3659 | |
| 3660 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 3661 | scan_notif->scanned_channels, |
| 3662 | scan_notif->tsf_low, |
| 3663 | scan_notif->tsf_high, scan_notif->status); |
| 3664 | |
| 3665 | /* The HW is no longer scanning */ |
| 3666 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 3667 | |
| 3668 | /* The scan completion notification came in, so kill that timer... */ |
| 3669 | cancel_delayed_work(&priv->scan_check); |
| 3670 | |
| 3671 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 3672 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 3673 | jiffies_to_msecs(elapsed_jiffies |
| 3674 | (priv->scan_pass_start, jiffies))); |
| 3675 | |
| 3676 | /* Remove this scanned band from the list |
| 3677 | * of pending bands to scan */ |
| 3678 | priv->scan_bands--; |
| 3679 | |
| 3680 | /* If a request to abort was given, or the scan did not succeed |
| 3681 | * then we reset the scan state machine and terminate, |
| 3682 | * re-queuing another scan if one has been requested */ |
| 3683 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 3684 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 3685 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 3686 | } else { |
| 3687 | /* If there are more bands on this scan pass reschedule */ |
| 3688 | if (priv->scan_bands > 0) |
| 3689 | goto reschedule; |
| 3690 | } |
| 3691 | |
| 3692 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3693 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3694 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 3695 | |
| 3696 | clear_bit(STATUS_SCANNING, &priv->status); |
| 3697 | |
| 3698 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 3699 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 3700 | |
| 3701 | queue_work(priv->workqueue, &priv->scan_completed); |
| 3702 | |
| 3703 | return; |
| 3704 | |
| 3705 | reschedule: |
| 3706 | priv->scan_pass_start = jiffies; |
| 3707 | queue_work(priv->workqueue, &priv->request_scan); |
| 3708 | } |
| 3709 | |
| 3710 | /* Handle notification from uCode that card's power state is changing |
| 3711 | * due to software, hardware, or critical temperature RFKILL */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3712 | static void iwl3945_rx_card_state_notif(struct iwl3945_priv *priv, |
| 3713 | struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3714 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3715 | struct iwl3945_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3716 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 3717 | unsigned long status = priv->status; |
| 3718 | |
| 3719 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 3720 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 3721 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 3722 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3723 | iwl3945_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3724 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 3725 | |
| 3726 | if (flags & HW_CARD_DISABLED) |
| 3727 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3728 | else |
| 3729 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3730 | |
| 3731 | |
| 3732 | if (flags & SW_CARD_DISABLED) |
| 3733 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3734 | else |
| 3735 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 3736 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3737 | iwl3945_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3738 | |
| 3739 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 3740 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 3741 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 3742 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 3743 | queue_work(priv->workqueue, &priv->rf_kill); |
| 3744 | else |
| 3745 | wake_up_interruptible(&priv->wait_command_queue); |
| 3746 | } |
| 3747 | |
| 3748 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3749 | * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3750 | * |
| 3751 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 3752 | * to the host. |
| 3753 | * |
| 3754 | * This function chains into the hardware specific files for them to setup |
| 3755 | * any hardware specific handlers as well. |
| 3756 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3757 | static void iwl3945_setup_rx_handlers(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3758 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3759 | priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive; |
| 3760 | priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta; |
| 3761 | priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error; |
| 3762 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl3945_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3763 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3764 | iwl3945_rx_spectrum_measure_notif; |
| 3765 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3766 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3767 | iwl3945_rx_pm_debug_statistics_notif; |
| 3768 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3769 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3770 | /* |
| 3771 | * The same handler is used for both the REPLY to a discrete |
| 3772 | * statistics request from the host as well as for the periodic |
| 3773 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3774 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3775 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics; |
| 3776 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3777 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3778 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl3945_rx_reply_scan; |
| 3779 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl3945_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3780 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3781 | iwl3945_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3782 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3783 | iwl3945_rx_scan_complete_notif; |
| 3784 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif; |
| 3785 | priv->rx_handlers[REPLY_TX] = iwl3945_rx_reply_tx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3786 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3787 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3788 | iwl3945_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3789 | } |
| 3790 | |
| 3791 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3792 | * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3793 | * @rxb: Rx buffer to reclaim |
| 3794 | * |
| 3795 | * If an Rx buffer has an async callback associated with it the callback |
| 3796 | * will be executed. The attached skb (if present) will only be freed |
| 3797 | * if the callback returns 1 |
| 3798 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3799 | static void iwl3945_tx_cmd_complete(struct iwl3945_priv *priv, |
| 3800 | struct iwl3945_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3801 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3802 | struct iwl3945_rx_packet *pkt = (struct iwl3945_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3803 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3804 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3805 | int index = SEQ_TO_INDEX(sequence); |
| 3806 | int huge = sequence & SEQ_HUGE_FRAME; |
| 3807 | int cmd_index; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3808 | struct iwl3945_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3809 | |
| 3810 | /* If a Tx command is being handled and it isn't in the actual |
| 3811 | * command queue then there a command routing bug has been introduced |
| 3812 | * in the queue management code. */ |
| 3813 | if (txq_id != IWL_CMD_QUEUE_NUM) |
| 3814 | IWL_ERROR("Error wrong command queue %d command id 0x%X\n", |
| 3815 | txq_id, pkt->hdr.cmd); |
| 3816 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 3817 | |
| 3818 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 3819 | cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
| 3820 | |
| 3821 | /* Input error checking is done when commands are added to queue. */ |
| 3822 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 3823 | cmd->meta.source->u.skb = rxb->skb; |
| 3824 | rxb->skb = NULL; |
| 3825 | } else if (cmd->meta.u.callback && |
| 3826 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 3827 | rxb->skb = NULL; |
| 3828 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3829 | iwl3945_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3830 | |
| 3831 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 3832 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3833 | wake_up_interruptible(&priv->wait_command_queue); |
| 3834 | } |
| 3835 | } |
| 3836 | |
| 3837 | /************************** RX-FUNCTIONS ****************************/ |
| 3838 | /* |
| 3839 | * Rx theory of operation |
| 3840 | * |
| 3841 | * The host allocates 32 DMA target addresses and passes the host address |
| 3842 | * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is |
| 3843 | * 0 to 31 |
| 3844 | * |
| 3845 | * Rx Queue Indexes |
| 3846 | * The host/firmware share two index registers for managing the Rx buffers. |
| 3847 | * |
| 3848 | * The READ index maps to the first position that the firmware may be writing |
| 3849 | * to -- the driver can read up to (but not including) this position and get |
| 3850 | * good data. |
| 3851 | * The READ index is managed by the firmware once the card is enabled. |
| 3852 | * |
| 3853 | * The WRITE index maps to the last position the driver has read from -- the |
| 3854 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 3855 | * |
| 3856 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 3857 | * WRITE = READ. |
| 3858 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3859 | * 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] | 3860 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 3861 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3862 | * 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] | 3863 | * and fire the RX interrupt. The driver can then query the READ index and |
| 3864 | * process as many packets as possible, moving the WRITE index forward as it |
| 3865 | * resets the Rx queue buffers with new memory. |
| 3866 | * |
| 3867 | * The management in the driver is as follows: |
| 3868 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 3869 | * 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] | 3870 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3871 | * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3872 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 3873 | * 'processed' and 'read' driver indexes as well) |
| 3874 | * + A received packet is processed and handed to the kernel network stack, |
| 3875 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 3876 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 3877 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 3878 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 3879 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 3880 | * |
| 3881 | * |
| 3882 | * Driver sequence: |
| 3883 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3884 | * iwl3945_rx_queue_alloc() Allocates rx_free |
| 3885 | * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3886 | * iwl3945_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3887 | * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3888 | * queue, updates firmware pointers, and updates |
| 3889 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3890 | * are available, schedules iwl3945_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3891 | * |
| 3892 | * -- enable interrupts -- |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3893 | * ISR - iwl3945_rx() Detach iwl3945_rx_mem_buffers from pool up to the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3894 | * READ INDEX, detaching the SKB from the pool. |
| 3895 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3896 | * Calls iwl3945_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3897 | * slots. |
| 3898 | * ... |
| 3899 | * |
| 3900 | */ |
| 3901 | |
| 3902 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3903 | * iwl3945_rx_queue_space - Return number of free slots available in queue. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3904 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3905 | static int iwl3945_rx_queue_space(const struct iwl3945_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3906 | { |
| 3907 | int s = q->read - q->write; |
| 3908 | if (s <= 0) |
| 3909 | s += RX_QUEUE_SIZE; |
| 3910 | /* keep some buffer to not confuse full and empty queue */ |
| 3911 | s -= 2; |
| 3912 | if (s < 0) |
| 3913 | s = 0; |
| 3914 | return s; |
| 3915 | } |
| 3916 | |
| 3917 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3918 | * iwl3945_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] | 3919 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3920 | int iwl3945_rx_queue_update_write_ptr(struct iwl3945_priv *priv, struct iwl3945_rx_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3921 | { |
| 3922 | u32 reg = 0; |
| 3923 | int rc = 0; |
| 3924 | unsigned long flags; |
| 3925 | |
| 3926 | spin_lock_irqsave(&q->lock, flags); |
| 3927 | |
| 3928 | if (q->need_update == 0) |
| 3929 | goto exit_unlock; |
| 3930 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3931 | /* If power-saving is in use, make sure device is awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3932 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3933 | reg = iwl3945_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3934 | |
| 3935 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3936 | iwl3945_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3937 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 3938 | goto exit_unlock; |
| 3939 | } |
| 3940 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3941 | rc = iwl3945_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3942 | if (rc) |
| 3943 | goto exit_unlock; |
| 3944 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3945 | /* Device expects a multiple of 8 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3946 | iwl3945_write_direct32(priv, FH_RSCSR_CHNL0_WPTR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3947 | q->write & ~0x7); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3948 | iwl3945_release_nic_access(priv); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3949 | |
| 3950 | /* Else device is assumed to be awake */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3951 | } else |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3952 | /* Device expects a multiple of 8 */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3953 | iwl3945_write32(priv, FH_RSCSR_CHNL0_WPTR, q->write & ~0x7); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3954 | |
| 3955 | |
| 3956 | q->need_update = 0; |
| 3957 | |
| 3958 | exit_unlock: |
| 3959 | spin_unlock_irqrestore(&q->lock, flags); |
| 3960 | return rc; |
| 3961 | } |
| 3962 | |
| 3963 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3964 | * iwl3945_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] | 3965 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3966 | static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3967 | dma_addr_t dma_addr) |
| 3968 | { |
| 3969 | return cpu_to_le32((u32)dma_addr); |
| 3970 | } |
| 3971 | |
| 3972 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3973 | * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3974 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3975 | * 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] | 3976 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3977 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3978 | * |
| 3979 | * This moves the 'write' index forward to catch up with 'processed', and |
| 3980 | * also updates the memory address in the firmware to reference the new |
| 3981 | * target buffer. |
| 3982 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3983 | static int iwl3945_rx_queue_restock(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3984 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3985 | struct iwl3945_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3986 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3987 | struct iwl3945_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3988 | unsigned long flags; |
| 3989 | int write, rc; |
| 3990 | |
| 3991 | spin_lock_irqsave(&rxq->lock, flags); |
| 3992 | write = rxq->write & ~0x7; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3993 | while ((iwl3945_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3994 | /* Get next free Rx buffer, remove from free list */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3995 | element = rxq->rx_free.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3996 | rxb = list_entry(element, struct iwl3945_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3997 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3998 | |
| 3999 | /* Point to Rx buffer via next RBD in circular buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4000 | rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->dma_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4001 | rxq->queue[rxq->write] = rxb; |
| 4002 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 4003 | rxq->free_count--; |
| 4004 | } |
| 4005 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4006 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 4007 | * refill it */ |
| 4008 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 4009 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 4010 | |
| 4011 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4012 | /* If we've added more space for the firmware to place data, tell it. |
| 4013 | * Increment device's write pointer in multiples of 8. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4014 | if ((write != (rxq->write & ~0x7)) |
| 4015 | || (abs(rxq->write - rxq->read) > 7)) { |
| 4016 | spin_lock_irqsave(&rxq->lock, flags); |
| 4017 | rxq->need_update = 1; |
| 4018 | spin_unlock_irqrestore(&rxq->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4019 | rc = iwl3945_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4020 | if (rc) |
| 4021 | return rc; |
| 4022 | } |
| 4023 | |
| 4024 | return 0; |
| 4025 | } |
| 4026 | |
| 4027 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4028 | * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4029 | * |
| 4030 | * When moving to rx_free an SKB is allocated for the slot. |
| 4031 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4032 | * Also restock the Rx queue via iwl3945_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 4033 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4034 | */ |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4035 | static void iwl3945_rx_allocate(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4036 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4037 | struct iwl3945_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4038 | struct list_head *element; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4039 | struct iwl3945_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4040 | unsigned long flags; |
| 4041 | spin_lock_irqsave(&rxq->lock, flags); |
| 4042 | while (!list_empty(&rxq->rx_used)) { |
| 4043 | element = rxq->rx_used.next; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4044 | rxb = list_entry(element, struct iwl3945_rx_mem_buffer, list); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4045 | |
| 4046 | /* Alloc a new receive buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4047 | rxb->skb = |
| 4048 | alloc_skb(IWL_RX_BUF_SIZE, __GFP_NOWARN | GFP_ATOMIC); |
| 4049 | if (!rxb->skb) { |
| 4050 | if (net_ratelimit()) |
| 4051 | printk(KERN_CRIT DRV_NAME |
| 4052 | ": Can not allocate SKB buffers\n"); |
| 4053 | /* We don't reschedule replenish work here -- we will |
| 4054 | * call the restock method and if it still needs |
| 4055 | * more buffers it will schedule replenish */ |
| 4056 | break; |
| 4057 | } |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 4058 | |
| 4059 | /* If radiotap head is required, reserve some headroom here. |
| 4060 | * The physical head count is a variable rx_stats->phy_count. |
| 4061 | * We reserve 4 bytes here. Plus these extra bytes, the |
| 4062 | * headroom of the physical head should be enough for the |
| 4063 | * radiotap head that iwl3945 supported. See iwl3945_rt. |
| 4064 | */ |
| 4065 | skb_reserve(rxb->skb, 4); |
| 4066 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4067 | priv->alloc_rxb_skb++; |
| 4068 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4069 | |
| 4070 | /* Get physical address of RB/SKB */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4071 | rxb->dma_addr = |
| 4072 | pci_map_single(priv->pci_dev, rxb->skb->data, |
| 4073 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4074 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 4075 | rxq->free_count++; |
| 4076 | } |
| 4077 | spin_unlock_irqrestore(&rxq->lock, flags); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | /* |
| 4081 | * this should be called while priv->lock is locked |
| 4082 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 4083 | static void __iwl3945_rx_replenish(void *data) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4084 | { |
| 4085 | struct iwl3945_priv *priv = data; |
| 4086 | |
| 4087 | iwl3945_rx_allocate(priv); |
| 4088 | iwl3945_rx_queue_restock(priv); |
| 4089 | } |
| 4090 | |
| 4091 | |
| 4092 | void iwl3945_rx_replenish(void *data) |
| 4093 | { |
| 4094 | struct iwl3945_priv *priv = data; |
| 4095 | unsigned long flags; |
| 4096 | |
| 4097 | iwl3945_rx_allocate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4098 | |
| 4099 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4100 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4101 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4102 | } |
| 4103 | |
| 4104 | /* 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] | 4105 | * 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] | 4106 | * This free routine walks the list of POOL entries and if SKB is set to |
| 4107 | * non NULL it is unmapped and freed |
| 4108 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4109 | static void iwl3945_rx_queue_free(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4110 | { |
| 4111 | int i; |
| 4112 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
| 4113 | if (rxq->pool[i].skb != NULL) { |
| 4114 | pci_unmap_single(priv->pci_dev, |
| 4115 | rxq->pool[i].dma_addr, |
| 4116 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4117 | dev_kfree_skb(rxq->pool[i].skb); |
| 4118 | } |
| 4119 | } |
| 4120 | |
| 4121 | pci_free_consistent(priv->pci_dev, 4 * RX_QUEUE_SIZE, rxq->bd, |
| 4122 | rxq->dma_addr); |
| 4123 | rxq->bd = NULL; |
| 4124 | } |
| 4125 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4126 | int iwl3945_rx_queue_alloc(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4127 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4128 | struct iwl3945_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4129 | struct pci_dev *dev = priv->pci_dev; |
| 4130 | int i; |
| 4131 | |
| 4132 | spin_lock_init(&rxq->lock); |
| 4133 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4134 | INIT_LIST_HEAD(&rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4135 | |
| 4136 | /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4137 | rxq->bd = pci_alloc_consistent(dev, 4 * RX_QUEUE_SIZE, &rxq->dma_addr); |
| 4138 | if (!rxq->bd) |
| 4139 | return -ENOMEM; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4140 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4141 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4142 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) |
| 4143 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4144 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4145 | /* Set us so that we have processed and used all buffers, but have |
| 4146 | * not restocked the Rx queue with fresh buffers */ |
| 4147 | rxq->read = rxq->write = 0; |
| 4148 | rxq->free_count = 0; |
| 4149 | rxq->need_update = 0; |
| 4150 | return 0; |
| 4151 | } |
| 4152 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4153 | void iwl3945_rx_queue_reset(struct iwl3945_priv *priv, struct iwl3945_rx_queue *rxq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4154 | { |
| 4155 | unsigned long flags; |
| 4156 | int i; |
| 4157 | spin_lock_irqsave(&rxq->lock, flags); |
| 4158 | INIT_LIST_HEAD(&rxq->rx_free); |
| 4159 | INIT_LIST_HEAD(&rxq->rx_used); |
| 4160 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 4161 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 4162 | /* In the reset function, these buffers may have been allocated |
| 4163 | * to an SKB, so we need to unmap and free potential storage */ |
| 4164 | if (rxq->pool[i].skb != NULL) { |
| 4165 | pci_unmap_single(priv->pci_dev, |
| 4166 | rxq->pool[i].dma_addr, |
| 4167 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4168 | priv->alloc_rxb_skb--; |
| 4169 | dev_kfree_skb(rxq->pool[i].skb); |
| 4170 | rxq->pool[i].skb = NULL; |
| 4171 | } |
| 4172 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 4173 | } |
| 4174 | |
| 4175 | /* Set us so that we have processed and used all buffers, but have |
| 4176 | * not restocked the Rx queue with fresh buffers */ |
| 4177 | rxq->read = rxq->write = 0; |
| 4178 | rxq->free_count = 0; |
| 4179 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4180 | } |
| 4181 | |
| 4182 | /* Convert linear signal-to-noise ratio into dB */ |
| 4183 | static u8 ratio2dB[100] = { |
| 4184 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 4185 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 4186 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 4187 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 4188 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 4189 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 4190 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 4191 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 4192 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 4193 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 4194 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 4195 | }; |
| 4196 | |
| 4197 | /* Calculates a relative dB value from a ratio of linear |
| 4198 | * (i.e. not dB) signal levels. |
| 4199 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4200 | int iwl3945_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4201 | { |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 4202 | /* 1000:1 or higher just report as 60 dB */ |
| 4203 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4204 | return 60; |
| 4205 | |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 4206 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4207 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 4208 | if (sig_ratio >= 100) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4209 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 4210 | |
| 4211 | /* We shouldn't see this */ |
| 4212 | if (sig_ratio < 1) |
| 4213 | return 0; |
| 4214 | |
| 4215 | /* Use table for ratios 1:1 - 99:1 */ |
| 4216 | return (int)ratio2dB[sig_ratio]; |
| 4217 | } |
| 4218 | |
| 4219 | #define PERFECT_RSSI (-20) /* dBm */ |
| 4220 | #define WORST_RSSI (-95) /* dBm */ |
| 4221 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 4222 | |
| 4223 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 4224 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 4225 | * about formulas used below. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4226 | int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4227 | { |
| 4228 | int sig_qual; |
| 4229 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 4230 | |
| 4231 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 4232 | * as indicator; formula is (signal dbm - noise dbm). |
| 4233 | * SNR at or above 40 is a great signal (100%). |
| 4234 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 4235 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 4236 | if (noise_dbm) { |
| 4237 | if (rssi_dbm - noise_dbm >= 40) |
| 4238 | return 100; |
| 4239 | else if (rssi_dbm < noise_dbm) |
| 4240 | return 0; |
| 4241 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 4242 | |
| 4243 | /* Else use just the signal level. |
| 4244 | * This formula is a least squares fit of data points collected and |
| 4245 | * compared with a reference system that had a percentage (%) display |
| 4246 | * for signal quality. */ |
| 4247 | } else |
| 4248 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 4249 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 4250 | (RSSI_RANGE * RSSI_RANGE); |
| 4251 | |
| 4252 | if (sig_qual > 100) |
| 4253 | sig_qual = 100; |
| 4254 | else if (sig_qual < 1) |
| 4255 | sig_qual = 0; |
| 4256 | |
| 4257 | return sig_qual; |
| 4258 | } |
| 4259 | |
| 4260 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4261 | * iwl3945_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4262 | * |
| 4263 | * Uses the priv->rx_handlers callback function array to invoke |
| 4264 | * the appropriate handlers, including command responses, |
| 4265 | * frame-received notifications, and other notifications. |
| 4266 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4267 | static void iwl3945_rx_handle(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4268 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4269 | struct iwl3945_rx_mem_buffer *rxb; |
| 4270 | struct iwl3945_rx_packet *pkt; |
| 4271 | struct iwl3945_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4272 | u32 r, i; |
| 4273 | int reclaim; |
| 4274 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4275 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 4276 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4277 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4278 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 4279 | * buffer that the driver may process (last buffer filled by ucode). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4280 | r = iwl3945_hw_get_rx_read(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4281 | i = rxq->read; |
| 4282 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4283 | if (iwl3945_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
| 4284 | fill_rx = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4285 | /* Rx interrupt, but nothing sent from uCode */ |
| 4286 | if (i == r) |
| 4287 | IWL_DEBUG(IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
| 4288 | |
| 4289 | while (i != r) { |
| 4290 | rxb = rxq->queue[i]; |
| 4291 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4292 | /* 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] | 4293 | * then a bug has been introduced in the queue refilling |
| 4294 | * routines -- catch it here */ |
| 4295 | BUG_ON(rxb == NULL); |
| 4296 | |
| 4297 | rxq->queue[i] = NULL; |
| 4298 | |
| 4299 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
| 4300 | IWL_RX_BUF_SIZE, |
| 4301 | PCI_DMA_FROMDEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4302 | pkt = (struct iwl3945_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4303 | |
| 4304 | /* Reclaim a command buffer only if this packet is a response |
| 4305 | * to a (driver-originated) command. |
| 4306 | * If the packet (e.g. Rx frame) originated from uCode, |
| 4307 | * there is no command buffer to reclaim. |
| 4308 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 4309 | * but apparently a few don't get set; catch them here. */ |
| 4310 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 4311 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 4312 | (pkt->hdr.cmd != REPLY_TX); |
| 4313 | |
| 4314 | /* Based on type of command response or notification, |
| 4315 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4316 | * rx_handlers table. See iwl3945_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4317 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
| 4318 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4319 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 4320 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 4321 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 4322 | } else { |
| 4323 | /* No handling needed */ |
| 4324 | IWL_DEBUG(IWL_DL_HOST_COMMAND | IWL_DL_RX | IWL_DL_ISR, |
| 4325 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 4326 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 4327 | pkt->hdr.cmd); |
| 4328 | } |
| 4329 | |
| 4330 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4331 | /* Invoke any callbacks, transfer the skb to caller, and |
| 4332 | * fire off the (possibly) blocking iwl3945_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4333 | * as we reclaim the driver command queue */ |
| 4334 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4335 | iwl3945_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4336 | else |
| 4337 | IWL_WARNING("Claim null rxb?\n"); |
| 4338 | } |
| 4339 | |
| 4340 | /* For now we just don't re-use anything. We can tweak this |
| 4341 | * later to try and re-use notification packets and SKBs that |
| 4342 | * fail to Rx correctly */ |
| 4343 | if (rxb->skb != NULL) { |
| 4344 | priv->alloc_rxb_skb--; |
| 4345 | dev_kfree_skb_any(rxb->skb); |
| 4346 | rxb->skb = NULL; |
| 4347 | } |
| 4348 | |
| 4349 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
| 4350 | IWL_RX_BUF_SIZE, PCI_DMA_FROMDEVICE); |
| 4351 | spin_lock_irqsave(&rxq->lock, flags); |
| 4352 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 4353 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 4354 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 4355 | /* If there are a lot of unused frames, |
| 4356 | * restock the Rx queue so ucode won't assert. */ |
| 4357 | if (fill_rx) { |
| 4358 | count++; |
| 4359 | if (count >= 8) { |
| 4360 | priv->rxq.read = i; |
| 4361 | __iwl3945_rx_replenish(priv); |
| 4362 | count = 0; |
| 4363 | } |
| 4364 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4365 | } |
| 4366 | |
| 4367 | /* Backtrack one entry */ |
| 4368 | priv->rxq.read = i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4369 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4370 | } |
| 4371 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4372 | /** |
| 4373 | * iwl3945_tx_queue_update_write_ptr - Send new write index to hardware |
| 4374 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4375 | static int iwl3945_tx_queue_update_write_ptr(struct iwl3945_priv *priv, |
| 4376 | struct iwl3945_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4377 | { |
| 4378 | u32 reg = 0; |
| 4379 | int rc = 0; |
| 4380 | int txq_id = txq->q.id; |
| 4381 | |
| 4382 | if (txq->need_update == 0) |
| 4383 | return rc; |
| 4384 | |
| 4385 | /* if we're trying to save power */ |
| 4386 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 4387 | /* wake up nic if it's powered down ... |
| 4388 | * uCode will wake up, and interrupt us again, so next |
| 4389 | * time we'll skip this part. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4390 | reg = iwl3945_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4391 | |
| 4392 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 4393 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4394 | iwl3945_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4395 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 4396 | return rc; |
| 4397 | } |
| 4398 | |
| 4399 | /* restore this queue's parameters in nic hardware. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4400 | rc = iwl3945_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4401 | if (rc) |
| 4402 | return rc; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4403 | iwl3945_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 4404 | txq->q.write_ptr | (txq_id << 8)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4405 | iwl3945_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4406 | |
| 4407 | /* else not in power-save mode, uCode will never sleep when we're |
| 4408 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 4409 | } else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4410 | iwl3945_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 4411 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4412 | |
| 4413 | txq->need_update = 0; |
| 4414 | |
| 4415 | return rc; |
| 4416 | } |
| 4417 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4418 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4419 | static void iwl3945_print_rx_config_cmd(struct iwl3945_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4420 | { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4421 | DECLARE_MAC_BUF(mac); |
| 4422 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4423 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4424 | iwl3945_print_hex_dump(IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4425 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 4426 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 4427 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 4428 | le32_to_cpu(rxon->filter_flags)); |
| 4429 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 4430 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 4431 | rxon->ofdm_basic_rates); |
| 4432 | 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] | 4433 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 4434 | print_mac(mac, rxon->node_addr)); |
| 4435 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 4436 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4437 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 4438 | } |
| 4439 | #endif |
| 4440 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4441 | static void iwl3945_enable_interrupts(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4442 | { |
| 4443 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 4444 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4445 | iwl3945_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4446 | } |
| 4447 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4448 | static inline void iwl3945_disable_interrupts(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4449 | { |
| 4450 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 4451 | |
| 4452 | /* disable interrupts from uCode/NIC to host */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4453 | iwl3945_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4454 | |
| 4455 | /* acknowledge/clear/reset any interrupts still pending |
| 4456 | * from uCode or flow handler (Rx/Tx DMA) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4457 | iwl3945_write32(priv, CSR_INT, 0xffffffff); |
| 4458 | iwl3945_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4459 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 4460 | } |
| 4461 | |
| 4462 | static const char *desc_lookup(int i) |
| 4463 | { |
| 4464 | switch (i) { |
| 4465 | case 1: |
| 4466 | return "FAIL"; |
| 4467 | case 2: |
| 4468 | return "BAD_PARAM"; |
| 4469 | case 3: |
| 4470 | return "BAD_CHECKSUM"; |
| 4471 | case 4: |
| 4472 | return "NMI_INTERRUPT"; |
| 4473 | case 5: |
| 4474 | return "SYSASSERT"; |
| 4475 | case 6: |
| 4476 | return "FATAL_ERROR"; |
| 4477 | } |
| 4478 | |
| 4479 | return "UNKNOWN"; |
| 4480 | } |
| 4481 | |
| 4482 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 4483 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 4484 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4485 | static void iwl3945_dump_nic_error_log(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4486 | { |
| 4487 | u32 i; |
| 4488 | u32 desc, time, count, base, data1; |
| 4489 | u32 blink1, blink2, ilink1, ilink2; |
| 4490 | int rc; |
| 4491 | |
| 4492 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 4493 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4494 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4495 | IWL_ERROR("Not valid error log pointer 0x%08X\n", base); |
| 4496 | return; |
| 4497 | } |
| 4498 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4499 | rc = iwl3945_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4500 | if (rc) { |
| 4501 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4502 | return; |
| 4503 | } |
| 4504 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4505 | count = iwl3945_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4506 | |
| 4507 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
| 4508 | IWL_ERROR("Start IWL Error Log Dump:\n"); |
| 4509 | IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n", |
| 4510 | priv->status, priv->config, count); |
| 4511 | } |
| 4512 | |
| 4513 | IWL_ERROR("Desc Time asrtPC blink2 " |
| 4514 | "ilink1 nmiPC Line\n"); |
| 4515 | for (i = ERROR_START_OFFSET; |
| 4516 | i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET; |
| 4517 | i += ERROR_ELEM_SIZE) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4518 | desc = iwl3945_read_targ_mem(priv, base + i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4519 | time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4520 | iwl3945_read_targ_mem(priv, base + i + 1 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4521 | blink1 = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4522 | iwl3945_read_targ_mem(priv, base + i + 2 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4523 | blink2 = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4524 | iwl3945_read_targ_mem(priv, base + i + 3 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4525 | ilink1 = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4526 | iwl3945_read_targ_mem(priv, base + i + 4 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4527 | ilink2 = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4528 | iwl3945_read_targ_mem(priv, base + i + 5 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4529 | data1 = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4530 | iwl3945_read_targ_mem(priv, base + i + 6 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4531 | |
| 4532 | IWL_ERROR |
| 4533 | ("%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n", |
| 4534 | desc_lookup(desc), desc, time, blink1, blink2, |
| 4535 | ilink1, ilink2, data1); |
| 4536 | } |
| 4537 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4538 | iwl3945_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4539 | |
| 4540 | } |
| 4541 | |
Ben Cahill | f58177b | 2007-11-29 11:09:43 +0800 | [diff] [blame] | 4542 | #define EVENT_START_OFFSET (6 * sizeof(u32)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4543 | |
| 4544 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4545 | * iwl3945_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4546 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4547 | * NOTE: Must be called with iwl3945_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4548 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4549 | static void iwl3945_print_event_log(struct iwl3945_priv *priv, u32 start_idx, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4550 | u32 num_events, u32 mode) |
| 4551 | { |
| 4552 | u32 i; |
| 4553 | u32 base; /* SRAM byte address of event log header */ |
| 4554 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 4555 | u32 ptr; /* SRAM byte address of log data */ |
| 4556 | u32 ev, time, data; /* event log data */ |
| 4557 | |
| 4558 | if (num_events == 0) |
| 4559 | return; |
| 4560 | |
| 4561 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 4562 | |
| 4563 | if (mode == 0) |
| 4564 | event_size = 2 * sizeof(u32); |
| 4565 | else |
| 4566 | event_size = 3 * sizeof(u32); |
| 4567 | |
| 4568 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 4569 | |
| 4570 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 4571 | * place event id # at far right for easier visual parsing. */ |
| 4572 | for (i = 0; i < num_events; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4573 | ev = iwl3945_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4574 | ptr += sizeof(u32); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4575 | time = iwl3945_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4576 | ptr += sizeof(u32); |
| 4577 | if (mode == 0) |
| 4578 | IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */ |
| 4579 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4580 | data = iwl3945_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4581 | ptr += sizeof(u32); |
| 4582 | IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev); |
| 4583 | } |
| 4584 | } |
| 4585 | } |
| 4586 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4587 | static void iwl3945_dump_nic_event_log(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4588 | { |
| 4589 | int rc; |
| 4590 | u32 base; /* SRAM byte address of event log header */ |
| 4591 | u32 capacity; /* event log capacity in # entries */ |
| 4592 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 4593 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 4594 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 4595 | u32 size; /* # entries that we'll print */ |
| 4596 | |
| 4597 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4598 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4599 | IWL_ERROR("Invalid event log pointer 0x%08X\n", base); |
| 4600 | return; |
| 4601 | } |
| 4602 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4603 | rc = iwl3945_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4604 | if (rc) { |
| 4605 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 4606 | return; |
| 4607 | } |
| 4608 | |
| 4609 | /* event log header */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4610 | capacity = iwl3945_read_targ_mem(priv, base); |
| 4611 | mode = iwl3945_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 4612 | num_wraps = iwl3945_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 4613 | next_entry = iwl3945_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4614 | |
| 4615 | size = num_wraps ? capacity : next_entry; |
| 4616 | |
| 4617 | /* bail out if nothing in log */ |
| 4618 | if (size == 0) { |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 4619 | IWL_ERROR("Start IWL Event Log Dump: nothing in log\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4620 | iwl3945_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4621 | return; |
| 4622 | } |
| 4623 | |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 4624 | 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] | 4625 | size, num_wraps); |
| 4626 | |
| 4627 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 4628 | * i.e the next one that uCode would fill. */ |
| 4629 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4630 | iwl3945_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4631 | capacity - next_entry, mode); |
| 4632 | |
| 4633 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4634 | iwl3945_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4635 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4636 | iwl3945_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4640 | * iwl3945_irq_handle_error - called for HW or SW error interrupt from card |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4641 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4642 | static void iwl3945_irq_handle_error(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4643 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4644 | /* Set the FW error flag -- cleared on iwl3945_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4645 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 4646 | |
| 4647 | /* Cancel currently queued command. */ |
| 4648 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 4649 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4650 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4651 | if (iwl3945_debug_level & IWL_DL_FW_ERRORS) { |
| 4652 | iwl3945_dump_nic_error_log(priv); |
| 4653 | iwl3945_dump_nic_event_log(priv); |
| 4654 | iwl3945_print_rx_config_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4655 | } |
| 4656 | #endif |
| 4657 | |
| 4658 | wake_up_interruptible(&priv->wait_command_queue); |
| 4659 | |
| 4660 | /* Keep the restart process from trying to send host |
| 4661 | * commands by clearing the INIT status bit */ |
| 4662 | clear_bit(STATUS_READY, &priv->status); |
| 4663 | |
| 4664 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 4665 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_FW_ERRORS, |
| 4666 | "Restarting adapter due to uCode error.\n"); |
| 4667 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4668 | if (iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4669 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 4670 | sizeof(priv->recovery_rxon)); |
| 4671 | priv->error_recovering = 1; |
| 4672 | } |
| 4673 | queue_work(priv->workqueue, &priv->restart); |
| 4674 | } |
| 4675 | } |
| 4676 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4677 | static void iwl3945_error_recovery(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4678 | { |
| 4679 | unsigned long flags; |
| 4680 | |
| 4681 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 4682 | sizeof(priv->staging_rxon)); |
| 4683 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4684 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4685 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4686 | iwl3945_add_station(priv, priv->bssid, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4687 | |
| 4688 | spin_lock_irqsave(&priv->lock, flags); |
| 4689 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 4690 | priv->error_recovering = 0; |
| 4691 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4692 | } |
| 4693 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4694 | static void iwl3945_irq_tasklet(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4695 | { |
| 4696 | u32 inta, handled = 0; |
| 4697 | u32 inta_fh; |
| 4698 | unsigned long flags; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4699 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4700 | u32 inta_mask; |
| 4701 | #endif |
| 4702 | |
| 4703 | spin_lock_irqsave(&priv->lock, flags); |
| 4704 | |
| 4705 | /* Ack/clear/reset pending uCode interrupts. |
| 4706 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 4707 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4708 | inta = iwl3945_read32(priv, CSR_INT); |
| 4709 | iwl3945_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4710 | |
| 4711 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 4712 | * Any new interrupts that happen after this, either while we're |
| 4713 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4714 | inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS); |
| 4715 | iwl3945_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4716 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4717 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4718 | if (iwl3945_debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4719 | /* just for debug */ |
| 4720 | inta_mask = iwl3945_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4721 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4722 | inta, inta_mask, inta_fh); |
| 4723 | } |
| 4724 | #endif |
| 4725 | |
| 4726 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 4727 | * atomic, make sure that inta covers all the interrupts that |
| 4728 | * we've discovered, even if FH interrupt came in just after |
| 4729 | * reading CSR_INT. */ |
| 4730 | if (inta_fh & CSR_FH_INT_RX_MASK) |
| 4731 | inta |= CSR_INT_BIT_FH_RX; |
| 4732 | if (inta_fh & CSR_FH_INT_TX_MASK) |
| 4733 | inta |= CSR_INT_BIT_FH_TX; |
| 4734 | |
| 4735 | /* Now service all interrupt bits discovered above. */ |
| 4736 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 4737 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 4738 | |
| 4739 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4740 | iwl3945_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4741 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4742 | iwl3945_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4743 | |
| 4744 | handled |= CSR_INT_BIT_HW_ERR; |
| 4745 | |
| 4746 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4747 | |
| 4748 | return; |
| 4749 | } |
| 4750 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4751 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4752 | if (iwl3945_debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4753 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4754 | if (inta & CSR_INT_BIT_SCD) |
| 4755 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 4756 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4757 | |
| 4758 | /* Alive notification via Rx interrupt will do the real work */ |
| 4759 | if (inta & CSR_INT_BIT_ALIVE) |
| 4760 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 4761 | } |
| 4762 | #endif |
| 4763 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4764 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4765 | |
| 4766 | /* HW RF KILL switch toggled (4965 only) */ |
| 4767 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 4768 | int hw_rf_kill = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4769 | if (!(iwl3945_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4770 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 4771 | hw_rf_kill = 1; |
| 4772 | |
| 4773 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL | IWL_DL_ISR, |
| 4774 | "RF_KILL bit toggled to %s.\n", |
| 4775 | hw_rf_kill ? "disable radio":"enable radio"); |
| 4776 | |
| 4777 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 4778 | * when we loaded driver, and is now set to "enable". |
| 4779 | * After we're Alive, RF_KILL gets handled by |
| 4780 | * iwl_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 4781 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 4782 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4783 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 4784 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4785 | |
| 4786 | handled |= CSR_INT_BIT_RF_KILL; |
| 4787 | } |
| 4788 | |
| 4789 | /* Chip got too hot and stopped itself (4965 only) */ |
| 4790 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 4791 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 4792 | handled |= CSR_INT_BIT_CT_KILL; |
| 4793 | } |
| 4794 | |
| 4795 | /* Error detected by uCode */ |
| 4796 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 4797 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 4798 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4799 | iwl3945_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4800 | handled |= CSR_INT_BIT_SW_ERR; |
| 4801 | } |
| 4802 | |
| 4803 | /* uCode wakes up after power-down sleep */ |
| 4804 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 4805 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4806 | iwl3945_rx_queue_update_write_ptr(priv, &priv->rxq); |
| 4807 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[0]); |
| 4808 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[1]); |
| 4809 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[2]); |
| 4810 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[3]); |
| 4811 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[4]); |
| 4812 | iwl3945_tx_queue_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4813 | |
| 4814 | handled |= CSR_INT_BIT_WAKEUP; |
| 4815 | } |
| 4816 | |
| 4817 | /* All uCode command responses, including Tx command responses, |
| 4818 | * Rx "responses" (frame-received notification), and other |
| 4819 | * notifications from uCode come through here*/ |
| 4820 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4821 | iwl3945_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4822 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 4823 | } |
| 4824 | |
| 4825 | if (inta & CSR_INT_BIT_FH_TX) { |
| 4826 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 4827 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4828 | iwl3945_write32(priv, CSR_FH_INT_STATUS, (1 << 6)); |
| 4829 | if (!iwl3945_grab_nic_access(priv)) { |
| 4830 | iwl3945_write_direct32(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4831 | FH_TCSR_CREDIT |
| 4832 | (ALM_FH_SRVC_CHNL), 0x0); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4833 | iwl3945_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4834 | } |
| 4835 | handled |= CSR_INT_BIT_FH_TX; |
| 4836 | } |
| 4837 | |
| 4838 | if (inta & ~handled) |
| 4839 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 4840 | |
| 4841 | if (inta & ~CSR_INI_SET_MASK) { |
| 4842 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 4843 | inta & ~CSR_INI_SET_MASK); |
| 4844 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 4845 | } |
| 4846 | |
| 4847 | /* Re-enable all interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4848 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4849 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4850 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4851 | if (iwl3945_debug_level & (IWL_DL_ISR)) { |
| 4852 | inta = iwl3945_read32(priv, CSR_INT); |
| 4853 | inta_mask = iwl3945_read32(priv, CSR_INT_MASK); |
| 4854 | inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4855 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 4856 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 4857 | } |
| 4858 | #endif |
| 4859 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4860 | } |
| 4861 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4862 | static irqreturn_t iwl3945_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4863 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4864 | struct iwl3945_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4865 | u32 inta, inta_mask; |
| 4866 | u32 inta_fh; |
| 4867 | if (!priv) |
| 4868 | return IRQ_NONE; |
| 4869 | |
| 4870 | spin_lock(&priv->lock); |
| 4871 | |
| 4872 | /* Disable (but don't clear!) interrupts here to avoid |
| 4873 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 4874 | * If we have something to service, the tasklet will re-enable ints. |
| 4875 | * If we *don't* have something, we'll re-enable before leaving here. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4876 | inta_mask = iwl3945_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 4877 | iwl3945_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4878 | |
| 4879 | /* Discover which interrupts are active/pending */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4880 | inta = iwl3945_read32(priv, CSR_INT); |
| 4881 | inta_fh = iwl3945_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4882 | |
| 4883 | /* Ignore interrupt if there's nothing in NIC to service. |
| 4884 | * This may be due to IRQ shared with another device, |
| 4885 | * or due to sporadic interrupts thrown from our NIC. */ |
| 4886 | if (!inta && !inta_fh) { |
| 4887 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 4888 | goto none; |
| 4889 | } |
| 4890 | |
| 4891 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
| 4892 | /* Hardware disappeared */ |
| 4893 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | cb4da1a | 2007-11-13 21:10:32 -0800 | [diff] [blame] | 4894 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 4898 | inta, inta_mask, inta_fh); |
| 4899 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4900 | inta &= ~CSR_INT_BIT_SCD; |
| 4901 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4902 | /* iwl3945_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 4903 | if (likely(inta || inta_fh)) |
| 4904 | tasklet_schedule(&priv->irq_tasklet); |
Oliver Neukum | cb4da1a | 2007-11-13 21:10:32 -0800 | [diff] [blame] | 4905 | unplugged: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4906 | spin_unlock(&priv->lock); |
| 4907 | |
| 4908 | return IRQ_HANDLED; |
| 4909 | |
| 4910 | none: |
| 4911 | /* re-enable interrupts here since we don't have anything to service. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4912 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4913 | spin_unlock(&priv->lock); |
| 4914 | return IRQ_NONE; |
| 4915 | } |
| 4916 | |
| 4917 | /************************** EEPROM BANDS **************************** |
| 4918 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4919 | * The iwl3945_eeprom_band definitions below provide the mapping from the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4920 | * EEPROM contents to the specific channel number supported for each |
| 4921 | * band. |
| 4922 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4923 | * For example, iwl3945_priv->eeprom.band_3_channels[4] from the band_3 |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4924 | * definition below maps to physical channel 42 in the 5.2GHz spectrum. |
| 4925 | * The specific geography and calibration information for that channel |
| 4926 | * is contained in the eeprom map itself. |
| 4927 | * |
| 4928 | * During init, we copy the eeprom information and channel map |
| 4929 | * information into priv->channel_info_24/52 and priv->channel_map_24/52 |
| 4930 | * |
| 4931 | * channel_map_24/52 provides the index in the channel_info array for a |
| 4932 | * given channel. We have to have two separate maps as there is channel |
| 4933 | * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and |
| 4934 | * band_2 |
| 4935 | * |
| 4936 | * A value of 0xff stored in the channel_map indicates that the channel |
| 4937 | * is not supported by the hardware at all. |
| 4938 | * |
| 4939 | * A value of 0xfe in the channel_map indicates that the channel is not |
| 4940 | * valid for Tx with the current hardware. This means that |
| 4941 | * while the system can tune and receive on a given channel, it may not |
| 4942 | * be able to associate or transmit any frames on that |
| 4943 | * channel. There is no corresponding channel information for that |
| 4944 | * entry. |
| 4945 | * |
| 4946 | *********************************************************************/ |
| 4947 | |
| 4948 | /* 2.4 GHz */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4949 | static const u8 iwl3945_eeprom_band_1[14] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4950 | 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 |
| 4951 | }; |
| 4952 | |
| 4953 | /* 5.2 GHz bands */ |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4954 | static const u8 iwl3945_eeprom_band_2[] = { /* 4915-5080MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4955 | 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16 |
| 4956 | }; |
| 4957 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4958 | static const u8 iwl3945_eeprom_band_3[] = { /* 5170-5320MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4959 | 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64 |
| 4960 | }; |
| 4961 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4962 | static const u8 iwl3945_eeprom_band_4[] = { /* 5500-5700MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4963 | 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 |
| 4964 | }; |
| 4965 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4966 | static const u8 iwl3945_eeprom_band_5[] = { /* 5725-5825MHz */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4967 | 145, 149, 153, 157, 161, 165 |
| 4968 | }; |
| 4969 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4970 | static void iwl3945_init_band_reference(const struct iwl3945_priv *priv, int band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4971 | int *eeprom_ch_count, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4972 | const struct iwl3945_eeprom_channel |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4973 | **eeprom_ch_info, |
| 4974 | const u8 **eeprom_ch_index) |
| 4975 | { |
| 4976 | switch (band) { |
| 4977 | case 1: /* 2.4GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4978 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4979 | *eeprom_ch_info = priv->eeprom.band_1_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4980 | *eeprom_ch_index = iwl3945_eeprom_band_1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4981 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4982 | case 2: /* 4.9GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4983 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4984 | *eeprom_ch_info = priv->eeprom.band_2_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4985 | *eeprom_ch_index = iwl3945_eeprom_band_2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4986 | break; |
| 4987 | case 3: /* 5.2GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4988 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4989 | *eeprom_ch_info = priv->eeprom.band_3_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4990 | *eeprom_ch_index = iwl3945_eeprom_band_3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4991 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4992 | case 4: /* 5.5GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4993 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_4); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4994 | *eeprom_ch_info = priv->eeprom.band_4_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4995 | *eeprom_ch_index = iwl3945_eeprom_band_4; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4996 | break; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4997 | case 5: /* 5.7GHz band */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4998 | *eeprom_ch_count = ARRAY_SIZE(iwl3945_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4999 | *eeprom_ch_info = priv->eeprom.band_5_channels; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5000 | *eeprom_ch_index = iwl3945_eeprom_band_5; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5001 | break; |
| 5002 | default: |
| 5003 | BUG(); |
| 5004 | return; |
| 5005 | } |
| 5006 | } |
| 5007 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5008 | /** |
| 5009 | * iwl3945_get_channel_info - Find driver's private channel info |
| 5010 | * |
| 5011 | * Based on band and channel number. |
| 5012 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5013 | const struct iwl3945_channel_info *iwl3945_get_channel_info(const struct iwl3945_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5014 | enum ieee80211_band band, u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5015 | { |
| 5016 | int i; |
| 5017 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5018 | switch (band) { |
| 5019 | case IEEE80211_BAND_5GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5020 | for (i = 14; i < priv->channel_count; i++) { |
| 5021 | if (priv->channel_info[i].channel == channel) |
| 5022 | return &priv->channel_info[i]; |
| 5023 | } |
| 5024 | break; |
| 5025 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5026 | case IEEE80211_BAND_2GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5027 | if (channel >= 1 && channel <= 14) |
| 5028 | return &priv->channel_info[channel - 1]; |
| 5029 | break; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5030 | case IEEE80211_NUM_BANDS: |
| 5031 | WARN_ON(1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5032 | } |
| 5033 | |
| 5034 | return NULL; |
| 5035 | } |
| 5036 | |
| 5037 | #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \ |
| 5038 | ? # x " " : "") |
| 5039 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5040 | /** |
| 5041 | * iwl3945_init_channel_map - Set up driver's info for all possible channels |
| 5042 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5043 | static int iwl3945_init_channel_map(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5044 | { |
| 5045 | int eeprom_ch_count = 0; |
| 5046 | const u8 *eeprom_ch_index = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5047 | const struct iwl3945_eeprom_channel *eeprom_ch_info = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5048 | int band, ch; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5049 | struct iwl3945_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5050 | |
| 5051 | if (priv->channel_count) { |
| 5052 | IWL_DEBUG_INFO("Channel map already initialized.\n"); |
| 5053 | return 0; |
| 5054 | } |
| 5055 | |
| 5056 | if (priv->eeprom.version < 0x2f) { |
| 5057 | IWL_WARNING("Unsupported EEPROM version: 0x%04X\n", |
| 5058 | priv->eeprom.version); |
| 5059 | return -EINVAL; |
| 5060 | } |
| 5061 | |
| 5062 | IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n"); |
| 5063 | |
| 5064 | priv->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5065 | ARRAY_SIZE(iwl3945_eeprom_band_1) + |
| 5066 | ARRAY_SIZE(iwl3945_eeprom_band_2) + |
| 5067 | ARRAY_SIZE(iwl3945_eeprom_band_3) + |
| 5068 | ARRAY_SIZE(iwl3945_eeprom_band_4) + |
| 5069 | ARRAY_SIZE(iwl3945_eeprom_band_5); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5070 | |
| 5071 | IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv->channel_count); |
| 5072 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5073 | priv->channel_info = kzalloc(sizeof(struct iwl3945_channel_info) * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5074 | priv->channel_count, GFP_KERNEL); |
| 5075 | if (!priv->channel_info) { |
| 5076 | IWL_ERROR("Could not allocate channel_info\n"); |
| 5077 | priv->channel_count = 0; |
| 5078 | return -ENOMEM; |
| 5079 | } |
| 5080 | |
| 5081 | ch_info = priv->channel_info; |
| 5082 | |
| 5083 | /* Loop through the 5 EEPROM bands adding them in order to the |
| 5084 | * channel map we maintain (that contains additional information than |
| 5085 | * what just in the EEPROM) */ |
| 5086 | for (band = 1; band <= 5; band++) { |
| 5087 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5088 | iwl3945_init_band_reference(priv, band, &eeprom_ch_count, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5089 | &eeprom_ch_info, &eeprom_ch_index); |
| 5090 | |
| 5091 | /* Loop through each band adding each of the channels */ |
| 5092 | for (ch = 0; ch < eeprom_ch_count; ch++) { |
| 5093 | ch_info->channel = eeprom_ch_index[ch]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5094 | ch_info->band = (band == 1) ? IEEE80211_BAND_2GHZ : |
| 5095 | IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5096 | |
| 5097 | /* permanently store EEPROM's channel regulatory flags |
| 5098 | * and max power in channel info database. */ |
| 5099 | ch_info->eeprom = eeprom_ch_info[ch]; |
| 5100 | |
| 5101 | /* Copy the run-time flags so they are there even on |
| 5102 | * invalid channels */ |
| 5103 | ch_info->flags = eeprom_ch_info[ch].flags; |
| 5104 | |
| 5105 | if (!(is_channel_valid(ch_info))) { |
| 5106 | IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - " |
| 5107 | "No traffic\n", |
| 5108 | ch_info->channel, |
| 5109 | ch_info->flags, |
| 5110 | is_channel_a_band(ch_info) ? |
| 5111 | "5.2" : "2.4"); |
| 5112 | ch_info++; |
| 5113 | continue; |
| 5114 | } |
| 5115 | |
| 5116 | /* Initialize regulatory-based run-time data */ |
| 5117 | ch_info->max_power_avg = ch_info->curr_txpow = |
| 5118 | eeprom_ch_info[ch].max_power_avg; |
| 5119 | ch_info->scan_power = eeprom_ch_info[ch].max_power_avg; |
| 5120 | ch_info->min_power = 0; |
| 5121 | |
| 5122 | IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x" |
| 5123 | " %ddBm): Ad-Hoc %ssupported\n", |
| 5124 | ch_info->channel, |
| 5125 | is_channel_a_band(ch_info) ? |
| 5126 | "5.2" : "2.4", |
| 5127 | CHECK_AND_PRINT(IBSS), |
| 5128 | CHECK_AND_PRINT(ACTIVE), |
| 5129 | CHECK_AND_PRINT(RADAR), |
| 5130 | CHECK_AND_PRINT(WIDE), |
| 5131 | CHECK_AND_PRINT(NARROW), |
| 5132 | CHECK_AND_PRINT(DFS), |
| 5133 | eeprom_ch_info[ch].flags, |
| 5134 | eeprom_ch_info[ch].max_power_avg, |
| 5135 | ((eeprom_ch_info[ch]. |
| 5136 | flags & EEPROM_CHANNEL_IBSS) |
| 5137 | && !(eeprom_ch_info[ch]. |
| 5138 | flags & EEPROM_CHANNEL_RADAR)) |
| 5139 | ? "" : "not "); |
| 5140 | |
| 5141 | /* Set the user_txpower_limit to the highest power |
| 5142 | * supported by any channel */ |
| 5143 | if (eeprom_ch_info[ch].max_power_avg > |
| 5144 | priv->user_txpower_limit) |
| 5145 | priv->user_txpower_limit = |
| 5146 | eeprom_ch_info[ch].max_power_avg; |
| 5147 | |
| 5148 | ch_info++; |
| 5149 | } |
| 5150 | } |
| 5151 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5152 | /* Set up txpower settings in driver for all channels */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5153 | if (iwl3945_txpower_set_from_eeprom(priv)) |
| 5154 | return -EIO; |
| 5155 | |
| 5156 | return 0; |
| 5157 | } |
| 5158 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5159 | /* |
| 5160 | * iwl3945_free_channel_map - undo allocations in iwl3945_init_channel_map |
| 5161 | */ |
| 5162 | static void iwl3945_free_channel_map(struct iwl3945_priv *priv) |
| 5163 | { |
| 5164 | kfree(priv->channel_info); |
| 5165 | priv->channel_count = 0; |
| 5166 | } |
| 5167 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5168 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 5169 | * sending probe req. This should be set long enough to hear probe responses |
| 5170 | * from more than one AP. */ |
| 5171 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5172 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 5173 | |
| 5174 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 5175 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 5176 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 5177 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 5178 | * no other traffic). |
| 5179 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 5180 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 5181 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 5182 | |
| 5183 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 5184 | * Must be set longer than active dwell time. |
| 5185 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 5186 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 5187 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 5188 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 5189 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 5190 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5191 | static inline u16 iwl3945_get_active_dwell_time(struct iwl3945_priv *priv, |
| 5192 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5193 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5194 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5195 | return IWL_ACTIVE_DWELL_TIME_52; |
| 5196 | else |
| 5197 | return IWL_ACTIVE_DWELL_TIME_24; |
| 5198 | } |
| 5199 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5200 | static u16 iwl3945_get_passive_dwell_time(struct iwl3945_priv *priv, |
| 5201 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5202 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5203 | u16 active = iwl3945_get_active_dwell_time(priv, band); |
| 5204 | u16 passive = (band == IEEE80211_BAND_2GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5205 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 5206 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 5207 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5208 | if (iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5209 | /* If we're associated, we clamp the maximum passive |
| 5210 | * dwell time to be 98% of the beacon interval (minus |
| 5211 | * 2 * channel tune time) */ |
| 5212 | passive = priv->beacon_int; |
| 5213 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 5214 | passive = IWL_PASSIVE_DWELL_BASE; |
| 5215 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 5216 | } |
| 5217 | |
| 5218 | if (passive <= active) |
| 5219 | passive = active + 1; |
| 5220 | |
| 5221 | return passive; |
| 5222 | } |
| 5223 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5224 | static int iwl3945_get_channels_for_scan(struct iwl3945_priv *priv, |
| 5225 | enum ieee80211_band band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5226 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5227 | struct iwl3945_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5228 | { |
| 5229 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5230 | const struct ieee80211_supported_band *sband; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5231 | const struct iwl3945_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5232 | u16 passive_dwell = 0; |
| 5233 | u16 active_dwell = 0; |
| 5234 | int added, i; |
| 5235 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5236 | sband = iwl3945_get_band(priv, band); |
| 5237 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5238 | return 0; |
| 5239 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5240 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5241 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5242 | active_dwell = iwl3945_get_active_dwell_time(priv, band); |
| 5243 | passive_dwell = iwl3945_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5244 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5245 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
| 5246 | if (channels[i].hw_value == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5247 | le16_to_cpu(priv->active_rxon.channel)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5248 | if (iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5249 | IWL_DEBUG_SCAN |
| 5250 | ("Skipping current channel %d\n", |
| 5251 | le16_to_cpu(priv->active_rxon.channel)); |
| 5252 | continue; |
| 5253 | } |
| 5254 | } else if (priv->only_active_channel) |
| 5255 | continue; |
| 5256 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5257 | scan_ch->channel = channels[i].hw_value; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5258 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5259 | ch_info = iwl3945_get_channel_info(priv, band, scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5260 | if (!is_channel_valid(ch_info)) { |
| 5261 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 5262 | scan_ch->channel); |
| 5263 | continue; |
| 5264 | } |
| 5265 | |
| 5266 | if (!is_active || is_channel_passive(ch_info) || |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5267 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5268 | scan_ch->type = 0; /* passive */ |
| 5269 | else |
| 5270 | scan_ch->type = 1; /* active */ |
| 5271 | |
| 5272 | if (scan_ch->type & 1) |
| 5273 | scan_ch->type |= (direct_mask << 1); |
| 5274 | |
| 5275 | if (is_channel_narrow(ch_info)) |
| 5276 | scan_ch->type |= (1 << 7); |
| 5277 | |
| 5278 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 5279 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 5280 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5281 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5282 | scan_ch->tpc.dsp_atten = 110; |
| 5283 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 5284 | |
| 5285 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5286 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5287 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 5288 | else { |
| 5289 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 5290 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5291 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 5292 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5293 | */ |
| 5294 | } |
| 5295 | |
| 5296 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 5297 | scan_ch->channel, |
| 5298 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 5299 | (scan_ch->type & 1) ? |
| 5300 | active_dwell : passive_dwell); |
| 5301 | |
| 5302 | scan_ch++; |
| 5303 | added++; |
| 5304 | } |
| 5305 | |
| 5306 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 5307 | return added; |
| 5308 | } |
| 5309 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5310 | static void iwl3945_init_hw_rates(struct iwl3945_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5311 | struct ieee80211_rate *rates) |
| 5312 | { |
| 5313 | int i; |
| 5314 | |
| 5315 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5316 | rates[i].bitrate = iwl3945_rates[i].ieee * 5; |
| 5317 | rates[i].hw_value = i; /* Rate scaling will work on indexes */ |
| 5318 | rates[i].hw_value_short = i; |
| 5319 | rates[i].flags = 0; |
| 5320 | if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5321 | /* |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5322 | * If CCK != 1M then set short preamble rate flag. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5323 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5324 | rates[i].flags |= (iwl3945_rates[i].plcp == 10) ? |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5325 | 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5326 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5327 | } |
| 5328 | } |
| 5329 | |
| 5330 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5331 | * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5332 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5333 | static int iwl3945_init_geos(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5334 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5335 | struct iwl3945_channel_info *ch; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5336 | struct ieee80211_supported_band *band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5337 | struct ieee80211_channel *channels; |
| 5338 | struct ieee80211_channel *geo_ch; |
| 5339 | struct ieee80211_rate *rates; |
| 5340 | int i = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5341 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5342 | if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates || |
| 5343 | priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5344 | IWL_DEBUG_INFO("Geography modes already initialized.\n"); |
| 5345 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5346 | return 0; |
| 5347 | } |
| 5348 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5349 | channels = kzalloc(sizeof(struct ieee80211_channel) * |
| 5350 | priv->channel_count, GFP_KERNEL); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5351 | if (!channels) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5352 | return -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5353 | |
| 5354 | rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_MAX_RATES + 1)), |
| 5355 | GFP_KERNEL); |
| 5356 | if (!rates) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5357 | kfree(channels); |
| 5358 | return -ENOMEM; |
| 5359 | } |
| 5360 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5361 | /* 5.2GHz channels start after the 2.4GHz channels */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5362 | band = &priv->bands[IEEE80211_BAND_5GHZ]; |
| 5363 | band->channels = &channels[ARRAY_SIZE(iwl3945_eeprom_band_1)]; |
| 5364 | band->bitrates = &rates[4]; |
| 5365 | band->n_bitrates = 8; /* just OFDM */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5366 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5367 | band = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 5368 | band->channels = channels; |
| 5369 | band->bitrates = rates; |
| 5370 | band->n_bitrates = 12; /* OFDM & CCK */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5371 | |
| 5372 | priv->ieee_channels = channels; |
| 5373 | priv->ieee_rates = rates; |
| 5374 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5375 | iwl3945_init_hw_rates(priv, rates); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5376 | |
| 5377 | for (i = 0, geo_ch = channels; i < priv->channel_count; i++) { |
| 5378 | ch = &priv->channel_info[i]; |
| 5379 | |
| 5380 | if (!is_channel_valid(ch)) { |
| 5381 | IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- " |
| 5382 | "skipping.\n", |
| 5383 | ch->channel, is_channel_a_band(ch) ? |
| 5384 | "5.2" : "2.4"); |
| 5385 | continue; |
| 5386 | } |
| 5387 | |
| 5388 | if (is_channel_a_band(ch)) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5389 | geo_ch = &priv->bands[IEEE80211_BAND_5GHZ].channels[priv->bands[IEEE80211_BAND_5GHZ].n_channels++]; |
| 5390 | else |
| 5391 | geo_ch = &priv->bands[IEEE80211_BAND_2GHZ].channels[priv->bands[IEEE80211_BAND_2GHZ].n_channels++]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5392 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5393 | geo_ch->center_freq = ieee80211chan2mhz(ch->channel); |
| 5394 | geo_ch->max_power = ch->max_power_avg; |
| 5395 | geo_ch->max_antenna_gain = 0xff; |
Mohamed Abbas | 7b72304 | 2008-01-31 21:46:40 -0800 | [diff] [blame] | 5396 | geo_ch->hw_value = ch->channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5397 | |
| 5398 | if (is_channel_valid(ch)) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5399 | if (!(ch->flags & EEPROM_CHANNEL_IBSS)) |
| 5400 | geo_ch->flags |= IEEE80211_CHAN_NO_IBSS; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5401 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5402 | if (!(ch->flags & EEPROM_CHANNEL_ACTIVE)) |
| 5403 | geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5404 | |
| 5405 | if (ch->flags & EEPROM_CHANNEL_RADAR) |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5406 | geo_ch->flags |= IEEE80211_CHAN_RADAR; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5407 | |
| 5408 | if (ch->max_power_avg > priv->max_channel_txpower_limit) |
| 5409 | priv->max_channel_txpower_limit = |
| 5410 | ch->max_power_avg; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5411 | } else |
| 5412 | geo_ch->flags |= IEEE80211_CHAN_DISABLED; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5413 | } |
| 5414 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5415 | if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) && priv->is_abg) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5416 | printk(KERN_INFO DRV_NAME |
| 5417 | ": Incorrectly detected BG card as ABG. Please send " |
| 5418 | "your PCI ID 0x%04X:0x%04X to maintainer.\n", |
| 5419 | priv->pci_dev->device, priv->pci_dev->subsystem_device); |
| 5420 | priv->is_abg = 0; |
| 5421 | } |
| 5422 | |
| 5423 | printk(KERN_INFO DRV_NAME |
| 5424 | ": Tunable channels: %d 802.11bg, %d 802.11a channels\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5425 | priv->bands[IEEE80211_BAND_2GHZ].n_channels, |
| 5426 | priv->bands[IEEE80211_BAND_5GHZ].n_channels); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5427 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5428 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->bands[IEEE80211_BAND_2GHZ]; |
| 5429 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->bands[IEEE80211_BAND_5GHZ]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5430 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5431 | set_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5432 | |
| 5433 | return 0; |
| 5434 | } |
| 5435 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5436 | /* |
| 5437 | * iwl3945_free_geos - undo allocations in iwl3945_init_geos |
| 5438 | */ |
| 5439 | static void iwl3945_free_geos(struct iwl3945_priv *priv) |
| 5440 | { |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5441 | kfree(priv->ieee_channels); |
| 5442 | kfree(priv->ieee_rates); |
| 5443 | clear_bit(STATUS_GEO_CONFIGURED, &priv->status); |
| 5444 | } |
| 5445 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5446 | /****************************************************************************** |
| 5447 | * |
| 5448 | * uCode download functions |
| 5449 | * |
| 5450 | ******************************************************************************/ |
| 5451 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5452 | static void iwl3945_dealloc_ucode_pci(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5453 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5454 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 5455 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 5456 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 5457 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 5458 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 5459 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5460 | } |
| 5461 | |
| 5462 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5463 | * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5464 | * looking at all data. |
| 5465 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5466 | static int iwl3945_verify_inst_full(struct iwl3945_priv *priv, __le32 * image, u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5467 | { |
| 5468 | u32 val; |
| 5469 | u32 save_len = len; |
| 5470 | int rc = 0; |
| 5471 | u32 errcnt; |
| 5472 | |
| 5473 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 5474 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5475 | rc = iwl3945_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5476 | if (rc) |
| 5477 | return rc; |
| 5478 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5479 | iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5480 | |
| 5481 | errcnt = 0; |
| 5482 | for (; len > 0; len -= sizeof(u32), image++) { |
| 5483 | /* read data comes through single port, auto-incr addr */ |
| 5484 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 5485 | * if IWL_DL_IO is set */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5486 | val = _iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5487 | if (val != le32_to_cpu(*image)) { |
| 5488 | IWL_ERROR("uCode INST section is invalid at " |
| 5489 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 5490 | save_len - len, val, le32_to_cpu(*image)); |
| 5491 | rc = -EIO; |
| 5492 | errcnt++; |
| 5493 | if (errcnt >= 20) |
| 5494 | break; |
| 5495 | } |
| 5496 | } |
| 5497 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5498 | iwl3945_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5499 | |
| 5500 | if (!errcnt) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 5501 | IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5502 | |
| 5503 | return rc; |
| 5504 | } |
| 5505 | |
| 5506 | |
| 5507 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5508 | * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5509 | * using sample data 100 bytes apart. If these sample points are good, |
| 5510 | * it's a pretty good bet that everything between them is good, too. |
| 5511 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5512 | static int iwl3945_verify_inst_sparse(struct iwl3945_priv *priv, __le32 *image, u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5513 | { |
| 5514 | u32 val; |
| 5515 | int rc = 0; |
| 5516 | u32 errcnt = 0; |
| 5517 | u32 i; |
| 5518 | |
| 5519 | IWL_DEBUG_INFO("ucode inst image size is %u\n", len); |
| 5520 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5521 | rc = iwl3945_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5522 | if (rc) |
| 5523 | return rc; |
| 5524 | |
| 5525 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 5526 | /* read data comes through single port, auto-incr addr */ |
| 5527 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 5528 | * if IWL_DL_IO is set */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5529 | iwl3945_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5530 | i + RTC_INST_LOWER_BOUND); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5531 | val = _iwl3945_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5532 | if (val != le32_to_cpu(*image)) { |
| 5533 | #if 0 /* Enable this if you want to see details */ |
| 5534 | IWL_ERROR("uCode INST section is invalid at " |
| 5535 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 5536 | i, val, *image); |
| 5537 | #endif |
| 5538 | rc = -EIO; |
| 5539 | errcnt++; |
| 5540 | if (errcnt >= 3) |
| 5541 | break; |
| 5542 | } |
| 5543 | } |
| 5544 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5545 | iwl3945_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5546 | |
| 5547 | return rc; |
| 5548 | } |
| 5549 | |
| 5550 | |
| 5551 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5552 | * iwl3945_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5553 | * and verify its contents |
| 5554 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5555 | static int iwl3945_verify_ucode(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5556 | { |
| 5557 | __le32 *image; |
| 5558 | u32 len; |
| 5559 | int rc = 0; |
| 5560 | |
| 5561 | /* Try bootstrap */ |
| 5562 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 5563 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5564 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5565 | if (rc == 0) { |
| 5566 | IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n"); |
| 5567 | return 0; |
| 5568 | } |
| 5569 | |
| 5570 | /* Try initialize */ |
| 5571 | image = (__le32 *)priv->ucode_init.v_addr; |
| 5572 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5573 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5574 | if (rc == 0) { |
| 5575 | IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n"); |
| 5576 | return 0; |
| 5577 | } |
| 5578 | |
| 5579 | /* Try runtime/protocol */ |
| 5580 | image = (__le32 *)priv->ucode_code.v_addr; |
| 5581 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5582 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5583 | if (rc == 0) { |
| 5584 | IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n"); |
| 5585 | return 0; |
| 5586 | } |
| 5587 | |
| 5588 | IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
| 5589 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5590 | /* Since nothing seems to match, show first several data entries in |
| 5591 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 5592 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5593 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 5594 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5595 | rc = iwl3945_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5596 | |
| 5597 | return rc; |
| 5598 | } |
| 5599 | |
| 5600 | |
| 5601 | /* check contents of special bootstrap uCode SRAM */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5602 | static int iwl3945_verify_bsm(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5603 | { |
| 5604 | __le32 *image = priv->ucode_boot.v_addr; |
| 5605 | u32 len = priv->ucode_boot.len; |
| 5606 | u32 reg; |
| 5607 | u32 val; |
| 5608 | |
| 5609 | IWL_DEBUG_INFO("Begin verify bsm\n"); |
| 5610 | |
| 5611 | /* verify BSM SRAM contents */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5612 | val = iwl3945_read_prph(priv, BSM_WR_DWCOUNT_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5613 | for (reg = BSM_SRAM_LOWER_BOUND; |
| 5614 | reg < BSM_SRAM_LOWER_BOUND + len; |
| 5615 | reg += sizeof(u32), image ++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5616 | val = iwl3945_read_prph(priv, reg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5617 | if (val != le32_to_cpu(*image)) { |
| 5618 | IWL_ERROR("BSM uCode verification failed at " |
| 5619 | "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", |
| 5620 | BSM_SRAM_LOWER_BOUND, |
| 5621 | reg - BSM_SRAM_LOWER_BOUND, len, |
| 5622 | val, le32_to_cpu(*image)); |
| 5623 | return -EIO; |
| 5624 | } |
| 5625 | } |
| 5626 | |
| 5627 | IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n"); |
| 5628 | |
| 5629 | return 0; |
| 5630 | } |
| 5631 | |
| 5632 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5633 | * iwl3945_load_bsm - Load bootstrap instructions |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5634 | * |
| 5635 | * BSM operation: |
| 5636 | * |
| 5637 | * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program |
| 5638 | * in special SRAM that does not power down during RFKILL. When powering back |
| 5639 | * up after power-saving sleeps (or during initial uCode load), the BSM loads |
| 5640 | * the bootstrap program into the on-board processor, and starts it. |
| 5641 | * |
| 5642 | * The bootstrap program loads (via DMA) instructions and data for a new |
| 5643 | * program from host DRAM locations indicated by the host driver in the |
| 5644 | * BSM_DRAM_* registers. Once the new program is loaded, it starts |
| 5645 | * automatically. |
| 5646 | * |
| 5647 | * When initializing the NIC, the host driver points the BSM to the |
| 5648 | * "initialize" uCode image. This uCode sets up some internal data, then |
| 5649 | * notifies host via "initialize alive" that it is complete. |
| 5650 | * |
| 5651 | * The host then replaces the BSM_DRAM_* pointer values to point to the |
| 5652 | * normal runtime uCode instructions and a backup uCode data cache buffer |
| 5653 | * (filled initially with starting data values for the on-board processor), |
| 5654 | * then triggers the "initialize" uCode to load and launch the runtime uCode, |
| 5655 | * which begins normal operation. |
| 5656 | * |
| 5657 | * When doing a power-save shutdown, runtime uCode saves data SRAM into |
| 5658 | * the backup data cache in DRAM before SRAM is powered down. |
| 5659 | * |
| 5660 | * When powering back up, the BSM loads the bootstrap program. This reloads |
| 5661 | * the runtime uCode instructions and the backup data cache into SRAM, |
| 5662 | * and re-launches the runtime uCode from where it left off. |
| 5663 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5664 | static int iwl3945_load_bsm(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5665 | { |
| 5666 | __le32 *image = priv->ucode_boot.v_addr; |
| 5667 | u32 len = priv->ucode_boot.len; |
| 5668 | dma_addr_t pinst; |
| 5669 | dma_addr_t pdata; |
| 5670 | u32 inst_len; |
| 5671 | u32 data_len; |
| 5672 | int rc; |
| 5673 | int i; |
| 5674 | u32 done; |
| 5675 | u32 reg_offset; |
| 5676 | |
| 5677 | IWL_DEBUG_INFO("Begin load bsm\n"); |
| 5678 | |
| 5679 | /* make sure bootstrap program is no larger than BSM's SRAM size */ |
| 5680 | if (len > IWL_MAX_BSM_SIZE) |
| 5681 | return -EINVAL; |
| 5682 | |
| 5683 | /* Tell bootstrap uCode where to find the "Initialize" uCode |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 5684 | * in host DRAM ... host DRAM physical address bits 31:0 for 3945. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5685 | * NOTE: iwl3945_initialize_alive_start() will replace these values, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5686 | * after the "initialize" uCode has run, to point to |
| 5687 | * runtime/protocol instructions and backup data cache. */ |
| 5688 | pinst = priv->ucode_init.p_addr; |
| 5689 | pdata = priv->ucode_init_data.p_addr; |
| 5690 | inst_len = priv->ucode_init.len; |
| 5691 | data_len = priv->ucode_init_data.len; |
| 5692 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5693 | rc = iwl3945_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5694 | if (rc) |
| 5695 | return rc; |
| 5696 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5697 | iwl3945_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 5698 | iwl3945_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 5699 | iwl3945_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); |
| 5700 | iwl3945_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5701 | |
| 5702 | /* Fill BSM memory with bootstrap instructions */ |
| 5703 | for (reg_offset = BSM_SRAM_LOWER_BOUND; |
| 5704 | reg_offset < BSM_SRAM_LOWER_BOUND + len; |
| 5705 | reg_offset += sizeof(u32), image++) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5706 | _iwl3945_write_prph(priv, reg_offset, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5707 | le32_to_cpu(*image)); |
| 5708 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5709 | rc = iwl3945_verify_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5710 | if (rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5711 | iwl3945_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5712 | return rc; |
| 5713 | } |
| 5714 | |
| 5715 | /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5716 | iwl3945_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0); |
| 5717 | iwl3945_write_prph(priv, BSM_WR_MEM_DST_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5718 | RTC_INST_LOWER_BOUND); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5719 | iwl3945_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5720 | |
| 5721 | /* Load bootstrap code into instruction SRAM now, |
| 5722 | * to prepare to load "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5723 | iwl3945_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5724 | BSM_WR_CTRL_REG_BIT_START); |
| 5725 | |
| 5726 | /* Wait for load of bootstrap uCode to finish */ |
| 5727 | for (i = 0; i < 100; i++) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5728 | done = iwl3945_read_prph(priv, BSM_WR_CTRL_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5729 | if (!(done & BSM_WR_CTRL_REG_BIT_START)) |
| 5730 | break; |
| 5731 | udelay(10); |
| 5732 | } |
| 5733 | if (i < 100) |
| 5734 | IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i); |
| 5735 | else { |
| 5736 | IWL_ERROR("BSM write did not complete!\n"); |
| 5737 | return -EIO; |
| 5738 | } |
| 5739 | |
| 5740 | /* Enable future boot loads whenever power management unit triggers it |
| 5741 | * (e.g. when powering back up after power-save shutdown) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5742 | iwl3945_write_prph(priv, BSM_WR_CTRL_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5743 | BSM_WR_CTRL_REG_BIT_START_EN); |
| 5744 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5745 | iwl3945_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5746 | |
| 5747 | return 0; |
| 5748 | } |
| 5749 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5750 | static void iwl3945_nic_start(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5751 | { |
| 5752 | /* Remove all resets to allow NIC to operate */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5753 | iwl3945_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5754 | } |
| 5755 | |
| 5756 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5757 | * iwl3945_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5758 | * |
| 5759 | * Copy into buffers for card to fetch via bus-mastering |
| 5760 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5761 | static int iwl3945_read_ucode(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5762 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5763 | struct iwl3945_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5764 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5765 | const struct firmware *ucode_raw; |
| 5766 | /* firmware file name contains uCode/driver compatibility version */ |
| 5767 | const char *name = "iwlwifi-3945" IWL3945_UCODE_API ".ucode"; |
| 5768 | u8 *src; |
| 5769 | size_t len; |
| 5770 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 5771 | |
| 5772 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 5773 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5774 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 5775 | if (ret < 0) { |
| 5776 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 5777 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5778 | goto error; |
| 5779 | } |
| 5780 | |
| 5781 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 5782 | name, ucode_raw->size); |
| 5783 | |
| 5784 | /* Make sure that we got at least our header! */ |
| 5785 | if (ucode_raw->size < sizeof(*ucode)) { |
| 5786 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5787 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5788 | goto err_release; |
| 5789 | } |
| 5790 | |
| 5791 | /* Data from ucode file: header followed by uCode images */ |
| 5792 | ucode = (void *)ucode_raw->data; |
| 5793 | |
| 5794 | ver = le32_to_cpu(ucode->ver); |
| 5795 | inst_size = le32_to_cpu(ucode->inst_size); |
| 5796 | data_size = le32_to_cpu(ucode->data_size); |
| 5797 | init_size = le32_to_cpu(ucode->init_size); |
| 5798 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 5799 | boot_size = le32_to_cpu(ucode->boot_size); |
| 5800 | |
| 5801 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 5802 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size); |
| 5803 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size); |
| 5804 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size); |
| 5805 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size); |
| 5806 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5807 | |
| 5808 | /* Verify size of file vs. image size info in file's header */ |
| 5809 | if (ucode_raw->size < sizeof(*ucode) + |
| 5810 | inst_size + data_size + init_size + |
| 5811 | init_data_size + boot_size) { |
| 5812 | |
| 5813 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 5814 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5815 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5816 | goto err_release; |
| 5817 | } |
| 5818 | |
| 5819 | /* Verify that uCode images will fit in card's SRAM */ |
| 5820 | if (inst_size > IWL_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5821 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 5822 | inst_size); |
| 5823 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5824 | goto err_release; |
| 5825 | } |
| 5826 | |
| 5827 | if (data_size > IWL_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5828 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 5829 | data_size); |
| 5830 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5831 | goto err_release; |
| 5832 | } |
| 5833 | if (init_size > IWL_MAX_INST_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5834 | IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n", |
| 5835 | init_size); |
| 5836 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5837 | goto err_release; |
| 5838 | } |
| 5839 | if (init_data_size > IWL_MAX_DATA_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5840 | IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n", |
| 5841 | init_data_size); |
| 5842 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5843 | goto err_release; |
| 5844 | } |
| 5845 | if (boot_size > IWL_MAX_BSM_SIZE) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5846 | IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n", |
| 5847 | boot_size); |
| 5848 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5849 | goto err_release; |
| 5850 | } |
| 5851 | |
| 5852 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 5853 | |
| 5854 | /* Runtime instructions and 2 copies of data: |
| 5855 | * 1) unmodified from disk |
| 5856 | * 2) backup cache for save/restore during power-downs */ |
| 5857 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5858 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5859 | |
| 5860 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5861 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5862 | |
| 5863 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5864 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5865 | |
| 5866 | if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr || |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5867 | !priv->ucode_data_backup.v_addr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5868 | goto err_pci_alloc; |
| 5869 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5870 | /* Initialization instructions and data */ |
| 5871 | if (init_size && init_data_size) { |
| 5872 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5873 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5874 | |
| 5875 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5876 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5877 | |
| 5878 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 5879 | goto err_pci_alloc; |
| 5880 | } |
| 5881 | |
| 5882 | /* Bootstrap (instructions only, no data) */ |
| 5883 | if (boot_size) { |
| 5884 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 5885 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5886 | |
| 5887 | if (!priv->ucode_boot.v_addr) |
| 5888 | goto err_pci_alloc; |
| 5889 | } |
| 5890 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5891 | /* Copy images into buffers for card's bus-master reads ... */ |
| 5892 | |
| 5893 | /* Runtime instructions (first block of data in file) */ |
| 5894 | src = &ucode->data[0]; |
| 5895 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5896 | 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] | 5897 | memcpy(priv->ucode_code.v_addr, src, len); |
| 5898 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 5899 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 5900 | |
| 5901 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5902 | * NOTE: Copy into backup buffer will be done in iwl3945_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5903 | src = &ucode->data[inst_size]; |
| 5904 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5905 | 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] | 5906 | memcpy(priv->ucode_data.v_addr, src, len); |
| 5907 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 5908 | |
| 5909 | /* Initialization instructions (3rd block) */ |
| 5910 | if (init_size) { |
| 5911 | src = &ucode->data[inst_size + data_size]; |
| 5912 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5913 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 5914 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5915 | memcpy(priv->ucode_init.v_addr, src, len); |
| 5916 | } |
| 5917 | |
| 5918 | /* Initialization data (4th block) */ |
| 5919 | if (init_data_size) { |
| 5920 | src = &ucode->data[inst_size + data_size + init_size]; |
| 5921 | len = priv->ucode_init_data.len; |
| 5922 | IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n", |
| 5923 | (int)len); |
| 5924 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 5925 | } |
| 5926 | |
| 5927 | /* Bootstrap instructions (5th block) */ |
| 5928 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 5929 | len = priv->ucode_boot.len; |
| 5930 | IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n", |
| 5931 | (int)len); |
| 5932 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 5933 | |
| 5934 | /* We have our copies now, allow OS release its copies */ |
| 5935 | release_firmware(ucode_raw); |
| 5936 | return 0; |
| 5937 | |
| 5938 | err_pci_alloc: |
| 5939 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5940 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5941 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5942 | |
| 5943 | err_release: |
| 5944 | release_firmware(ucode_raw); |
| 5945 | |
| 5946 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 5947 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5948 | } |
| 5949 | |
| 5950 | |
| 5951 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5952 | * iwl3945_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5953 | * |
| 5954 | * Tell initialization uCode where to find runtime uCode. |
| 5955 | * |
| 5956 | * BSM registers initially contain pointers to initialization uCode. |
| 5957 | * We need to replace them to load runtime uCode inst and data, |
| 5958 | * and to save runtime data when powering down. |
| 5959 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5960 | static int iwl3945_set_ucode_ptrs(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5961 | { |
| 5962 | dma_addr_t pinst; |
| 5963 | dma_addr_t pdata; |
| 5964 | int rc = 0; |
| 5965 | unsigned long flags; |
| 5966 | |
| 5967 | /* bits 31:0 for 3945 */ |
| 5968 | pinst = priv->ucode_code.p_addr; |
| 5969 | pdata = priv->ucode_data_backup.p_addr; |
| 5970 | |
| 5971 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5972 | rc = iwl3945_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5973 | if (rc) { |
| 5974 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5975 | return rc; |
| 5976 | } |
| 5977 | |
| 5978 | /* Tell bootstrap uCode where to find image to load */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5979 | iwl3945_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 5980 | iwl3945_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 5981 | iwl3945_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5982 | priv->ucode_data.len); |
| 5983 | |
| 5984 | /* Inst bytecount must be last to set up, bit 31 signals uCode |
| 5985 | * that all new ptr/size info is in place */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5986 | iwl3945_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5987 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 5988 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5989 | iwl3945_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5990 | |
| 5991 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5992 | |
| 5993 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 5994 | |
| 5995 | return rc; |
| 5996 | } |
| 5997 | |
| 5998 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5999 | * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6000 | * |
| 6001 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 6002 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6003 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6004 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6005 | static void iwl3945_init_alive_start(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6006 | { |
| 6007 | /* Check alive response for "valid" sign from uCode */ |
| 6008 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 6009 | /* We had an error bringing up the hardware, so take it |
| 6010 | * all the way back down so we can try again */ |
| 6011 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 6012 | goto restart; |
| 6013 | } |
| 6014 | |
| 6015 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 6016 | * This is a paranoid check, because we would not have gotten the |
| 6017 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6018 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6019 | /* Runtime instruction load was bad; |
| 6020 | * take it all the way back down so we can try again */ |
| 6021 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 6022 | goto restart; |
| 6023 | } |
| 6024 | |
| 6025 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 6026 | * load and launch runtime uCode, which will send us another "Alive" |
| 6027 | * notification. */ |
| 6028 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6029 | if (iwl3945_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6030 | /* Runtime instruction load won't happen; |
| 6031 | * take it all the way back down so we can try again */ |
| 6032 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 6033 | goto restart; |
| 6034 | } |
| 6035 | return; |
| 6036 | |
| 6037 | restart: |
| 6038 | queue_work(priv->workqueue, &priv->restart); |
| 6039 | } |
| 6040 | |
| 6041 | |
| 6042 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6043 | * iwl3945_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6044 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6045 | * Alive gets handled by iwl3945_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6046 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6047 | static void iwl3945_alive_start(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6048 | { |
| 6049 | int rc = 0; |
| 6050 | int thermal_spin = 0; |
| 6051 | u32 rfkill; |
| 6052 | |
| 6053 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 6054 | |
| 6055 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 6056 | /* We had an error bringing up the hardware, so take it |
| 6057 | * all the way back down so we can try again */ |
| 6058 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 6059 | goto restart; |
| 6060 | } |
| 6061 | |
| 6062 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 6063 | * This is a paranoid check, because we would not have gotten the |
| 6064 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6065 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6066 | /* Runtime instruction load was bad; |
| 6067 | * take it all the way back down so we can try again */ |
| 6068 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 6069 | goto restart; |
| 6070 | } |
| 6071 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6072 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6073 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6074 | rc = iwl3945_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6075 | if (rc) { |
| 6076 | IWL_WARNING("Can not read rfkill status from adapter\n"); |
| 6077 | return; |
| 6078 | } |
| 6079 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6080 | rfkill = iwl3945_read_prph(priv, APMG_RFKILL_REG); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6081 | IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6082 | iwl3945_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6083 | |
| 6084 | if (rfkill & 0x1) { |
| 6085 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 6086 | /* if rfkill is not on, then wait for thermal |
| 6087 | * sensor in adapter to kick in */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6088 | while (iwl3945_hw_get_temperature(priv) == 0) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6089 | thermal_spin++; |
| 6090 | udelay(10); |
| 6091 | } |
| 6092 | |
| 6093 | if (thermal_spin) |
| 6094 | IWL_DEBUG_INFO("Thermal calibration took %dus\n", |
| 6095 | thermal_spin * 10); |
| 6096 | } else |
| 6097 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 6098 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6099 | /* After the ALIVE response, we can send commands to 3945 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6100 | set_bit(STATUS_ALIVE, &priv->status); |
| 6101 | |
| 6102 | /* Clear out the uCode error bit if it is set */ |
| 6103 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 6104 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6105 | if (iwl3945_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6106 | return; |
| 6107 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6108 | ieee80211_start_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6109 | |
| 6110 | priv->active_rate = priv->rates_mask; |
| 6111 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 6112 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6113 | iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(priv->power_mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6114 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6115 | if (iwl3945_is_associated(priv)) { |
| 6116 | struct iwl3945_rxon_cmd *active_rxon = |
| 6117 | (struct iwl3945_rxon_cmd *)(&priv->active_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6118 | |
| 6119 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 6120 | sizeof(priv->staging_rxon)); |
| 6121 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 6122 | } else { |
| 6123 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6124 | iwl3945_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6125 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 6126 | } |
| 6127 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 6128 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6129 | iwl3945_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6130 | |
| 6131 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6132 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6133 | |
| 6134 | /* At this point, the NIC is initialized and operational */ |
| 6135 | priv->notif_missed_beacons = 0; |
| 6136 | set_bit(STATUS_READY, &priv->status); |
| 6137 | |
| 6138 | iwl3945_reg_txpower_periodic(priv); |
| 6139 | |
| 6140 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6141 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6142 | |
| 6143 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6144 | iwl3945_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6145 | |
| 6146 | return; |
| 6147 | |
| 6148 | restart: |
| 6149 | queue_work(priv->workqueue, &priv->restart); |
| 6150 | } |
| 6151 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6152 | static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6153 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6154 | static void __iwl3945_down(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6155 | { |
| 6156 | unsigned long flags; |
| 6157 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6158 | struct ieee80211_conf *conf = NULL; |
| 6159 | |
| 6160 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 6161 | |
| 6162 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6163 | |
| 6164 | if (!exit_pending) |
| 6165 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6166 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6167 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6168 | |
| 6169 | /* Unblock any waiting calls */ |
| 6170 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 6171 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6172 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 6173 | * exiting the module */ |
| 6174 | if (!exit_pending) |
| 6175 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 6176 | |
| 6177 | /* stop and reset the on-board processor */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6178 | iwl3945_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6179 | |
| 6180 | /* tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6181 | iwl3945_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6182 | |
| 6183 | if (priv->mac80211_registered) |
| 6184 | ieee80211_stop_queues(priv->hw); |
| 6185 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6186 | /* If we have not previously called iwl3945_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6187 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6188 | if (!iwl3945_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6189 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6190 | STATUS_RF_KILL_HW | |
| 6191 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6192 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 6193 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 6194 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6195 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6196 | STATUS_IN_SUSPEND; |
| 6197 | goto exit; |
| 6198 | } |
| 6199 | |
| 6200 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 6201 | * SUSPEND bits and continue taking the NIC down. */ |
| 6202 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 6203 | STATUS_RF_KILL_HW | |
| 6204 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 6205 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 6206 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 6207 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6208 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 6209 | STATUS_IN_SUSPEND | |
| 6210 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 6211 | STATUS_FW_ERROR; |
| 6212 | |
| 6213 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6214 | iwl3945_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6215 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6216 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6217 | iwl3945_hw_txq_ctx_stop(priv); |
| 6218 | iwl3945_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6219 | |
| 6220 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6221 | if (!iwl3945_grab_nic_access(priv)) { |
| 6222 | iwl3945_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6223 | APMG_CLK_VAL_DMA_CLK_RQT); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6224 | iwl3945_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6225 | } |
| 6226 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6227 | |
| 6228 | udelay(5); |
| 6229 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6230 | iwl3945_hw_nic_stop_master(priv); |
| 6231 | iwl3945_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
| 6232 | iwl3945_hw_nic_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6233 | |
| 6234 | exit: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6235 | memset(&priv->card_alive, 0, sizeof(struct iwl3945_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6236 | |
| 6237 | if (priv->ibss_beacon) |
| 6238 | dev_kfree_skb(priv->ibss_beacon); |
| 6239 | priv->ibss_beacon = NULL; |
| 6240 | |
| 6241 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6242 | iwl3945_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6243 | } |
| 6244 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6245 | static void iwl3945_down(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6246 | { |
| 6247 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6248 | __iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6249 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 6250 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6251 | iwl3945_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6252 | } |
| 6253 | |
| 6254 | #define MAX_HW_RESTARTS 5 |
| 6255 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6256 | static int __iwl3945_up(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6257 | { |
| 6258 | int rc, i; |
| 6259 | |
| 6260 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6261 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 6262 | return -EIO; |
| 6263 | } |
| 6264 | |
| 6265 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 6266 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 6267 | "parameter)\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6268 | return -ENODEV; |
| 6269 | } |
| 6270 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 6271 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 6272 | IWL_ERROR("ucode not available for device bringup\n"); |
| 6273 | return -EIO; |
| 6274 | } |
| 6275 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6276 | /* If platform's RF_KILL switch is NOT set to KILL */ |
| 6277 | if (iwl3945_read32(priv, CSR_GP_CNTRL) & |
| 6278 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 6279 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 6280 | else { |
| 6281 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 6282 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
| 6283 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 6284 | return -ENODEV; |
| 6285 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6286 | } |
| 6287 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6288 | iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6289 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6290 | rc = iwl3945_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6291 | if (rc) { |
| 6292 | IWL_ERROR("Unable to int nic\n"); |
| 6293 | return rc; |
| 6294 | } |
| 6295 | |
| 6296 | /* make sure rfkill handshake bits are cleared */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6297 | iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6298 | iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6299 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 6300 | |
| 6301 | /* clear (again), then enable host interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6302 | iwl3945_write32(priv, CSR_INT, 0xFFFFFFFF); |
| 6303 | iwl3945_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6304 | |
| 6305 | /* really make sure rfkill handshake bits are cleared */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6306 | iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 6307 | iwl3945_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6308 | |
| 6309 | /* Copy original ucode data image from disk into backup cache. |
| 6310 | * This will be used to initialize the on-board processor's |
| 6311 | * data SRAM for a clean start when the runtime program first loads. */ |
| 6312 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6313 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6314 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6315 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 6316 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 6317 | return 0; |
| 6318 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6319 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 6320 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6321 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6322 | |
| 6323 | /* load bootstrap state machine, |
| 6324 | * load bootstrap program into processor's memory, |
| 6325 | * prepare to load the "initialize" uCode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6326 | rc = iwl3945_load_bsm(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6327 | |
| 6328 | if (rc) { |
| 6329 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc); |
| 6330 | continue; |
| 6331 | } |
| 6332 | |
| 6333 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6334 | iwl3945_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6335 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6336 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 6337 | |
| 6338 | return 0; |
| 6339 | } |
| 6340 | |
| 6341 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6342 | __iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6343 | |
| 6344 | /* tried to restart and config the device for as long as our |
| 6345 | * patience could withstand */ |
| 6346 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 6347 | return -EIO; |
| 6348 | } |
| 6349 | |
| 6350 | |
| 6351 | /***************************************************************************** |
| 6352 | * |
| 6353 | * Workqueue callbacks |
| 6354 | * |
| 6355 | *****************************************************************************/ |
| 6356 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6357 | static void iwl3945_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6358 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6359 | struct iwl3945_priv *priv = |
| 6360 | container_of(data, struct iwl3945_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6361 | |
| 6362 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6363 | return; |
| 6364 | |
| 6365 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6366 | iwl3945_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6367 | mutex_unlock(&priv->mutex); |
| 6368 | } |
| 6369 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6370 | static void iwl3945_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6371 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6372 | struct iwl3945_priv *priv = |
| 6373 | container_of(data, struct iwl3945_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6374 | |
| 6375 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6376 | return; |
| 6377 | |
| 6378 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6379 | iwl3945_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6380 | mutex_unlock(&priv->mutex); |
| 6381 | } |
| 6382 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6383 | static void iwl3945_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6384 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6385 | struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6386 | |
| 6387 | wake_up_interruptible(&priv->wait_command_queue); |
| 6388 | |
| 6389 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6390 | return; |
| 6391 | |
| 6392 | mutex_lock(&priv->mutex); |
| 6393 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6394 | if (!iwl3945_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6395 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_RF_KILL, |
| 6396 | "HW and/or SW RF Kill no longer active, restarting " |
| 6397 | "device\n"); |
| 6398 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6399 | queue_work(priv->workqueue, &priv->restart); |
| 6400 | } else { |
| 6401 | |
| 6402 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 6403 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 6404 | "disabled by SW switch\n"); |
| 6405 | else |
| 6406 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 6407 | "Kill switch must be turned off for " |
| 6408 | "wireless networking to work.\n"); |
| 6409 | } |
| 6410 | mutex_unlock(&priv->mutex); |
| 6411 | } |
| 6412 | |
| 6413 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 6414 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6415 | static void iwl3945_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6416 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6417 | struct iwl3945_priv *priv = |
| 6418 | container_of(data, struct iwl3945_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6419 | |
| 6420 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6421 | return; |
| 6422 | |
| 6423 | mutex_lock(&priv->mutex); |
| 6424 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 6425 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6426 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, |
| 6427 | "Scan completion watchdog resetting adapter (%dms)\n", |
| 6428 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6429 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6430 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6431 | iwl3945_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6432 | } |
| 6433 | mutex_unlock(&priv->mutex); |
| 6434 | } |
| 6435 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6436 | static void iwl3945_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6437 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6438 | struct iwl3945_priv *priv = |
| 6439 | container_of(data, struct iwl3945_priv, request_scan); |
| 6440 | struct iwl3945_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6441 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6442 | .len = sizeof(struct iwl3945_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6443 | .meta.flags = CMD_SIZE_HUGE, |
| 6444 | }; |
| 6445 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6446 | struct iwl3945_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6447 | struct ieee80211_conf *conf = NULL; |
| 6448 | u8 direct_mask; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6449 | enum ieee80211_band band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6450 | |
| 6451 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6452 | |
| 6453 | mutex_lock(&priv->mutex); |
| 6454 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6455 | if (!iwl3945_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6456 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 6457 | goto done; |
| 6458 | } |
| 6459 | |
| 6460 | /* Make sure the scan wasn't cancelled before this queued work |
| 6461 | * was given the chance to run... */ |
| 6462 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 6463 | goto done; |
| 6464 | |
| 6465 | /* This should never be called or scheduled if there is currently |
| 6466 | * a scan active in the hardware. */ |
| 6467 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 6468 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 6469 | "Ignoring second request.\n"); |
| 6470 | rc = -EIO; |
| 6471 | goto done; |
| 6472 | } |
| 6473 | |
| 6474 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 6475 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 6476 | goto done; |
| 6477 | } |
| 6478 | |
| 6479 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 6480 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 6481 | goto done; |
| 6482 | } |
| 6483 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6484 | if (iwl3945_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6485 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 6486 | goto done; |
| 6487 | } |
| 6488 | |
| 6489 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 6490 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 6491 | goto done; |
| 6492 | } |
| 6493 | |
| 6494 | if (!priv->scan_bands) { |
| 6495 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 6496 | goto done; |
| 6497 | } |
| 6498 | |
| 6499 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6500 | priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6501 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 6502 | if (!priv->scan) { |
| 6503 | rc = -ENOMEM; |
| 6504 | goto done; |
| 6505 | } |
| 6506 | } |
| 6507 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6508 | memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6509 | |
| 6510 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 6511 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 6512 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6513 | if (iwl3945_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6514 | u16 interval = 0; |
| 6515 | u32 extra; |
| 6516 | u32 suspend_time = 100; |
| 6517 | u32 scan_suspend_time = 100; |
| 6518 | unsigned long flags; |
| 6519 | |
| 6520 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 6521 | |
| 6522 | spin_lock_irqsave(&priv->lock, flags); |
| 6523 | interval = priv->beacon_int; |
| 6524 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6525 | |
| 6526 | scan->suspend_time = 0; |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6527 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6528 | if (!interval) |
| 6529 | interval = suspend_time; |
| 6530 | /* |
| 6531 | * suspend time format: |
| 6532 | * 0-19: beacon interval in usec (time before exec.) |
| 6533 | * 20-23: 0 |
| 6534 | * 24-31: number of beacons (suspend between channels) |
| 6535 | */ |
| 6536 | |
| 6537 | extra = (suspend_time / interval) << 24; |
| 6538 | scan_suspend_time = 0xFF0FFFFF & |
| 6539 | (extra | ((suspend_time % interval) * 1024)); |
| 6540 | |
| 6541 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 6542 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 6543 | scan_suspend_time, interval); |
| 6544 | } |
| 6545 | |
| 6546 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 6547 | if (priv->one_direct_scan) { |
| 6548 | IWL_DEBUG_SCAN |
| 6549 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6550 | iwl3945_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6551 | priv->direct_ssid_len)); |
| 6552 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 6553 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 6554 | memcpy(scan->direct_scan[0].ssid, |
| 6555 | priv->direct_ssid, priv->direct_ssid_len); |
| 6556 | direct_mask = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6557 | } else if (!iwl3945_is_associated(priv) && priv->essid_len) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6558 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 6559 | scan->direct_scan[0].len = priv->essid_len; |
| 6560 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 6561 | direct_mask = 1; |
| 6562 | } else |
| 6563 | direct_mask = 0; |
| 6564 | |
| 6565 | /* We don't build a direct scan probe request; the uCode will do |
| 6566 | * that based on the direct_mask added to each channel entry */ |
| 6567 | scan->tx_cmd.len = cpu_to_le16( |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6568 | iwl3945_fill_probe_req(priv, (struct ieee80211_mgmt *)scan->data, |
Cyrill Gorcunov | 18904f5 | 2008-01-26 19:09:36 +0300 | [diff] [blame] | 6569 | IWL_MAX_SCAN_SIZE - sizeof(*scan), 0)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6570 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
| 6571 | scan->tx_cmd.sta_id = priv->hw_setting.bcast_sta_id; |
| 6572 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 6573 | |
| 6574 | /* flags + rate selection */ |
| 6575 | |
| 6576 | switch (priv->scan_bands) { |
| 6577 | case 2: |
| 6578 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 6579 | scan->tx_cmd.rate = IWL_RATE_1M_PLCP; |
| 6580 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6581 | band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6582 | break; |
| 6583 | |
| 6584 | case 1: |
| 6585 | scan->tx_cmd.rate = IWL_RATE_6M_PLCP; |
| 6586 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6587 | band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6588 | break; |
| 6589 | |
| 6590 | default: |
| 6591 | IWL_WARNING("Invalid scan band count\n"); |
| 6592 | goto done; |
| 6593 | } |
| 6594 | |
| 6595 | /* select Rx antennas */ |
| 6596 | scan->flags |= iwl3945_get_antenna_flags(priv); |
| 6597 | |
| 6598 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 6599 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 6600 | |
| 6601 | if (direct_mask) |
| 6602 | IWL_DEBUG_SCAN |
| 6603 | ("Initiating direct scan for %s.\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6604 | iwl3945_escape_essid(priv->essid, priv->essid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6605 | else |
| 6606 | IWL_DEBUG_SCAN("Initiating indirect scan.\n"); |
| 6607 | |
| 6608 | scan->channel_count = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6609 | iwl3945_get_channels_for_scan( |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6610 | priv, band, 1, /* active */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6611 | direct_mask, |
| 6612 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
| 6613 | |
| 6614 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6615 | scan->channel_count * sizeof(struct iwl3945_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6616 | cmd.data = scan; |
| 6617 | scan->len = cpu_to_le16(cmd.len); |
| 6618 | |
| 6619 | set_bit(STATUS_SCAN_HW, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6620 | rc = iwl3945_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6621 | if (rc) |
| 6622 | goto done; |
| 6623 | |
| 6624 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 6625 | IWL_SCAN_CHECK_WATCHDOG); |
| 6626 | |
| 6627 | mutex_unlock(&priv->mutex); |
| 6628 | return; |
| 6629 | |
| 6630 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 6631 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6632 | queue_work(priv->workqueue, &priv->scan_completed); |
| 6633 | mutex_unlock(&priv->mutex); |
| 6634 | } |
| 6635 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6636 | static void iwl3945_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6637 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6638 | struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6639 | |
| 6640 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6641 | return; |
| 6642 | |
| 6643 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6644 | __iwl3945_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6645 | mutex_unlock(&priv->mutex); |
| 6646 | } |
| 6647 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6648 | static void iwl3945_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6649 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6650 | struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6651 | |
| 6652 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6653 | return; |
| 6654 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6655 | iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6656 | queue_work(priv->workqueue, &priv->up); |
| 6657 | } |
| 6658 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6659 | static void iwl3945_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6660 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6661 | struct iwl3945_priv *priv = |
| 6662 | container_of(data, struct iwl3945_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6663 | |
| 6664 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6665 | return; |
| 6666 | |
| 6667 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6668 | iwl3945_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6669 | mutex_unlock(&priv->mutex); |
| 6670 | } |
| 6671 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6672 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 6673 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6674 | static void iwl3945_bg_post_associate(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6675 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6676 | struct iwl3945_priv *priv = container_of(data, struct iwl3945_priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6677 | post_associate.work); |
| 6678 | |
| 6679 | int rc = 0; |
| 6680 | struct ieee80211_conf *conf = NULL; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6681 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6682 | |
| 6683 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 6684 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 6685 | return; |
| 6686 | } |
| 6687 | |
| 6688 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6689 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 6690 | priv->assoc_id, |
| 6691 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6692 | |
| 6693 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6694 | return; |
| 6695 | |
| 6696 | mutex_lock(&priv->mutex); |
| 6697 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6698 | if (!priv->vif || !priv->is_open) { |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6699 | mutex_unlock(&priv->mutex); |
| 6700 | return; |
| 6701 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6702 | iwl3945_scan_cancel_timeout(priv, 200); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 6703 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6704 | conf = ieee80211_get_hw_conf(priv->hw); |
| 6705 | |
| 6706 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6707 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6708 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6709 | memset(&priv->rxon_timing, 0, sizeof(struct iwl3945_rxon_time_cmd)); |
| 6710 | iwl3945_setup_rxon_timing(priv); |
| 6711 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6712 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 6713 | if (rc) |
| 6714 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 6715 | "Attempting to continue.\n"); |
| 6716 | |
| 6717 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 6718 | |
| 6719 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 6720 | |
| 6721 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 6722 | priv->assoc_id, priv->beacon_int); |
| 6723 | |
| 6724 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 6725 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6726 | else |
| 6727 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 6728 | |
| 6729 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 6730 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 6731 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 6732 | else |
| 6733 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 6734 | |
| 6735 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 6736 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 6737 | |
| 6738 | } |
| 6739 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6740 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6741 | |
| 6742 | switch (priv->iw_mode) { |
| 6743 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6744 | iwl3945_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6745 | break; |
| 6746 | |
| 6747 | case IEEE80211_IF_TYPE_IBSS: |
| 6748 | |
| 6749 | /* clear out the station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6750 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6751 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6752 | iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0); |
| 6753 | iwl3945_add_station(priv, priv->bssid, 0, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6754 | iwl3945_sync_sta(priv, IWL_STA_ID, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6755 | (priv->band == IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6756 | IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP, |
| 6757 | CMD_ASYNC); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6758 | iwl3945_rate_scale_init(priv->hw, IWL_STA_ID); |
| 6759 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6760 | |
| 6761 | break; |
| 6762 | |
| 6763 | default: |
| 6764 | IWL_ERROR("%s Should not be called in %d mode\n", |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 6765 | __FUNCTION__, priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6766 | break; |
| 6767 | } |
| 6768 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6769 | iwl3945_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6770 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6771 | iwl3945_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 6772 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 6773 | /* we have just associated, don't start scan too early */ |
| 6774 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6775 | mutex_unlock(&priv->mutex); |
| 6776 | } |
| 6777 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6778 | static void iwl3945_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6779 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6780 | struct iwl3945_priv *priv = container_of(work, struct iwl3945_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6781 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6782 | if (!iwl3945_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6783 | return; |
| 6784 | |
| 6785 | mutex_lock(&priv->mutex); |
| 6786 | |
| 6787 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6788 | iwl3945_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6789 | |
| 6790 | mutex_unlock(&priv->mutex); |
| 6791 | } |
| 6792 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6793 | static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 6794 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6795 | static void iwl3945_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6796 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6797 | struct iwl3945_priv *priv = |
| 6798 | container_of(work, struct iwl3945_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6799 | |
| 6800 | IWL_DEBUG(IWL_DL_INFO | IWL_DL_SCAN, "SCAN complete scan\n"); |
| 6801 | |
| 6802 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 6803 | return; |
| 6804 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 6805 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
| 6806 | iwl3945_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 6807 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6808 | ieee80211_scan_completed(priv->hw); |
| 6809 | |
| 6810 | /* Since setting the TXPOWER may have been deferred while |
| 6811 | * performing the scan, fire one off */ |
| 6812 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6813 | iwl3945_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6814 | mutex_unlock(&priv->mutex); |
| 6815 | } |
| 6816 | |
| 6817 | /***************************************************************************** |
| 6818 | * |
| 6819 | * mac80211 entry point functions |
| 6820 | * |
| 6821 | *****************************************************************************/ |
| 6822 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6823 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 6824 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6825 | static int iwl3945_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6826 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6827 | struct iwl3945_priv *priv = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6828 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6829 | |
| 6830 | IWL_DEBUG_MAC80211("enter\n"); |
| 6831 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6832 | if (pci_enable_device(priv->pci_dev)) { |
| 6833 | IWL_ERROR("Fail to pci_enable_device\n"); |
| 6834 | return -ENODEV; |
| 6835 | } |
| 6836 | pci_restore_state(priv->pci_dev); |
| 6837 | pci_enable_msi(priv->pci_dev); |
| 6838 | |
| 6839 | ret = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED, |
| 6840 | DRV_NAME, priv); |
| 6841 | if (ret) { |
| 6842 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 6843 | goto out_disable_msi; |
| 6844 | } |
| 6845 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6846 | /* we should be verifying the device is ready to be opened */ |
| 6847 | mutex_lock(&priv->mutex); |
| 6848 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6849 | memset(&priv->staging_rxon, 0, sizeof(struct iwl3945_rxon_cmd)); |
| 6850 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 6851 | * ucode filename and max sizes are card-specific. */ |
| 6852 | |
| 6853 | if (!priv->ucode_code.len) { |
| 6854 | ret = iwl3945_read_ucode(priv); |
| 6855 | if (ret) { |
| 6856 | IWL_ERROR("Could not read microcode: %d\n", ret); |
| 6857 | mutex_unlock(&priv->mutex); |
| 6858 | goto out_release_irq; |
| 6859 | } |
| 6860 | } |
| 6861 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6862 | ret = __iwl3945_up(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6863 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6864 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6865 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6866 | if (ret) |
| 6867 | goto out_release_irq; |
| 6868 | |
| 6869 | IWL_DEBUG_INFO("Start UP work.\n"); |
| 6870 | |
| 6871 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 6872 | return 0; |
| 6873 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6874 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 6875 | * mac80211 will not be run successfully. */ |
| 6876 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 6877 | test_bit(STATUS_READY, &priv->status), |
| 6878 | UCODE_READY_TIMEOUT); |
| 6879 | if (!ret) { |
| 6880 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 6881 | IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n", |
| 6882 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 6883 | ret = -ETIMEDOUT; |
| 6884 | goto out_release_irq; |
| 6885 | } |
| 6886 | } |
| 6887 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6888 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6889 | IWL_DEBUG_MAC80211("leave\n"); |
| 6890 | return 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6891 | |
| 6892 | out_release_irq: |
| 6893 | free_irq(priv->pci_dev->irq, priv); |
| 6894 | out_disable_msi: |
| 6895 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6896 | pci_disable_device(priv->pci_dev); |
| 6897 | priv->is_open = 0; |
| 6898 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6899 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6900 | } |
| 6901 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6902 | static void iwl3945_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6903 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6904 | struct iwl3945_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6905 | |
| 6906 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6907 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6908 | if (!priv->is_open) { |
| 6909 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 6910 | return; |
| 6911 | } |
| 6912 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6913 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6914 | |
| 6915 | if (iwl3945_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6916 | /* stop mac, cancel any scan request and clear |
| 6917 | * RXON_FILTER_ASSOC_MSK BIT |
| 6918 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6919 | mutex_lock(&priv->mutex); |
| 6920 | iwl3945_scan_cancel_timeout(priv, 100); |
| 6921 | cancel_delayed_work(&priv->post_associate); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6922 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 6923 | } |
| 6924 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6925 | iwl3945_down(priv); |
| 6926 | |
| 6927 | flush_workqueue(priv->workqueue); |
| 6928 | free_irq(priv->pci_dev->irq, priv); |
| 6929 | pci_disable_msi(priv->pci_dev); |
| 6930 | pci_save_state(priv->pci_dev); |
| 6931 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 6932 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6933 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6934 | } |
| 6935 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6936 | static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6937 | struct ieee80211_tx_control *ctl) |
| 6938 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6939 | struct iwl3945_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6940 | |
| 6941 | IWL_DEBUG_MAC80211("enter\n"); |
| 6942 | |
| 6943 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 6944 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 6945 | return -1; |
| 6946 | } |
| 6947 | |
| 6948 | 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] | 6949 | ctl->tx_rate->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6950 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6951 | if (iwl3945_tx_skb(priv, skb, ctl)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6952 | dev_kfree_skb_any(skb); |
| 6953 | |
| 6954 | IWL_DEBUG_MAC80211("leave\n"); |
| 6955 | return 0; |
| 6956 | } |
| 6957 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6958 | static int iwl3945_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6959 | struct ieee80211_if_init_conf *conf) |
| 6960 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6961 | struct iwl3945_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6962 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 6963 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6964 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6965 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6966 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6967 | if (priv->vif) { |
| 6968 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6969 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6970 | } |
| 6971 | |
| 6972 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 6973 | priv->vif = conf->vif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6974 | |
| 6975 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6976 | |
| 6977 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 6978 | |
| 6979 | if (conf->mac_addr) { |
| 6980 | IWL_DEBUG_MAC80211("Set: %s\n", print_mac(mac, conf->mac_addr)); |
| 6981 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 6982 | } |
| 6983 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6984 | if (iwl3945_is_ready(priv)) |
| 6985 | iwl3945_set_mode(priv, conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6986 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6987 | mutex_unlock(&priv->mutex); |
| 6988 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6989 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6990 | return 0; |
| 6991 | } |
| 6992 | |
| 6993 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6994 | * iwl3945_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6995 | * |
| 6996 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 6997 | * be set inappropriately and the driver currently sets the hardware up to |
| 6998 | * use it whenever needed. |
| 6999 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7000 | static int iwl3945_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7001 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7002 | struct iwl3945_priv *priv = hw->priv; |
| 7003 | const struct iwl3945_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7004 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7005 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7006 | |
| 7007 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7008 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7009 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 7010 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
| 7011 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7012 | if (!iwl3945_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7013 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7014 | ret = -EIO; |
| 7015 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7016 | } |
| 7017 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7018 | if (unlikely(!iwl3945_param_disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7019 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7020 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 7021 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7022 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7023 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7024 | } |
| 7025 | |
| 7026 | spin_lock_irqsave(&priv->lock, flags); |
| 7027 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7028 | ch_info = iwl3945_get_channel_info(priv, conf->channel->band, |
| 7029 | conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7030 | if (!is_channel_valid(ch_info)) { |
| 7031 | IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n", |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7032 | conf->channel->hw_value, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7033 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 7034 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7035 | ret = -EINVAL; |
| 7036 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7037 | } |
| 7038 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7039 | iwl3945_set_rxon_channel(priv, conf->channel->band, conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7040 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 7041 | iwl3945_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7042 | |
| 7043 | /* The list of supported rates and rate mask can be different |
| 7044 | * for each phymode; since the phymode may have changed, reset |
| 7045 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7046 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7047 | |
| 7048 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7049 | |
| 7050 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 7051 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7052 | iwl3945_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7053 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7054 | } |
| 7055 | #endif |
| 7056 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7057 | iwl3945_radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7058 | |
| 7059 | if (!conf->radio_enabled) { |
| 7060 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7061 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7062 | } |
| 7063 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7064 | if (iwl3945_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7065 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7066 | ret = -EIO; |
| 7067 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7068 | } |
| 7069 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7070 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7071 | |
| 7072 | if (memcmp(&priv->active_rxon, |
| 7073 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7074 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7075 | else |
| 7076 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 7077 | |
| 7078 | IWL_DEBUG_MAC80211("leave\n"); |
| 7079 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7080 | out: |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 7081 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7082 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 7083 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7084 | } |
| 7085 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7086 | static void iwl3945_config_ap(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7087 | { |
| 7088 | int rc = 0; |
| 7089 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 7090 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7091 | return; |
| 7092 | |
| 7093 | /* The following should be done only at AP bring up */ |
| 7094 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 7095 | |
| 7096 | /* RXON - unassoc (to set timing command) */ |
| 7097 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7098 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7099 | |
| 7100 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7101 | memset(&priv->rxon_timing, 0, sizeof(struct iwl3945_rxon_time_cmd)); |
| 7102 | iwl3945_setup_rxon_timing(priv); |
| 7103 | rc = iwl3945_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7104 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 7105 | if (rc) |
| 7106 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 7107 | "Attempting to continue.\n"); |
| 7108 | |
| 7109 | /* FIXME: what should be the assoc_id for AP? */ |
| 7110 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 7111 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 7112 | priv->staging_rxon.flags |= |
| 7113 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7114 | else |
| 7115 | priv->staging_rxon.flags &= |
| 7116 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 7117 | |
| 7118 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 7119 | if (priv->assoc_capability & |
| 7120 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 7121 | priv->staging_rxon.flags |= |
| 7122 | RXON_FLG_SHORT_SLOT_MSK; |
| 7123 | else |
| 7124 | priv->staging_rxon.flags &= |
| 7125 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7126 | |
| 7127 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 7128 | priv->staging_rxon.flags &= |
| 7129 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 7130 | } |
| 7131 | /* restore RXON assoc */ |
| 7132 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7133 | iwl3945_commit_rxon(priv); |
| 7134 | iwl3945_add_station(priv, iwl3945_broadcast_addr, 0, 0); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 7135 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7136 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7137 | |
| 7138 | /* FIXME - we need to add code here to detect a totally new |
| 7139 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 7140 | * clear sta table, add BCAST sta... */ |
| 7141 | } |
| 7142 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7143 | static int iwl3945_mac_config_interface(struct ieee80211_hw *hw, |
| 7144 | struct ieee80211_vif *vif, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7145 | struct ieee80211_if_conf *conf) |
| 7146 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7147 | struct iwl3945_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7148 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7149 | unsigned long flags; |
| 7150 | int rc; |
| 7151 | |
| 7152 | if (conf == NULL) |
| 7153 | return -EIO; |
| 7154 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7155 | /* XXX: this MUST use conf->mac_addr */ |
| 7156 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7157 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 7158 | (!conf->beacon || !conf->ssid_len)) { |
| 7159 | IWL_DEBUG_MAC80211 |
| 7160 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 7161 | return 0; |
| 7162 | } |
| 7163 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 7164 | if (!iwl3945_is_alive(priv)) |
| 7165 | return -EAGAIN; |
| 7166 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7167 | mutex_lock(&priv->mutex); |
| 7168 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7169 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7170 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 7171 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7172 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7173 | /* |
| 7174 | * very dubious code was here; the probe filtering flag is never set: |
| 7175 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7176 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 7177 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7178 | */ |
| 7179 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7180 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 7181 | mutex_unlock(&priv->mutex); |
| 7182 | return 0; |
| 7183 | } |
| 7184 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7185 | if (priv->vif != vif) { |
| 7186 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7187 | mutex_unlock(&priv->mutex); |
| 7188 | return 0; |
| 7189 | } |
| 7190 | |
| 7191 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 7192 | if (!conf->bssid) { |
| 7193 | conf->bssid = priv->mac_addr; |
| 7194 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7195 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 7196 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7197 | } |
| 7198 | if (priv->ibss_beacon) |
| 7199 | dev_kfree_skb(priv->ibss_beacon); |
| 7200 | |
| 7201 | priv->ibss_beacon = conf->beacon; |
| 7202 | } |
| 7203 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7204 | if (iwl3945_is_rfkill(priv)) |
| 7205 | goto done; |
| 7206 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7207 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 7208 | !is_multicast_ether_addr(conf->bssid)) { |
| 7209 | /* If there is currently a HW scan going on in the background |
| 7210 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7211 | if (iwl3945_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7212 | IWL_WARNING("Aborted scan still in progress " |
| 7213 | "after 100ms\n"); |
| 7214 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 7215 | mutex_unlock(&priv->mutex); |
| 7216 | return -EAGAIN; |
| 7217 | } |
| 7218 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 7219 | |
| 7220 | /* TODO: Audit driver for usage of these members and see |
| 7221 | * if mac80211 deprecates them (priv->bssid looks like it |
| 7222 | * shouldn't be there, but I haven't scanned the IBSS code |
| 7223 | * to verify) - jpk */ |
| 7224 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 7225 | |
| 7226 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7227 | iwl3945_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7228 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7229 | rc = iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7230 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7231 | iwl3945_add_station(priv, |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 7232 | priv->active_rxon.bssid_addr, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7233 | } |
| 7234 | |
| 7235 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7236 | iwl3945_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7237 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7238 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7239 | } |
| 7240 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7241 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7242 | spin_lock_irqsave(&priv->lock, flags); |
| 7243 | if (!conf->ssid_len) |
| 7244 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7245 | else |
| 7246 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 7247 | |
| 7248 | priv->essid_len = conf->ssid_len; |
| 7249 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7250 | |
| 7251 | IWL_DEBUG_MAC80211("leave\n"); |
| 7252 | mutex_unlock(&priv->mutex); |
| 7253 | |
| 7254 | return 0; |
| 7255 | } |
| 7256 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7257 | static void iwl3945_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7258 | unsigned int changed_flags, |
| 7259 | unsigned int *total_flags, |
| 7260 | int mc_count, struct dev_addr_list *mc_list) |
| 7261 | { |
| 7262 | /* |
| 7263 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7264 | * see also iwl3945_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 7265 | */ |
| 7266 | *total_flags = 0; |
| 7267 | } |
| 7268 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7269 | static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7270 | struct ieee80211_if_init_conf *conf) |
| 7271 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7272 | struct iwl3945_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7273 | |
| 7274 | IWL_DEBUG_MAC80211("enter\n"); |
| 7275 | |
| 7276 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 7277 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7278 | if (iwl3945_is_ready_rf(priv)) { |
| 7279 | iwl3945_scan_cancel_timeout(priv, 100); |
| 7280 | cancel_delayed_work(&priv->post_associate); |
| 7281 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 7282 | iwl3945_commit_rxon(priv); |
| 7283 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 7284 | if (priv->vif == conf->vif) { |
| 7285 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7286 | memset(priv->bssid, 0, ETH_ALEN); |
| 7287 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 7288 | priv->essid_len = 0; |
| 7289 | } |
| 7290 | mutex_unlock(&priv->mutex); |
| 7291 | |
| 7292 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7293 | } |
| 7294 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7295 | static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7296 | { |
| 7297 | int rc = 0; |
| 7298 | unsigned long flags; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7299 | struct iwl3945_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7300 | |
| 7301 | IWL_DEBUG_MAC80211("enter\n"); |
| 7302 | |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 7303 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7304 | spin_lock_irqsave(&priv->lock, flags); |
| 7305 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7306 | if (!iwl3945_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7307 | rc = -EIO; |
| 7308 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 7309 | goto out_unlock; |
| 7310 | } |
| 7311 | |
| 7312 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 7313 | rc = -EIO; |
| 7314 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 7315 | goto out_unlock; |
| 7316 | } |
| 7317 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7318 | /* we don't schedule scan within next_scan_jiffies period */ |
| 7319 | if (priv->next_scan_jiffies && |
| 7320 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 7321 | rc = -EAGAIN; |
| 7322 | goto out_unlock; |
| 7323 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7324 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7325 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 7326 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7327 | rc = -EAGAIN; |
| 7328 | goto out_unlock; |
| 7329 | } |
| 7330 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 7331 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7332 | iwl3945_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7333 | |
| 7334 | priv->one_direct_scan = 1; |
| 7335 | priv->direct_ssid_len = (u8) |
| 7336 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 7337 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 7338 | } else |
| 7339 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7340 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7341 | rc = iwl3945_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7342 | |
| 7343 | IWL_DEBUG_MAC80211("leave\n"); |
| 7344 | |
| 7345 | out_unlock: |
| 7346 | spin_unlock_irqrestore(&priv->lock, flags); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 7347 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7348 | |
| 7349 | return rc; |
| 7350 | } |
| 7351 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7352 | static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7353 | const u8 *local_addr, const u8 *addr, |
| 7354 | struct ieee80211_key_conf *key) |
| 7355 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7356 | struct iwl3945_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7357 | int rc = 0; |
| 7358 | u8 sta_id; |
| 7359 | |
| 7360 | IWL_DEBUG_MAC80211("enter\n"); |
| 7361 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7362 | if (!iwl3945_param_hwcrypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7363 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 7364 | return -EOPNOTSUPP; |
| 7365 | } |
| 7366 | |
| 7367 | if (is_zero_ether_addr(addr)) |
| 7368 | /* only support pairwise keys */ |
| 7369 | return -EOPNOTSUPP; |
| 7370 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7371 | sta_id = iwl3945_hw_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7372 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 7373 | DECLARE_MAC_BUF(mac); |
| 7374 | |
| 7375 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 7376 | print_mac(mac, addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7377 | return -EINVAL; |
| 7378 | } |
| 7379 | |
| 7380 | mutex_lock(&priv->mutex); |
| 7381 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7382 | iwl3945_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 7383 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7384 | switch (cmd) { |
| 7385 | case SET_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7386 | rc = iwl3945_update_sta_key_info(priv, key, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7387 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7388 | iwl3945_set_rxon_hwcrypto(priv, 1); |
| 7389 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7390 | key->hw_key_idx = sta_id; |
| 7391 | IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n"); |
| 7392 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 7393 | } |
| 7394 | break; |
| 7395 | case DISABLE_KEY: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7396 | rc = iwl3945_clear_sta_key_info(priv, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7397 | if (!rc) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7398 | iwl3945_set_rxon_hwcrypto(priv, 0); |
| 7399 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7400 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
| 7401 | } |
| 7402 | break; |
| 7403 | default: |
| 7404 | rc = -EINVAL; |
| 7405 | } |
| 7406 | |
| 7407 | IWL_DEBUG_MAC80211("leave\n"); |
| 7408 | mutex_unlock(&priv->mutex); |
| 7409 | |
| 7410 | return rc; |
| 7411 | } |
| 7412 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7413 | static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, int queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7414 | const struct ieee80211_tx_queue_params *params) |
| 7415 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7416 | struct iwl3945_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7417 | unsigned long flags; |
| 7418 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7419 | |
| 7420 | IWL_DEBUG_MAC80211("enter\n"); |
| 7421 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7422 | if (!iwl3945_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7423 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7424 | return -EIO; |
| 7425 | } |
| 7426 | |
| 7427 | if (queue >= AC_NUM) { |
| 7428 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 7429 | return 0; |
| 7430 | } |
| 7431 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7432 | if (!priv->qos_data.qos_enable) { |
| 7433 | priv->qos_data.qos_active = 0; |
| 7434 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 7435 | return 0; |
| 7436 | } |
| 7437 | q = AC_NUM - 1 - queue; |
| 7438 | |
| 7439 | spin_lock_irqsave(&priv->lock, flags); |
| 7440 | |
| 7441 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 7442 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 7443 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 7444 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame^] | 7445 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7446 | |
| 7447 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 7448 | priv->qos_data.qos_active = 1; |
| 7449 | |
| 7450 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7451 | |
| 7452 | mutex_lock(&priv->mutex); |
| 7453 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7454 | iwl3945_activate_qos(priv, 1); |
| 7455 | else if (priv->assoc_id && iwl3945_is_associated(priv)) |
| 7456 | iwl3945_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7457 | |
| 7458 | mutex_unlock(&priv->mutex); |
| 7459 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7460 | IWL_DEBUG_MAC80211("leave\n"); |
| 7461 | return 0; |
| 7462 | } |
| 7463 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7464 | static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7465 | struct ieee80211_tx_queue_stats *stats) |
| 7466 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7467 | struct iwl3945_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7468 | int i, avail; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7469 | struct iwl3945_tx_queue *txq; |
| 7470 | struct iwl3945_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7471 | unsigned long flags; |
| 7472 | |
| 7473 | IWL_DEBUG_MAC80211("enter\n"); |
| 7474 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7475 | if (!iwl3945_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7476 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7477 | return -EIO; |
| 7478 | } |
| 7479 | |
| 7480 | spin_lock_irqsave(&priv->lock, flags); |
| 7481 | |
| 7482 | for (i = 0; i < AC_NUM; i++) { |
| 7483 | txq = &priv->txq[i]; |
| 7484 | q = &txq->q; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7485 | avail = iwl3945_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7486 | |
| 7487 | stats->data[i].len = q->n_window - avail; |
| 7488 | stats->data[i].limit = q->n_window - q->high_mark; |
| 7489 | stats->data[i].count = q->n_window; |
| 7490 | |
| 7491 | } |
| 7492 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7493 | |
| 7494 | IWL_DEBUG_MAC80211("leave\n"); |
| 7495 | |
| 7496 | return 0; |
| 7497 | } |
| 7498 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7499 | static int iwl3945_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7500 | struct ieee80211_low_level_stats *stats) |
| 7501 | { |
| 7502 | IWL_DEBUG_MAC80211("enter\n"); |
| 7503 | IWL_DEBUG_MAC80211("leave\n"); |
| 7504 | |
| 7505 | return 0; |
| 7506 | } |
| 7507 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7508 | static u64 iwl3945_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7509 | { |
| 7510 | IWL_DEBUG_MAC80211("enter\n"); |
| 7511 | IWL_DEBUG_MAC80211("leave\n"); |
| 7512 | |
| 7513 | return 0; |
| 7514 | } |
| 7515 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7516 | static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7517 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7518 | struct iwl3945_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7519 | unsigned long flags; |
| 7520 | |
| 7521 | mutex_lock(&priv->mutex); |
| 7522 | IWL_DEBUG_MAC80211("enter\n"); |
| 7523 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7524 | iwl3945_reset_qos(priv); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 7525 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7526 | cancel_delayed_work(&priv->post_associate); |
| 7527 | |
| 7528 | spin_lock_irqsave(&priv->lock, flags); |
| 7529 | priv->assoc_id = 0; |
| 7530 | priv->assoc_capability = 0; |
| 7531 | priv->call_post_assoc_from_beacon = 0; |
| 7532 | |
| 7533 | /* new association get rid of ibss beacon skb */ |
| 7534 | if (priv->ibss_beacon) |
| 7535 | dev_kfree_skb(priv->ibss_beacon); |
| 7536 | |
| 7537 | priv->ibss_beacon = NULL; |
| 7538 | |
| 7539 | priv->beacon_int = priv->hw->conf.beacon_int; |
| 7540 | priv->timestamp1 = 0; |
| 7541 | priv->timestamp0 = 0; |
| 7542 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 7543 | priv->beacon_int = 0; |
| 7544 | |
| 7545 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7546 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 7547 | if (!iwl3945_is_ready_rf(priv)) { |
| 7548 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 7549 | mutex_unlock(&priv->mutex); |
| 7550 | return; |
| 7551 | } |
| 7552 | |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 7553 | /* we are restarting association process |
| 7554 | * clear RXON_FILTER_ASSOC_MSK bit |
| 7555 | */ |
| 7556 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7557 | iwl3945_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 7558 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7559 | iwl3945_commit_rxon(priv); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 7560 | } |
| 7561 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7562 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 7563 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 7564 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7565 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 7566 | mutex_unlock(&priv->mutex); |
| 7567 | return; |
| 7568 | } |
| 7569 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7570 | priv->only_active_channel = 0; |
| 7571 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7572 | iwl3945_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7573 | |
| 7574 | mutex_unlock(&priv->mutex); |
| 7575 | |
| 7576 | IWL_DEBUG_MAC80211("leave\n"); |
| 7577 | |
| 7578 | } |
| 7579 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7580 | static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7581 | struct ieee80211_tx_control *control) |
| 7582 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7583 | struct iwl3945_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7584 | unsigned long flags; |
| 7585 | |
| 7586 | mutex_lock(&priv->mutex); |
| 7587 | IWL_DEBUG_MAC80211("enter\n"); |
| 7588 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7589 | if (!iwl3945_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7590 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 7591 | mutex_unlock(&priv->mutex); |
| 7592 | return -EIO; |
| 7593 | } |
| 7594 | |
| 7595 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 7596 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 7597 | mutex_unlock(&priv->mutex); |
| 7598 | return -EIO; |
| 7599 | } |
| 7600 | |
| 7601 | spin_lock_irqsave(&priv->lock, flags); |
| 7602 | |
| 7603 | if (priv->ibss_beacon) |
| 7604 | dev_kfree_skb(priv->ibss_beacon); |
| 7605 | |
| 7606 | priv->ibss_beacon = skb; |
| 7607 | |
| 7608 | priv->assoc_id = 0; |
| 7609 | |
| 7610 | IWL_DEBUG_MAC80211("leave\n"); |
| 7611 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7612 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7613 | iwl3945_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7614 | |
| 7615 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 7616 | |
| 7617 | mutex_unlock(&priv->mutex); |
| 7618 | |
| 7619 | return 0; |
| 7620 | } |
| 7621 | |
| 7622 | /***************************************************************************** |
| 7623 | * |
| 7624 | * sysfs attributes |
| 7625 | * |
| 7626 | *****************************************************************************/ |
| 7627 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7628 | #ifdef CONFIG_IWL3945_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7629 | |
| 7630 | /* |
| 7631 | * The following adds a new attribute to the sysfs representation |
| 7632 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 7633 | * used for controlling the debug level. |
| 7634 | * |
| 7635 | * See the level definitions in iwl for details. |
| 7636 | */ |
| 7637 | |
| 7638 | static ssize_t show_debug_level(struct device_driver *d, char *buf) |
| 7639 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7640 | return sprintf(buf, "0x%08X\n", iwl3945_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7641 | } |
| 7642 | static ssize_t store_debug_level(struct device_driver *d, |
| 7643 | const char *buf, size_t count) |
| 7644 | { |
| 7645 | char *p = (char *)buf; |
| 7646 | u32 val; |
| 7647 | |
| 7648 | val = simple_strtoul(p, &p, 0); |
| 7649 | if (p == buf) |
| 7650 | printk(KERN_INFO DRV_NAME |
| 7651 | ": %s is not in hex or decimal form.\n", buf); |
| 7652 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7653 | iwl3945_debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7654 | |
| 7655 | return strnlen(buf, count); |
| 7656 | } |
| 7657 | |
| 7658 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 7659 | show_debug_level, store_debug_level); |
| 7660 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7661 | #endif /* CONFIG_IWL3945_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7662 | |
| 7663 | static ssize_t show_rf_kill(struct device *d, |
| 7664 | struct device_attribute *attr, char *buf) |
| 7665 | { |
| 7666 | /* |
| 7667 | * 0 - RF kill not enabled |
| 7668 | * 1 - SW based RF kill active (sysfs) |
| 7669 | * 2 - HW based RF kill active |
| 7670 | * 3 - Both HW and SW based RF kill active |
| 7671 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7672 | struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7673 | int val = (test_bit(STATUS_RF_KILL_SW, &priv->status) ? 0x1 : 0x0) | |
| 7674 | (test_bit(STATUS_RF_KILL_HW, &priv->status) ? 0x2 : 0x0); |
| 7675 | |
| 7676 | return sprintf(buf, "%i\n", val); |
| 7677 | } |
| 7678 | |
| 7679 | static ssize_t store_rf_kill(struct device *d, |
| 7680 | struct device_attribute *attr, |
| 7681 | const char *buf, size_t count) |
| 7682 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7683 | struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7684 | |
| 7685 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7686 | iwl3945_radio_kill_sw(priv, buf[0] == '1'); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7687 | mutex_unlock(&priv->mutex); |
| 7688 | |
| 7689 | return count; |
| 7690 | } |
| 7691 | |
| 7692 | static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill); |
| 7693 | |
| 7694 | static ssize_t show_temperature(struct device *d, |
| 7695 | struct device_attribute *attr, char *buf) |
| 7696 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7697 | struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7698 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7699 | if (!iwl3945_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7700 | return -EAGAIN; |
| 7701 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7702 | return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7703 | } |
| 7704 | |
| 7705 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 7706 | |
| 7707 | static ssize_t show_rs_window(struct device *d, |
| 7708 | struct device_attribute *attr, |
| 7709 | char *buf) |
| 7710 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7711 | struct iwl3945_priv *priv = d->driver_data; |
| 7712 | return iwl3945_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7713 | } |
| 7714 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 7715 | |
| 7716 | static ssize_t show_tx_power(struct device *d, |
| 7717 | struct device_attribute *attr, char *buf) |
| 7718 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7719 | struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7720 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 7721 | } |
| 7722 | |
| 7723 | static ssize_t store_tx_power(struct device *d, |
| 7724 | struct device_attribute *attr, |
| 7725 | const char *buf, size_t count) |
| 7726 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7727 | struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7728 | char *p = (char *)buf; |
| 7729 | u32 val; |
| 7730 | |
| 7731 | val = simple_strtoul(p, &p, 10); |
| 7732 | if (p == buf) |
| 7733 | printk(KERN_INFO DRV_NAME |
| 7734 | ": %s is not in decimal form.\n", buf); |
| 7735 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7736 | iwl3945_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7737 | |
| 7738 | return count; |
| 7739 | } |
| 7740 | |
| 7741 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 7742 | |
| 7743 | static ssize_t show_flags(struct device *d, |
| 7744 | struct device_attribute *attr, char *buf) |
| 7745 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7746 | struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7747 | |
| 7748 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 7749 | } |
| 7750 | |
| 7751 | static ssize_t store_flags(struct device *d, |
| 7752 | struct device_attribute *attr, |
| 7753 | const char *buf, size_t count) |
| 7754 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7755 | struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7756 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 7757 | |
| 7758 | mutex_lock(&priv->mutex); |
| 7759 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 7760 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7761 | if (iwl3945_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7762 | IWL_WARNING("Could not cancel scan.\n"); |
| 7763 | else { |
| 7764 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 7765 | flags); |
| 7766 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7767 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7768 | } |
| 7769 | } |
| 7770 | mutex_unlock(&priv->mutex); |
| 7771 | |
| 7772 | return count; |
| 7773 | } |
| 7774 | |
| 7775 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 7776 | |
| 7777 | static ssize_t show_filter_flags(struct device *d, |
| 7778 | struct device_attribute *attr, char *buf) |
| 7779 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7780 | struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7781 | |
| 7782 | return sprintf(buf, "0x%04X\n", |
| 7783 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 7784 | } |
| 7785 | |
| 7786 | static ssize_t store_filter_flags(struct device *d, |
| 7787 | struct device_attribute *attr, |
| 7788 | const char *buf, size_t count) |
| 7789 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7790 | struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7791 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 7792 | |
| 7793 | mutex_lock(&priv->mutex); |
| 7794 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 7795 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7796 | if (iwl3945_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7797 | IWL_WARNING("Could not cancel scan.\n"); |
| 7798 | else { |
| 7799 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 7800 | "0x%04X\n", filter_flags); |
| 7801 | priv->staging_rxon.filter_flags = |
| 7802 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7803 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7804 | } |
| 7805 | } |
| 7806 | mutex_unlock(&priv->mutex); |
| 7807 | |
| 7808 | return count; |
| 7809 | } |
| 7810 | |
| 7811 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 7812 | store_filter_flags); |
| 7813 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7814 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7815 | |
| 7816 | static ssize_t show_measurement(struct device *d, |
| 7817 | struct device_attribute *attr, char *buf) |
| 7818 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7819 | struct iwl3945_priv *priv = dev_get_drvdata(d); |
| 7820 | struct iwl3945_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7821 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 7822 | u8 *data = (u8 *) & measure_report; |
| 7823 | unsigned long flags; |
| 7824 | |
| 7825 | spin_lock_irqsave(&priv->lock, flags); |
| 7826 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 7827 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7828 | return 0; |
| 7829 | } |
| 7830 | memcpy(&measure_report, &priv->measure_report, size); |
| 7831 | priv->measurement_status = 0; |
| 7832 | spin_unlock_irqrestore(&priv->lock, flags); |
| 7833 | |
| 7834 | while (size && (PAGE_SIZE - len)) { |
| 7835 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 7836 | PAGE_SIZE - len, 1); |
| 7837 | len = strlen(buf); |
| 7838 | if (PAGE_SIZE - len) |
| 7839 | buf[len++] = '\n'; |
| 7840 | |
| 7841 | ofs += 16; |
| 7842 | size -= min(size, 16U); |
| 7843 | } |
| 7844 | |
| 7845 | return len; |
| 7846 | } |
| 7847 | |
| 7848 | static ssize_t store_measurement(struct device *d, |
| 7849 | struct device_attribute *attr, |
| 7850 | const char *buf, size_t count) |
| 7851 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7852 | struct iwl3945_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7853 | struct ieee80211_measurement_params params = { |
| 7854 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 7855 | .start_time = cpu_to_le64(priv->last_tsf), |
| 7856 | .duration = cpu_to_le16(1), |
| 7857 | }; |
| 7858 | u8 type = IWL_MEASURE_BASIC; |
| 7859 | u8 buffer[32]; |
| 7860 | u8 channel; |
| 7861 | |
| 7862 | if (count) { |
| 7863 | char *p = buffer; |
| 7864 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 7865 | channel = simple_strtoul(p, NULL, 0); |
| 7866 | if (channel) |
| 7867 | params.channel = channel; |
| 7868 | |
| 7869 | p = buffer; |
| 7870 | while (*p && *p != ' ') |
| 7871 | p++; |
| 7872 | if (*p) |
| 7873 | type = simple_strtoul(p + 1, NULL, 0); |
| 7874 | } |
| 7875 | |
| 7876 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 7877 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7878 | iwl3945_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7879 | |
| 7880 | return count; |
| 7881 | } |
| 7882 | |
| 7883 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 7884 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 7885 | #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7886 | |
| 7887 | static ssize_t show_rate(struct device *d, |
| 7888 | struct device_attribute *attr, char *buf) |
| 7889 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7890 | struct iwl3945_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7891 | unsigned long flags; |
| 7892 | int i; |
| 7893 | |
| 7894 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 7895 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) |
| 7896 | i = priv->stations[IWL_AP_ID].current_rate.s.rate; |
| 7897 | else |
| 7898 | i = priv->stations[IWL_STA_ID].current_rate.s.rate; |
| 7899 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 7900 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7901 | i = iwl3945_rate_index_from_plcp(i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7902 | if (i == -1) |
| 7903 | return sprintf(buf, "0\n"); |
| 7904 | |
| 7905 | return sprintf(buf, "%d%s\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7906 | (iwl3945_rates[i].ieee >> 1), |
| 7907 | (iwl3945_rates[i].ieee & 0x1) ? ".5" : ""); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7908 | } |
| 7909 | |
| 7910 | static DEVICE_ATTR(rate, S_IRUSR, show_rate, NULL); |
| 7911 | |
| 7912 | static ssize_t store_retry_rate(struct device *d, |
| 7913 | struct device_attribute *attr, |
| 7914 | const char *buf, size_t count) |
| 7915 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7916 | struct iwl3945_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7917 | |
| 7918 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 7919 | if (priv->retry_rate <= 0) |
| 7920 | priv->retry_rate = 1; |
| 7921 | |
| 7922 | return count; |
| 7923 | } |
| 7924 | |
| 7925 | static ssize_t show_retry_rate(struct device *d, |
| 7926 | struct device_attribute *attr, char *buf) |
| 7927 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7928 | struct iwl3945_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7929 | return sprintf(buf, "%d", priv->retry_rate); |
| 7930 | } |
| 7931 | |
| 7932 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 7933 | store_retry_rate); |
| 7934 | |
| 7935 | static ssize_t store_power_level(struct device *d, |
| 7936 | struct device_attribute *attr, |
| 7937 | const char *buf, size_t count) |
| 7938 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7939 | struct iwl3945_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7940 | int rc; |
| 7941 | int mode; |
| 7942 | |
| 7943 | mode = simple_strtoul(buf, NULL, 0); |
| 7944 | mutex_lock(&priv->mutex); |
| 7945 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7946 | if (!iwl3945_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7947 | rc = -EAGAIN; |
| 7948 | goto out; |
| 7949 | } |
| 7950 | |
| 7951 | if ((mode < 1) || (mode > IWL_POWER_LIMIT) || (mode == IWL_POWER_AC)) |
| 7952 | mode = IWL_POWER_AC; |
| 7953 | else |
| 7954 | mode |= IWL_POWER_ENABLED; |
| 7955 | |
| 7956 | if (mode != priv->power_mode) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7957 | rc = iwl3945_send_power_mode(priv, IWL_POWER_LEVEL(mode)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7958 | if (rc) { |
| 7959 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 7960 | goto out; |
| 7961 | } |
| 7962 | priv->power_mode = mode; |
| 7963 | } |
| 7964 | |
| 7965 | rc = count; |
| 7966 | |
| 7967 | out: |
| 7968 | mutex_unlock(&priv->mutex); |
| 7969 | return rc; |
| 7970 | } |
| 7971 | |
| 7972 | #define MAX_WX_STRING 80 |
| 7973 | |
| 7974 | /* Values are in microsecond */ |
| 7975 | static const s32 timeout_duration[] = { |
| 7976 | 350000, |
| 7977 | 250000, |
| 7978 | 75000, |
| 7979 | 37000, |
| 7980 | 25000, |
| 7981 | }; |
| 7982 | static const s32 period_duration[] = { |
| 7983 | 400000, |
| 7984 | 700000, |
| 7985 | 1000000, |
| 7986 | 1000000, |
| 7987 | 1000000 |
| 7988 | }; |
| 7989 | |
| 7990 | static ssize_t show_power_level(struct device *d, |
| 7991 | struct device_attribute *attr, char *buf) |
| 7992 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 7993 | struct iwl3945_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 7994 | int level = IWL_POWER_LEVEL(priv->power_mode); |
| 7995 | char *p = buf; |
| 7996 | |
| 7997 | p += sprintf(p, "%d ", level); |
| 7998 | switch (level) { |
| 7999 | case IWL_POWER_MODE_CAM: |
| 8000 | case IWL_POWER_AC: |
| 8001 | p += sprintf(p, "(AC)"); |
| 8002 | break; |
| 8003 | case IWL_POWER_BATTERY: |
| 8004 | p += sprintf(p, "(BATTERY)"); |
| 8005 | break; |
| 8006 | default: |
| 8007 | p += sprintf(p, |
| 8008 | "(Timeout %dms, Period %dms)", |
| 8009 | timeout_duration[level - 1] / 1000, |
| 8010 | period_duration[level - 1] / 1000); |
| 8011 | } |
| 8012 | |
| 8013 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 8014 | p += sprintf(p, " OFF\n"); |
| 8015 | else |
| 8016 | p += sprintf(p, " \n"); |
| 8017 | |
| 8018 | return (p - buf + 1); |
| 8019 | |
| 8020 | } |
| 8021 | |
| 8022 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 8023 | store_power_level); |
| 8024 | |
| 8025 | static ssize_t show_channels(struct device *d, |
| 8026 | struct device_attribute *attr, char *buf) |
| 8027 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 8028 | /* all this shit doesn't belong into sysfs anyway */ |
| 8029 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8030 | } |
| 8031 | |
| 8032 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 8033 | |
| 8034 | static ssize_t show_statistics(struct device *d, |
| 8035 | struct device_attribute *attr, char *buf) |
| 8036 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8037 | struct iwl3945_priv *priv = dev_get_drvdata(d); |
| 8038 | u32 size = sizeof(struct iwl3945_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8039 | u32 len = 0, ofs = 0; |
| 8040 | u8 *data = (u8 *) & priv->statistics; |
| 8041 | int rc = 0; |
| 8042 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8043 | if (!iwl3945_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8044 | return -EAGAIN; |
| 8045 | |
| 8046 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8047 | rc = iwl3945_send_statistics_request(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8048 | mutex_unlock(&priv->mutex); |
| 8049 | |
| 8050 | if (rc) { |
| 8051 | len = sprintf(buf, |
| 8052 | "Error sending statistics request: 0x%08X\n", rc); |
| 8053 | return len; |
| 8054 | } |
| 8055 | |
| 8056 | while (size && (PAGE_SIZE - len)) { |
| 8057 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 8058 | PAGE_SIZE - len, 1); |
| 8059 | len = strlen(buf); |
| 8060 | if (PAGE_SIZE - len) |
| 8061 | buf[len++] = '\n'; |
| 8062 | |
| 8063 | ofs += 16; |
| 8064 | size -= min(size, 16U); |
| 8065 | } |
| 8066 | |
| 8067 | return len; |
| 8068 | } |
| 8069 | |
| 8070 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 8071 | |
| 8072 | static ssize_t show_antenna(struct device *d, |
| 8073 | struct device_attribute *attr, char *buf) |
| 8074 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8075 | struct iwl3945_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8076 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8077 | if (!iwl3945_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8078 | return -EAGAIN; |
| 8079 | |
| 8080 | return sprintf(buf, "%d\n", priv->antenna); |
| 8081 | } |
| 8082 | |
| 8083 | static ssize_t store_antenna(struct device *d, |
| 8084 | struct device_attribute *attr, |
| 8085 | const char *buf, size_t count) |
| 8086 | { |
| 8087 | int ant; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8088 | struct iwl3945_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8089 | |
| 8090 | if (count == 0) |
| 8091 | return 0; |
| 8092 | |
| 8093 | if (sscanf(buf, "%1i", &ant) != 1) { |
| 8094 | IWL_DEBUG_INFO("not in hex or decimal form.\n"); |
| 8095 | return count; |
| 8096 | } |
| 8097 | |
| 8098 | if ((ant >= 0) && (ant <= 2)) { |
| 8099 | IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8100 | priv->antenna = (enum iwl3945_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8101 | } else |
| 8102 | IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant); |
| 8103 | |
| 8104 | |
| 8105 | return count; |
| 8106 | } |
| 8107 | |
| 8108 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 8109 | |
| 8110 | static ssize_t show_status(struct device *d, |
| 8111 | struct device_attribute *attr, char *buf) |
| 8112 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8113 | struct iwl3945_priv *priv = (struct iwl3945_priv *)d->driver_data; |
| 8114 | if (!iwl3945_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8115 | return -EAGAIN; |
| 8116 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 8117 | } |
| 8118 | |
| 8119 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 8120 | |
| 8121 | static ssize_t dump_error_log(struct device *d, |
| 8122 | struct device_attribute *attr, |
| 8123 | const char *buf, size_t count) |
| 8124 | { |
| 8125 | char *p = (char *)buf; |
| 8126 | |
| 8127 | if (p[0] == '1') |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8128 | iwl3945_dump_nic_error_log((struct iwl3945_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8129 | |
| 8130 | return strnlen(buf, count); |
| 8131 | } |
| 8132 | |
| 8133 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 8134 | |
| 8135 | static ssize_t dump_event_log(struct device *d, |
| 8136 | struct device_attribute *attr, |
| 8137 | const char *buf, size_t count) |
| 8138 | { |
| 8139 | char *p = (char *)buf; |
| 8140 | |
| 8141 | if (p[0] == '1') |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8142 | iwl3945_dump_nic_event_log((struct iwl3945_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8143 | |
| 8144 | return strnlen(buf, count); |
| 8145 | } |
| 8146 | |
| 8147 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 8148 | |
| 8149 | /***************************************************************************** |
| 8150 | * |
| 8151 | * driver setup and teardown |
| 8152 | * |
| 8153 | *****************************************************************************/ |
| 8154 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8155 | static void iwl3945_setup_deferred_work(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8156 | { |
| 8157 | priv->workqueue = create_workqueue(DRV_NAME); |
| 8158 | |
| 8159 | init_waitqueue_head(&priv->wait_command_queue); |
| 8160 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8161 | INIT_WORK(&priv->up, iwl3945_bg_up); |
| 8162 | INIT_WORK(&priv->restart, iwl3945_bg_restart); |
| 8163 | INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish); |
| 8164 | INIT_WORK(&priv->scan_completed, iwl3945_bg_scan_completed); |
| 8165 | INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan); |
| 8166 | INIT_WORK(&priv->abort_scan, iwl3945_bg_abort_scan); |
| 8167 | INIT_WORK(&priv->rf_kill, iwl3945_bg_rf_kill); |
| 8168 | INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update); |
| 8169 | INIT_DELAYED_WORK(&priv->post_associate, iwl3945_bg_post_associate); |
| 8170 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start); |
| 8171 | INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start); |
| 8172 | INIT_DELAYED_WORK(&priv->scan_check, iwl3945_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8173 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8174 | iwl3945_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8175 | |
| 8176 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8177 | iwl3945_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8178 | } |
| 8179 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8180 | static void iwl3945_cancel_deferred_work(struct iwl3945_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8181 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8182 | iwl3945_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8183 | |
Joonwoo Park | e47eb6a | 2007-11-29 10:42:49 +0900 | [diff] [blame] | 8184 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8185 | cancel_delayed_work(&priv->scan_check); |
| 8186 | cancel_delayed_work(&priv->alive_start); |
| 8187 | cancel_delayed_work(&priv->post_associate); |
| 8188 | cancel_work_sync(&priv->beacon_update); |
| 8189 | } |
| 8190 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8191 | static struct attribute *iwl3945_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8192 | &dev_attr_antenna.attr, |
| 8193 | &dev_attr_channels.attr, |
| 8194 | &dev_attr_dump_errors.attr, |
| 8195 | &dev_attr_dump_events.attr, |
| 8196 | &dev_attr_flags.attr, |
| 8197 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8198 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8199 | &dev_attr_measurement.attr, |
| 8200 | #endif |
| 8201 | &dev_attr_power_level.attr, |
| 8202 | &dev_attr_rate.attr, |
| 8203 | &dev_attr_retry_rate.attr, |
| 8204 | &dev_attr_rf_kill.attr, |
| 8205 | &dev_attr_rs_window.attr, |
| 8206 | &dev_attr_statistics.attr, |
| 8207 | &dev_attr_status.attr, |
| 8208 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8209 | &dev_attr_tx_power.attr, |
| 8210 | |
| 8211 | NULL |
| 8212 | }; |
| 8213 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8214 | static struct attribute_group iwl3945_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8215 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8216 | .attrs = iwl3945_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8217 | }; |
| 8218 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8219 | static struct ieee80211_ops iwl3945_hw_ops = { |
| 8220 | .tx = iwl3945_mac_tx, |
| 8221 | .start = iwl3945_mac_start, |
| 8222 | .stop = iwl3945_mac_stop, |
| 8223 | .add_interface = iwl3945_mac_add_interface, |
| 8224 | .remove_interface = iwl3945_mac_remove_interface, |
| 8225 | .config = iwl3945_mac_config, |
| 8226 | .config_interface = iwl3945_mac_config_interface, |
| 8227 | .configure_filter = iwl3945_configure_filter, |
| 8228 | .set_key = iwl3945_mac_set_key, |
| 8229 | .get_stats = iwl3945_mac_get_stats, |
| 8230 | .get_tx_stats = iwl3945_mac_get_tx_stats, |
| 8231 | .conf_tx = iwl3945_mac_conf_tx, |
| 8232 | .get_tsf = iwl3945_mac_get_tsf, |
| 8233 | .reset_tsf = iwl3945_mac_reset_tsf, |
| 8234 | .beacon_update = iwl3945_mac_beacon_update, |
| 8235 | .hw_scan = iwl3945_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8236 | }; |
| 8237 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8238 | static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8239 | { |
| 8240 | int err = 0; |
| 8241 | u32 pci_id; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8242 | struct iwl3945_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8243 | struct ieee80211_hw *hw; |
| 8244 | int i; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8245 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8246 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8247 | /* Disabling hardware scan means that mac80211 will perform scans |
| 8248 | * "the hard way", rather than using device's scan. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8249 | if (iwl3945_param_disable_hw_scan) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8250 | IWL_DEBUG_INFO("Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8251 | iwl3945_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8252 | } |
| 8253 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8254 | if ((iwl3945_param_queues_num > IWL_MAX_NUM_QUEUES) || |
| 8255 | (iwl3945_param_queues_num < IWL_MIN_NUM_QUEUES)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8256 | IWL_ERROR("invalid queues_num, should be between %d and %d\n", |
| 8257 | IWL_MIN_NUM_QUEUES, IWL_MAX_NUM_QUEUES); |
| 8258 | err = -EINVAL; |
| 8259 | goto out; |
| 8260 | } |
| 8261 | |
| 8262 | /* mac80211 allocates memory for this device instance, including |
| 8263 | * space for this driver's private structure */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8264 | hw = ieee80211_alloc_hw(sizeof(struct iwl3945_priv), &iwl3945_hw_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8265 | if (hw == NULL) { |
| 8266 | IWL_ERROR("Can not allocate network device\n"); |
| 8267 | err = -ENOMEM; |
| 8268 | goto out; |
| 8269 | } |
| 8270 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 8271 | |
Johannes Berg | f51359a | 2007-10-28 14:53:36 +0100 | [diff] [blame] | 8272 | hw->rate_control_algorithm = "iwl-3945-rs"; |
| 8273 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8274 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
| 8275 | priv = hw->priv; |
| 8276 | priv->hw = hw; |
| 8277 | |
| 8278 | priv->pci_dev = pdev; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8279 | |
| 8280 | /* Select antenna (may be helpful if only one antenna is connected) */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8281 | priv->antenna = (enum iwl3945_antenna)iwl3945_param_antenna; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8282 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8283 | iwl3945_debug_level = iwl3945_param_debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8284 | atomic_set(&priv->restrict_refcnt, 0); |
| 8285 | #endif |
| 8286 | priv->retry_rate = 1; |
| 8287 | |
| 8288 | priv->ibss_beacon = NULL; |
| 8289 | |
| 8290 | /* Tell mac80211 and its clients (e.g. Wireless Extensions) |
| 8291 | * the range of signal quality values that we'll provide. |
| 8292 | * Negative values for level/noise indicate that we'll provide dBm. |
| 8293 | * For WE, at least, non-0 values here *enable* display of values |
| 8294 | * in app (iwconfig). */ |
| 8295 | hw->max_rssi = -20; /* signal level, negative indicates dBm */ |
| 8296 | hw->max_noise = -20; /* noise level, negative indicates dBm */ |
| 8297 | hw->max_signal = 100; /* link quality indication (%) */ |
| 8298 | |
| 8299 | /* Tell mac80211 our Tx characteristics */ |
| 8300 | hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE; |
| 8301 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8302 | /* 4 EDCA QOS priorities */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8303 | hw->queues = 4; |
| 8304 | |
| 8305 | spin_lock_init(&priv->lock); |
| 8306 | spin_lock_init(&priv->power_data.lock); |
| 8307 | spin_lock_init(&priv->sta_lock); |
| 8308 | spin_lock_init(&priv->hcmd_lock); |
| 8309 | |
| 8310 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) |
| 8311 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
| 8312 | |
| 8313 | INIT_LIST_HEAD(&priv->free_frames); |
| 8314 | |
| 8315 | mutex_init(&priv->mutex); |
| 8316 | if (pci_enable_device(pdev)) { |
| 8317 | err = -ENODEV; |
| 8318 | goto out_ieee80211_free_hw; |
| 8319 | } |
| 8320 | |
| 8321 | pci_set_master(pdev); |
| 8322 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8323 | /* Clear the driver's (not device's) station table */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8324 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8325 | |
| 8326 | priv->data_retry_limit = -1; |
| 8327 | priv->ieee_channels = NULL; |
| 8328 | priv->ieee_rates = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 8329 | priv->band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8330 | |
| 8331 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 8332 | if (!err) |
| 8333 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 8334 | if (err) { |
| 8335 | printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n"); |
| 8336 | goto out_pci_disable_device; |
| 8337 | } |
| 8338 | |
| 8339 | pci_set_drvdata(pdev, priv); |
| 8340 | err = pci_request_regions(pdev, DRV_NAME); |
| 8341 | if (err) |
| 8342 | goto out_pci_disable_device; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8343 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8344 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 8345 | * PCI Tx retries from interfering with C3 CPU state */ |
| 8346 | pci_write_config_byte(pdev, 0x41, 0x00); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8347 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8348 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 8349 | if (!priv->hw_base) { |
| 8350 | err = -ENODEV; |
| 8351 | goto out_pci_release_regions; |
| 8352 | } |
| 8353 | |
| 8354 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 8355 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 8356 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 8357 | |
| 8358 | /* Initialize module parameter values here */ |
| 8359 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 8360 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8361 | if (iwl3945_param_disable) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8362 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 8363 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 8364 | } |
| 8365 | |
| 8366 | priv->iw_mode = IEEE80211_IF_TYPE_STA; |
| 8367 | |
| 8368 | pci_id = |
| 8369 | (priv->pci_dev->device << 16) | priv->pci_dev->subsystem_device; |
| 8370 | |
| 8371 | switch (pci_id) { |
| 8372 | case 0x42221005: /* 0x4222 0x8086 0x1005 is BG SKU */ |
| 8373 | case 0x42221034: /* 0x4222 0x8086 0x1034 is BG SKU */ |
| 8374 | case 0x42271014: /* 0x4227 0x8086 0x1014 is BG SKU */ |
| 8375 | case 0x42221044: /* 0x4222 0x8086 0x1044 is BG SKU */ |
| 8376 | priv->is_abg = 0; |
| 8377 | break; |
| 8378 | |
| 8379 | /* |
| 8380 | * Rest are assumed ABG SKU -- if this is not the |
| 8381 | * case then the card will get the wrong 'Detected' |
| 8382 | * line in the kernel log however the code that |
| 8383 | * initializes the GEO table will detect no A-band |
| 8384 | * channels and remove the is_abg mask. |
| 8385 | */ |
| 8386 | default: |
| 8387 | priv->is_abg = 1; |
| 8388 | break; |
| 8389 | } |
| 8390 | |
| 8391 | printk(KERN_INFO DRV_NAME |
| 8392 | ": Detected Intel PRO/Wireless 3945%sBG Network Connection\n", |
| 8393 | priv->is_abg ? "A" : ""); |
| 8394 | |
| 8395 | /* Device-specific setup */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8396 | if (iwl3945_hw_set_hw_setting(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8397 | IWL_ERROR("failed to set hw settings\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8398 | goto out_iounmap; |
| 8399 | } |
| 8400 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8401 | if (iwl3945_param_qos_enable) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8402 | priv->qos_data.qos_enable = 1; |
| 8403 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8404 | iwl3945_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8405 | |
| 8406 | priv->qos_data.qos_active = 0; |
| 8407 | priv->qos_data.qos_cap.val = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8408 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 8409 | iwl3945_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8410 | iwl3945_setup_deferred_work(priv); |
| 8411 | iwl3945_setup_rx_handlers(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8412 | |
| 8413 | priv->rates_mask = IWL_RATES_MASK; |
| 8414 | /* If power management is turned on, default to AC mode */ |
| 8415 | priv->power_mode = IWL_POWER_AC; |
| 8416 | priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; |
| 8417 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8418 | iwl3945_disable_interrupts(priv); |
Jes Sorensen | 49df2b3 | 2007-10-26 16:10:39 +0200 | [diff] [blame] | 8419 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8420 | err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8421 | if (err) { |
| 8422 | IWL_ERROR("failed to create sysfs device attributes\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8423 | goto out_release_irq; |
| 8424 | } |
| 8425 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8426 | /* nic init */ |
| 8427 | iwl3945_set_bit(priv, CSR_GIO_CHICKEN_BITS, |
| 8428 | CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); |
| 8429 | |
| 8430 | iwl3945_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); |
| 8431 | err = iwl3945_poll_bit(priv, CSR_GP_CNTRL, |
| 8432 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, |
| 8433 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); |
| 8434 | if (err < 0) { |
| 8435 | IWL_DEBUG_INFO("Failed to init the card\n"); |
| 8436 | goto out_remove_sysfs; |
| 8437 | } |
| 8438 | /* Read the EEPROM */ |
| 8439 | err = iwl3945_eeprom_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8440 | if (err) { |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8441 | IWL_ERROR("Unable to init EEPROM\n"); |
| 8442 | goto out_remove_sysfs; |
| 8443 | } |
| 8444 | /* MAC Address location in EEPROM same for 3945/4965 */ |
| 8445 | get_eeprom_mac(priv, priv->mac_addr); |
| 8446 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); |
| 8447 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 8448 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8449 | err = iwl3945_init_channel_map(priv); |
| 8450 | if (err) { |
| 8451 | IWL_ERROR("initializing regulatory failed: %d\n", err); |
| 8452 | goto out_remove_sysfs; |
| 8453 | } |
| 8454 | |
| 8455 | err = iwl3945_init_geos(priv); |
| 8456 | if (err) { |
| 8457 | IWL_ERROR("initializing geos failed: %d\n", err); |
| 8458 | goto out_free_channel_map; |
| 8459 | } |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8460 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8461 | iwl3945_rate_control_register(priv->hw); |
| 8462 | err = ieee80211_register_hw(priv->hw); |
| 8463 | if (err) { |
| 8464 | IWL_ERROR("Failed to register network device (error %d)\n", err); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8465 | goto out_free_geos; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8466 | } |
| 8467 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8468 | priv->hw->conf.beacon_int = 100; |
| 8469 | priv->mac80211_registered = 1; |
| 8470 | pci_save_state(pdev); |
| 8471 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8472 | |
| 8473 | return 0; |
| 8474 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8475 | out_free_geos: |
| 8476 | iwl3945_free_geos(priv); |
| 8477 | out_free_channel_map: |
| 8478 | iwl3945_free_channel_map(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 8479 | out_remove_sysfs: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8480 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8481 | |
| 8482 | out_release_irq: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8483 | destroy_workqueue(priv->workqueue); |
| 8484 | priv->workqueue = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8485 | iwl3945_unset_hw_setting(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8486 | |
| 8487 | out_iounmap: |
| 8488 | pci_iounmap(pdev, priv->hw_base); |
| 8489 | out_pci_release_regions: |
| 8490 | pci_release_regions(pdev); |
| 8491 | out_pci_disable_device: |
| 8492 | pci_disable_device(pdev); |
| 8493 | pci_set_drvdata(pdev, NULL); |
| 8494 | out_ieee80211_free_hw: |
| 8495 | ieee80211_free_hw(priv->hw); |
| 8496 | out: |
| 8497 | return err; |
| 8498 | } |
| 8499 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8500 | static void iwl3945_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8501 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8502 | struct iwl3945_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8503 | struct list_head *p, *q; |
| 8504 | int i; |
| 8505 | |
| 8506 | if (!priv) |
| 8507 | return; |
| 8508 | |
| 8509 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 8510 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8511 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 8512 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8513 | iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8514 | |
| 8515 | /* Free MAC hash list for ADHOC */ |
| 8516 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 8517 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 8518 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8519 | kfree(list_entry(p, struct iwl3945_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8520 | } |
| 8521 | } |
| 8522 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8523 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8524 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8525 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8526 | |
| 8527 | if (priv->rxq.bd) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8528 | iwl3945_rx_queue_free(priv, &priv->rxq); |
| 8529 | iwl3945_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8530 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8531 | iwl3945_unset_hw_setting(priv); |
| 8532 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8533 | |
| 8534 | if (priv->mac80211_registered) { |
| 8535 | ieee80211_unregister_hw(priv->hw); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8536 | iwl3945_rate_control_unregister(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8537 | } |
| 8538 | |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 8539 | /*netif_stop_queue(dev); */ |
| 8540 | flush_workqueue(priv->workqueue); |
| 8541 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8542 | /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8543 | * priv->workqueue... so we can't take down the workqueue |
| 8544 | * until now... */ |
| 8545 | destroy_workqueue(priv->workqueue); |
| 8546 | priv->workqueue = NULL; |
| 8547 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8548 | pci_iounmap(pdev, priv->hw_base); |
| 8549 | pci_release_regions(pdev); |
| 8550 | pci_disable_device(pdev); |
| 8551 | pci_set_drvdata(pdev, NULL); |
| 8552 | |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 8553 | iwl3945_free_channel_map(priv); |
| 8554 | iwl3945_free_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8555 | |
| 8556 | if (priv->ibss_beacon) |
| 8557 | dev_kfree_skb(priv->ibss_beacon); |
| 8558 | |
| 8559 | ieee80211_free_hw(priv->hw); |
| 8560 | } |
| 8561 | |
| 8562 | #ifdef CONFIG_PM |
| 8563 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8564 | static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8565 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8566 | struct iwl3945_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8567 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 8568 | if (priv->is_open) { |
| 8569 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 8570 | iwl3945_mac_stop(priv->hw); |
| 8571 | priv->is_open = 1; |
| 8572 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8573 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8574 | pci_set_power_state(pdev, PCI_D3hot); |
| 8575 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8576 | return 0; |
| 8577 | } |
| 8578 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8579 | static int iwl3945_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8580 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8581 | struct iwl3945_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8582 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8583 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8584 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 8585 | if (priv->is_open) |
| 8586 | iwl3945_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8587 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 8588 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8589 | return 0; |
| 8590 | } |
| 8591 | |
| 8592 | #endif /* CONFIG_PM */ |
| 8593 | |
| 8594 | /***************************************************************************** |
| 8595 | * |
| 8596 | * driver and module entry point |
| 8597 | * |
| 8598 | *****************************************************************************/ |
| 8599 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8600 | static struct pci_driver iwl3945_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8601 | .name = DRV_NAME, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8602 | .id_table = iwl3945_hw_card_ids, |
| 8603 | .probe = iwl3945_pci_probe, |
| 8604 | .remove = __devexit_p(iwl3945_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8605 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8606 | .suspend = iwl3945_pci_suspend, |
| 8607 | .resume = iwl3945_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8608 | #endif |
| 8609 | }; |
| 8610 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8611 | static int __init iwl3945_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8612 | { |
| 8613 | |
| 8614 | int ret; |
| 8615 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 8616 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8617 | ret = pci_register_driver(&iwl3945_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8618 | if (ret) { |
| 8619 | IWL_ERROR("Unable to initialize PCI module\n"); |
| 8620 | return ret; |
| 8621 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8622 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8623 | ret = driver_create_file(&iwl3945_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8624 | if (ret) { |
| 8625 | IWL_ERROR("Unable to create driver sysfs file\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8626 | pci_unregister_driver(&iwl3945_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8627 | return ret; |
| 8628 | } |
| 8629 | #endif |
| 8630 | |
| 8631 | return ret; |
| 8632 | } |
| 8633 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8634 | static void __exit iwl3945_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8635 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 8636 | #ifdef CONFIG_IWL3945_DEBUG |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8637 | driver_remove_file(&iwl3945_driver.driver, &driver_attr_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8638 | #endif |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8639 | pci_unregister_driver(&iwl3945_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8640 | } |
| 8641 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8642 | module_param_named(antenna, iwl3945_param_antenna, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8643 | MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8644 | module_param_named(disable, iwl3945_param_disable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8645 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8646 | module_param_named(hwcrypto, iwl3945_param_hwcrypto, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8647 | MODULE_PARM_DESC(hwcrypto, |
| 8648 | "using hardware crypto engine (default 0 [software])\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8649 | module_param_named(debug, iwl3945_param_debug, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8650 | MODULE_PARM_DESC(debug, "debug output mask"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8651 | module_param_named(disable_hw_scan, iwl3945_param_disable_hw_scan, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8652 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 8653 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8654 | module_param_named(queues_num, iwl3945_param_queues_num, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8655 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 8656 | |
| 8657 | /* QoS */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8658 | module_param_named(qos_enable, iwl3945_param_qos_enable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 8659 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionality"); |
| 8660 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 8661 | module_exit(iwl3945_exit); |
| 8662 | module_init(iwl3945_init); |