Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | eb7ae89 | 2008-03-11 16:17:17 -0700 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
| 25 | * James P. Ketrenos <ipw2100-admin@linux.intel.com> |
| 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
| 32 | #include <linux/version.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/pci.h> |
| 35 | #include <linux/dma-mapping.h> |
| 36 | #include <linux/delay.h> |
| 37 | #include <linux/skbuff.h> |
| 38 | #include <linux/netdevice.h> |
| 39 | #include <linux/wireless.h> |
| 40 | #include <linux/firmware.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 41 | #include <linux/etherdevice.h> |
| 42 | #include <linux/if_arp.h> |
| 43 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 44 | #include <net/mac80211.h> |
| 45 | |
| 46 | #include <asm/div64.h> |
| 47 | |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 48 | #include "iwl-eeprom.h" |
Tomas Winkler | 3e0d4cb | 2008-04-24 11:55:38 -0700 | [diff] [blame] | 49 | #include "iwl-dev.h" |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 50 | #include "iwl-core.h" |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 51 | #include "iwl-io.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 52 | #include "iwl-helpers.h" |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 53 | #include "iwl-sta.h" |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 54 | #include "iwl-calib.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 55 | |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 56 | static int iwl_txq_update_write_ptr(struct iwl_priv *priv, |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 57 | struct iwl_tx_queue *txq); |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 58 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 59 | /****************************************************************************** |
| 60 | * |
| 61 | * module boiler plate |
| 62 | * |
| 63 | ******************************************************************************/ |
| 64 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 65 | /* |
| 66 | * module name, copyright, version, etc. |
| 67 | * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk |
| 68 | */ |
| 69 | |
| 70 | #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux" |
| 71 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 72 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 73 | #define VD "d" |
| 74 | #else |
| 75 | #define VD |
| 76 | #endif |
| 77 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 78 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 79 | #define VS "s" |
| 80 | #else |
| 81 | #define VS |
| 82 | #endif |
| 83 | |
Tomas Winkler | df48c32 | 2008-03-06 10:40:19 -0800 | [diff] [blame] | 84 | #define DRV_VERSION IWLWIFI_VERSION VD VS |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 85 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 86 | |
| 87 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 88 | MODULE_VERSION(DRV_VERSION); |
| 89 | MODULE_AUTHOR(DRV_COPYRIGHT); |
| 90 | MODULE_LICENSE("GPL"); |
| 91 | |
| 92 | __le16 *ieee80211_get_qos_ctrl(struct ieee80211_hdr *hdr) |
| 93 | { |
| 94 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 95 | int hdr_len = ieee80211_get_hdrlen(fc); |
| 96 | |
| 97 | if ((fc & 0x00cc) == (IEEE80211_STYPE_QOS_DATA | IEEE80211_FTYPE_DATA)) |
| 98 | return (__le16 *) ((u8 *) hdr + hdr_len - QOS_CONTROL_LEN); |
| 99 | return NULL; |
| 100 | } |
| 101 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 102 | static const struct ieee80211_supported_band *iwl_get_hw_mode( |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 103 | struct iwl_priv *priv, enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 104 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 105 | return priv->hw->wiphy->bands[band]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 108 | static int iwl4965_is_empty_essid(const char *essid, int essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 109 | { |
| 110 | /* Single white space is for Linksys APs */ |
| 111 | if (essid_len == 1 && essid[0] == ' ') |
| 112 | return 1; |
| 113 | |
| 114 | /* Otherwise, if the entire essid is 0, we assume it is hidden */ |
| 115 | while (essid_len) { |
| 116 | essid_len--; |
| 117 | if (essid[essid_len] != '\0') |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | return 1; |
| 122 | } |
| 123 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 124 | static const char *iwl4965_escape_essid(const char *essid, u8 essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 125 | { |
| 126 | static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
| 127 | const char *s = essid; |
| 128 | char *d = escaped; |
| 129 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 130 | if (iwl4965_is_empty_essid(essid, essid_len)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 131 | memcpy(escaped, "<hidden>", sizeof("<hidden>")); |
| 132 | return escaped; |
| 133 | } |
| 134 | |
| 135 | essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE); |
| 136 | while (essid_len--) { |
| 137 | if (*s == '\0') { |
| 138 | *d++ = '\\'; |
| 139 | *d++ = '0'; |
| 140 | s++; |
| 141 | } else |
| 142 | *d++ = *s++; |
| 143 | } |
| 144 | *d = '\0'; |
| 145 | return escaped; |
| 146 | } |
| 147 | |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 148 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 149 | /*************** DMA-QUEUE-GENERAL-FUNCTIONS ***** |
| 150 | * DMA services |
| 151 | * |
| 152 | * Theory of operation |
| 153 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 154 | * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer |
| 155 | * of buffer descriptors, each of which points to one or more data buffers for |
| 156 | * the device to read from or fill. Driver and device exchange status of each |
| 157 | * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty |
| 158 | * entries in each circular buffer, to protect against confusing empty and full |
| 159 | * queue states. |
| 160 | * |
| 161 | * The device reads or writes the data in the queues via the device's several |
| 162 | * DMA/FIFO channels. Each queue is mapped to a single DMA channel. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 163 | * |
| 164 | * For Tx queue, there are low mark and high mark limits. If, after queuing |
| 165 | * the packet for Tx, free space become < low mark, Tx queue stopped. When |
| 166 | * reclaiming packets (on 'tx done IRQ), if free space become > high mark, |
| 167 | * Tx queue resumed. |
| 168 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 169 | * The 4965 operates with up to 17 queues: One receive queue, one transmit |
| 170 | * queue (#4) for sending commands to the device firmware, and 15 other |
| 171 | * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels. |
Ben Cahill | e385144 | 2007-11-29 11:10:07 +0800 | [diff] [blame] | 172 | * |
| 173 | * See more detailed info in iwl-4965-hw.h. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 174 | ***************************************************/ |
| 175 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 176 | int iwl_queue_space(const struct iwl_queue *q) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 177 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 178 | int s = q->read_ptr - q->write_ptr; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 179 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 180 | if (q->read_ptr > q->write_ptr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 181 | s -= q->n_bd; |
| 182 | |
| 183 | if (s <= 0) |
| 184 | s += q->n_window; |
| 185 | /* keep some reserve to not confuse empty and full situations */ |
| 186 | s -= 2; |
| 187 | if (s < 0) |
| 188 | s = 0; |
| 189 | return s; |
| 190 | } |
| 191 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 192 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 193 | static inline int iwl_queue_used(const struct iwl_queue *q, int i) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 194 | { |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 195 | return q->write_ptr > q->read_ptr ? |
| 196 | (i >= q->read_ptr && i < q->write_ptr) : |
| 197 | !(i < q->read_ptr && i >= q->write_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 200 | static inline u8 get_cmd_index(struct iwl_queue *q, u32 index, int is_huge) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 201 | { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 202 | /* 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] | 203 | if (is_huge) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 204 | return q->n_window; /* must be power of 2 */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 205 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 206 | /* Otherwise, use normal size buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 207 | return index & (q->n_window - 1); |
| 208 | } |
| 209 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 210 | const u8 iwl4965_broadcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 211 | |
| 212 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 213 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 214 | * the functionality provided here |
| 215 | */ |
| 216 | |
| 217 | /**************************************************************/ |
| 218 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 219 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 220 | /** |
| 221 | * iwl4965_remove_station - Remove driver's knowledge of station. |
| 222 | * |
| 223 | * NOTE: This does not remove station from device's station table. |
| 224 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 225 | static u8 iwl4965_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 226 | { |
| 227 | int index = IWL_INVALID_STATION; |
| 228 | int i; |
| 229 | unsigned long flags; |
| 230 | |
| 231 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 232 | |
| 233 | if (is_ap) |
| 234 | index = IWL_AP_ID; |
| 235 | else if (is_broadcast_ether_addr(addr)) |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 236 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 237 | else |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 238 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 239 | if (priv->stations[i].used && |
| 240 | !compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 241 | addr)) { |
| 242 | index = i; |
| 243 | break; |
| 244 | } |
| 245 | |
| 246 | if (unlikely(index == IWL_INVALID_STATION)) |
| 247 | goto out; |
| 248 | |
| 249 | if (priv->stations[index].used) { |
| 250 | priv->stations[index].used = 0; |
| 251 | priv->num_stations--; |
| 252 | } |
| 253 | |
| 254 | BUG_ON(priv->num_stations < 0); |
| 255 | |
| 256 | out: |
| 257 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 258 | return 0; |
| 259 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 260 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 261 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 262 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 263 | * iwl4965_add_station_flags - Add station to tables in driver and device |
| 264 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 265 | u8 iwl4965_add_station_flags(struct iwl_priv *priv, const u8 *addr, |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 266 | int is_ap, u8 flags, void *ht_data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 267 | { |
| 268 | int i; |
| 269 | int index = IWL_INVALID_STATION; |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 270 | struct iwl_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 271 | unsigned long flags_spin; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 272 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 273 | |
| 274 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 275 | if (is_ap) |
| 276 | index = IWL_AP_ID; |
| 277 | else if (is_broadcast_ether_addr(addr)) |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 278 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 279 | else |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 280 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 281 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 282 | addr)) { |
| 283 | index = i; |
| 284 | break; |
| 285 | } |
| 286 | |
| 287 | if (!priv->stations[i].used && |
| 288 | index == IWL_INVALID_STATION) |
| 289 | index = i; |
| 290 | } |
| 291 | |
| 292 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 293 | /* These two conditions have the same outcome, but keep them separate |
| 294 | since they have different meanings */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 295 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 296 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 297 | return index; |
| 298 | } |
| 299 | |
| 300 | if (priv->stations[index].used && |
| 301 | !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) { |
| 302 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 303 | return index; |
| 304 | } |
| 305 | |
| 306 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 307 | 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] | 308 | station = &priv->stations[index]; |
| 309 | station->used = 1; |
| 310 | priv->num_stations++; |
| 311 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 312 | /* Set up the REPLY_ADD_STA command to send to device */ |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 313 | memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 314 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 315 | station->sta.mode = 0; |
| 316 | station->sta.sta.sta_id = index; |
| 317 | station->sta.station_flags = 0; |
| 318 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 319 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 320 | /* BCAST station and IBSS stations do not work in HT mode */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 321 | if (index != priv->hw_params.bcast_sta_id && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 322 | priv->iw_mode != IEEE80211_IF_TYPE_IBSS) |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 323 | iwl4965_set_ht_add_station(priv, index, |
| 324 | (struct ieee80211_ht_info *) ht_data); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 325 | #endif /*CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 326 | |
| 327 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 328 | |
| 329 | /* Add station to device's station table */ |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 330 | iwl_send_add_sta(priv, &station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 331 | return index; |
| 332 | |
| 333 | } |
| 334 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 335 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 336 | |
| 337 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 338 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 339 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 340 | * iwl4965_enqueue_hcmd - enqueue a uCode command |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 341 | * @priv: device private data point |
| 342 | * @cmd: a point to the ucode command structure |
| 343 | * |
| 344 | * The function returns < 0 values to indicate the operation is |
| 345 | * failed. On success, it turns the index (> 0) of command in the |
| 346 | * command queue. |
| 347 | */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 348 | int iwl4965_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 349 | { |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 350 | struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 351 | struct iwl_queue *q = &txq->q; |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 352 | struct iwl_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 353 | u32 *control_flags; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 354 | struct iwl_cmd *out_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 355 | u32 idx; |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 356 | u16 fix_size; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 357 | dma_addr_t phys_addr; |
| 358 | int ret; |
| 359 | unsigned long flags; |
| 360 | |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 361 | cmd->len = priv->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len); |
| 362 | fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 363 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 364 | /* If any of the command structures end up being larger than |
| 365 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
| 366 | * we will need to increase the size of the TFD entries */ |
| 367 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
| 368 | !(cmd->meta.flags & CMD_SIZE_HUGE)); |
| 369 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 370 | if (iwl_is_rfkill(priv)) { |
Gregory Greenman | c342a1b | 2008-02-06 11:20:40 -0800 | [diff] [blame] | 371 | IWL_DEBUG_INFO("Not sending command - RF KILL"); |
| 372 | return -EIO; |
| 373 | } |
| 374 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 375 | if (iwl_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 376 | IWL_ERROR("No space for Tx\n"); |
| 377 | return -ENOSPC; |
| 378 | } |
| 379 | |
| 380 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 381 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 382 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 383 | memset(tfd, 0, sizeof(*tfd)); |
| 384 | |
| 385 | control_flags = (u32 *) tfd; |
| 386 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 387 | 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] | 388 | out_cmd = &txq->cmd[idx]; |
| 389 | |
| 390 | out_cmd->hdr.cmd = cmd->id; |
| 391 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 392 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 393 | |
| 394 | /* At this point, the out_cmd now has all of the incoming cmd |
| 395 | * information */ |
| 396 | |
| 397 | out_cmd->hdr.flags = 0; |
| 398 | 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] | 399 | INDEX_TO_SEQ(q->write_ptr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 400 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
| 401 | out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME); |
| 402 | |
| 403 | phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx + |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 404 | offsetof(struct iwl_cmd, hdr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 405 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, fix_size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 406 | |
| 407 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 408 | "%d bytes at %d[%d]:%d\n", |
| 409 | get_cmd_string(out_cmd->hdr.cmd), |
| 410 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 411 | fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 412 | |
| 413 | txq->need_update = 1; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 414 | |
| 415 | /* Set up entry in queue's byte count circular buffer */ |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 416 | priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, 0); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 417 | |
| 418 | /* Increment and update queue's write index */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 419 | q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 420 | ret = iwl_txq_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 421 | |
| 422 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 423 | return ret ? ret : idx; |
| 424 | } |
| 425 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 426 | static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) |
| 427 | { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 428 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 429 | |
| 430 | if (hw_decrypt) |
| 431 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 432 | else |
| 433 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 434 | |
| 435 | } |
| 436 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 437 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 438 | * iwl4965_rxon_add_station - add station into station table. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 439 | * |
| 440 | * there is only one AP station with id= IWL_AP_ID |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 441 | * NOTE: mutex must be held before calling this fnction |
| 442 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 443 | static int iwl4965_rxon_add_station(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 444 | const u8 *addr, int is_ap) |
| 445 | { |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 446 | u8 sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 447 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 448 | /* Add station to device's station table */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 449 | #ifdef CONFIG_IWL4965_HT |
| 450 | struct ieee80211_conf *conf = &priv->hw->conf; |
| 451 | struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf; |
| 452 | |
| 453 | if ((is_ap) && |
| 454 | (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) && |
| 455 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 456 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, |
| 457 | 0, cur_ht_config); |
| 458 | else |
| 459 | #endif /* CONFIG_IWL4965_HT */ |
| 460 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, |
| 461 | 0, NULL); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 462 | |
| 463 | /* Set up default rate scaling table in device's station table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 464 | iwl4965_add_station(priv, addr, is_ap); |
| 465 | |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 466 | return sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 470 | * iwl4965_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 471 | * |
| 472 | * NOTE: This is really only useful during development and can eventually |
| 473 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 474 | * making changes |
| 475 | */ |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 476 | static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 477 | { |
| 478 | int error = 0; |
| 479 | int counter = 1; |
| 480 | |
| 481 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 482 | error |= le32_to_cpu(rxon->flags & |
| 483 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 484 | RXON_FLG_RADAR_DETECT_MSK)); |
| 485 | if (error) |
| 486 | IWL_WARNING("check 24G fields %d | %d\n", |
| 487 | counter++, error); |
| 488 | } else { |
| 489 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 490 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 491 | if (error) |
| 492 | IWL_WARNING("check 52 fields %d | %d\n", |
| 493 | counter++, error); |
| 494 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 495 | if (error) |
| 496 | IWL_WARNING("check 52 CCK %d | %d\n", |
| 497 | counter++, error); |
| 498 | } |
| 499 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 500 | if (error) |
| 501 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); |
| 502 | |
| 503 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 504 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 505 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 506 | if (error) |
| 507 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); |
| 508 | |
| 509 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 510 | if (error) |
| 511 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); |
| 512 | |
| 513 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 514 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 515 | if (error) |
| 516 | IWL_WARNING("check CCK and short slot %d | %d\n", |
| 517 | counter++, error); |
| 518 | |
| 519 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 520 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 521 | if (error) |
| 522 | IWL_WARNING("check CCK & auto detect %d | %d\n", |
| 523 | counter++, error); |
| 524 | |
| 525 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 526 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 527 | if (error) |
| 528 | IWL_WARNING("check TGG and auto detect %d | %d\n", |
| 529 | counter++, error); |
| 530 | |
| 531 | if (error) |
| 532 | IWL_WARNING("Tuning to channel %d\n", |
| 533 | le16_to_cpu(rxon->channel)); |
| 534 | |
| 535 | if (error) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 536 | IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 537 | return -1; |
| 538 | } |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 543 | * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 544 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 545 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 546 | * If the RXON structure is changing enough to require a new tune, |
| 547 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 548 | * 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] | 549 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 550 | static int iwl4965_full_rxon_required(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 551 | { |
| 552 | |
| 553 | /* These items are only settable from the full RXON command */ |
| 554 | if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || |
| 555 | compare_ether_addr(priv->staging_rxon.bssid_addr, |
| 556 | priv->active_rxon.bssid_addr) || |
| 557 | compare_ether_addr(priv->staging_rxon.node_addr, |
| 558 | priv->active_rxon.node_addr) || |
| 559 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, |
| 560 | priv->active_rxon.wlap_bssid_addr) || |
| 561 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || |
| 562 | (priv->staging_rxon.channel != priv->active_rxon.channel) || |
| 563 | (priv->staging_rxon.air_propagation != |
| 564 | priv->active_rxon.air_propagation) || |
| 565 | (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != |
| 566 | priv->active_rxon.ofdm_ht_single_stream_basic_rates) || |
| 567 | (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != |
| 568 | priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || |
| 569 | (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) || |
| 570 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) |
| 571 | return 1; |
| 572 | |
| 573 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 574 | * be updated with the RXON_ASSOC command -- however only some |
| 575 | * flag transitions are allowed using RXON_ASSOC */ |
| 576 | |
| 577 | /* Check if we are not switching bands */ |
| 578 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 579 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
| 580 | return 1; |
| 581 | |
| 582 | /* Check if we are switching association toggle */ |
| 583 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 584 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
| 585 | return 1; |
| 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 590 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 591 | * iwl4965_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 592 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 593 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 594 | * the active_rxon structure is updated with the new data. This |
| 595 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 596 | * a HW tune is required based on the RXON structure changes. |
| 597 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 598 | static int iwl4965_commit_rxon(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 599 | { |
| 600 | /* cast away the const for active_rxon in this function */ |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 601 | struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 602 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 603 | int rc = 0; |
| 604 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 605 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 606 | return -1; |
| 607 | |
| 608 | /* always get timestamp with Rx frame */ |
| 609 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
| 610 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 611 | rc = iwl4965_check_rxon_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 612 | if (rc) { |
| 613 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); |
| 614 | return -EINVAL; |
| 615 | } |
| 616 | |
| 617 | /* 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] | 618 | * iwl4965_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 619 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 620 | if (!iwl4965_full_rxon_required(priv)) { |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 621 | rc = iwl_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 622 | if (rc) { |
| 623 | IWL_ERROR("Error setting RXON_ASSOC " |
| 624 | "configuration (%d).\n", rc); |
| 625 | return rc; |
| 626 | } |
| 627 | |
| 628 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 629 | |
| 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | /* station table will be cleared */ |
| 634 | priv->assoc_station_added = 0; |
| 635 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 636 | /* If we are currently associated and the new config requires |
| 637 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 638 | * we must clear the associated from the active configuration |
| 639 | * before we apply the new config */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 640 | if (iwl_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 641 | (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
| 642 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 643 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 644 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 645 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 646 | sizeof(struct iwl_rxon_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 647 | &priv->active_rxon); |
| 648 | |
| 649 | /* If the mask clearing failed then we set |
| 650 | * active_rxon back to what it was previously */ |
| 651 | if (rc) { |
| 652 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 653 | IWL_ERROR("Error clearing ASSOC_MSK on current " |
| 654 | "configuration (%d).\n", rc); |
| 655 | return rc; |
| 656 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | IWL_DEBUG_INFO("Sending RXON\n" |
| 660 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 661 | "* channel = %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 662 | "* bssid = %s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 663 | ((priv->staging_rxon.filter_flags & |
| 664 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
| 665 | le16_to_cpu(priv->staging_rxon.channel), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 666 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 667 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 668 | iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 669 | /* Apply the new configuration */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 670 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 671 | sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 672 | if (rc) { |
| 673 | IWL_ERROR("Error setting new configuration (%d).\n", rc); |
| 674 | return rc; |
| 675 | } |
| 676 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 677 | iwlcore_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 678 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 679 | if (!priv->error_recovering) |
| 680 | priv->start_calib = 0; |
| 681 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 682 | iwl_init_sensitivity(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 683 | |
| 684 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 685 | |
| 686 | /* If we issue a new RXON command which required a tune then we must |
| 687 | * 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] | 688 | rc = iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 689 | if (rc) { |
| 690 | IWL_ERROR("Error setting Tx power (%d).\n", rc); |
| 691 | return rc; |
| 692 | } |
| 693 | |
| 694 | /* Add the broadcast address so we can send broadcast frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 695 | if (iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 696 | IWL_INVALID_STATION) { |
| 697 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); |
| 698 | return -EIO; |
| 699 | } |
| 700 | |
| 701 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 702 | * add the IWL_AP_ID to the station rate table */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 703 | if (iwl_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 704 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 705 | if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 706 | == IWL_INVALID_STATION) { |
| 707 | IWL_ERROR("Error adding AP address for transmit.\n"); |
| 708 | return -EIO; |
| 709 | } |
| 710 | priv->assoc_station_added = 1; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 711 | if (priv->default_wep_key && |
| 712 | iwl_send_static_wepkey_cmd(priv, 0)) |
| 713 | IWL_ERROR("Could not send WEP static key.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | return 0; |
| 717 | } |
| 718 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 719 | void iwl4965_update_chain_flags(struct iwl_priv *priv) |
| 720 | { |
| 721 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 722 | iwl_set_rxon_chain(priv); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 723 | iwl4965_commit_rxon(priv); |
| 724 | } |
| 725 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 726 | static int iwl4965_send_bt_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 727 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 728 | struct iwl4965_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 729 | .flags = 3, |
| 730 | .lead_time = 0xAA, |
| 731 | .max_kill = 1, |
| 732 | .kill_ack_mask = 0, |
| 733 | .kill_cts_mask = 0, |
| 734 | }; |
| 735 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 736 | return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 737 | sizeof(struct iwl4965_bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 740 | static int iwl4965_send_scan_abort(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 741 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 742 | int ret = 0; |
| 743 | struct iwl_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 744 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 745 | .id = REPLY_SCAN_ABORT_CMD, |
| 746 | .meta.flags = CMD_WANT_SKB, |
| 747 | }; |
| 748 | |
| 749 | /* If there isn't a scan actively going on in the hardware |
| 750 | * then we are in between scan bands and not actually |
| 751 | * actively scanning, so don't send the abort command */ |
| 752 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 753 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 754 | return 0; |
| 755 | } |
| 756 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 757 | ret = iwl_send_cmd_sync(priv, &cmd); |
| 758 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 759 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 760 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 761 | } |
| 762 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 763 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 764 | if (res->u.status != CAN_ABORT_STATUS) { |
| 765 | /* The scan abort will return 1 for success or |
| 766 | * 2 for "failure". A failure condition can be |
| 767 | * due to simply not being in an active scan which |
| 768 | * can occur if we send the scan abort before we |
| 769 | * the microcode has notified us that a scan is |
| 770 | * completed. */ |
| 771 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 772 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 773 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 774 | } |
| 775 | |
| 776 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 777 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 778 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 779 | } |
| 780 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 781 | /* |
| 782 | * CARD_STATE_CMD |
| 783 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 784 | * 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] | 785 | * |
| 786 | * When in the 'enable' state the card operates as normal. |
| 787 | * When in the 'disable' state, the card enters into a low power mode. |
| 788 | * When in the 'halt' state, the card is shut down and must be fully |
| 789 | * restarted to come back on. |
| 790 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 791 | static int iwl4965_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 792 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 793 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 794 | .id = REPLY_CARD_STATE_CMD, |
| 795 | .len = sizeof(u32), |
| 796 | .data = &flags, |
| 797 | .meta.flags = meta_flag, |
| 798 | }; |
| 799 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 800 | return iwl_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 803 | static void iwl_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 804 | { |
| 805 | struct list_head *element; |
| 806 | |
| 807 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 808 | priv->frames_count); |
| 809 | |
| 810 | while (!list_empty(&priv->free_frames)) { |
| 811 | element = priv->free_frames.next; |
| 812 | list_del(element); |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 813 | kfree(list_entry(element, struct iwl_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 814 | priv->frames_count--; |
| 815 | } |
| 816 | |
| 817 | if (priv->frames_count) { |
| 818 | IWL_WARNING("%d frames still in use. Did we lose one?\n", |
| 819 | priv->frames_count); |
| 820 | priv->frames_count = 0; |
| 821 | } |
| 822 | } |
| 823 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 824 | static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 825 | { |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 826 | struct iwl_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 827 | struct list_head *element; |
| 828 | if (list_empty(&priv->free_frames)) { |
| 829 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 830 | if (!frame) { |
| 831 | IWL_ERROR("Could not allocate frame!\n"); |
| 832 | return NULL; |
| 833 | } |
| 834 | |
| 835 | priv->frames_count++; |
| 836 | return frame; |
| 837 | } |
| 838 | |
| 839 | element = priv->free_frames.next; |
| 840 | list_del(element); |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 841 | return list_entry(element, struct iwl_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 844 | static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 845 | { |
| 846 | memset(frame, 0, sizeof(*frame)); |
| 847 | list_add(&frame->list, &priv->free_frames); |
| 848 | } |
| 849 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 850 | unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 851 | struct ieee80211_hdr *hdr, |
| 852 | const u8 *dest, int left) |
| 853 | { |
| 854 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 855 | if (!iwl_is_associated(priv) || !priv->ibss_beacon || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 856 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
| 857 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) |
| 858 | return 0; |
| 859 | |
| 860 | if (priv->ibss_beacon->len > left) |
| 861 | return 0; |
| 862 | |
| 863 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 864 | |
| 865 | return priv->ibss_beacon->len; |
| 866 | } |
| 867 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 868 | static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 869 | { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 870 | int i; |
| 871 | int rate_mask; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 872 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 873 | /* Set rate mask*/ |
| 874 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 875 | rate_mask = priv->active_rate_basic & 0xF; |
| 876 | else |
| 877 | rate_mask = priv->active_rate_basic & 0xFF0; |
| 878 | |
| 879 | /* Find lowest valid rate */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 880 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame^] | 881 | i = iwl_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 882 | if (rate_mask & (1 << i)) |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame^] | 883 | return iwl_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 884 | } |
| 885 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 886 | /* No valid rate was found. Assign the lowest one */ |
| 887 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 888 | return IWL_RATE_1M_PLCP; |
| 889 | else |
| 890 | return IWL_RATE_6M_PLCP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 891 | } |
| 892 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 893 | static int iwl4965_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 894 | { |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 895 | struct iwl_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 896 | unsigned int frame_size; |
| 897 | int rc; |
| 898 | u8 rate; |
| 899 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 900 | frame = iwl_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 901 | |
| 902 | if (!frame) { |
| 903 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 904 | "command.\n"); |
| 905 | return -ENOMEM; |
| 906 | } |
| 907 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 908 | rate = iwl4965_rate_get_lowest_plcp(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 909 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 910 | frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 911 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 912 | rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 913 | &frame->u.cmd[0]); |
| 914 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 915 | iwl_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 916 | |
| 917 | return rc; |
| 918 | } |
| 919 | |
| 920 | /****************************************************************************** |
| 921 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 922 | * Misc. internal state and helper functions |
| 923 | * |
| 924 | ******************************************************************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 925 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 926 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 927 | * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 928 | * |
| 929 | * return : set the bit for each supported rate insert in ie |
| 930 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 931 | static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 932 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 933 | { |
| 934 | u16 ret_rates = 0, bit; |
| 935 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 936 | u8 *cnt = ie; |
| 937 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 938 | |
| 939 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 940 | if (bit & supported_rate) { |
| 941 | ret_rates |= bit; |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame^] | 942 | rates[*cnt] = iwl_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 943 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 944 | (*cnt)++; |
| 945 | (*left)--; |
| 946 | if ((*left <= 0) || |
| 947 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 948 | break; |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | return ret_rates; |
| 953 | } |
| 954 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 955 | #ifdef CONFIG_IWL4965_HT |
| 956 | static void iwl4965_ht_conf(struct iwl_priv *priv, |
| 957 | struct ieee80211_bss_conf *bss_conf) |
| 958 | { |
| 959 | struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf; |
| 960 | struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf; |
| 961 | struct iwl_ht_info *iwl_conf = &priv->current_ht_config; |
| 962 | |
| 963 | IWL_DEBUG_MAC80211("enter: \n"); |
| 964 | |
| 965 | iwl_conf->is_ht = bss_conf->assoc_ht; |
| 966 | |
| 967 | if (!iwl_conf->is_ht) |
| 968 | return; |
| 969 | |
| 970 | priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 971 | |
| 972 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) |
| 973 | iwl_conf->sgf |= 0x1; |
| 974 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) |
| 975 | iwl_conf->sgf |= 0x2; |
| 976 | |
| 977 | iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); |
| 978 | iwl_conf->max_amsdu_size = |
| 979 | !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); |
| 980 | |
| 981 | iwl_conf->supported_chan_width = |
| 982 | !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); |
| 983 | iwl_conf->extension_chan_offset = |
| 984 | ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; |
| 985 | /* If no above or below channel supplied disable FAT channel */ |
| 986 | if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE && |
| 987 | iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW) |
| 988 | iwl_conf->supported_chan_width = 0; |
| 989 | |
| 990 | iwl_conf->tx_mimo_ps_mode = |
| 991 | (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 992 | memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); |
| 993 | |
| 994 | iwl_conf->control_channel = ht_bss_conf->primary_channel; |
| 995 | iwl_conf->tx_chan_width = |
| 996 | !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); |
| 997 | iwl_conf->ht_protection = |
| 998 | ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; |
| 999 | iwl_conf->non_GF_STA_present = |
| 1000 | !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT); |
| 1001 | |
| 1002 | IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel); |
| 1003 | IWL_DEBUG_MAC80211("leave\n"); |
| 1004 | } |
| 1005 | |
| 1006 | static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband, |
| 1007 | u8 *pos, int *left) |
| 1008 | { |
| 1009 | struct ieee80211_ht_cap *ht_cap; |
| 1010 | |
| 1011 | if (!sband || !sband->ht_info.ht_supported) |
| 1012 | return; |
| 1013 | |
| 1014 | if (*left < sizeof(struct ieee80211_ht_cap)) |
| 1015 | return; |
| 1016 | |
| 1017 | *pos++ = sizeof(struct ieee80211_ht_cap); |
| 1018 | ht_cap = (struct ieee80211_ht_cap *) pos; |
| 1019 | |
| 1020 | ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap); |
| 1021 | memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16); |
| 1022 | ht_cap->ampdu_params_info = |
| 1023 | (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) | |
| 1024 | ((sband->ht_info.ampdu_density << 2) & |
| 1025 | IEEE80211_HT_CAP_AMPDU_DENSITY); |
| 1026 | *left -= sizeof(struct ieee80211_ht_cap); |
| 1027 | } |
| 1028 | #else |
| 1029 | static inline void iwl4965_ht_conf(struct iwl_priv *priv, |
| 1030 | struct ieee80211_bss_conf *bss_conf) |
| 1031 | { |
| 1032 | } |
| 1033 | static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband, |
| 1034 | u8 *pos, int *left) |
| 1035 | { |
| 1036 | } |
| 1037 | #endif |
| 1038 | |
| 1039 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1040 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1041 | * iwl4965_fill_probe_req - fill in all required fields and IE for probe request |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1042 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1043 | static u16 iwl4965_fill_probe_req(struct iwl_priv *priv, |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1044 | enum ieee80211_band band, |
| 1045 | struct ieee80211_mgmt *frame, |
| 1046 | int left, int is_direct) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1047 | { |
| 1048 | int len = 0; |
| 1049 | u8 *pos = NULL; |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1050 | u16 active_rates, ret_rates, cck_rates, active_rate_basic; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1051 | const struct ieee80211_supported_band *sband = |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 1052 | iwl_get_hw_mode(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1053 | |
| 1054 | /* Make sure there is enough space for the probe request, |
| 1055 | * two mandatory IEs and the data */ |
| 1056 | left -= 24; |
| 1057 | if (left < 0) |
| 1058 | return 0; |
| 1059 | len += 24; |
| 1060 | |
| 1061 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1062 | memcpy(frame->da, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1063 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1064 | memcpy(frame->bssid, iwl4965_broadcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1065 | frame->seq_ctrl = 0; |
| 1066 | |
| 1067 | /* fill in our indirect SSID IE */ |
| 1068 | /* ...next IE... */ |
| 1069 | |
| 1070 | left -= 2; |
| 1071 | if (left < 0) |
| 1072 | return 0; |
| 1073 | len += 2; |
| 1074 | pos = &(frame->u.probe_req.variable[0]); |
| 1075 | *pos++ = WLAN_EID_SSID; |
| 1076 | *pos++ = 0; |
| 1077 | |
| 1078 | /* fill in our direct SSID IE... */ |
| 1079 | if (is_direct) { |
| 1080 | /* ...next IE... */ |
| 1081 | left -= 2 + priv->essid_len; |
| 1082 | if (left < 0) |
| 1083 | return 0; |
| 1084 | /* ... fill it in... */ |
| 1085 | *pos++ = WLAN_EID_SSID; |
| 1086 | *pos++ = priv->essid_len; |
| 1087 | memcpy(pos, priv->essid, priv->essid_len); |
| 1088 | pos += priv->essid_len; |
| 1089 | len += 2 + priv->essid_len; |
| 1090 | } |
| 1091 | |
| 1092 | /* fill in supported rate */ |
| 1093 | /* ...next IE... */ |
| 1094 | left -= 2; |
| 1095 | if (left < 0) |
| 1096 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1097 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1098 | /* ... fill it in... */ |
| 1099 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1100 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1101 | |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1102 | /* exclude 60M rate */ |
| 1103 | active_rates = priv->rates_mask; |
| 1104 | active_rates &= ~IWL_RATE_60M_MASK; |
| 1105 | |
| 1106 | active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1107 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1108 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1109 | ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1110 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1111 | active_rates &= ~ret_rates; |
| 1112 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1113 | ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1114 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1115 | active_rates &= ~ret_rates; |
| 1116 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1117 | len += 2 + *pos; |
| 1118 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1119 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1120 | goto fill_end; |
| 1121 | |
| 1122 | /* fill in supported extended rate */ |
| 1123 | /* ...next IE... */ |
| 1124 | left -= 2; |
| 1125 | if (left < 0) |
| 1126 | return 0; |
| 1127 | /* ... fill it in... */ |
| 1128 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1129 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1130 | iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1131 | active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1132 | if (*pos > 0) |
| 1133 | len += 2 + *pos; |
| 1134 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1135 | fill_end: |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 1136 | /* fill in HT IE */ |
| 1137 | left -= 2; |
| 1138 | if (left < 0) |
| 1139 | return 0; |
| 1140 | |
| 1141 | *pos++ = WLAN_EID_HT_CAPABILITY; |
| 1142 | *pos = 0; |
| 1143 | |
| 1144 | iwl_ht_cap_to_ie(sband, pos, &left); |
| 1145 | |
| 1146 | if (*pos > 0) |
| 1147 | len += 2 + *pos; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1148 | return (u16)len; |
| 1149 | } |
| 1150 | |
| 1151 | /* |
| 1152 | * QoS support |
| 1153 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1154 | static int iwl4965_send_qos_params_command(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1155 | struct iwl4965_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1156 | { |
| 1157 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1158 | return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1159 | sizeof(struct iwl4965_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1162 | static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1163 | { |
| 1164 | unsigned long flags; |
| 1165 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1166 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 1167 | return; |
| 1168 | |
| 1169 | if (!priv->qos_data.qos_enable) |
| 1170 | return; |
| 1171 | |
| 1172 | spin_lock_irqsave(&priv->lock, flags); |
| 1173 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 1174 | |
| 1175 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 1176 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 1177 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1178 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1179 | if (priv->qos_data.qos_active) |
| 1180 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1181 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 1182 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1183 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 1184 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1185 | priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1186 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1187 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1188 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1189 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1190 | if (force || iwl_is_associated(priv)) { |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1191 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 1192 | priv->qos_data.qos_active, |
| 1193 | priv->qos_data.def_qos_parm.qos_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1194 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1195 | iwl4965_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1196 | &(priv->qos_data.def_qos_parm)); |
| 1197 | } |
| 1198 | } |
| 1199 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1200 | int iwl4965_is_network_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1201 | { |
| 1202 | /* Filter incoming packets to determine if they are targeted toward |
| 1203 | * this network, discarding packets coming from ourselves */ |
| 1204 | switch (priv->iw_mode) { |
| 1205 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 1206 | /* packets from our adapter are dropped (echo) */ |
| 1207 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 1208 | return 0; |
| 1209 | /* {broad,multi}cast packets to our IBSS go through */ |
| 1210 | if (is_multicast_ether_addr(header->addr1)) |
| 1211 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 1212 | /* packets to our adapter go through */ |
| 1213 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 1214 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 1215 | /* packets from our adapter are dropped (echo) */ |
| 1216 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 1217 | return 0; |
| 1218 | /* {broad,multi}cast packets to our BSS go through */ |
| 1219 | if (is_multicast_ether_addr(header->addr1)) |
| 1220 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 1221 | /* packets to our adapter go through */ |
| 1222 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1223 | default: |
| 1224 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | return 1; |
| 1228 | } |
| 1229 | |
| 1230 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 1231 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1232 | static const char *iwl4965_get_tx_fail_reason(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1233 | { |
| 1234 | switch (status & TX_STATUS_MSK) { |
| 1235 | case TX_STATUS_SUCCESS: |
| 1236 | return "SUCCESS"; |
| 1237 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 1238 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 1239 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 1240 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 1241 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 1242 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 1243 | TX_STATUS_ENTRY(DEST_PS); |
| 1244 | TX_STATUS_ENTRY(ABORTED); |
| 1245 | TX_STATUS_ENTRY(BT_RETRY); |
| 1246 | TX_STATUS_ENTRY(STA_INVALID); |
| 1247 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 1248 | TX_STATUS_ENTRY(TID_DISABLE); |
| 1249 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 1250 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 1251 | TX_STATUS_ENTRY(TX_LOCKED); |
| 1252 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 1253 | } |
| 1254 | |
| 1255 | return "UNKNOWN"; |
| 1256 | } |
| 1257 | |
| 1258 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1259 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1260 | * |
| 1261 | * NOTE: priv->mutex is not required before calling this function |
| 1262 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1263 | static int iwl4965_scan_cancel(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1264 | { |
| 1265 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1266 | clear_bit(STATUS_SCANNING, &priv->status); |
| 1267 | return 0; |
| 1268 | } |
| 1269 | |
| 1270 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1271 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1272 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 1273 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1274 | queue_work(priv->workqueue, &priv->abort_scan); |
| 1275 | |
| 1276 | } else |
| 1277 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 1278 | |
| 1279 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1280 | } |
| 1281 | |
| 1282 | return 0; |
| 1283 | } |
| 1284 | |
| 1285 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1286 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1287 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 1288 | * |
| 1289 | * NOTE: priv->mutex must be held before calling this function |
| 1290 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1291 | static int iwl4965_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1292 | { |
| 1293 | unsigned long now = jiffies; |
| 1294 | int ret; |
| 1295 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1296 | ret = iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1297 | if (ret && ms) { |
| 1298 | mutex_unlock(&priv->mutex); |
| 1299 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 1300 | test_bit(STATUS_SCANNING, &priv->status)) |
| 1301 | msleep(1); |
| 1302 | mutex_lock(&priv->mutex); |
| 1303 | |
| 1304 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1305 | } |
| 1306 | |
| 1307 | return ret; |
| 1308 | } |
| 1309 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1310 | static void iwl4965_sequence_reset(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1311 | { |
| 1312 | /* Reset ieee stats */ |
| 1313 | |
| 1314 | /* We don't reset the net_device_stats (ieee->stats) on |
| 1315 | * re-association */ |
| 1316 | |
| 1317 | priv->last_seq_num = -1; |
| 1318 | priv->last_frag_num = -1; |
| 1319 | priv->last_packet_time = 0; |
| 1320 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1321 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 1325 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 1326 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1327 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1328 | { |
| 1329 | u16 new_val = 0; |
| 1330 | u16 beacon_factor = 0; |
| 1331 | |
| 1332 | beacon_factor = |
| 1333 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 1334 | / MAX_UCODE_BEACON_INTERVAL; |
| 1335 | new_val = beacon_val / beacon_factor; |
| 1336 | |
| 1337 | return cpu_to_le16(new_val); |
| 1338 | } |
| 1339 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1340 | static void iwl4965_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1341 | { |
| 1342 | u64 interval_tm_unit; |
| 1343 | u64 tsf, result; |
| 1344 | unsigned long flags; |
| 1345 | struct ieee80211_conf *conf = NULL; |
| 1346 | u16 beacon_int = 0; |
| 1347 | |
| 1348 | conf = ieee80211_get_hw_conf(priv->hw); |
| 1349 | |
| 1350 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1351 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32); |
| 1352 | priv->rxon_timing.timestamp.dw[0] = |
| 1353 | cpu_to_le32(priv->timestamp & 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1354 | |
| 1355 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 1356 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1357 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1358 | |
| 1359 | beacon_int = priv->beacon_int; |
| 1360 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1361 | |
| 1362 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 1363 | if (beacon_int == 0) { |
| 1364 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 1365 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 1366 | } else { |
| 1367 | priv->rxon_timing.beacon_interval = |
| 1368 | cpu_to_le16(beacon_int); |
| 1369 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1370 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1371 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1372 | } |
| 1373 | |
| 1374 | priv->rxon_timing.atim_window = 0; |
| 1375 | } else { |
| 1376 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1377 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1378 | /* TODO: we need to get atim_window from upper stack |
| 1379 | * for now we set to 0 */ |
| 1380 | priv->rxon_timing.atim_window = 0; |
| 1381 | } |
| 1382 | |
| 1383 | interval_tm_unit = |
| 1384 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 1385 | result = do_div(tsf, interval_tm_unit); |
| 1386 | priv->rxon_timing.beacon_init_val = |
| 1387 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 1388 | |
| 1389 | IWL_DEBUG_ASSOC |
| 1390 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 1391 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 1392 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 1393 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 1394 | } |
| 1395 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1396 | static int iwl4965_scan_initiate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1397 | { |
| 1398 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 1399 | IWL_ERROR("APs don't scan.\n"); |
| 1400 | return 0; |
| 1401 | } |
| 1402 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1403 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1404 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 1405 | return -EIO; |
| 1406 | } |
| 1407 | |
| 1408 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1409 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 1410 | return -EAGAIN; |
| 1411 | } |
| 1412 | |
| 1413 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1414 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 1415 | "Queuing.\n"); |
| 1416 | return -EAGAIN; |
| 1417 | } |
| 1418 | |
| 1419 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 1420 | priv->scan_bands = 2; |
| 1421 | set_bit(STATUS_SCANNING, &priv->status); |
| 1422 | priv->scan_start = jiffies; |
| 1423 | priv->scan_pass_start = priv->scan_start; |
| 1424 | |
| 1425 | queue_work(priv->workqueue, &priv->request_scan); |
| 1426 | |
| 1427 | return 0; |
| 1428 | } |
| 1429 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1430 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1431 | static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1432 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1433 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1434 | if (band == IEEE80211_BAND_5GHZ) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1435 | priv->staging_rxon.flags &= |
| 1436 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 1437 | | RXON_FLG_CCK_MSK); |
| 1438 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1439 | } else { |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 1440 | /* Copied from iwl4965_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1441 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 1442 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1443 | else |
| 1444 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1445 | |
| 1446 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 1447 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1448 | |
| 1449 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 1450 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 1451 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1456 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1457 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1458 | static void iwl4965_connection_init_rx_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1459 | { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1460 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1461 | |
| 1462 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 1463 | |
| 1464 | switch (priv->iw_mode) { |
| 1465 | case IEEE80211_IF_TYPE_AP: |
| 1466 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 1467 | break; |
| 1468 | |
| 1469 | case IEEE80211_IF_TYPE_STA: |
| 1470 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 1471 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 1472 | break; |
| 1473 | |
| 1474 | case IEEE80211_IF_TYPE_IBSS: |
| 1475 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 1476 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1477 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 1478 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1479 | break; |
| 1480 | |
| 1481 | case IEEE80211_IF_TYPE_MNTR: |
| 1482 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 1483 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 1484 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1485 | break; |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1486 | default: |
| 1487 | IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode); |
| 1488 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1489 | } |
| 1490 | |
| 1491 | #if 0 |
| 1492 | /* TODO: Figure out when short_preamble would be set and cache from |
| 1493 | * that */ |
| 1494 | if (!hw_to_local(priv->hw)->short_preamble) |
| 1495 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1496 | else |
| 1497 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1498 | #endif |
| 1499 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1500 | ch_info = iwl_get_channel_info(priv, priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1501 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1502 | |
| 1503 | if (!ch_info) |
| 1504 | ch_info = &priv->channel_info[0]; |
| 1505 | |
| 1506 | /* |
| 1507 | * in some case A channels are all non IBSS |
| 1508 | * in this case force B/G channel |
| 1509 | */ |
| 1510 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 1511 | !(is_channel_ibss(ch_info))) |
| 1512 | ch_info = &priv->channel_info[0]; |
| 1513 | |
| 1514 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1515 | priv->band = ch_info->band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1516 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1517 | iwl4965_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1518 | |
| 1519 | priv->staging_rxon.ofdm_basic_rates = |
| 1520 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1521 | priv->staging_rxon.cck_basic_rates = |
| 1522 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1523 | |
| 1524 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 1525 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 1526 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1527 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 1528 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 1529 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 1530 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1531 | } |
| 1532 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1533 | static int iwl4965_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1534 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1535 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1536 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1537 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1538 | ch_info = iwl_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1539 | priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1540 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1541 | |
| 1542 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 1543 | IWL_ERROR("channel %d not IBSS channel\n", |
| 1544 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1545 | return -EINVAL; |
| 1546 | } |
| 1547 | } |
| 1548 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1549 | priv->iw_mode = mode; |
| 1550 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1551 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1552 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1553 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1554 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1555 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1556 | /* dont commit rxon if rf-kill is on*/ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1557 | if (!iwl_is_ready_rf(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1558 | return -EAGAIN; |
| 1559 | |
| 1560 | cancel_delayed_work(&priv->scan_check); |
| 1561 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
| 1562 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 1563 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 1564 | return -EAGAIN; |
| 1565 | } |
| 1566 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1567 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1568 | |
| 1569 | return 0; |
| 1570 | } |
| 1571 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1572 | static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1573 | struct ieee80211_tx_control *ctl, |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1574 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1575 | struct sk_buff *skb_frag, |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 1576 | int sta_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1577 | { |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 1578 | struct iwl_hw_key *keyinfo = &priv->stations[sta_id].keyinfo; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1579 | struct iwl_wep_key *wepkey; |
| 1580 | int keyidx = 0; |
| 1581 | |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 1582 | BUG_ON(ctl->hw_key->hw_key_idx > 3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1583 | |
| 1584 | switch (keyinfo->alg) { |
| 1585 | case ALG_CCMP: |
| 1586 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM; |
| 1587 | memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen); |
Max Stepanov | 8236e18 | 2008-03-12 16:58:48 -0700 | [diff] [blame] | 1588 | if (ctl->flags & IEEE80211_TXCTL_AMPDU) |
| 1589 | cmd->cmd.tx.tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1590 | IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n"); |
| 1591 | break; |
| 1592 | |
| 1593 | case ALG_TKIP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1594 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP; |
Emmanuel Grumbach | 2bc7508 | 2008-03-19 16:41:45 -0700 | [diff] [blame] | 1595 | ieee80211_get_tkip_key(keyinfo->conf, skb_frag, |
| 1596 | IEEE80211_TKIP_P2_KEY, cmd->cmd.tx.key); |
| 1597 | IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1598 | break; |
| 1599 | |
| 1600 | case ALG_WEP: |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 1601 | wepkey = &priv->wep_keys[ctl->hw_key->hw_key_idx]; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1602 | cmd->cmd.tx.sec_ctl = 0; |
| 1603 | if (priv->default_wep_key) { |
| 1604 | /* the WEP key was sent as static */ |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 1605 | keyidx = ctl->hw_key->hw_key_idx; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1606 | memcpy(&cmd->cmd.tx.key[3], wepkey->key, |
| 1607 | wepkey->key_size); |
| 1608 | if (wepkey->key_size == WEP_KEY_LEN_128) |
| 1609 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
| 1610 | } else { |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 1611 | /* the WEP key was sent as dynamic */ |
| 1612 | keyidx = keyinfo->keyidx; |
| 1613 | memcpy(&cmd->cmd.tx.key[3], keyinfo->key, |
| 1614 | keyinfo->keylen); |
| 1615 | if (keyinfo->keylen == WEP_KEY_LEN_128) |
| 1616 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1617 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1618 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1619 | cmd->cmd.tx.sec_ctl |= (TX_CMD_SEC_WEP | |
| 1620 | (keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1621 | |
| 1622 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1623 | "with key %d\n", keyidx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1624 | break; |
| 1625 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1626 | default: |
| 1627 | printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg); |
| 1628 | break; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | /* |
| 1633 | * handle build REPLY_TX command notification. |
| 1634 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1635 | static void iwl4965_build_tx_cmd_basic(struct iwl_priv *priv, |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1636 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1637 | struct ieee80211_tx_control *ctrl, |
| 1638 | struct ieee80211_hdr *hdr, |
| 1639 | int is_unicast, u8 std_id) |
| 1640 | { |
| 1641 | __le16 *qc; |
| 1642 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 1643 | __le32 tx_flags = cmd->cmd.tx.tx_flags; |
| 1644 | |
| 1645 | cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 1646 | if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) { |
| 1647 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
| 1648 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 1649 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1650 | if (ieee80211_is_probe_response(fc) && |
| 1651 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 1652 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 1653 | } else { |
| 1654 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 1655 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1656 | } |
| 1657 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 1658 | if (ieee80211_is_back_request(fc)) |
| 1659 | tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK; |
| 1660 | |
| 1661 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1662 | cmd->cmd.tx.sta_id = std_id; |
| 1663 | if (ieee80211_get_morefrag(hdr)) |
| 1664 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 1665 | |
| 1666 | qc = ieee80211_get_qos_ctrl(hdr); |
| 1667 | if (qc) { |
| 1668 | cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf); |
| 1669 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
| 1670 | } else |
| 1671 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1672 | |
| 1673 | if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) { |
| 1674 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 1675 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
| 1676 | } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { |
| 1677 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 1678 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 1679 | } |
| 1680 | |
| 1681 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 1682 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 1683 | |
| 1684 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
| 1685 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { |
| 1686 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || |
| 1687 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1688 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1689 | else |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1690 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 1691 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1692 | cmd->cmd.tx.timeout.pm_frame_timeout = 0; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 1693 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1694 | |
| 1695 | cmd->cmd.tx.driver_txop = 0; |
| 1696 | cmd->cmd.tx.tx_flags = tx_flags; |
| 1697 | cmd->cmd.tx.next_frame_len = 0; |
| 1698 | } |
Tomas Winkler | 19758be | 2008-03-12 16:58:51 -0700 | [diff] [blame] | 1699 | static void iwl_update_tx_stats(struct iwl_priv *priv, u16 fc, u16 len) |
| 1700 | { |
| 1701 | /* 0 - mgmt, 1 - cnt, 2 - data */ |
| 1702 | int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2; |
| 1703 | priv->tx_stats[idx].cnt++; |
| 1704 | priv->tx_stats[idx].bytes += len; |
| 1705 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1706 | /** |
| 1707 | * iwl4965_get_sta_id - Find station's index within station table |
| 1708 | * |
| 1709 | * If new IBSS station, create new entry in station table |
| 1710 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1711 | static int iwl4965_get_sta_id(struct iwl_priv *priv, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1712 | struct ieee80211_hdr *hdr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1713 | { |
| 1714 | int sta_id; |
| 1715 | u16 fc = le16_to_cpu(hdr->frame_control); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1716 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1717 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1718 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1719 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 1720 | is_multicast_ether_addr(hdr->addr1)) |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1721 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1722 | |
| 1723 | switch (priv->iw_mode) { |
| 1724 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1725 | /* If we are a client station in a BSS network, use the special |
| 1726 | * AP station entry (that's the only station we communicate with) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1727 | case IEEE80211_IF_TYPE_STA: |
| 1728 | return IWL_AP_ID; |
| 1729 | |
| 1730 | /* If we are an AP, then find the station, or use BCAST */ |
| 1731 | case IEEE80211_IF_TYPE_AP: |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 1732 | sta_id = iwl_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1733 | if (sta_id != IWL_INVALID_STATION) |
| 1734 | return sta_id; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1735 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1736 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1737 | /* If this frame is going out to an IBSS network, find the station, |
| 1738 | * or create a new station table entry */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1739 | case IEEE80211_IF_TYPE_IBSS: |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 1740 | sta_id = iwl_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1741 | if (sta_id != IWL_INVALID_STATION) |
| 1742 | return sta_id; |
| 1743 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1744 | /* Create new station table entry */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 1745 | sta_id = iwl4965_add_station_flags(priv, hdr->addr1, |
| 1746 | 0, CMD_ASYNC, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1747 | |
| 1748 | if (sta_id != IWL_INVALID_STATION) |
| 1749 | return sta_id; |
| 1750 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1751 | IWL_DEBUG_DROP("Station %s not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1752 | "Defaulting to broadcast...\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1753 | print_mac(mac, hdr->addr1)); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1754 | iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1755 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1756 | |
| 1757 | default: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1758 | IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1759 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | /* |
| 1764 | * start REPLY_TX command process |
| 1765 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1766 | static int iwl4965_tx_skb(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1767 | struct sk_buff *skb, struct ieee80211_tx_control *ctl) |
| 1768 | { |
| 1769 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 1770 | struct iwl_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1771 | u32 *control_flags; |
| 1772 | int txq_id = ctl->queue; |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 1773 | struct iwl_tx_queue *txq = NULL; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 1774 | struct iwl_queue *q = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1775 | dma_addr_t phys_addr; |
| 1776 | dma_addr_t txcmd_phys; |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 1777 | dma_addr_t scratch_phys; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1778 | struct iwl_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1779 | u16 len, idx, len_org; |
| 1780 | u8 id, hdr_len, unicast; |
| 1781 | u8 sta_id; |
| 1782 | u16 seq_number = 0; |
| 1783 | u16 fc; |
| 1784 | __le16 *qc; |
| 1785 | u8 wait_write_ptr = 0; |
| 1786 | unsigned long flags; |
| 1787 | int rc; |
| 1788 | |
| 1789 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1790 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1791 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 1792 | goto drop_unlock; |
| 1793 | } |
| 1794 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 1795 | if (!priv->vif) { |
| 1796 | IWL_DEBUG_DROP("Dropping - !priv->vif\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1797 | goto drop_unlock; |
| 1798 | } |
| 1799 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1800 | if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1801 | IWL_ERROR("ERROR: No TX rate available.\n"); |
| 1802 | goto drop_unlock; |
| 1803 | } |
| 1804 | |
| 1805 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 1806 | id = 0; |
| 1807 | |
| 1808 | fc = le16_to_cpu(hdr->frame_control); |
| 1809 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1810 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1811 | if (ieee80211_is_auth(fc)) |
| 1812 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
| 1813 | else if (ieee80211_is_assoc_request(fc)) |
| 1814 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
| 1815 | else if (ieee80211_is_reassoc_request(fc)) |
| 1816 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 1817 | #endif |
| 1818 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 1819 | /* drop all data frame if we are not associated */ |
Gregory Greenman | 76f3915 | 2008-01-23 10:15:21 -0800 | [diff] [blame] | 1820 | if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) && |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1821 | (!iwl_is_associated(priv) || |
Reinette Chatre | a647724 | 2008-02-14 10:40:28 -0800 | [diff] [blame] | 1822 | ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id) || |
Gregory Greenman | 76f3915 | 2008-01-23 10:15:21 -0800 | [diff] [blame] | 1823 | !priv->assoc_station_added)) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1824 | IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1825 | goto drop_unlock; |
| 1826 | } |
| 1827 | |
| 1828 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1829 | |
| 1830 | hdr_len = ieee80211_get_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1831 | |
| 1832 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1833 | sta_id = iwl4965_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1834 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1835 | DECLARE_MAC_BUF(mac); |
| 1836 | |
| 1837 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n", |
| 1838 | print_mac(mac, hdr->addr1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1839 | goto drop; |
| 1840 | } |
| 1841 | |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 1842 | IWL_DEBUG_TX("station Id %d\n", sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1843 | |
| 1844 | qc = ieee80211_get_qos_ctrl(hdr); |
| 1845 | if (qc) { |
| 1846 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 1847 | seq_number = priv->stations[sta_id].tid[tid].seq_number & |
| 1848 | IEEE80211_SCTL_SEQ; |
| 1849 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 1850 | (hdr->seq_ctrl & |
| 1851 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 1852 | seq_number += 0x10; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1853 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1854 | /* aggregation is on for this <sta,tid> */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1855 | if (ctl->flags & IEEE80211_TXCTL_AMPDU) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1856 | txq_id = priv->stations[sta_id].tid[tid].agg.txq_id; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1857 | priv->stations[sta_id].tid[tid].tfds_in_queue++; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1858 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1859 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1860 | |
| 1861 | /* Descriptor for chosen Tx queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1862 | txq = &priv->txq[txq_id]; |
| 1863 | q = &txq->q; |
| 1864 | |
| 1865 | spin_lock_irqsave(&priv->lock, flags); |
| 1866 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1867 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1868 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1869 | memset(tfd, 0, sizeof(*tfd)); |
| 1870 | control_flags = (u32 *) tfd; |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1871 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1872 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1873 | /* Set up driver data for this TFD */ |
Tomas Winkler | 8567c63 | 2008-05-15 13:53:58 +0800 | [diff] [blame] | 1874 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1875 | txq->txb[q->write_ptr].skb[0] = skb; |
| 1876 | memcpy(&(txq->txb[q->write_ptr].status.control), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1877 | ctl, sizeof(struct ieee80211_tx_control)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1878 | |
| 1879 | /* Set up first empty entry in queue's array of Tx/cmd buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1880 | out_cmd = &txq->cmd[idx]; |
| 1881 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 1882 | memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1883 | |
| 1884 | /* |
| 1885 | * Set up the Tx-command (not MAC!) header. |
| 1886 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 1887 | * after Tx, uCode's Tx response will return this value so driver can |
| 1888 | * locate the frame within the tx queue and do post-tx processing. |
| 1889 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1890 | out_cmd->hdr.cmd = REPLY_TX; |
| 1891 | 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] | 1892 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1893 | |
| 1894 | /* Copy MAC header from skb into command buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1895 | memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); |
| 1896 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1897 | /* |
| 1898 | * Use the first empty entry in this queue's command buffer array |
| 1899 | * to contain the Tx command and MAC header concatenated together |
| 1900 | * (payload data will be in another buffer). |
| 1901 | * Size of this varies, due to varying MAC header length. |
| 1902 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 1903 | * of the MAC header (device reads on dword boundaries). |
| 1904 | * We'll tell device about this padding later. |
| 1905 | */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1906 | len = priv->hw_params.tx_cmd_len + |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1907 | sizeof(struct iwl_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1908 | |
| 1909 | len_org = len; |
| 1910 | len = (len + 3) & ~3; |
| 1911 | |
| 1912 | if (len_org != len) |
| 1913 | len_org = 1; |
| 1914 | else |
| 1915 | len_org = 0; |
| 1916 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1917 | /* Physical address of this Tx command's header (not MAC header!), |
| 1918 | * within command buffer array. */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1919 | txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx + |
| 1920 | offsetof(struct iwl_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1921 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1922 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 1923 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1924 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1925 | |
| 1926 | if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 1927 | iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1928 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1929 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 1930 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1931 | len = skb->len - hdr_len; |
| 1932 | if (len) { |
| 1933 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 1934 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1935 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1938 | /* Tell 4965 about any 2-byte padding after MAC header */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1939 | if (len_org) |
| 1940 | out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK; |
| 1941 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1942 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1943 | len = (u16)skb->len; |
| 1944 | out_cmd->cmd.tx.len = cpu_to_le16(len); |
| 1945 | |
| 1946 | /* TODO need this for burst mode later on */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1947 | iwl4965_build_tx_cmd_basic(priv, out_cmd, ctl, hdr, unicast, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1948 | |
| 1949 | /* set is_hcca to 0; it probably will never be implemented */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1950 | iwl4965_hw_build_tx_cmd_rate(priv, out_cmd, ctl, hdr, sta_id, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1951 | |
Tomas Winkler | 19758be | 2008-03-12 16:58:51 -0700 | [diff] [blame] | 1952 | iwl_update_tx_stats(priv, fc, len); |
| 1953 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1954 | scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) + |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 1955 | offsetof(struct iwl4965_tx_cmd, scratch); |
| 1956 | out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys); |
| 1957 | out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys); |
| 1958 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1959 | if (!ieee80211_get_morefrag(hdr)) { |
| 1960 | txq->need_update = 1; |
| 1961 | if (qc) { |
| 1962 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 1963 | priv->stations[sta_id].tid[tid].seq_number = seq_number; |
| 1964 | } |
| 1965 | } else { |
| 1966 | wait_write_ptr = 1; |
| 1967 | txq->need_update = 0; |
| 1968 | } |
| 1969 | |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1970 | iwl_print_hex_dump(priv, IWL_DL_TX, out_cmd->cmd.payload, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1971 | sizeof(out_cmd->cmd.tx)); |
| 1972 | |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1973 | iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)out_cmd->cmd.tx.hdr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1974 | ieee80211_get_hdrlen(fc)); |
| 1975 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1976 | /* Set up entry for this TFD in Tx byte-count array */ |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 1977 | priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1978 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1979 | /* Tell device the write index *just past* this latest filled TFD */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 1980 | q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 1981 | rc = iwl_txq_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1982 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1983 | |
| 1984 | if (rc) |
| 1985 | return rc; |
| 1986 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 1987 | if ((iwl_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1988 | && priv->mac80211_registered) { |
| 1989 | if (wait_write_ptr) { |
| 1990 | spin_lock_irqsave(&priv->lock, flags); |
| 1991 | txq->need_update = 1; |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 1992 | iwl_txq_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1993 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1994 | } |
| 1995 | |
| 1996 | ieee80211_stop_queue(priv->hw, ctl->queue); |
| 1997 | } |
| 1998 | |
| 1999 | return 0; |
| 2000 | |
| 2001 | drop_unlock: |
| 2002 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2003 | drop: |
| 2004 | return -1; |
| 2005 | } |
| 2006 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2007 | static void iwl4965_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2008 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2009 | const struct ieee80211_supported_band *hw = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2010 | struct ieee80211_rate *rate; |
| 2011 | int i; |
| 2012 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 2013 | hw = iwl_get_hw_mode(priv, priv->band); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 2014 | if (!hw) { |
| 2015 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 2016 | return; |
| 2017 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2018 | |
| 2019 | priv->active_rate = 0; |
| 2020 | priv->active_rate_basic = 0; |
| 2021 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2022 | for (i = 0; i < hw->n_bitrates; i++) { |
| 2023 | rate = &(hw->bitrates[i]); |
| 2024 | if (rate->hw_value < IWL_RATE_COUNT) |
| 2025 | priv->active_rate |= (1 << rate->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 2029 | priv->active_rate, priv->active_rate_basic); |
| 2030 | |
| 2031 | /* |
| 2032 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 2033 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 2034 | * OFDM |
| 2035 | */ |
| 2036 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 2037 | priv->staging_rxon.cck_basic_rates = |
| 2038 | ((priv->active_rate_basic & |
| 2039 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2040 | else |
| 2041 | priv->staging_rxon.cck_basic_rates = |
| 2042 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2043 | |
| 2044 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 2045 | priv->staging_rxon.ofdm_basic_rates = |
| 2046 | ((priv->active_rate_basic & |
| 2047 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 2048 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2049 | else |
| 2050 | priv->staging_rxon.ofdm_basic_rates = |
| 2051 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2052 | } |
| 2053 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2054 | void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2055 | { |
| 2056 | unsigned long flags; |
| 2057 | |
| 2058 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 2059 | return; |
| 2060 | |
| 2061 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 2062 | disable_radio ? "OFF" : "ON"); |
| 2063 | |
| 2064 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2065 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2066 | /* FIXME: This is a workaround for AP */ |
| 2067 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 2068 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2069 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2070 | CSR_UCODE_SW_BIT_RFKILL); |
| 2071 | spin_unlock_irqrestore(&priv->lock, flags); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2072 | /* call the host command only if no hw rf-kill set */ |
Mohamed Abbas | 5900383 | 2008-04-15 16:01:46 -0700 | [diff] [blame] | 2073 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status) && |
| 2074 | iwl_is_ready(priv)) |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2075 | iwl4965_send_card_state(priv, |
| 2076 | CARD_STATE_CMD_DISABLE, |
| 2077 | 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2078 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2079 | |
| 2080 | /* make sure mac80211 stop sending Tx frame */ |
| 2081 | if (priv->mac80211_registered) |
| 2082 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2083 | } |
| 2084 | return; |
| 2085 | } |
| 2086 | |
| 2087 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2088 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2089 | |
| 2090 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2091 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2092 | |
| 2093 | /* wake up ucode */ |
| 2094 | msleep(10); |
| 2095 | |
| 2096 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2097 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 2098 | if (!iwl_grab_nic_access(priv)) |
| 2099 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2100 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2101 | |
| 2102 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 2103 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 2104 | "disabled by HW switch\n"); |
| 2105 | return; |
| 2106 | } |
| 2107 | |
| 2108 | queue_work(priv->workqueue, &priv->restart); |
| 2109 | return; |
| 2110 | } |
| 2111 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2112 | #define IWL_PACKET_RETRY_TIME HZ |
| 2113 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2114 | int iwl4965_is_duplicate_packet(struct iwl_priv *priv, struct ieee80211_hdr *header) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2115 | { |
| 2116 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 2117 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 2118 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 2119 | u16 *last_seq, *last_frag; |
| 2120 | unsigned long *last_time; |
| 2121 | |
| 2122 | switch (priv->iw_mode) { |
| 2123 | case IEEE80211_IF_TYPE_IBSS:{ |
| 2124 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2125 | struct iwl4965_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2126 | u8 *mac = header->addr2; |
| 2127 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 2128 | |
| 2129 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2130 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2131 | if (!compare_ether_addr(entry->mac, mac)) |
| 2132 | break; |
| 2133 | } |
| 2134 | if (p == &priv->ibss_mac_hash[index]) { |
| 2135 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 2136 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2137 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2138 | return 0; |
| 2139 | } |
| 2140 | memcpy(entry->mac, mac, ETH_ALEN); |
| 2141 | entry->seq_num = seq; |
| 2142 | entry->frag_num = frag; |
| 2143 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2144 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2145 | return 0; |
| 2146 | } |
| 2147 | last_seq = &entry->seq_num; |
| 2148 | last_frag = &entry->frag_num; |
| 2149 | last_time = &entry->packet_time; |
| 2150 | break; |
| 2151 | } |
| 2152 | case IEEE80211_IF_TYPE_STA: |
| 2153 | last_seq = &priv->last_seq_num; |
| 2154 | last_frag = &priv->last_frag_num; |
| 2155 | last_time = &priv->last_packet_time; |
| 2156 | break; |
| 2157 | default: |
| 2158 | return 0; |
| 2159 | } |
| 2160 | if ((*last_seq == seq) && |
| 2161 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 2162 | if (*last_frag == frag) |
| 2163 | goto drop; |
| 2164 | if (*last_frag + 1 != frag) |
| 2165 | /* out-of-order fragment */ |
| 2166 | goto drop; |
| 2167 | } else |
| 2168 | *last_seq = seq; |
| 2169 | |
| 2170 | *last_frag = frag; |
| 2171 | *last_time = jiffies; |
| 2172 | return 0; |
| 2173 | |
| 2174 | drop: |
| 2175 | return 1; |
| 2176 | } |
| 2177 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2178 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2179 | |
| 2180 | #include "iwl-spectrum.h" |
| 2181 | |
| 2182 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 2183 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 2184 | #define TIME_UNIT 1024 |
| 2185 | |
| 2186 | /* |
| 2187 | * extended beacon time format |
| 2188 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 2189 | * the high 1 byte is the beacon counts |
| 2190 | * the lower 3 bytes is the time in usec within one beacon interval |
| 2191 | */ |
| 2192 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2193 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2194 | { |
| 2195 | u32 quot; |
| 2196 | u32 rem; |
| 2197 | u32 interval = beacon_interval * 1024; |
| 2198 | |
| 2199 | if (!interval || !usec) |
| 2200 | return 0; |
| 2201 | |
| 2202 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 2203 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 2204 | |
| 2205 | return (quot << 24) + rem; |
| 2206 | } |
| 2207 | |
| 2208 | /* base is usually what we get from ucode with each received frame, |
| 2209 | * the same as HW timer counter counting down |
| 2210 | */ |
| 2211 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2212 | static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2213 | { |
| 2214 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 2215 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 2216 | u32 interval = beacon_interval * TIME_UNIT; |
| 2217 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 2218 | (addon & BEACON_TIME_MASK_HIGH); |
| 2219 | |
| 2220 | if (base_low > addon_low) |
| 2221 | res += base_low - addon_low; |
| 2222 | else if (base_low < addon_low) { |
| 2223 | res += interval + base_low - addon_low; |
| 2224 | res += (1 << 24); |
| 2225 | } else |
| 2226 | res += (1 << 24); |
| 2227 | |
| 2228 | return cpu_to_le32(res); |
| 2229 | } |
| 2230 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2231 | static int iwl4965_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2232 | struct ieee80211_measurement_params *params, |
| 2233 | u8 type) |
| 2234 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2235 | struct iwl4965_spectrum_cmd spectrum; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2236 | struct iwl_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2237 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2238 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 2239 | .data = (void *)&spectrum, |
| 2240 | .meta.flags = CMD_WANT_SKB, |
| 2241 | }; |
| 2242 | u32 add_time = le64_to_cpu(params->start_time); |
| 2243 | int rc; |
| 2244 | int spectrum_resp_status; |
| 2245 | int duration = le16_to_cpu(params->duration); |
| 2246 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2247 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2248 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2249 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2250 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 2251 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2252 | |
| 2253 | memset(&spectrum, 0, sizeof(spectrum)); |
| 2254 | |
| 2255 | spectrum.channel_count = cpu_to_le16(1); |
| 2256 | spectrum.flags = |
| 2257 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 2258 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 2259 | cmd.len = sizeof(spectrum); |
| 2260 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 2261 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2262 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2263 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2264 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2265 | add_time, |
| 2266 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2267 | else |
| 2268 | spectrum.start_time = 0; |
| 2269 | |
| 2270 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 2271 | spectrum.channels[0].channel = params->channel; |
| 2272 | spectrum.channels[0].type = type; |
| 2273 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 2274 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 2275 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 2276 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2277 | rc = iwl_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2278 | if (rc) |
| 2279 | return rc; |
| 2280 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2281 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2282 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 2283 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 2284 | rc = -EIO; |
| 2285 | } |
| 2286 | |
| 2287 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 2288 | switch (spectrum_resp_status) { |
| 2289 | case 0: /* Command will be handled */ |
| 2290 | if (res->u.spectrum.id != 0xff) { |
| 2291 | IWL_DEBUG_INFO |
| 2292 | ("Replaced existing measurement: %d\n", |
| 2293 | res->u.spectrum.id); |
| 2294 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 2295 | } |
| 2296 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 2297 | rc = 0; |
| 2298 | break; |
| 2299 | |
| 2300 | case 1: /* Command will not be handled */ |
| 2301 | rc = -EAGAIN; |
| 2302 | break; |
| 2303 | } |
| 2304 | |
| 2305 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 2306 | |
| 2307 | return rc; |
| 2308 | } |
| 2309 | #endif |
| 2310 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2311 | static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv, |
Tomas Winkler | 8567c63 | 2008-05-15 13:53:58 +0800 | [diff] [blame] | 2312 | struct iwl_tx_info *tx_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2313 | { |
| 2314 | |
| 2315 | tx_sta->status.ack_signal = 0; |
| 2316 | tx_sta->status.excessive_retries = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2317 | |
| 2318 | if (in_interrupt()) |
| 2319 | ieee80211_tx_status_irqsafe(priv->hw, |
| 2320 | tx_sta->skb[0], &(tx_sta->status)); |
| 2321 | else |
| 2322 | ieee80211_tx_status(priv->hw, |
| 2323 | tx_sta->skb[0], &(tx_sta->status)); |
| 2324 | |
| 2325 | tx_sta->skb[0] = NULL; |
| 2326 | } |
| 2327 | |
| 2328 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2329 | * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2330 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2331 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 2332 | * need to be reclaimed. As result, some free space forms. If there is |
| 2333 | * enough free space (> low mark), wake the stack that feeds us. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2334 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2335 | int iwl4965_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2336 | { |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 2337 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 2338 | struct iwl_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2339 | int nfreed = 0; |
| 2340 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 2341 | if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2342 | IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " |
| 2343 | "is out of range [0-%d] %d %d.\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2344 | index, q->n_bd, q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2345 | return 0; |
| 2346 | } |
| 2347 | |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2348 | for (index = iwl_queue_inc_wrap(index, q->n_bd); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2349 | q->read_ptr != index; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2350 | q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2351 | if (txq_id != IWL_CMD_QUEUE_NUM) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2352 | iwl4965_txstatus_to_ieee(priv, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2353 | &(txq->txb[txq->q.read_ptr])); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 2354 | iwl_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2355 | } else if (nfreed > 1) { |
| 2356 | IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2357 | q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2358 | queue_work(priv->workqueue, &priv->restart); |
| 2359 | } |
| 2360 | nfreed++; |
| 2361 | } |
| 2362 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2363 | return nfreed; |
| 2364 | } |
| 2365 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2366 | static int iwl4965_is_tx_success(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2367 | { |
| 2368 | status &= TX_STATUS_MSK; |
| 2369 | return (status == TX_STATUS_SUCCESS) |
| 2370 | || (status == TX_STATUS_DIRECT_DONE); |
| 2371 | } |
| 2372 | |
| 2373 | /****************************************************************************** |
| 2374 | * |
| 2375 | * Generic RX handler implementations |
| 2376 | * |
| 2377 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2378 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2379 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2380 | static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2381 | struct ieee80211_hdr *hdr) |
| 2382 | { |
| 2383 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) |
| 2384 | return IWL_AP_ID; |
| 2385 | else { |
| 2386 | u8 *da = ieee80211_get_DA(hdr); |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 2387 | return iwl_find_station(priv, da); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2388 | } |
| 2389 | } |
| 2390 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2391 | static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr( |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2392 | struct iwl_priv *priv, int txq_id, int idx) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2393 | { |
| 2394 | if (priv->txq[txq_id].txb[idx].skb[0]) |
| 2395 | return (struct ieee80211_hdr *)priv->txq[txq_id]. |
| 2396 | txb[idx].skb[0]->data; |
| 2397 | return NULL; |
| 2398 | } |
| 2399 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2400 | static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2401 | { |
| 2402 | __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + |
| 2403 | tx_resp->frame_count); |
| 2404 | return le32_to_cpu(*scd_ssn) & MAX_SN; |
| 2405 | |
| 2406 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2407 | |
| 2408 | /** |
| 2409 | * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue |
| 2410 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2411 | static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv, |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 2412 | struct iwl_ht_agg *agg, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2413 | struct iwl4965_tx_resp_agg *tx_resp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2414 | u16 start_idx) |
| 2415 | { |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2416 | u16 status; |
| 2417 | struct agg_tx_status *frame_status = &tx_resp->status; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2418 | struct ieee80211_tx_status *tx_status = NULL; |
| 2419 | struct ieee80211_hdr *hdr = NULL; |
| 2420 | int i, sh; |
| 2421 | int txq_id, idx; |
| 2422 | u16 seq; |
| 2423 | |
| 2424 | if (agg->wait_for_ba) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2425 | IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2426 | |
| 2427 | agg->frame_count = tx_resp->frame_count; |
| 2428 | agg->start_idx = start_idx; |
| 2429 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2430 | agg->bitmap = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2431 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2432 | /* # frames attempted by Tx command */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2433 | if (agg->frame_count == 1) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2434 | /* Only one frame was attempted; no block-ack will arrive */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2435 | status = le16_to_cpu(frame_status[0].status); |
| 2436 | seq = le16_to_cpu(frame_status[0].sequence); |
| 2437 | idx = SEQ_TO_INDEX(seq); |
| 2438 | txq_id = SEQ_TO_QUEUE(seq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2439 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2440 | /* FIXME: code repetition */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2441 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n", |
| 2442 | agg->frame_count, agg->start_idx, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2443 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2444 | tx_status = &(priv->txq[txq_id].txb[idx].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2445 | tx_status->retry_count = tx_resp->failure_frame; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2446 | tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2447 | tx_status->flags = iwl4965_is_tx_success(status)? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2448 | IEEE80211_TX_STATUS_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 2449 | iwl4965_hwrate_to_tx_control(priv, |
| 2450 | le32_to_cpu(tx_resp->rate_n_flags), |
| 2451 | &tx_status->control); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2452 | /* FIXME: code repetition end */ |
| 2453 | |
| 2454 | IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", |
| 2455 | status & 0xff, tx_resp->failure_frame); |
| 2456 | IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2457 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2458 | |
| 2459 | agg->wait_for_ba = 0; |
| 2460 | } else { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2461 | /* Two or more frames were attempted; expect block-ack */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2462 | u64 bitmap = 0; |
| 2463 | int start = agg->start_idx; |
| 2464 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2465 | /* Construct bit-map of pending frames within Tx window */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2466 | for (i = 0; i < agg->frame_count; i++) { |
| 2467 | u16 sc; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2468 | status = le16_to_cpu(frame_status[i].status); |
| 2469 | seq = le16_to_cpu(frame_status[i].sequence); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2470 | idx = SEQ_TO_INDEX(seq); |
| 2471 | txq_id = SEQ_TO_QUEUE(seq); |
| 2472 | |
| 2473 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 2474 | AGG_TX_STATE_ABORT_MSK)) |
| 2475 | continue; |
| 2476 | |
| 2477 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
| 2478 | agg->frame_count, txq_id, idx); |
| 2479 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2480 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2481 | |
| 2482 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 2483 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
| 2484 | IWL_ERROR("BUG_ON idx doesn't match seq control" |
| 2485 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 2486 | idx, SEQ_TO_SN(sc), |
| 2487 | hdr->seq_ctrl); |
| 2488 | return -1; |
| 2489 | } |
| 2490 | |
| 2491 | IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
| 2492 | i, idx, SEQ_TO_SN(sc)); |
| 2493 | |
| 2494 | sh = idx - start; |
| 2495 | if (sh > 64) { |
| 2496 | sh = (start - idx) + 0xff; |
| 2497 | bitmap = bitmap << sh; |
| 2498 | sh = 0; |
| 2499 | start = idx; |
| 2500 | } else if (sh < -64) |
| 2501 | sh = 0xff - (start - idx); |
| 2502 | else if (sh < 0) { |
| 2503 | sh = start - idx; |
| 2504 | start = idx; |
| 2505 | bitmap = bitmap << sh; |
| 2506 | sh = 0; |
| 2507 | } |
| 2508 | bitmap |= (1 << sh); |
| 2509 | IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n", |
| 2510 | start, (u32)(bitmap & 0xFFFFFFFF)); |
| 2511 | } |
| 2512 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2513 | agg->bitmap = bitmap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2514 | agg->start_idx = start; |
| 2515 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2516 | IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2517 | agg->frame_count, agg->start_idx, |
John W. Linville | 06501d2 | 2008-04-01 17:38:47 -0400 | [diff] [blame] | 2518 | (unsigned long long)agg->bitmap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2519 | |
| 2520 | if (bitmap) |
| 2521 | agg->wait_for_ba = 1; |
| 2522 | } |
| 2523 | return 0; |
| 2524 | } |
| 2525 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2526 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2527 | /** |
| 2528 | * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response |
| 2529 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2530 | static void iwl4965_rx_reply_tx(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2531 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2532 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2533 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2534 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 2535 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 2536 | int index = SEQ_TO_INDEX(sequence); |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 2537 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2538 | struct ieee80211_tx_status *tx_status; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2539 | struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2540 | u32 status = le32_to_cpu(tx_resp->status); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2541 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2542 | int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION; |
| 2543 | struct ieee80211_hdr *hdr; |
| 2544 | __le16 *qc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2545 | #endif |
| 2546 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 2547 | if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2548 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 2549 | "is out of range [0-%d] %d %d\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2550 | index, txq->q.n_bd, txq->q.write_ptr, |
| 2551 | txq->q.read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2552 | return; |
| 2553 | } |
| 2554 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2555 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2556 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index); |
| 2557 | qc = ieee80211_get_qos_ctrl(hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2558 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2559 | if (qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2560 | tid = le16_to_cpu(*qc) & 0xf; |
| 2561 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2562 | sta_id = iwl4965_get_ra_sta_id(priv, hdr); |
| 2563 | if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) { |
| 2564 | IWL_ERROR("Station not known\n"); |
| 2565 | return; |
| 2566 | } |
| 2567 | |
| 2568 | if (txq->sched_retry) { |
| 2569 | const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp); |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 2570 | struct iwl_ht_agg *agg = NULL; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2571 | |
| 2572 | if (!qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2573 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2574 | |
| 2575 | agg = &priv->stations[sta_id].tid[tid].agg; |
| 2576 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2577 | iwl4965_tx_status_reply_tx(priv, agg, |
| 2578 | (struct iwl4965_tx_resp_agg *)tx_resp, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2579 | |
| 2580 | if ((tx_resp->frame_count == 1) && |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2581 | !iwl4965_is_tx_success(status)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2582 | /* TODO: send BAR */ |
| 2583 | } |
| 2584 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2585 | if (txq->q.read_ptr != (scd_ssn & 0xff)) { |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 2586 | int freed, ampdu_q; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2587 | index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2588 | IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " |
| 2589 | "%d index %d\n", scd_ssn , index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2590 | freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
| 2591 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 2592 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 2593 | if (iwl_queue_space(&txq->q) > txq->q.low_mark && |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2594 | txq_id >= 0 && priv->mac80211_registered && |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 2595 | agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) { |
| 2596 | /* calculate mac80211 ampdu sw queue to wake */ |
| 2597 | ampdu_q = txq_id - IWL_BACK_QUEUE_FIRST_ID + |
| 2598 | priv->hw->queues; |
| 2599 | if (agg->state == IWL_AGG_OFF) |
| 2600 | ieee80211_wake_queue(priv->hw, txq_id); |
| 2601 | else |
| 2602 | ieee80211_wake_queue(priv->hw, ampdu_q); |
| 2603 | } |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2604 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2605 | } |
| 2606 | } else { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2607 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2608 | tx_status = &(txq->txb[txq->q.read_ptr].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2609 | |
| 2610 | tx_status->retry_count = tx_resp->failure_frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2611 | tx_status->flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2612 | iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 2613 | iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags), |
| 2614 | &tx_status->control); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2615 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2616 | IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x " |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2617 | "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2618 | status, le32_to_cpu(tx_resp->rate_n_flags), |
| 2619 | tx_resp->failure_frame); |
| 2620 | |
| 2621 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 2622 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2623 | if (index != -1) { |
| 2624 | int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2625 | if (tid != MAX_TID_COUNT) |
| 2626 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 2627 | if (iwl_queue_space(&txq->q) > txq->q.low_mark && |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 2628 | (txq_id >= 0) && priv->mac80211_registered) |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2629 | ieee80211_wake_queue(priv->hw, txq_id); |
| 2630 | if (tid != MAX_TID_COUNT) |
| 2631 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2632 | } |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2633 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2634 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2635 | |
| 2636 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 2637 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 2638 | } |
| 2639 | |
| 2640 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2641 | static void iwl4965_rx_reply_alive(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2642 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2643 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2644 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2645 | struct iwl4965_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2646 | struct delayed_work *pwork; |
| 2647 | |
| 2648 | palive = &pkt->u.alive_frame; |
| 2649 | |
| 2650 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 2651 | "0x%01X 0x%01X\n", |
| 2652 | palive->is_valid, palive->ver_type, |
| 2653 | palive->ver_subtype); |
| 2654 | |
| 2655 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 2656 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 2657 | memcpy(&priv->card_alive_init, |
| 2658 | &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2659 | sizeof(struct iwl4965_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2660 | pwork = &priv->init_alive_start; |
| 2661 | } else { |
| 2662 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 2663 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2664 | sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2665 | pwork = &priv->alive_start; |
| 2666 | } |
| 2667 | |
| 2668 | /* We delay the ALIVE response by 5ms to |
| 2669 | * give the HW RF Kill time to activate... */ |
| 2670 | if (palive->is_valid == UCODE_VALID_OK) |
| 2671 | queue_delayed_work(priv->workqueue, pwork, |
| 2672 | msecs_to_jiffies(5)); |
| 2673 | else |
| 2674 | IWL_WARNING("uCode did not respond OK.\n"); |
| 2675 | } |
| 2676 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2677 | static void iwl4965_rx_reply_add_sta(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2678 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2679 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2680 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2681 | |
| 2682 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 2683 | return; |
| 2684 | } |
| 2685 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2686 | static void iwl4965_rx_reply_error(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2687 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2688 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2689 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2690 | |
| 2691 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 2692 | "seq 0x%04X ser 0x%08X\n", |
| 2693 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 2694 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 2695 | pkt->u.err_resp.cmd_id, |
| 2696 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 2697 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 2698 | } |
| 2699 | |
| 2700 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2701 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2702 | static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2703 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2704 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 2705 | struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2706 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2707 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 2708 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 2709 | rxon->channel = csa->channel; |
| 2710 | priv->staging_rxon.channel = csa->channel; |
| 2711 | } |
| 2712 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2713 | static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2714 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2715 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2716 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2717 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2718 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2719 | |
| 2720 | if (!report->state) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2721 | IWL_DEBUG(IWL_DL_11H, |
| 2722 | "Spectrum Measure Notification: Start\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2723 | return; |
| 2724 | } |
| 2725 | |
| 2726 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 2727 | priv->measurement_status |= MEASUREMENT_READY; |
| 2728 | #endif |
| 2729 | } |
| 2730 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2731 | static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2732 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2733 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2734 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2735 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2736 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2737 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 2738 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 2739 | #endif |
| 2740 | } |
| 2741 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2742 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2743 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2744 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2745 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2746 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 2747 | "notification for %s:\n", |
| 2748 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2749 | iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2750 | } |
| 2751 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2752 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2753 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2754 | struct iwl_priv *priv = |
| 2755 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2756 | struct sk_buff *beacon; |
| 2757 | |
| 2758 | /* 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] | 2759 | beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2760 | |
| 2761 | if (!beacon) { |
| 2762 | IWL_ERROR("update beacon failed\n"); |
| 2763 | return; |
| 2764 | } |
| 2765 | |
| 2766 | mutex_lock(&priv->mutex); |
| 2767 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 2768 | if (priv->ibss_beacon) |
| 2769 | dev_kfree_skb(priv->ibss_beacon); |
| 2770 | |
| 2771 | priv->ibss_beacon = beacon; |
| 2772 | mutex_unlock(&priv->mutex); |
| 2773 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2774 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2775 | } |
| 2776 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2777 | static void iwl4965_rx_beacon_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2778 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2779 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2780 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2781 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2782 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 2783 | u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2784 | |
| 2785 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 2786 | "tsf %d %d rate %d\n", |
| 2787 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 2788 | beacon->beacon_notify_hdr.failure_frame, |
| 2789 | le32_to_cpu(beacon->ibss_mgr_status), |
| 2790 | le32_to_cpu(beacon->high_tsf), |
| 2791 | le32_to_cpu(beacon->low_tsf), rate); |
| 2792 | #endif |
| 2793 | |
| 2794 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 2795 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 2796 | queue_work(priv->workqueue, &priv->beacon_update); |
| 2797 | } |
| 2798 | |
| 2799 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2800 | static void iwl4965_rx_reply_scan(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2801 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2802 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2803 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2804 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2805 | struct iwl4965_scanreq_notification *notif = |
| 2806 | (struct iwl4965_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2807 | |
| 2808 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 2809 | #endif |
| 2810 | } |
| 2811 | |
| 2812 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2813 | static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2814 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2815 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2816 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2817 | struct iwl4965_scanstart_notification *notif = |
| 2818 | (struct iwl4965_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2819 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 2820 | IWL_DEBUG_SCAN("Scan start: " |
| 2821 | "%d [802.11%s] " |
| 2822 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 2823 | notif->channel, |
| 2824 | notif->band ? "bg" : "a", |
| 2825 | notif->tsf_high, |
| 2826 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 2827 | } |
| 2828 | |
| 2829 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2830 | static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2831 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2832 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2833 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2834 | struct iwl4965_scanresults_notification *notif = |
| 2835 | (struct iwl4965_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2836 | |
| 2837 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 2838 | "%d [802.11%s] " |
| 2839 | "(TSF: 0x%08X:%08X) - %d " |
| 2840 | "elapsed=%lu usec (%dms since last)\n", |
| 2841 | notif->channel, |
| 2842 | notif->band ? "bg" : "a", |
| 2843 | le32_to_cpu(notif->tsf_high), |
| 2844 | le32_to_cpu(notif->tsf_low), |
| 2845 | le32_to_cpu(notif->statistics[0]), |
| 2846 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 2847 | jiffies_to_msecs(elapsed_jiffies |
| 2848 | (priv->last_scan_jiffies, jiffies))); |
| 2849 | |
| 2850 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2851 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2855 | static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2856 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2857 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2858 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2859 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2860 | |
| 2861 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 2862 | scan_notif->scanned_channels, |
| 2863 | scan_notif->tsf_low, |
| 2864 | scan_notif->tsf_high, scan_notif->status); |
| 2865 | |
| 2866 | /* The HW is no longer scanning */ |
| 2867 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 2868 | |
| 2869 | /* The scan completion notification came in, so kill that timer... */ |
| 2870 | cancel_delayed_work(&priv->scan_check); |
| 2871 | |
| 2872 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 2873 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 2874 | jiffies_to_msecs(elapsed_jiffies |
| 2875 | (priv->scan_pass_start, jiffies))); |
| 2876 | |
| 2877 | /* Remove this scanned band from the list |
| 2878 | * of pending bands to scan */ |
| 2879 | priv->scan_bands--; |
| 2880 | |
| 2881 | /* If a request to abort was given, or the scan did not succeed |
| 2882 | * then we reset the scan state machine and terminate, |
| 2883 | * re-queuing another scan if one has been requested */ |
| 2884 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2885 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 2886 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2887 | } else { |
| 2888 | /* If there are more bands on this scan pass reschedule */ |
| 2889 | if (priv->scan_bands > 0) |
| 2890 | goto reschedule; |
| 2891 | } |
| 2892 | |
| 2893 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2894 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2895 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 2896 | |
| 2897 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2898 | |
| 2899 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 2900 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 2901 | |
| 2902 | queue_work(priv->workqueue, &priv->scan_completed); |
| 2903 | |
| 2904 | return; |
| 2905 | |
| 2906 | reschedule: |
| 2907 | priv->scan_pass_start = jiffies; |
| 2908 | queue_work(priv->workqueue, &priv->request_scan); |
| 2909 | } |
| 2910 | |
| 2911 | /* Handle notification from uCode that card's power state is changing |
| 2912 | * due to software, hardware, or critical temperature RFKILL */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2913 | static void iwl4965_rx_card_state_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2914 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2915 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2916 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2917 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 2918 | unsigned long status = priv->status; |
| 2919 | |
| 2920 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 2921 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 2922 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 2923 | |
| 2924 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 2925 | RF_CARD_DISABLED)) { |
| 2926 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2927 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2928 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 2929 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2930 | if (!iwl_grab_nic_access(priv)) { |
| 2931 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2932 | priv, HBUS_TARG_MBX_C, |
| 2933 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 2934 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2935 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | if (!(flags & RXON_CARD_DISABLED)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2939 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2940 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2941 | if (!iwl_grab_nic_access(priv)) { |
| 2942 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2943 | priv, HBUS_TARG_MBX_C, |
| 2944 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 2945 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2946 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2947 | } |
| 2948 | } |
| 2949 | |
| 2950 | if (flags & RF_CARD_DISABLED) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2951 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2952 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2953 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 2954 | if (!iwl_grab_nic_access(priv)) |
| 2955 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2956 | } |
| 2957 | } |
| 2958 | |
| 2959 | if (flags & HW_CARD_DISABLED) |
| 2960 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2961 | else |
| 2962 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2963 | |
| 2964 | |
| 2965 | if (flags & SW_CARD_DISABLED) |
| 2966 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2967 | else |
| 2968 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2969 | |
| 2970 | if (!(flags & RXON_CARD_DISABLED)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2971 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2972 | |
| 2973 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 2974 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 2975 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 2976 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 2977 | queue_work(priv->workqueue, &priv->rf_kill); |
| 2978 | else |
| 2979 | wake_up_interruptible(&priv->wait_command_queue); |
| 2980 | } |
| 2981 | |
| 2982 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2983 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2984 | * |
| 2985 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 2986 | * to the host. |
| 2987 | * |
| 2988 | * This function chains into the hardware specific files for them to setup |
| 2989 | * any hardware specific handlers as well. |
| 2990 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2991 | static void iwl4965_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2992 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2993 | priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive; |
| 2994 | priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta; |
| 2995 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 2996 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2997 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2998 | iwl4965_rx_spectrum_measure_notif; |
| 2999 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3000 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3001 | iwl4965_rx_pm_debug_statistics_notif; |
| 3002 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3003 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3004 | /* |
| 3005 | * The same handler is used for both the REPLY to a discrete |
| 3006 | * statistics request from the host as well as for the periodic |
| 3007 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3008 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3009 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
| 3010 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3011 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3012 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
| 3013 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3014 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3015 | iwl4965_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3016 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3017 | iwl4965_rx_scan_complete_notif; |
| 3018 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
| 3019 | priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3020 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3021 | /* Set up hardware specific Rx handlers */ |
Emmanuel Grumbach | d4789ef | 2008-04-24 11:55:20 -0700 | [diff] [blame] | 3022 | priv->cfg->ops->lib->rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3026 | * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3027 | * @rxb: Rx buffer to reclaim |
| 3028 | * |
| 3029 | * If an Rx buffer has an async callback associated with it the callback |
| 3030 | * will be executed. The attached skb (if present) will only be freed |
| 3031 | * if the callback returns 1 |
| 3032 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3033 | static void iwl4965_tx_cmd_complete(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3034 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3035 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 3036 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3037 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3038 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3039 | int index = SEQ_TO_INDEX(sequence); |
| 3040 | int huge = sequence & SEQ_HUGE_FRAME; |
| 3041 | int cmd_index; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3042 | struct iwl_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3043 | |
| 3044 | /* If a Tx command is being handled and it isn't in the actual |
| 3045 | * command queue then there a command routing bug has been introduced |
| 3046 | * in the queue management code. */ |
| 3047 | if (txq_id != IWL_CMD_QUEUE_NUM) |
| 3048 | IWL_ERROR("Error wrong command queue %d command id 0x%X\n", |
| 3049 | txq_id, pkt->hdr.cmd); |
| 3050 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 3051 | |
| 3052 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 3053 | cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
| 3054 | |
| 3055 | /* Input error checking is done when commands are added to queue. */ |
| 3056 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 3057 | cmd->meta.source->u.skb = rxb->skb; |
| 3058 | rxb->skb = NULL; |
| 3059 | } else if (cmd->meta.u.callback && |
| 3060 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 3061 | rxb->skb = NULL; |
| 3062 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3063 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3064 | |
| 3065 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 3066 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3067 | wake_up_interruptible(&priv->wait_command_queue); |
| 3068 | } |
| 3069 | } |
| 3070 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3071 | /* |
| 3072 | * this should be called while priv->lock is locked |
| 3073 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3074 | static void __iwl_rx_replenish(struct iwl_priv *priv) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3075 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3076 | iwl_rx_allocate(priv); |
| 3077 | iwl_rx_queue_restock(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3078 | } |
| 3079 | |
| 3080 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3081 | /** |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3082 | * iwl_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3083 | * |
| 3084 | * Uses the priv->rx_handlers callback function array to invoke |
| 3085 | * the appropriate handlers, including command responses, |
| 3086 | * frame-received notifications, and other notifications. |
| 3087 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3088 | void iwl_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3089 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3090 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 3091 | struct iwl_rx_packet *pkt; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3092 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3093 | u32 r, i; |
| 3094 | int reclaim; |
| 3095 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3096 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 3097 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3098 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3099 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 3100 | * buffer that the driver may process (last buffer filled by ucode). */ |
Ron Rindjunsky | d67f548 | 2008-05-05 10:22:49 +0800 | [diff] [blame] | 3101 | r = priv->cfg->ops->lib->shared_mem_rx_idx(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3102 | i = rxq->read; |
| 3103 | |
| 3104 | /* Rx interrupt, but nothing sent from uCode */ |
| 3105 | if (i == r) |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3106 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3107 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3108 | if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3109 | fill_rx = 1; |
| 3110 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3111 | while (i != r) { |
| 3112 | rxb = rxq->queue[i]; |
| 3113 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3114 | /* 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] | 3115 | * then a bug has been introduced in the queue refilling |
| 3116 | * routines -- catch it here */ |
| 3117 | BUG_ON(rxb == NULL); |
| 3118 | |
| 3119 | rxq->queue[i] = NULL; |
| 3120 | |
| 3121 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3122 | priv->hw_params.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3123 | PCI_DMA_FROMDEVICE); |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 3124 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3125 | |
| 3126 | /* Reclaim a command buffer only if this packet is a response |
| 3127 | * to a (driver-originated) command. |
| 3128 | * If the packet (e.g. Rx frame) originated from uCode, |
| 3129 | * there is no command buffer to reclaim. |
| 3130 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 3131 | * but apparently a few don't get set; catch them here. */ |
| 3132 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 3133 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3134 | (pkt->hdr.cmd != REPLY_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 3135 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3136 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 3137 | (pkt->hdr.cmd != REPLY_TX); |
| 3138 | |
| 3139 | /* Based on type of command response or notification, |
| 3140 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3141 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3142 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3143 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r, |
| 3144 | i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3145 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 3146 | } else { |
| 3147 | /* No handling needed */ |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3148 | IWL_DEBUG(IWL_DL_RX, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3149 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 3150 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 3151 | pkt->hdr.cmd); |
| 3152 | } |
| 3153 | |
| 3154 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3155 | /* Invoke any callbacks, transfer the skb to caller, and |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3156 | * fire off the (possibly) blocking iwl_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3157 | * as we reclaim the driver command queue */ |
| 3158 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3159 | iwl4965_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3160 | else |
| 3161 | IWL_WARNING("Claim null rxb?\n"); |
| 3162 | } |
| 3163 | |
| 3164 | /* For now we just don't re-use anything. We can tweak this |
| 3165 | * later to try and re-use notification packets and SKBs that |
| 3166 | * fail to Rx correctly */ |
| 3167 | if (rxb->skb != NULL) { |
| 3168 | priv->alloc_rxb_skb--; |
| 3169 | dev_kfree_skb_any(rxb->skb); |
| 3170 | rxb->skb = NULL; |
| 3171 | } |
| 3172 | |
| 3173 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3174 | priv->hw_params.rx_buf_size, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 3175 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3176 | spin_lock_irqsave(&rxq->lock, flags); |
| 3177 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 3178 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3179 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3180 | /* If there are a lot of unused frames, |
| 3181 | * restock the Rx queue so ucode wont assert. */ |
| 3182 | if (fill_rx) { |
| 3183 | count++; |
| 3184 | if (count >= 8) { |
| 3185 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3186 | __iwl_rx_replenish(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3187 | count = 0; |
| 3188 | } |
| 3189 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | /* Backtrack one entry */ |
| 3193 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3194 | iwl_rx_queue_restock(priv); |
| 3195 | } |
| 3196 | /* Convert linear signal-to-noise ratio into dB */ |
| 3197 | static u8 ratio2dB[100] = { |
| 3198 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 3199 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 3200 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 3201 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 3202 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 3203 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 3204 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 3205 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 3206 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 3207 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 3208 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 3209 | }; |
| 3210 | |
| 3211 | /* Calculates a relative dB value from a ratio of linear |
| 3212 | * (i.e. not dB) signal levels. |
| 3213 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
| 3214 | int iwl4965_calc_db_from_ratio(int sig_ratio) |
| 3215 | { |
| 3216 | /* 1000:1 or higher just report as 60 dB */ |
| 3217 | if (sig_ratio >= 1000) |
| 3218 | return 60; |
| 3219 | |
| 3220 | /* 100:1 or higher, divide by 10 and use table, |
| 3221 | * add 20 dB to make up for divide by 10 */ |
| 3222 | if (sig_ratio >= 100) |
| 3223 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 3224 | |
| 3225 | /* We shouldn't see this */ |
| 3226 | if (sig_ratio < 1) |
| 3227 | return 0; |
| 3228 | |
| 3229 | /* Use table for ratios 1:1 - 99:1 */ |
| 3230 | return (int)ratio2dB[sig_ratio]; |
| 3231 | } |
| 3232 | |
| 3233 | #define PERFECT_RSSI (-20) /* dBm */ |
| 3234 | #define WORST_RSSI (-95) /* dBm */ |
| 3235 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 3236 | |
| 3237 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 3238 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 3239 | * about formulas used below. */ |
| 3240 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) |
| 3241 | { |
| 3242 | int sig_qual; |
| 3243 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 3244 | |
| 3245 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 3246 | * as indicator; formula is (signal dbm - noise dbm). |
| 3247 | * SNR at or above 40 is a great signal (100%). |
| 3248 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 3249 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 3250 | if (noise_dbm) { |
| 3251 | if (rssi_dbm - noise_dbm >= 40) |
| 3252 | return 100; |
| 3253 | else if (rssi_dbm < noise_dbm) |
| 3254 | return 0; |
| 3255 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 3256 | |
| 3257 | /* Else use just the signal level. |
| 3258 | * This formula is a least squares fit of data points collected and |
| 3259 | * compared with a reference system that had a percentage (%) display |
| 3260 | * for signal quality. */ |
| 3261 | } else |
| 3262 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 3263 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 3264 | (RSSI_RANGE * RSSI_RANGE); |
| 3265 | |
| 3266 | if (sig_qual > 100) |
| 3267 | sig_qual = 100; |
| 3268 | else if (sig_qual < 1) |
| 3269 | sig_qual = 0; |
| 3270 | |
| 3271 | return sig_qual; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3272 | } |
| 3273 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3274 | /** |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3275 | * iwl_txq_update_write_ptr - Send new write index to hardware |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3276 | */ |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3277 | static int iwl_txq_update_write_ptr(struct iwl_priv *priv, |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 3278 | struct iwl_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3279 | { |
| 3280 | u32 reg = 0; |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3281 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3282 | int txq_id = txq->q.id; |
| 3283 | |
| 3284 | if (txq->need_update == 0) |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3285 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3286 | |
| 3287 | /* if we're trying to save power */ |
| 3288 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 3289 | /* wake up nic if it's powered down ... |
| 3290 | * uCode will wake up, and interrupt us again, so next |
| 3291 | * time we'll skip this part. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3292 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3293 | |
| 3294 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 3295 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3296 | iwl_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3297 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3298 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | /* restore this queue's parameters in nic hardware. */ |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3302 | ret = iwl_grab_nic_access(priv); |
| 3303 | if (ret) |
| 3304 | return ret; |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3305 | iwl_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3306 | txq->q.write_ptr | (txq_id << 8)); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3307 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3308 | |
| 3309 | /* else not in power-save mode, uCode will never sleep when we're |
| 3310 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 3311 | } else |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3312 | iwl_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3313 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3314 | |
| 3315 | txq->need_update = 0; |
| 3316 | |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3317 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3318 | } |
| 3319 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3320 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3321 | static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3322 | { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 3323 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3324 | DECLARE_MAC_BUF(mac); |
| 3325 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3326 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3327 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3328 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 3329 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 3330 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 3331 | le32_to_cpu(rxon->filter_flags)); |
| 3332 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 3333 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 3334 | rxon->ofdm_basic_rates); |
| 3335 | 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] | 3336 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 3337 | print_mac(mac, rxon->node_addr)); |
| 3338 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 3339 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3340 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 3341 | } |
| 3342 | #endif |
| 3343 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3344 | static void iwl4965_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3345 | { |
| 3346 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 3347 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3348 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3349 | } |
| 3350 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3351 | /* call this function to flush any scheduled tasklet */ |
| 3352 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
| 3353 | { |
| 3354 | /* wait to make sure we flush pedding tasklet*/ |
| 3355 | synchronize_irq(priv->pci_dev->irq); |
| 3356 | tasklet_kill(&priv->irq_tasklet); |
| 3357 | } |
| 3358 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3359 | static inline void iwl4965_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3360 | { |
| 3361 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 3362 | |
| 3363 | /* disable interrupts from uCode/NIC to host */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3364 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3365 | |
| 3366 | /* acknowledge/clear/reset any interrupts still pending |
| 3367 | * from uCode or flow handler (Rx/Tx DMA) */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3368 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 3369 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3370 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 3371 | } |
| 3372 | |
| 3373 | static const char *desc_lookup(int i) |
| 3374 | { |
| 3375 | switch (i) { |
| 3376 | case 1: |
| 3377 | return "FAIL"; |
| 3378 | case 2: |
| 3379 | return "BAD_PARAM"; |
| 3380 | case 3: |
| 3381 | return "BAD_CHECKSUM"; |
| 3382 | case 4: |
| 3383 | return "NMI_INTERRUPT"; |
| 3384 | case 5: |
| 3385 | return "SYSASSERT"; |
| 3386 | case 6: |
| 3387 | return "FATAL_ERROR"; |
| 3388 | } |
| 3389 | |
| 3390 | return "UNKNOWN"; |
| 3391 | } |
| 3392 | |
| 3393 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 3394 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 3395 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3396 | static void iwl4965_dump_nic_error_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3397 | { |
| 3398 | u32 data2, line; |
| 3399 | u32 desc, time, count, base, data1; |
| 3400 | u32 blink1, blink2, ilink1, ilink2; |
| 3401 | int rc; |
| 3402 | |
| 3403 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 3404 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3405 | if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3406 | IWL_ERROR("Not valid error log pointer 0x%08X\n", base); |
| 3407 | return; |
| 3408 | } |
| 3409 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3410 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3411 | if (rc) { |
| 3412 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 3413 | return; |
| 3414 | } |
| 3415 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3416 | count = iwl_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3417 | |
| 3418 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
| 3419 | IWL_ERROR("Start IWL Error Log Dump:\n"); |
Tomas Winkler | 2acae16 | 2008-03-02 01:25:59 +0200 | [diff] [blame] | 3420 | IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3421 | } |
| 3422 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3423 | desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32)); |
| 3424 | blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32)); |
| 3425 | blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32)); |
| 3426 | ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32)); |
| 3427 | ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32)); |
| 3428 | data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32)); |
| 3429 | data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32)); |
| 3430 | line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32)); |
| 3431 | time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3432 | |
| 3433 | IWL_ERROR("Desc Time " |
| 3434 | "data1 data2 line\n"); |
| 3435 | IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n", |
| 3436 | desc_lookup(desc), desc, time, data1, data2, line); |
| 3437 | IWL_ERROR("blink1 blink2 ilink1 ilink2\n"); |
| 3438 | IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2, |
| 3439 | ilink1, ilink2); |
| 3440 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3441 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3442 | } |
| 3443 | |
| 3444 | #define EVENT_START_OFFSET (4 * sizeof(u32)) |
| 3445 | |
| 3446 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3447 | * iwl4965_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3448 | * |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3449 | * NOTE: Must be called with iwl_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3450 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3451 | static void iwl4965_print_event_log(struct iwl_priv *priv, u32 start_idx, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3452 | u32 num_events, u32 mode) |
| 3453 | { |
| 3454 | u32 i; |
| 3455 | u32 base; /* SRAM byte address of event log header */ |
| 3456 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 3457 | u32 ptr; /* SRAM byte address of log data */ |
| 3458 | u32 ev, time, data; /* event log data */ |
| 3459 | |
| 3460 | if (num_events == 0) |
| 3461 | return; |
| 3462 | |
| 3463 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 3464 | |
| 3465 | if (mode == 0) |
| 3466 | event_size = 2 * sizeof(u32); |
| 3467 | else |
| 3468 | event_size = 3 * sizeof(u32); |
| 3469 | |
| 3470 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 3471 | |
| 3472 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 3473 | * place event id # at far right for easier visual parsing. */ |
| 3474 | for (i = 0; i < num_events; i++) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3475 | ev = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3476 | ptr += sizeof(u32); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3477 | time = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3478 | ptr += sizeof(u32); |
| 3479 | if (mode == 0) |
| 3480 | IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */ |
| 3481 | else { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3482 | data = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3483 | ptr += sizeof(u32); |
| 3484 | IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev); |
| 3485 | } |
| 3486 | } |
| 3487 | } |
| 3488 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3489 | static void iwl4965_dump_nic_event_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3490 | { |
| 3491 | int rc; |
| 3492 | u32 base; /* SRAM byte address of event log header */ |
| 3493 | u32 capacity; /* event log capacity in # entries */ |
| 3494 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 3495 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 3496 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 3497 | u32 size; /* # entries that we'll print */ |
| 3498 | |
| 3499 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3500 | if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3501 | IWL_ERROR("Invalid event log pointer 0x%08X\n", base); |
| 3502 | return; |
| 3503 | } |
| 3504 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3505 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3506 | if (rc) { |
| 3507 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 3508 | return; |
| 3509 | } |
| 3510 | |
| 3511 | /* event log header */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3512 | capacity = iwl_read_targ_mem(priv, base); |
| 3513 | mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 3514 | num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 3515 | next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3516 | |
| 3517 | size = num_wraps ? capacity : next_entry; |
| 3518 | |
| 3519 | /* bail out if nothing in log */ |
| 3520 | if (size == 0) { |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 3521 | IWL_ERROR("Start IWL Event Log Dump: nothing in log\n"); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3522 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3523 | return; |
| 3524 | } |
| 3525 | |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 3526 | 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] | 3527 | size, num_wraps); |
| 3528 | |
| 3529 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 3530 | * i.e the next one that uCode would fill. */ |
| 3531 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3532 | iwl4965_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3533 | capacity - next_entry, mode); |
| 3534 | |
| 3535 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3536 | iwl4965_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3537 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3538 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3539 | } |
| 3540 | |
| 3541 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3542 | * iwl4965_irq_handle_error - called for HW or SW error interrupt from card |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3543 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3544 | static void iwl4965_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3545 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3546 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3547 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 3548 | |
| 3549 | /* Cancel currently queued command. */ |
| 3550 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3551 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3552 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3553 | if (priv->debug_level & IWL_DL_FW_ERRORS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3554 | iwl4965_dump_nic_error_log(priv); |
| 3555 | iwl4965_dump_nic_event_log(priv); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3556 | iwl4965_print_rx_config_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3557 | } |
| 3558 | #endif |
| 3559 | |
| 3560 | wake_up_interruptible(&priv->wait_command_queue); |
| 3561 | |
| 3562 | /* Keep the restart process from trying to send host |
| 3563 | * commands by clearing the INIT status bit */ |
| 3564 | clear_bit(STATUS_READY, &priv->status); |
| 3565 | |
| 3566 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3567 | IWL_DEBUG(IWL_DL_FW_ERRORS, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3568 | "Restarting adapter due to uCode error.\n"); |
| 3569 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3570 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3571 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 3572 | sizeof(priv->recovery_rxon)); |
| 3573 | priv->error_recovering = 1; |
| 3574 | } |
Ester Kummer | 3a1081e | 2008-05-06 11:05:14 +0800 | [diff] [blame] | 3575 | if (priv->cfg->mod_params->restart_fw) |
| 3576 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3577 | } |
| 3578 | } |
| 3579 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3580 | static void iwl4965_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3581 | { |
| 3582 | unsigned long flags; |
| 3583 | |
| 3584 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 3585 | sizeof(priv->staging_rxon)); |
| 3586 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3587 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3588 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3589 | iwl4965_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3590 | |
| 3591 | spin_lock_irqsave(&priv->lock, flags); |
| 3592 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 3593 | priv->error_recovering = 0; |
| 3594 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3595 | } |
| 3596 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3597 | static void iwl4965_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3598 | { |
| 3599 | u32 inta, handled = 0; |
| 3600 | u32 inta_fh; |
| 3601 | unsigned long flags; |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3602 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3603 | u32 inta_mask; |
| 3604 | #endif |
| 3605 | |
| 3606 | spin_lock_irqsave(&priv->lock, flags); |
| 3607 | |
| 3608 | /* Ack/clear/reset pending uCode interrupts. |
| 3609 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 3610 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3611 | inta = iwl_read32(priv, CSR_INT); |
| 3612 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3613 | |
| 3614 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 3615 | * Any new interrupts that happen after this, either while we're |
| 3616 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3617 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 3618 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3619 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3620 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3621 | if (priv->debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3622 | /* just for debug */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3623 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3624 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 3625 | inta, inta_mask, inta_fh); |
| 3626 | } |
| 3627 | #endif |
| 3628 | |
| 3629 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 3630 | * atomic, make sure that inta covers all the interrupts that |
| 3631 | * we've discovered, even if FH interrupt came in just after |
| 3632 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 3633 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3634 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 3635 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3636 | inta |= CSR_INT_BIT_FH_TX; |
| 3637 | |
| 3638 | /* Now service all interrupt bits discovered above. */ |
| 3639 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 3640 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 3641 | |
| 3642 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3643 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3644 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3645 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3646 | |
| 3647 | handled |= CSR_INT_BIT_HW_ERR; |
| 3648 | |
| 3649 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3650 | |
| 3651 | return; |
| 3652 | } |
| 3653 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3654 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3655 | if (priv->debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3656 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3657 | if (inta & CSR_INT_BIT_SCD) |
| 3658 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 3659 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3660 | |
| 3661 | /* Alive notification via Rx interrupt will do the real work */ |
| 3662 | if (inta & CSR_INT_BIT_ALIVE) |
| 3663 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 3664 | } |
| 3665 | #endif |
| 3666 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3667 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3668 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3669 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3670 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 3671 | int hw_rf_kill = 0; |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3672 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3673 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 3674 | hw_rf_kill = 1; |
| 3675 | |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3676 | IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3677 | hw_rf_kill ? "disable radio":"enable radio"); |
| 3678 | |
| 3679 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 3680 | * when we loaded driver, and is now set to "enable". |
| 3681 | * After we're Alive, RF_KILL gets handled by |
Reinette Chatre | 3230455 | 2008-02-15 14:34:37 -0800 | [diff] [blame] | 3682 | * iwl4965_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 3683 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 3684 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3685 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 3686 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3687 | |
| 3688 | handled |= CSR_INT_BIT_RF_KILL; |
| 3689 | } |
| 3690 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3691 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3692 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 3693 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 3694 | handled |= CSR_INT_BIT_CT_KILL; |
| 3695 | } |
| 3696 | |
| 3697 | /* Error detected by uCode */ |
| 3698 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 3699 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 3700 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3701 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3702 | handled |= CSR_INT_BIT_SW_ERR; |
| 3703 | } |
| 3704 | |
| 3705 | /* uCode wakes up after power-down sleep */ |
| 3706 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 3707 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3708 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3709 | iwl_txq_update_write_ptr(priv, &priv->txq[0]); |
| 3710 | iwl_txq_update_write_ptr(priv, &priv->txq[1]); |
| 3711 | iwl_txq_update_write_ptr(priv, &priv->txq[2]); |
| 3712 | iwl_txq_update_write_ptr(priv, &priv->txq[3]); |
| 3713 | iwl_txq_update_write_ptr(priv, &priv->txq[4]); |
| 3714 | iwl_txq_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3715 | |
| 3716 | handled |= CSR_INT_BIT_WAKEUP; |
| 3717 | } |
| 3718 | |
| 3719 | /* All uCode command responses, including Tx command responses, |
| 3720 | * Rx "responses" (frame-received notification), and other |
| 3721 | * notifications from uCode come through here*/ |
| 3722 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3723 | iwl_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3724 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 3725 | } |
| 3726 | |
| 3727 | if (inta & CSR_INT_BIT_FH_TX) { |
| 3728 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 3729 | handled |= CSR_INT_BIT_FH_TX; |
| 3730 | } |
| 3731 | |
| 3732 | if (inta & ~handled) |
| 3733 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 3734 | |
| 3735 | if (inta & ~CSR_INI_SET_MASK) { |
| 3736 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 3737 | inta & ~CSR_INI_SET_MASK); |
| 3738 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 3739 | } |
| 3740 | |
| 3741 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3742 | /* only Re-enable if diabled by irq */ |
| 3743 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 3744 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3745 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3746 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3747 | if (priv->debug_level & (IWL_DL_ISR)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3748 | inta = iwl_read32(priv, CSR_INT); |
| 3749 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 3750 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3751 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 3752 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 3753 | } |
| 3754 | #endif |
| 3755 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3756 | } |
| 3757 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3758 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3759 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3760 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3761 | u32 inta, inta_mask; |
| 3762 | u32 inta_fh; |
| 3763 | if (!priv) |
| 3764 | return IRQ_NONE; |
| 3765 | |
| 3766 | spin_lock(&priv->lock); |
| 3767 | |
| 3768 | /* Disable (but don't clear!) interrupts here to avoid |
| 3769 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 3770 | * If we have something to service, the tasklet will re-enable ints. |
| 3771 | * If we *don't* have something, we'll re-enable before leaving here. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3772 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 3773 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3774 | |
| 3775 | /* Discover which interrupts are active/pending */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3776 | inta = iwl_read32(priv, CSR_INT); |
| 3777 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3778 | |
| 3779 | /* Ignore interrupt if there's nothing in NIC to service. |
| 3780 | * This may be due to IRQ shared with another device, |
| 3781 | * or due to sporadic interrupts thrown from our NIC. */ |
| 3782 | if (!inta && !inta_fh) { |
| 3783 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 3784 | goto none; |
| 3785 | } |
| 3786 | |
| 3787 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 3788 | /* Hardware disappeared. It might have already raised |
| 3789 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3790 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 3791 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 3795 | inta, inta_mask, inta_fh); |
| 3796 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3797 | inta &= ~CSR_INT_BIT_SCD; |
| 3798 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3799 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3800 | if (likely(inta || inta_fh)) |
| 3801 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3802 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 3803 | unplugged: |
| 3804 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3805 | return IRQ_HANDLED; |
| 3806 | |
| 3807 | none: |
| 3808 | /* re-enable interrupts here since we don't have anything to service. */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3809 | /* only Re-enable if diabled by irq */ |
| 3810 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 3811 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3812 | spin_unlock(&priv->lock); |
| 3813 | return IRQ_NONE; |
| 3814 | } |
| 3815 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3816 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 3817 | * sending probe req. This should be set long enough to hear probe responses |
| 3818 | * from more than one AP. */ |
| 3819 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 3820 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 3821 | |
| 3822 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 3823 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 3824 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 3825 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 3826 | * no other traffic). |
| 3827 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 3828 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 3829 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 3830 | |
| 3831 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 3832 | * Must be set longer than active dwell time. |
| 3833 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 3834 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 3835 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 3836 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 3837 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 3838 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3839 | static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3840 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3841 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3842 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3843 | return IWL_ACTIVE_DWELL_TIME_52; |
| 3844 | else |
| 3845 | return IWL_ACTIVE_DWELL_TIME_24; |
| 3846 | } |
| 3847 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3848 | static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3849 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3850 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3851 | u16 active = iwl4965_get_active_dwell_time(priv, band); |
| 3852 | u16 passive = (band != IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3853 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 3854 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 3855 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3856 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3857 | /* If we're associated, we clamp the maximum passive |
| 3858 | * dwell time to be 98% of the beacon interval (minus |
| 3859 | * 2 * channel tune time) */ |
| 3860 | passive = priv->beacon_int; |
| 3861 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 3862 | passive = IWL_PASSIVE_DWELL_BASE; |
| 3863 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 3864 | } |
| 3865 | |
| 3866 | if (passive <= active) |
| 3867 | passive = active + 1; |
| 3868 | |
| 3869 | return passive; |
| 3870 | } |
| 3871 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3872 | static int iwl4965_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3873 | enum ieee80211_band band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3874 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3875 | struct iwl4965_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3876 | { |
| 3877 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3878 | const struct ieee80211_supported_band *sband; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3879 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3880 | u16 passive_dwell = 0; |
| 3881 | u16 active_dwell = 0; |
| 3882 | int added, i; |
| 3883 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 3884 | sband = iwl_get_hw_mode(priv, band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3885 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3886 | return 0; |
| 3887 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3888 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3889 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3890 | active_dwell = iwl4965_get_active_dwell_time(priv, band); |
| 3891 | passive_dwell = iwl4965_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3892 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3893 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 3894 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 3895 | continue; |
| 3896 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3897 | scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3898 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 3899 | ch_info = iwl_get_channel_info(priv, band, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3900 | scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3901 | if (!is_channel_valid(ch_info)) { |
| 3902 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 3903 | scan_ch->channel); |
| 3904 | continue; |
| 3905 | } |
| 3906 | |
| 3907 | if (!is_active || is_channel_passive(ch_info) || |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3908 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3909 | scan_ch->type = 0; /* passive */ |
| 3910 | else |
| 3911 | scan_ch->type = 1; /* active */ |
| 3912 | |
| 3913 | if (scan_ch->type & 1) |
| 3914 | scan_ch->type |= (direct_mask << 1); |
| 3915 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3916 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 3917 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 3918 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3919 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3920 | scan_ch->tpc.dsp_atten = 110; |
| 3921 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 3922 | |
| 3923 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3924 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3925 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 3926 | else { |
| 3927 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 3928 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3929 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 3930 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3931 | */ |
| 3932 | } |
| 3933 | |
| 3934 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 3935 | scan_ch->channel, |
| 3936 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 3937 | (scan_ch->type & 1) ? |
| 3938 | active_dwell : passive_dwell); |
| 3939 | |
| 3940 | scan_ch++; |
| 3941 | added++; |
| 3942 | } |
| 3943 | |
| 3944 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 3945 | return added; |
| 3946 | } |
| 3947 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3948 | /****************************************************************************** |
| 3949 | * |
| 3950 | * uCode download functions |
| 3951 | * |
| 3952 | ******************************************************************************/ |
| 3953 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3954 | static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3955 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3956 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 3957 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 3958 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 3959 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 3960 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 3961 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3962 | } |
| 3963 | |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 3964 | static void iwl4965_nic_start(struct iwl_priv *priv) |
| 3965 | { |
| 3966 | /* Remove all resets to allow NIC to operate */ |
| 3967 | iwl_write32(priv, CSR_RESET, 0); |
| 3968 | } |
| 3969 | |
| 3970 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3971 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3972 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3973 | * |
| 3974 | * Copy into buffers for card to fetch via bus-mastering |
| 3975 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3976 | static int iwl4965_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3977 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3978 | struct iwl4965_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3979 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3980 | const struct firmware *ucode_raw; |
Tomas Winkler | 4bf775c | 2008-03-04 18:09:31 -0800 | [diff] [blame] | 3981 | const char *name = priv->cfg->fw_name; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3982 | u8 *src; |
| 3983 | size_t len; |
| 3984 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 3985 | |
| 3986 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 3987 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3988 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 3989 | if (ret < 0) { |
| 3990 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 3991 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3992 | goto error; |
| 3993 | } |
| 3994 | |
| 3995 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 3996 | name, ucode_raw->size); |
| 3997 | |
| 3998 | /* Make sure that we got at least our header! */ |
| 3999 | if (ucode_raw->size < sizeof(*ucode)) { |
| 4000 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4001 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4002 | goto err_release; |
| 4003 | } |
| 4004 | |
| 4005 | /* Data from ucode file: header followed by uCode images */ |
| 4006 | ucode = (void *)ucode_raw->data; |
| 4007 | |
| 4008 | ver = le32_to_cpu(ucode->ver); |
| 4009 | inst_size = le32_to_cpu(ucode->inst_size); |
| 4010 | data_size = le32_to_cpu(ucode->data_size); |
| 4011 | init_size = le32_to_cpu(ucode->init_size); |
| 4012 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 4013 | boot_size = le32_to_cpu(ucode->boot_size); |
| 4014 | |
| 4015 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 4016 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 4017 | inst_size); |
| 4018 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 4019 | data_size); |
| 4020 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 4021 | init_size); |
| 4022 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 4023 | init_data_size); |
| 4024 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 4025 | boot_size); |
| 4026 | |
| 4027 | /* Verify size of file vs. image size info in file's header */ |
| 4028 | if (ucode_raw->size < sizeof(*ucode) + |
| 4029 | inst_size + data_size + init_size + |
| 4030 | init_data_size + boot_size) { |
| 4031 | |
| 4032 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 4033 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4034 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4035 | goto err_release; |
| 4036 | } |
| 4037 | |
| 4038 | /* Verify that uCode images will fit in card's SRAM */ |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4039 | if (inst_size > priv->hw_params.max_inst_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4040 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 4041 | inst_size); |
| 4042 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4043 | goto err_release; |
| 4044 | } |
| 4045 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4046 | if (data_size > priv->hw_params.max_data_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4047 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 4048 | data_size); |
| 4049 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4050 | goto err_release; |
| 4051 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4052 | if (init_size > priv->hw_params.max_inst_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4053 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4054 | ("uCode init instr len %d too large to fit in\n", |
| 4055 | init_size); |
| 4056 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4057 | goto err_release; |
| 4058 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4059 | if (init_data_size > priv->hw_params.max_data_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4060 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4061 | ("uCode init data len %d too large to fit in\n", |
| 4062 | init_data_size); |
| 4063 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4064 | goto err_release; |
| 4065 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4066 | if (boot_size > priv->hw_params.max_bsm_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4067 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4068 | ("uCode boot instr len %d too large to fit in\n", |
| 4069 | boot_size); |
| 4070 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4071 | goto err_release; |
| 4072 | } |
| 4073 | |
| 4074 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 4075 | |
| 4076 | /* Runtime instructions and 2 copies of data: |
| 4077 | * 1) unmodified from disk |
| 4078 | * 2) backup cache for save/restore during power-downs */ |
| 4079 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4080 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4081 | |
| 4082 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4083 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4084 | |
| 4085 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4086 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4087 | |
| 4088 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4089 | if (init_size && init_data_size) { |
| 4090 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4091 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4092 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4093 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4094 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4095 | |
| 4096 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 4097 | goto err_pci_alloc; |
| 4098 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4099 | |
| 4100 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4101 | if (boot_size) { |
| 4102 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4103 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4104 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4105 | if (!priv->ucode_boot.v_addr) |
| 4106 | goto err_pci_alloc; |
| 4107 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4108 | |
| 4109 | /* Copy images into buffers for card's bus-master reads ... */ |
| 4110 | |
| 4111 | /* Runtime instructions (first block of data in file) */ |
| 4112 | src = &ucode->data[0]; |
| 4113 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4114 | 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] | 4115 | memcpy(priv->ucode_code.v_addr, src, len); |
| 4116 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 4117 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 4118 | |
| 4119 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4120 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4121 | src = &ucode->data[inst_size]; |
| 4122 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4123 | 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] | 4124 | memcpy(priv->ucode_data.v_addr, src, len); |
| 4125 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 4126 | |
| 4127 | /* Initialization instructions (3rd block) */ |
| 4128 | if (init_size) { |
| 4129 | src = &ucode->data[inst_size + data_size]; |
| 4130 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4131 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 4132 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4133 | memcpy(priv->ucode_init.v_addr, src, len); |
| 4134 | } |
| 4135 | |
| 4136 | /* Initialization data (4th block) */ |
| 4137 | if (init_data_size) { |
| 4138 | src = &ucode->data[inst_size + data_size + init_size]; |
| 4139 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4140 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 4141 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4142 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 4143 | } |
| 4144 | |
| 4145 | /* Bootstrap instructions (5th block) */ |
| 4146 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 4147 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4148 | IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4149 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 4150 | |
| 4151 | /* We have our copies now, allow OS release its copies */ |
| 4152 | release_firmware(ucode_raw); |
| 4153 | return 0; |
| 4154 | |
| 4155 | err_pci_alloc: |
| 4156 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4157 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4158 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4159 | |
| 4160 | err_release: |
| 4161 | release_firmware(ucode_raw); |
| 4162 | |
| 4163 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4164 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4165 | } |
| 4166 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4167 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4168 | * iwl4965_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4169 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4170 | * Alive gets handled by iwl4965_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4171 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4172 | static void iwl4965_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4173 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4174 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4175 | |
| 4176 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 4177 | |
| 4178 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 4179 | /* We had an error bringing up the hardware, so take it |
| 4180 | * all the way back down so we can try again */ |
| 4181 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 4182 | goto restart; |
| 4183 | } |
| 4184 | |
| 4185 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 4186 | * This is a paranoid check, because we would not have gotten the |
| 4187 | * "runtime" alive if code weren't properly loaded. */ |
Emmanuel Grumbach | b0692f2 | 2008-04-24 11:55:18 -0700 | [diff] [blame] | 4188 | if (iwl_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4189 | /* Runtime instruction load was bad; |
| 4190 | * take it all the way back down so we can try again */ |
| 4191 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 4192 | goto restart; |
| 4193 | } |
| 4194 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4195 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4196 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4197 | ret = priv->cfg->ops->lib->alive_notify(priv); |
| 4198 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4199 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4200 | ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4201 | goto restart; |
| 4202 | } |
| 4203 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4204 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4205 | set_bit(STATUS_ALIVE, &priv->status); |
| 4206 | |
| 4207 | /* Clear out the uCode error bit if it is set */ |
| 4208 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 4209 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4210 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4211 | return; |
| 4212 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4213 | ieee80211_start_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4214 | |
| 4215 | priv->active_rate = priv->rates_mask; |
| 4216 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 4217 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4218 | if (iwl_is_associated(priv)) { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 4219 | struct iwl_rxon_cmd *active_rxon = |
| 4220 | (struct iwl_rxon_cmd *)&priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4221 | |
| 4222 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 4223 | sizeof(priv->staging_rxon)); |
| 4224 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 4225 | } else { |
| 4226 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4227 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4228 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 4229 | } |
| 4230 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4231 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4232 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4233 | |
| 4234 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4235 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4236 | |
| 4237 | /* At this point, the NIC is initialized and operational */ |
| 4238 | priv->notif_missed_beacons = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4239 | |
| 4240 | iwl4965_rf_kill_ct_config(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4241 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 4242 | iwl_leds_register(priv); |
| 4243 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4244 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 4245 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4246 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4247 | |
| 4248 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4249 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4250 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 4251 | iwlcore_low_level_notify(priv, IWLCORE_START_EVT); |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 4252 | ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4253 | return; |
| 4254 | |
| 4255 | restart: |
| 4256 | queue_work(priv->workqueue, &priv->restart); |
| 4257 | } |
| 4258 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4259 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4260 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4261 | static void __iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4262 | { |
| 4263 | unsigned long flags; |
| 4264 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 4265 | struct ieee80211_conf *conf = NULL; |
| 4266 | |
| 4267 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 4268 | |
| 4269 | conf = ieee80211_get_hw_conf(priv->hw); |
| 4270 | |
| 4271 | if (!exit_pending) |
| 4272 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 4273 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 4274 | iwl_leds_unregister(priv); |
| 4275 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 4276 | iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT); |
| 4277 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4278 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4279 | |
| 4280 | /* Unblock any waiting calls */ |
| 4281 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 4282 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4283 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 4284 | * exiting the module */ |
| 4285 | if (!exit_pending) |
| 4286 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 4287 | |
| 4288 | /* stop and reset the on-board processor */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4289 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4290 | |
| 4291 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4292 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4293 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4294 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4295 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4296 | |
| 4297 | if (priv->mac80211_registered) |
| 4298 | ieee80211_stop_queues(priv->hw); |
| 4299 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4300 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4301 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4302 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4303 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 4304 | STATUS_RF_KILL_HW | |
| 4305 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 4306 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 4307 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 4308 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4309 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 4310 | STATUS_IN_SUSPEND; |
| 4311 | goto exit; |
| 4312 | } |
| 4313 | |
| 4314 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 4315 | * SUSPEND bits and continue taking the NIC down. */ |
| 4316 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 4317 | STATUS_RF_KILL_HW | |
| 4318 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 4319 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 4320 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 4321 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4322 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 4323 | STATUS_IN_SUSPEND | |
| 4324 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 4325 | STATUS_FW_ERROR; |
| 4326 | |
| 4327 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4328 | iwl_clear_bit(priv, CSR_GP_CNTRL, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4329 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4330 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4331 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4332 | iwl4965_hw_txq_ctx_stop(priv); |
| 4333 | iwl4965_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4334 | |
| 4335 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4336 | if (!iwl_grab_nic_access(priv)) { |
| 4337 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4338 | APMG_CLK_VAL_DMA_CLK_RQT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4339 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4340 | } |
| 4341 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4342 | |
| 4343 | udelay(5); |
| 4344 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4345 | iwl4965_hw_nic_stop_master(priv); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4346 | iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4347 | iwl4965_hw_nic_reset(priv); |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 4348 | priv->cfg->ops->lib->free_shared_mem(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4349 | |
| 4350 | exit: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4351 | memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4352 | |
| 4353 | if (priv->ibss_beacon) |
| 4354 | dev_kfree_skb(priv->ibss_beacon); |
| 4355 | priv->ibss_beacon = NULL; |
| 4356 | |
| 4357 | /* clear out any free frames */ |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 4358 | iwl_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4359 | } |
| 4360 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4361 | static void iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4362 | { |
| 4363 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4364 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4365 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 4366 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4367 | iwl4965_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | #define MAX_HW_RESTARTS 5 |
| 4371 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4372 | static int __iwl4965_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4373 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4374 | int i; |
| 4375 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4376 | |
| 4377 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 4378 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 4379 | return -EIO; |
| 4380 | } |
| 4381 | |
| 4382 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 4383 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 4384 | "parameter)\n"); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4385 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4386 | return -ENODEV; |
| 4387 | } |
| 4388 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 4389 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 4390 | IWL_ERROR("ucode not available for device bringup\n"); |
| 4391 | return -EIO; |
| 4392 | } |
| 4393 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4394 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4395 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4396 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 4397 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4398 | else { |
| 4399 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4400 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4401 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4402 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 4403 | return -ENODEV; |
| 4404 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4405 | } |
| 4406 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4407 | iwl_rfkill_set_hw_state(priv); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4408 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4409 | |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 4410 | ret = priv->cfg->ops->lib->alloc_shared_mem(priv); |
| 4411 | if (ret) { |
| 4412 | IWL_ERROR("Unable to allocate shared memory\n"); |
| 4413 | return ret; |
| 4414 | } |
| 4415 | |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 4416 | ret = iwl_hw_nic_init(priv); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4417 | if (ret) { |
| 4418 | IWL_ERROR("Unable to init nic\n"); |
| 4419 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | /* make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4423 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 4424 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4425 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 4426 | |
| 4427 | /* clear (again), then enable host interrupts */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4428 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4429 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4430 | |
| 4431 | /* really make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4432 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 4433 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4434 | |
| 4435 | /* Copy original ucode data image from disk into backup cache. |
| 4436 | * This will be used to initialize the on-board processor's |
| 4437 | * data SRAM for a clean start when the runtime program first loads. */ |
| 4438 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4439 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4440 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4441 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 4442 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4443 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4444 | |
| 4445 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 4446 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4447 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4448 | |
| 4449 | /* load bootstrap state machine, |
| 4450 | * load bootstrap program into processor's memory, |
| 4451 | * prepare to load the "initialize" uCode */ |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4452 | ret = priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4453 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4454 | if (ret) { |
| 4455 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4456 | continue; |
| 4457 | } |
| 4458 | |
| 4459 | /* start card; "initialize" will load runtime ucode */ |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 4460 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4461 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4462 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 4463 | |
| 4464 | return 0; |
| 4465 | } |
| 4466 | |
| 4467 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4468 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4469 | |
| 4470 | /* tried to restart and config the device for as long as our |
| 4471 | * patience could withstand */ |
| 4472 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 4473 | return -EIO; |
| 4474 | } |
| 4475 | |
| 4476 | |
| 4477 | /***************************************************************************** |
| 4478 | * |
| 4479 | * Workqueue callbacks |
| 4480 | * |
| 4481 | *****************************************************************************/ |
| 4482 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4483 | static void iwl4965_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4484 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4485 | struct iwl_priv *priv = |
| 4486 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4487 | |
| 4488 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4489 | return; |
| 4490 | |
| 4491 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | f3ccc08 | 2008-05-05 10:22:45 +0800 | [diff] [blame] | 4492 | priv->cfg->ops->lib->init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4493 | mutex_unlock(&priv->mutex); |
| 4494 | } |
| 4495 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4496 | static void iwl4965_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4497 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4498 | struct iwl_priv *priv = |
| 4499 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4500 | |
| 4501 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4502 | return; |
| 4503 | |
| 4504 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4505 | iwl4965_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4506 | mutex_unlock(&priv->mutex); |
| 4507 | } |
| 4508 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4509 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4510 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4511 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4512 | |
| 4513 | wake_up_interruptible(&priv->wait_command_queue); |
| 4514 | |
| 4515 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4516 | return; |
| 4517 | |
| 4518 | mutex_lock(&priv->mutex); |
| 4519 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4520 | if (!iwl_is_rfkill(priv)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 4521 | IWL_DEBUG(IWL_DL_RF_KILL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4522 | "HW and/or SW RF Kill no longer active, restarting " |
| 4523 | "device\n"); |
| 4524 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4525 | queue_work(priv->workqueue, &priv->restart); |
| 4526 | } else { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4527 | /* make sure mac80211 stop sending Tx frame */ |
| 4528 | if (priv->mac80211_registered) |
| 4529 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4530 | |
| 4531 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 4532 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 4533 | "disabled by SW switch\n"); |
| 4534 | else |
| 4535 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 4536 | "Kill switch must be turned off for " |
| 4537 | "wireless networking to work.\n"); |
| 4538 | } |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4539 | iwl_rfkill_set_hw_state(priv); |
| 4540 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4541 | mutex_unlock(&priv->mutex); |
| 4542 | } |
| 4543 | |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 4544 | static void iwl4965_bg_set_monitor(struct work_struct *work) |
| 4545 | { |
| 4546 | struct iwl_priv *priv = container_of(work, |
| 4547 | struct iwl_priv, set_monitor); |
| 4548 | |
| 4549 | IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n"); |
| 4550 | |
| 4551 | mutex_lock(&priv->mutex); |
| 4552 | |
| 4553 | if (!iwl_is_ready(priv)) |
| 4554 | IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n"); |
| 4555 | else |
| 4556 | if (iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR) != 0) |
| 4557 | IWL_ERROR("iwl4965_set_mode() failed\n"); |
| 4558 | |
| 4559 | mutex_unlock(&priv->mutex); |
| 4560 | } |
| 4561 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4562 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 4563 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4564 | static void iwl4965_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4565 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4566 | struct iwl_priv *priv = |
| 4567 | container_of(data, struct iwl_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4568 | |
| 4569 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4570 | return; |
| 4571 | |
| 4572 | mutex_lock(&priv->mutex); |
| 4573 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 4574 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 4575 | IWL_DEBUG(IWL_DL_SCAN, "Scan completion watchdog resetting " |
| 4576 | "adapter (%dms)\n", |
| 4577 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4578 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4579 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4580 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4581 | } |
| 4582 | mutex_unlock(&priv->mutex); |
| 4583 | } |
| 4584 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4585 | static void iwl4965_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4586 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4587 | struct iwl_priv *priv = |
| 4588 | container_of(data, struct iwl_priv, request_scan); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4589 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4590 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4591 | .len = sizeof(struct iwl4965_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4592 | .meta.flags = CMD_SIZE_HUGE, |
| 4593 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4594 | struct iwl4965_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4595 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 4596 | u16 cmd_len; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4597 | enum ieee80211_band band; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 4598 | u8 direct_mask; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4599 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4600 | |
| 4601 | conf = ieee80211_get_hw_conf(priv->hw); |
| 4602 | |
| 4603 | mutex_lock(&priv->mutex); |
| 4604 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4605 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4606 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 4607 | goto done; |
| 4608 | } |
| 4609 | |
| 4610 | /* Make sure the scan wasn't cancelled before this queued work |
| 4611 | * was given the chance to run... */ |
| 4612 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 4613 | goto done; |
| 4614 | |
| 4615 | /* This should never be called or scheduled if there is currently |
| 4616 | * a scan active in the hardware. */ |
| 4617 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 4618 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 4619 | "Ignoring second request.\n"); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4620 | ret = -EIO; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4621 | goto done; |
| 4622 | } |
| 4623 | |
| 4624 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 4625 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 4626 | goto done; |
| 4627 | } |
| 4628 | |
| 4629 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 4630 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 4631 | goto done; |
| 4632 | } |
| 4633 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4634 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4635 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 4636 | goto done; |
| 4637 | } |
| 4638 | |
| 4639 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 4640 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 4641 | goto done; |
| 4642 | } |
| 4643 | |
| 4644 | if (!priv->scan_bands) { |
| 4645 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 4646 | goto done; |
| 4647 | } |
| 4648 | |
| 4649 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4650 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4651 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 4652 | if (!priv->scan) { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4653 | ret = -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4654 | goto done; |
| 4655 | } |
| 4656 | } |
| 4657 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4658 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4659 | |
| 4660 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 4661 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 4662 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4663 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4664 | u16 interval = 0; |
| 4665 | u32 extra; |
| 4666 | u32 suspend_time = 100; |
| 4667 | u32 scan_suspend_time = 100; |
| 4668 | unsigned long flags; |
| 4669 | |
| 4670 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 4671 | |
| 4672 | spin_lock_irqsave(&priv->lock, flags); |
| 4673 | interval = priv->beacon_int; |
| 4674 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4675 | |
| 4676 | scan->suspend_time = 0; |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4677 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4678 | if (!interval) |
| 4679 | interval = suspend_time; |
| 4680 | |
| 4681 | extra = (suspend_time / interval) << 22; |
| 4682 | scan_suspend_time = (extra | |
| 4683 | ((suspend_time % interval) * 1024)); |
| 4684 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 4685 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 4686 | scan_suspend_time, interval); |
| 4687 | } |
| 4688 | |
| 4689 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 4690 | if (priv->one_direct_scan) { |
| 4691 | IWL_DEBUG_SCAN |
| 4692 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4693 | iwl4965_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4694 | priv->direct_ssid_len)); |
| 4695 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 4696 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 4697 | memcpy(scan->direct_scan[0].ssid, |
| 4698 | priv->direct_ssid, priv->direct_ssid_len); |
| 4699 | direct_mask = 1; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4700 | } else if (!iwl_is_associated(priv) && priv->essid_len) { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 4701 | IWL_DEBUG_SCAN |
| 4702 | ("Kicking off one direct scan for '%s' when not associated\n", |
| 4703 | iwl4965_escape_essid(priv->essid, priv->essid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4704 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 4705 | scan->direct_scan[0].len = priv->essid_len; |
| 4706 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 4707 | direct_mask = 1; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4708 | } else { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 4709 | IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4710 | direct_mask = 0; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4711 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4712 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4713 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 4714 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4715 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 4716 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4717 | |
| 4718 | switch (priv->scan_bands) { |
| 4719 | case 2: |
| 4720 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 4721 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4722 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4723 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 4724 | |
| 4725 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4726 | band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4727 | break; |
| 4728 | |
| 4729 | case 1: |
| 4730 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4731 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4732 | RATE_MCS_ANT_B_MSK); |
| 4733 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4734 | band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4735 | break; |
| 4736 | |
| 4737 | default: |
| 4738 | IWL_WARNING("Invalid scan band count\n"); |
| 4739 | goto done; |
| 4740 | } |
| 4741 | |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 4742 | /* We don't build a direct scan probe request; the uCode will do |
| 4743 | * that based on the direct_mask added to each channel entry */ |
| 4744 | cmd_len = iwl4965_fill_probe_req(priv, band, |
| 4745 | (struct ieee80211_mgmt *)scan->data, |
| 4746 | IWL_MAX_SCAN_SIZE - sizeof(*scan), 0); |
| 4747 | |
| 4748 | scan->tx_cmd.len = cpu_to_le16(cmd_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4749 | /* select Rx chains */ |
| 4750 | |
| 4751 | /* Force use of chains B and C (0x6) for scan Rx. |
| 4752 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 4753 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 4754 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 4755 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 4756 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 4757 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 4758 | |
| 4759 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 4760 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 4761 | |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 4762 | if (direct_mask) |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 4763 | scan->channel_count = |
| 4764 | iwl4965_get_channels_for_scan( |
| 4765 | priv, band, 1, /* active */ |
| 4766 | direct_mask, |
| 4767 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 4768 | else |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 4769 | scan->channel_count = |
| 4770 | iwl4965_get_channels_for_scan( |
| 4771 | priv, band, 0, /* passive */ |
| 4772 | direct_mask, |
| 4773 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4774 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4775 | scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | |
| 4776 | RXON_FILTER_BCON_AWARE_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4777 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4778 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4779 | cmd.data = scan; |
| 4780 | scan->len = cpu_to_le16(cmd.len); |
| 4781 | |
| 4782 | set_bit(STATUS_SCAN_HW, &priv->status); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4783 | ret = iwl_send_cmd_sync(priv, &cmd); |
| 4784 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4785 | goto done; |
| 4786 | |
| 4787 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 4788 | IWL_SCAN_CHECK_WATCHDOG); |
| 4789 | |
| 4790 | mutex_unlock(&priv->mutex); |
| 4791 | return; |
| 4792 | |
| 4793 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 4794 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4795 | queue_work(priv->workqueue, &priv->scan_completed); |
| 4796 | mutex_unlock(&priv->mutex); |
| 4797 | } |
| 4798 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4799 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4800 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4801 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4802 | |
| 4803 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4804 | return; |
| 4805 | |
| 4806 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4807 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4808 | mutex_unlock(&priv->mutex); |
| 4809 | } |
| 4810 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4811 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4812 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4813 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4814 | |
| 4815 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4816 | return; |
| 4817 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4818 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4819 | queue_work(priv->workqueue, &priv->up); |
| 4820 | } |
| 4821 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4822 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4823 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4824 | struct iwl_priv *priv = |
| 4825 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4826 | |
| 4827 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4828 | return; |
| 4829 | |
| 4830 | mutex_lock(&priv->mutex); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 4831 | iwl_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4832 | mutex_unlock(&priv->mutex); |
| 4833 | } |
| 4834 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4835 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 4836 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4837 | static void iwl4965_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4838 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4839 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4840 | int ret = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4841 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4842 | |
| 4843 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 4844 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 4845 | return; |
| 4846 | } |
| 4847 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4848 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 4849 | priv->assoc_id, |
| 4850 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4851 | |
| 4852 | |
| 4853 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4854 | return; |
| 4855 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4856 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4857 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4858 | return; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4859 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4860 | iwl4965_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4861 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4862 | conf = ieee80211_get_hw_conf(priv->hw); |
| 4863 | |
| 4864 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4865 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4866 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4867 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 4868 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4869 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4870 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4871 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4872 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 4873 | "Attempting to continue.\n"); |
| 4874 | |
| 4875 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 4876 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4877 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 4878 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 4879 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4880 | #endif /* CONFIG_IWL4965_HT*/ |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4881 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4882 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 4883 | |
| 4884 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 4885 | priv->assoc_id, priv->beacon_int); |
| 4886 | |
| 4887 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 4888 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4889 | else |
| 4890 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4891 | |
| 4892 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 4893 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 4894 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 4895 | else |
| 4896 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 4897 | |
| 4898 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 4899 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 4900 | |
| 4901 | } |
| 4902 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4903 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4904 | |
| 4905 | switch (priv->iw_mode) { |
| 4906 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4907 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4908 | break; |
| 4909 | |
| 4910 | case IEEE80211_IF_TYPE_IBSS: |
| 4911 | |
| 4912 | /* clear out the station table */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4913 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4914 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4915 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
| 4916 | iwl4965_rxon_add_station(priv, priv->bssid, 0); |
| 4917 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
| 4918 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4919 | |
| 4920 | break; |
| 4921 | |
| 4922 | default: |
| 4923 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 4924 | __FUNCTION__, priv->iw_mode); |
| 4925 | break; |
| 4926 | } |
| 4927 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4928 | iwl4965_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4929 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4930 | /* Enable Rx differential gain and sensitivity calibrations */ |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 4931 | iwl_chain_noise_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4932 | priv->start_calib = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4933 | |
| 4934 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 4935 | priv->assoc_station_added = 1; |
| 4936 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4937 | iwl4965_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 4938 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4939 | iwl_power_update_mode(priv, 0); |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4940 | /* we have just associated, don't start scan too early */ |
| 4941 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | |
| 4945 | static void iwl4965_bg_post_associate(struct work_struct *data) |
| 4946 | { |
| 4947 | struct iwl_priv *priv = container_of(data, struct iwl_priv, |
| 4948 | post_associate.work); |
| 4949 | |
| 4950 | mutex_lock(&priv->mutex); |
| 4951 | iwl4965_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4952 | mutex_unlock(&priv->mutex); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4953 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4954 | } |
| 4955 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4956 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4957 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4958 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4959 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4960 | if (!iwl_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4961 | return; |
| 4962 | |
| 4963 | mutex_lock(&priv->mutex); |
| 4964 | |
| 4965 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4966 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4967 | |
| 4968 | mutex_unlock(&priv->mutex); |
| 4969 | } |
| 4970 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4971 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 4972 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4973 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4974 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4975 | struct iwl_priv *priv = |
| 4976 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4977 | |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 4978 | IWL_DEBUG(IWL_DL_SCAN, "SCAN complete scan\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4979 | |
| 4980 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4981 | return; |
| 4982 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 4983 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
| 4984 | iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4985 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4986 | ieee80211_scan_completed(priv->hw); |
| 4987 | |
| 4988 | /* Since setting the TXPOWER may have been deferred while |
| 4989 | * performing the scan, fire one off */ |
| 4990 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4991 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4992 | mutex_unlock(&priv->mutex); |
| 4993 | } |
| 4994 | |
| 4995 | /***************************************************************************** |
| 4996 | * |
| 4997 | * mac80211 entry point functions |
| 4998 | * |
| 4999 | *****************************************************************************/ |
| 5000 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5001 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 5002 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5003 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5004 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5005 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5006 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5007 | |
| 5008 | IWL_DEBUG_MAC80211("enter\n"); |
| 5009 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5010 | if (pci_enable_device(priv->pci_dev)) { |
| 5011 | IWL_ERROR("Fail to pci_enable_device\n"); |
| 5012 | return -ENODEV; |
| 5013 | } |
| 5014 | pci_restore_state(priv->pci_dev); |
| 5015 | pci_enable_msi(priv->pci_dev); |
| 5016 | |
| 5017 | ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, |
| 5018 | DRV_NAME, priv); |
| 5019 | if (ret) { |
| 5020 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 5021 | goto out_disable_msi; |
| 5022 | } |
| 5023 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5024 | /* we should be verifying the device is ready to be opened */ |
| 5025 | mutex_lock(&priv->mutex); |
| 5026 | |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 5027 | memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd)); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5028 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 5029 | * ucode filename and max sizes are card-specific. */ |
| 5030 | |
| 5031 | if (!priv->ucode_code.len) { |
| 5032 | ret = iwl4965_read_ucode(priv); |
| 5033 | if (ret) { |
| 5034 | IWL_ERROR("Could not read microcode: %d\n", ret); |
| 5035 | mutex_unlock(&priv->mutex); |
| 5036 | goto out_release_irq; |
| 5037 | } |
| 5038 | } |
| 5039 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5040 | ret = __iwl4965_up(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5041 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5042 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5043 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5044 | if (ret) |
| 5045 | goto out_release_irq; |
| 5046 | |
| 5047 | IWL_DEBUG_INFO("Start UP work done.\n"); |
| 5048 | |
| 5049 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 5050 | return 0; |
| 5051 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5052 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 5053 | * mac80211 will not be run successfully. */ |
| 5054 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 5055 | test_bit(STATUS_READY, &priv->status), |
| 5056 | UCODE_READY_TIMEOUT); |
| 5057 | if (!ret) { |
| 5058 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 5059 | IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n", |
| 5060 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 5061 | ret = -ETIMEDOUT; |
| 5062 | goto out_release_irq; |
| 5063 | } |
| 5064 | } |
| 5065 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5066 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5067 | IWL_DEBUG_MAC80211("leave\n"); |
| 5068 | return 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5069 | |
| 5070 | out_release_irq: |
| 5071 | free_irq(priv->pci_dev->irq, priv); |
| 5072 | out_disable_msi: |
| 5073 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5074 | pci_disable_device(priv->pci_dev); |
| 5075 | priv->is_open = 0; |
| 5076 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5077 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5078 | } |
| 5079 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5080 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5081 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5082 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5083 | |
| 5084 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5085 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5086 | if (!priv->is_open) { |
| 5087 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 5088 | return; |
| 5089 | } |
| 5090 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5091 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5092 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5093 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5094 | /* stop mac, cancel any scan request and clear |
| 5095 | * RXON_FILTER_ASSOC_MSK BIT |
| 5096 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5097 | mutex_lock(&priv->mutex); |
| 5098 | iwl4965_scan_cancel_timeout(priv, 100); |
| 5099 | cancel_delayed_work(&priv->post_associate); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5100 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5101 | } |
| 5102 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5103 | iwl4965_down(priv); |
| 5104 | |
| 5105 | flush_workqueue(priv->workqueue); |
| 5106 | free_irq(priv->pci_dev->irq, priv); |
| 5107 | pci_disable_msi(priv->pci_dev); |
| 5108 | pci_save_state(priv->pci_dev); |
| 5109 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5110 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5111 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5112 | } |
| 5113 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5114 | static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5115 | struct ieee80211_tx_control *ctl) |
| 5116 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5117 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5118 | |
| 5119 | IWL_DEBUG_MAC80211("enter\n"); |
| 5120 | |
| 5121 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 5122 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 5123 | return -1; |
| 5124 | } |
| 5125 | |
| 5126 | 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] | 5127 | ctl->tx_rate->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5128 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5129 | if (iwl4965_tx_skb(priv, skb, ctl)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5130 | dev_kfree_skb_any(skb); |
| 5131 | |
| 5132 | IWL_DEBUG_MAC80211("leave\n"); |
| 5133 | return 0; |
| 5134 | } |
| 5135 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5136 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5137 | struct ieee80211_if_init_conf *conf) |
| 5138 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5139 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5140 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5141 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5142 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5143 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5144 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5145 | if (priv->vif) { |
| 5146 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Reinette Chatre | 75849d2 | 2008-01-23 10:15:17 -0800 | [diff] [blame] | 5147 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5148 | } |
| 5149 | |
| 5150 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5151 | priv->vif = conf->vif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5152 | |
| 5153 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5154 | |
| 5155 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 5156 | |
| 5157 | if (conf->mac_addr) { |
| 5158 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 5159 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 5160 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5161 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5162 | if (iwl_is_ready(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5163 | iwl4965_set_mode(priv, conf->type); |
| 5164 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5165 | mutex_unlock(&priv->mutex); |
| 5166 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5167 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5168 | return 0; |
| 5169 | } |
| 5170 | |
| 5171 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5172 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5173 | * |
| 5174 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 5175 | * be set inappropriately and the driver currently sets the hardware up to |
| 5176 | * use it whenever needed. |
| 5177 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5178 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5179 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5180 | struct iwl_priv *priv = hw->priv; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5181 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5182 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5183 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5184 | |
| 5185 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5186 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5187 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 5188 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
| 5189 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5190 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5191 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5192 | ret = -EIO; |
| 5193 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5194 | } |
| 5195 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 5196 | if (unlikely(!priv->cfg->mod_params->disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5197 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 5198 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 5199 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5200 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 5201 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | spin_lock_irqsave(&priv->lock, flags); |
| 5205 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 5206 | ch_info = iwl_get_channel_info(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5207 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5208 | if (!is_channel_valid(ch_info)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5209 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 5210 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5211 | ret = -EINVAL; |
| 5212 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5213 | } |
| 5214 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5215 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5216 | /* if we are switching from ht to 2.4 clear flags |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5217 | * from any ht related info since 2.4 does not |
| 5218 | * support ht */ |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5219 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5220 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 5221 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 5222 | #endif |
| 5223 | ) |
| 5224 | priv->staging_rxon.flags = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5225 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5226 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5227 | iwl_set_rxon_channel(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5228 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5229 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5230 | iwl4965_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5231 | |
| 5232 | /* The list of supported rates and rate mask can be different |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5233 | * for each band; since the band may have changed, reset |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5234 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5235 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5236 | |
| 5237 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5238 | |
| 5239 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 5240 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5241 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5242 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5243 | } |
| 5244 | #endif |
| 5245 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 5246 | if (priv->cfg->ops->lib->radio_kill_sw) |
| 5247 | priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5248 | |
| 5249 | if (!conf->radio_enabled) { |
| 5250 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5251 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5252 | } |
| 5253 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5254 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5255 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5256 | ret = -EIO; |
| 5257 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5258 | } |
| 5259 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5260 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5261 | |
| 5262 | if (memcmp(&priv->active_rxon, |
| 5263 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5264 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5265 | else |
| 5266 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 5267 | |
| 5268 | IWL_DEBUG_MAC80211("leave\n"); |
| 5269 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 5270 | out: |
| 5271 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5272 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5273 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5274 | } |
| 5275 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5276 | static void iwl4965_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5277 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5278 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5279 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 5280 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5281 | return; |
| 5282 | |
| 5283 | /* The following should be done only at AP bring up */ |
| 5284 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 5285 | |
| 5286 | /* RXON - unassoc (to set timing command) */ |
| 5287 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5288 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5289 | |
| 5290 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5291 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 5292 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5293 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5294 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5295 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5296 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 5297 | "Attempting to continue.\n"); |
| 5298 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5299 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5300 | |
| 5301 | /* FIXME: what should be the assoc_id for AP? */ |
| 5302 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 5303 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 5304 | priv->staging_rxon.flags |= |
| 5305 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5306 | else |
| 5307 | priv->staging_rxon.flags &= |
| 5308 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5309 | |
| 5310 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 5311 | if (priv->assoc_capability & |
| 5312 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 5313 | priv->staging_rxon.flags |= |
| 5314 | RXON_FLG_SHORT_SLOT_MSK; |
| 5315 | else |
| 5316 | priv->staging_rxon.flags &= |
| 5317 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 5318 | |
| 5319 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 5320 | priv->staging_rxon.flags &= |
| 5321 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 5322 | } |
| 5323 | /* restore RXON assoc */ |
| 5324 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5325 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5326 | iwl4965_activate_qos(priv, 1); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5327 | iwl4965_rxon_add_station(priv, iwl4965_broadcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 5328 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5329 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5330 | |
| 5331 | /* FIXME - we need to add code here to detect a totally new |
| 5332 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 5333 | * clear sta table, add BCAST sta... */ |
| 5334 | } |
| 5335 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5336 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, |
| 5337 | struct ieee80211_vif *vif, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5338 | struct ieee80211_if_conf *conf) |
| 5339 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5340 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5341 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5342 | unsigned long flags; |
| 5343 | int rc; |
| 5344 | |
| 5345 | if (conf == NULL) |
| 5346 | return -EIO; |
| 5347 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 5348 | if (priv->vif != vif) { |
| 5349 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 5350 | return 0; |
| 5351 | } |
| 5352 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5353 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 5354 | (!conf->beacon || !conf->ssid_len)) { |
| 5355 | IWL_DEBUG_MAC80211 |
| 5356 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 5357 | return 0; |
| 5358 | } |
| 5359 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5360 | if (!iwl_is_alive(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5361 | return -EAGAIN; |
| 5362 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5363 | mutex_lock(&priv->mutex); |
| 5364 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5365 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5366 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 5367 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5368 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 5369 | /* |
| 5370 | * very dubious code was here; the probe filtering flag is never set: |
| 5371 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5372 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 5373 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 5374 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5375 | |
| 5376 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 5377 | if (!conf->bssid) { |
| 5378 | conf->bssid = priv->mac_addr; |
| 5379 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5380 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 5381 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5382 | } |
| 5383 | if (priv->ibss_beacon) |
| 5384 | dev_kfree_skb(priv->ibss_beacon); |
| 5385 | |
| 5386 | priv->ibss_beacon = conf->beacon; |
| 5387 | } |
| 5388 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5389 | if (iwl_is_rfkill(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5390 | goto done; |
| 5391 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5392 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 5393 | !is_multicast_ether_addr(conf->bssid)) { |
| 5394 | /* If there is currently a HW scan going on in the background |
| 5395 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5396 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5397 | IWL_WARNING("Aborted scan still in progress " |
| 5398 | "after 100ms\n"); |
| 5399 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 5400 | mutex_unlock(&priv->mutex); |
| 5401 | return -EAGAIN; |
| 5402 | } |
| 5403 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 5404 | |
| 5405 | /* TODO: Audit driver for usage of these members and see |
| 5406 | * if mac80211 deprecates them (priv->bssid looks like it |
| 5407 | * shouldn't be there, but I haven't scanned the IBSS code |
| 5408 | * to verify) - jpk */ |
| 5409 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 5410 | |
| 5411 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5412 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5413 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5414 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5415 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5416 | iwl4965_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5417 | priv, priv->active_rxon.bssid_addr, 1); |
| 5418 | } |
| 5419 | |
| 5420 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5421 | iwl4965_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5422 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5423 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5424 | } |
| 5425 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5426 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5427 | spin_lock_irqsave(&priv->lock, flags); |
| 5428 | if (!conf->ssid_len) |
| 5429 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 5430 | else |
| 5431 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 5432 | |
| 5433 | priv->essid_len = conf->ssid_len; |
| 5434 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5435 | |
| 5436 | IWL_DEBUG_MAC80211("leave\n"); |
| 5437 | mutex_unlock(&priv->mutex); |
| 5438 | |
| 5439 | return 0; |
| 5440 | } |
| 5441 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5442 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 5443 | unsigned int changed_flags, |
| 5444 | unsigned int *total_flags, |
| 5445 | int mc_count, struct dev_addr_list *mc_list) |
| 5446 | { |
| 5447 | /* |
| 5448 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5449 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 5450 | */ |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 5451 | struct iwl_priv *priv = hw->priv; |
| 5452 | int new_flags = 0; |
| 5453 | if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { |
| 5454 | if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { |
| 5455 | IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n", |
| 5456 | IEEE80211_IF_TYPE_MNTR, |
| 5457 | changed_flags, *total_flags); |
| 5458 | /* queue work 'cuz mac80211 is holding a lock which |
| 5459 | * prevents us from issuing (synchronous) f/w cmds */ |
| 5460 | queue_work(priv->workqueue, &priv->set_monitor); |
| 5461 | new_flags &= FIF_PROMISC_IN_BSS | |
| 5462 | FIF_OTHER_BSS | |
| 5463 | FIF_ALLMULTI; |
| 5464 | } |
| 5465 | } |
| 5466 | *total_flags = new_flags; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 5467 | } |
| 5468 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5469 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5470 | struct ieee80211_if_init_conf *conf) |
| 5471 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5472 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5473 | |
| 5474 | IWL_DEBUG_MAC80211("enter\n"); |
| 5475 | |
| 5476 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5477 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5478 | if (iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5479 | iwl4965_scan_cancel_timeout(priv, 100); |
| 5480 | cancel_delayed_work(&priv->post_associate); |
| 5481 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 5482 | iwl4965_commit_rxon(priv); |
| 5483 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5484 | if (priv->vif == conf->vif) { |
| 5485 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5486 | memset(priv->bssid, 0, ETH_ALEN); |
| 5487 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 5488 | priv->essid_len = 0; |
| 5489 | } |
| 5490 | mutex_unlock(&priv->mutex); |
| 5491 | |
| 5492 | IWL_DEBUG_MAC80211("leave\n"); |
| 5493 | |
| 5494 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5495 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5496 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5497 | static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, |
| 5498 | struct ieee80211_vif *vif, |
| 5499 | struct ieee80211_bss_conf *bss_conf, |
| 5500 | u32 changes) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5501 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5502 | struct iwl_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5503 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5504 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
| 5505 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5506 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5507 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
| 5508 | bss_conf->use_short_preamble); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5509 | if (bss_conf->use_short_preamble) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5510 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5511 | else |
| 5512 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5513 | } |
| 5514 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5515 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5516 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5517 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5518 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 5519 | else |
| 5520 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 5521 | } |
| 5522 | |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 5523 | if (changes & BSS_CHANGED_HT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5524 | IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 5525 | iwl4965_ht_conf(priv, bss_conf); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5526 | iwl_set_rxon_chain(priv); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 5527 | } |
| 5528 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5529 | if (changes & BSS_CHANGED_ASSOC) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5530 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5531 | /* This should never happen as this function should |
| 5532 | * never be called from interrupt context. */ |
| 5533 | if (WARN_ON_ONCE(in_interrupt())) |
| 5534 | return; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5535 | if (bss_conf->assoc) { |
| 5536 | priv->assoc_id = bss_conf->aid; |
| 5537 | priv->beacon_int = bss_conf->beacon_int; |
| 5538 | priv->timestamp = bss_conf->timestamp; |
| 5539 | priv->assoc_capability = bss_conf->assoc_capability; |
| 5540 | priv->next_scan_jiffies = jiffies + |
| 5541 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5542 | mutex_lock(&priv->mutex); |
| 5543 | iwl4965_post_associate(priv); |
| 5544 | mutex_unlock(&priv->mutex); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5545 | } else { |
| 5546 | priv->assoc_id = 0; |
| 5547 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); |
| 5548 | } |
| 5549 | } else if (changes && iwl_is_associated(priv) && priv->assoc_id) { |
| 5550 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 5551 | iwl_send_rxon_assoc(priv); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5552 | } |
| 5553 | |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5554 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5555 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5556 | static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5557 | { |
| 5558 | int rc = 0; |
| 5559 | unsigned long flags; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5560 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5561 | |
| 5562 | IWL_DEBUG_MAC80211("enter\n"); |
| 5563 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5564 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5565 | spin_lock_irqsave(&priv->lock, flags); |
| 5566 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5567 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5568 | rc = -EIO; |
| 5569 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 5570 | goto out_unlock; |
| 5571 | } |
| 5572 | |
| 5573 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 5574 | rc = -EIO; |
| 5575 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 5576 | goto out_unlock; |
| 5577 | } |
| 5578 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5579 | /* we don't schedule scan within next_scan_jiffies period */ |
| 5580 | if (priv->next_scan_jiffies && |
| 5581 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 5582 | rc = -EAGAIN; |
| 5583 | goto out_unlock; |
| 5584 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5585 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5586 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 5587 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5588 | rc = -EAGAIN; |
| 5589 | goto out_unlock; |
| 5590 | } |
| 5591 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5592 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5593 | iwl4965_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5594 | |
| 5595 | priv->one_direct_scan = 1; |
| 5596 | priv->direct_ssid_len = (u8) |
| 5597 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 5598 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5599 | } else |
| 5600 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5601 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5602 | rc = iwl4965_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5603 | |
| 5604 | IWL_DEBUG_MAC80211("leave\n"); |
| 5605 | |
| 5606 | out_unlock: |
| 5607 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5608 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5609 | |
| 5610 | return rc; |
| 5611 | } |
| 5612 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5613 | static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 5614 | struct ieee80211_key_conf *keyconf, const u8 *addr, |
| 5615 | u32 iv32, u16 *phase1key) |
| 5616 | { |
| 5617 | struct iwl_priv *priv = hw->priv; |
| 5618 | u8 sta_id = IWL_INVALID_STATION; |
| 5619 | unsigned long flags; |
| 5620 | __le16 key_flags = 0; |
| 5621 | int i; |
| 5622 | DECLARE_MAC_BUF(mac); |
| 5623 | |
| 5624 | IWL_DEBUG_MAC80211("enter\n"); |
| 5625 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 5626 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5627 | if (sta_id == IWL_INVALID_STATION) { |
| 5628 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 5629 | print_mac(mac, addr)); |
| 5630 | return; |
| 5631 | } |
| 5632 | |
| 5633 | iwl4965_scan_cancel_timeout(priv, 100); |
| 5634 | |
| 5635 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); |
| 5636 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 5637 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 5638 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 5639 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5640 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 5641 | |
| 5642 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 5643 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5644 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 5645 | priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; |
| 5646 | |
| 5647 | for (i = 0; i < 5; i++) |
| 5648 | priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = |
| 5649 | cpu_to_le16(phase1key[i]); |
| 5650 | |
| 5651 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 5652 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 5653 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 5654 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5655 | |
| 5656 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 5657 | |
| 5658 | IWL_DEBUG_MAC80211("leave\n"); |
| 5659 | } |
| 5660 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5661 | static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5662 | const u8 *local_addr, const u8 *addr, |
| 5663 | struct ieee80211_key_conf *key) |
| 5664 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5665 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5666 | DECLARE_MAC_BUF(mac); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5667 | int ret = 0; |
| 5668 | u8 sta_id = IWL_INVALID_STATION; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5669 | u8 is_default_wep_key = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5670 | |
| 5671 | IWL_DEBUG_MAC80211("enter\n"); |
| 5672 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 5673 | if (priv->hw_params.sw_crypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5674 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 5675 | return -EOPNOTSUPP; |
| 5676 | } |
| 5677 | |
| 5678 | if (is_zero_ether_addr(addr)) |
| 5679 | /* only support pairwise keys */ |
| 5680 | return -EOPNOTSUPP; |
| 5681 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 5682 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5683 | if (sta_id == IWL_INVALID_STATION) { |
| 5684 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 5685 | print_mac(mac, addr)); |
| 5686 | return -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5687 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5688 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5689 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5690 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5691 | iwl4965_scan_cancel_timeout(priv, 100); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5692 | mutex_unlock(&priv->mutex); |
| 5693 | |
| 5694 | /* If we are getting WEP group key and we didn't receive any key mapping |
| 5695 | * so far, we are in legacy wep mode (group key only), otherwise we are |
| 5696 | * in 1X mode. |
| 5697 | * In legacy wep mode, we use another host command to the uCode */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 5698 | if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id && |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5699 | priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 5700 | if (cmd == SET_KEY) |
| 5701 | is_default_wep_key = !priv->key_mapping_key; |
| 5702 | else |
| 5703 | is_default_wep_key = priv->default_wep_key; |
| 5704 | } |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5705 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5706 | switch (cmd) { |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5707 | case SET_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5708 | if (is_default_wep_key) |
| 5709 | ret = iwl_set_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5710 | else |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 5711 | ret = iwl_set_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5712 | |
| 5713 | IWL_DEBUG_MAC80211("enable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5714 | break; |
| 5715 | case DISABLE_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5716 | if (is_default_wep_key) |
| 5717 | ret = iwl_remove_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5718 | else |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 5719 | ret = iwl_remove_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5720 | |
| 5721 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5722 | break; |
| 5723 | default: |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5724 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5725 | } |
| 5726 | |
| 5727 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5728 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5729 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5730 | } |
| 5731 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 5732 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5733 | const struct ieee80211_tx_queue_params *params) |
| 5734 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5735 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5736 | unsigned long flags; |
| 5737 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5738 | |
| 5739 | IWL_DEBUG_MAC80211("enter\n"); |
| 5740 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5741 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5742 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 5743 | return -EIO; |
| 5744 | } |
| 5745 | |
| 5746 | if (queue >= AC_NUM) { |
| 5747 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 5748 | return 0; |
| 5749 | } |
| 5750 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5751 | if (!priv->qos_data.qos_enable) { |
| 5752 | priv->qos_data.qos_active = 0; |
| 5753 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 5754 | return 0; |
| 5755 | } |
| 5756 | q = AC_NUM - 1 - queue; |
| 5757 | |
| 5758 | spin_lock_irqsave(&priv->lock, flags); |
| 5759 | |
| 5760 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 5761 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 5762 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 5763 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 5764 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5765 | |
| 5766 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 5767 | priv->qos_data.qos_active = 1; |
| 5768 | |
| 5769 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5770 | |
| 5771 | mutex_lock(&priv->mutex); |
| 5772 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5773 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5774 | else if (priv->assoc_id && iwl_is_associated(priv)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5775 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5776 | |
| 5777 | mutex_unlock(&priv->mutex); |
| 5778 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5779 | IWL_DEBUG_MAC80211("leave\n"); |
| 5780 | return 0; |
| 5781 | } |
| 5782 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5783 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5784 | struct ieee80211_tx_queue_stats *stats) |
| 5785 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5786 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5787 | int i, avail; |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 5788 | struct iwl_tx_queue *txq; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 5789 | struct iwl_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5790 | unsigned long flags; |
| 5791 | |
| 5792 | IWL_DEBUG_MAC80211("enter\n"); |
| 5793 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5794 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5795 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 5796 | return -EIO; |
| 5797 | } |
| 5798 | |
| 5799 | spin_lock_irqsave(&priv->lock, flags); |
| 5800 | |
| 5801 | for (i = 0; i < AC_NUM; i++) { |
| 5802 | txq = &priv->txq[i]; |
| 5803 | q = &txq->q; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 5804 | avail = iwl_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5805 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 5806 | stats[i].len = q->n_window - avail; |
| 5807 | stats[i].limit = q->n_window - q->high_mark; |
| 5808 | stats[i].count = q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5809 | |
| 5810 | } |
| 5811 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5812 | |
| 5813 | IWL_DEBUG_MAC80211("leave\n"); |
| 5814 | |
| 5815 | return 0; |
| 5816 | } |
| 5817 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5818 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5819 | struct ieee80211_low_level_stats *stats) |
| 5820 | { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 5821 | struct iwl_priv *priv = hw->priv; |
| 5822 | |
| 5823 | priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5824 | IWL_DEBUG_MAC80211("enter\n"); |
| 5825 | IWL_DEBUG_MAC80211("leave\n"); |
| 5826 | |
| 5827 | return 0; |
| 5828 | } |
| 5829 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5830 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5831 | { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 5832 | struct iwl_priv *priv; |
| 5833 | |
| 5834 | priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5835 | IWL_DEBUG_MAC80211("enter\n"); |
| 5836 | IWL_DEBUG_MAC80211("leave\n"); |
| 5837 | |
| 5838 | return 0; |
| 5839 | } |
| 5840 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5841 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5842 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5843 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5844 | unsigned long flags; |
| 5845 | |
| 5846 | mutex_lock(&priv->mutex); |
| 5847 | IWL_DEBUG_MAC80211("enter\n"); |
| 5848 | |
| 5849 | priv->lq_mngr.lq_ready = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5850 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5851 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 5852 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5853 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5854 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5855 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5856 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5857 | |
| 5858 | cancel_delayed_work(&priv->post_associate); |
| 5859 | |
| 5860 | spin_lock_irqsave(&priv->lock, flags); |
| 5861 | priv->assoc_id = 0; |
| 5862 | priv->assoc_capability = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5863 | priv->assoc_station_added = 0; |
| 5864 | |
| 5865 | /* new association get rid of ibss beacon skb */ |
| 5866 | if (priv->ibss_beacon) |
| 5867 | dev_kfree_skb(priv->ibss_beacon); |
| 5868 | |
| 5869 | priv->ibss_beacon = NULL; |
| 5870 | |
| 5871 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5872 | priv->timestamp = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5873 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 5874 | priv->beacon_int = 0; |
| 5875 | |
| 5876 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5877 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5878 | if (!iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5879 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 5880 | mutex_unlock(&priv->mutex); |
| 5881 | return; |
| 5882 | } |
| 5883 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5884 | /* we are restarting association process |
| 5885 | * clear RXON_FILTER_ASSOC_MSK bit |
| 5886 | */ |
| 5887 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5888 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5889 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5890 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5891 | } |
| 5892 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 5893 | iwl_power_update_mode(priv, 0); |
| 5894 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5895 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 5896 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5897 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5898 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 5899 | mutex_unlock(&priv->mutex); |
| 5900 | return; |
| 5901 | } |
| 5902 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5903 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5904 | |
| 5905 | mutex_unlock(&priv->mutex); |
| 5906 | |
| 5907 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5908 | } |
| 5909 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5910 | static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5911 | struct ieee80211_tx_control *control) |
| 5912 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5913 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5914 | unsigned long flags; |
| 5915 | |
| 5916 | mutex_lock(&priv->mutex); |
| 5917 | IWL_DEBUG_MAC80211("enter\n"); |
| 5918 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5919 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5920 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 5921 | mutex_unlock(&priv->mutex); |
| 5922 | return -EIO; |
| 5923 | } |
| 5924 | |
| 5925 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 5926 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 5927 | mutex_unlock(&priv->mutex); |
| 5928 | return -EIO; |
| 5929 | } |
| 5930 | |
| 5931 | spin_lock_irqsave(&priv->lock, flags); |
| 5932 | |
| 5933 | if (priv->ibss_beacon) |
| 5934 | dev_kfree_skb(priv->ibss_beacon); |
| 5935 | |
| 5936 | priv->ibss_beacon = skb; |
| 5937 | |
| 5938 | priv->assoc_id = 0; |
| 5939 | |
| 5940 | IWL_DEBUG_MAC80211("leave\n"); |
| 5941 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5942 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5943 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5944 | |
| 5945 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 5946 | |
| 5947 | mutex_unlock(&priv->mutex); |
| 5948 | |
| 5949 | return 0; |
| 5950 | } |
| 5951 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5952 | /***************************************************************************** |
| 5953 | * |
| 5954 | * sysfs attributes |
| 5955 | * |
| 5956 | *****************************************************************************/ |
| 5957 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 5958 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5959 | |
| 5960 | /* |
| 5961 | * The following adds a new attribute to the sysfs representation |
| 5962 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 5963 | * used for controlling the debug level. |
| 5964 | * |
| 5965 | * See the level definitions in iwl for details. |
| 5966 | */ |
| 5967 | |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5968 | static ssize_t show_debug_level(struct device *d, |
| 5969 | struct device_attribute *attr, char *buf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5970 | { |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5971 | struct iwl_priv *priv = d->driver_data; |
| 5972 | |
| 5973 | return sprintf(buf, "0x%08X\n", priv->debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5974 | } |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5975 | static ssize_t store_debug_level(struct device *d, |
| 5976 | struct device_attribute *attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5977 | const char *buf, size_t count) |
| 5978 | { |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5979 | struct iwl_priv *priv = d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5980 | char *p = (char *)buf; |
| 5981 | u32 val; |
| 5982 | |
| 5983 | val = simple_strtoul(p, &p, 0); |
| 5984 | if (p == buf) |
| 5985 | printk(KERN_INFO DRV_NAME |
| 5986 | ": %s is not in hex or decimal form.\n", buf); |
| 5987 | else |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5988 | priv->debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5989 | |
| 5990 | return strnlen(buf, count); |
| 5991 | } |
| 5992 | |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5993 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 5994 | show_debug_level, store_debug_level); |
| 5995 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5996 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 5997 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5998 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5999 | |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 6000 | static ssize_t show_version(struct device *d, |
| 6001 | struct device_attribute *attr, char *buf) |
| 6002 | { |
| 6003 | struct iwl_priv *priv = d->driver_data; |
| 6004 | struct iwl4965_alive_resp *palive = &priv->card_alive; |
| 6005 | |
| 6006 | if (palive->is_valid) |
| 6007 | return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n" |
| 6008 | "fw type: 0x%01X 0x%01X\n", |
| 6009 | palive->ucode_major, palive->ucode_minor, |
| 6010 | palive->sw_rev[0], palive->sw_rev[1], |
| 6011 | palive->ver_type, palive->ver_subtype); |
| 6012 | |
| 6013 | else |
| 6014 | return sprintf(buf, "fw not loaded\n"); |
| 6015 | } |
| 6016 | |
| 6017 | static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL); |
| 6018 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6019 | static ssize_t show_temperature(struct device *d, |
| 6020 | struct device_attribute *attr, char *buf) |
| 6021 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6022 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6023 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6024 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6025 | return -EAGAIN; |
| 6026 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6027 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6028 | } |
| 6029 | |
| 6030 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 6031 | |
| 6032 | static ssize_t show_rs_window(struct device *d, |
| 6033 | struct device_attribute *attr, |
| 6034 | char *buf) |
| 6035 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6036 | struct iwl_priv *priv = d->driver_data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6037 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6038 | } |
| 6039 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 6040 | |
| 6041 | static ssize_t show_tx_power(struct device *d, |
| 6042 | struct device_attribute *attr, char *buf) |
| 6043 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6044 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6045 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 6046 | } |
| 6047 | |
| 6048 | static ssize_t store_tx_power(struct device *d, |
| 6049 | struct device_attribute *attr, |
| 6050 | const char *buf, size_t count) |
| 6051 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6052 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6053 | char *p = (char *)buf; |
| 6054 | u32 val; |
| 6055 | |
| 6056 | val = simple_strtoul(p, &p, 10); |
| 6057 | if (p == buf) |
| 6058 | printk(KERN_INFO DRV_NAME |
| 6059 | ": %s is not in decimal form.\n", buf); |
| 6060 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6061 | iwl4965_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6062 | |
| 6063 | return count; |
| 6064 | } |
| 6065 | |
| 6066 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 6067 | |
| 6068 | static ssize_t show_flags(struct device *d, |
| 6069 | struct device_attribute *attr, char *buf) |
| 6070 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6071 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6072 | |
| 6073 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 6074 | } |
| 6075 | |
| 6076 | static ssize_t store_flags(struct device *d, |
| 6077 | struct device_attribute *attr, |
| 6078 | const char *buf, size_t count) |
| 6079 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6080 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6081 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 6082 | |
| 6083 | mutex_lock(&priv->mutex); |
| 6084 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 6085 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6086 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6087 | IWL_WARNING("Could not cancel scan.\n"); |
| 6088 | else { |
| 6089 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 6090 | flags); |
| 6091 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6092 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6093 | } |
| 6094 | } |
| 6095 | mutex_unlock(&priv->mutex); |
| 6096 | |
| 6097 | return count; |
| 6098 | } |
| 6099 | |
| 6100 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 6101 | |
| 6102 | static ssize_t show_filter_flags(struct device *d, |
| 6103 | struct device_attribute *attr, char *buf) |
| 6104 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6105 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6106 | |
| 6107 | return sprintf(buf, "0x%04X\n", |
| 6108 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 6109 | } |
| 6110 | |
| 6111 | static ssize_t store_filter_flags(struct device *d, |
| 6112 | struct device_attribute *attr, |
| 6113 | const char *buf, size_t count) |
| 6114 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6115 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6116 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 6117 | |
| 6118 | mutex_lock(&priv->mutex); |
| 6119 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 6120 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6121 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6122 | IWL_WARNING("Could not cancel scan.\n"); |
| 6123 | else { |
| 6124 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 6125 | "0x%04X\n", filter_flags); |
| 6126 | priv->staging_rxon.filter_flags = |
| 6127 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6128 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6129 | } |
| 6130 | } |
| 6131 | mutex_unlock(&priv->mutex); |
| 6132 | |
| 6133 | return count; |
| 6134 | } |
| 6135 | |
| 6136 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 6137 | store_filter_flags); |
| 6138 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6139 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6140 | |
| 6141 | static ssize_t show_measurement(struct device *d, |
| 6142 | struct device_attribute *attr, char *buf) |
| 6143 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6144 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6145 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6146 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 6147 | u8 *data = (u8 *) & measure_report; |
| 6148 | unsigned long flags; |
| 6149 | |
| 6150 | spin_lock_irqsave(&priv->lock, flags); |
| 6151 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 6152 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6153 | return 0; |
| 6154 | } |
| 6155 | memcpy(&measure_report, &priv->measure_report, size); |
| 6156 | priv->measurement_status = 0; |
| 6157 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6158 | |
| 6159 | while (size && (PAGE_SIZE - len)) { |
| 6160 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 6161 | PAGE_SIZE - len, 1); |
| 6162 | len = strlen(buf); |
| 6163 | if (PAGE_SIZE - len) |
| 6164 | buf[len++] = '\n'; |
| 6165 | |
| 6166 | ofs += 16; |
| 6167 | size -= min(size, 16U); |
| 6168 | } |
| 6169 | |
| 6170 | return len; |
| 6171 | } |
| 6172 | |
| 6173 | static ssize_t store_measurement(struct device *d, |
| 6174 | struct device_attribute *attr, |
| 6175 | const char *buf, size_t count) |
| 6176 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6177 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6178 | struct ieee80211_measurement_params params = { |
| 6179 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 6180 | .start_time = cpu_to_le64(priv->last_tsf), |
| 6181 | .duration = cpu_to_le16(1), |
| 6182 | }; |
| 6183 | u8 type = IWL_MEASURE_BASIC; |
| 6184 | u8 buffer[32]; |
| 6185 | u8 channel; |
| 6186 | |
| 6187 | if (count) { |
| 6188 | char *p = buffer; |
| 6189 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 6190 | channel = simple_strtoul(p, NULL, 0); |
| 6191 | if (channel) |
| 6192 | params.channel = channel; |
| 6193 | |
| 6194 | p = buffer; |
| 6195 | while (*p && *p != ' ') |
| 6196 | p++; |
| 6197 | if (*p) |
| 6198 | type = simple_strtoul(p + 1, NULL, 0); |
| 6199 | } |
| 6200 | |
| 6201 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 6202 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6203 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6204 | |
| 6205 | return count; |
| 6206 | } |
| 6207 | |
| 6208 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 6209 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6210 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6211 | |
| 6212 | static ssize_t store_retry_rate(struct device *d, |
| 6213 | struct device_attribute *attr, |
| 6214 | const char *buf, size_t count) |
| 6215 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6216 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6217 | |
| 6218 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 6219 | if (priv->retry_rate <= 0) |
| 6220 | priv->retry_rate = 1; |
| 6221 | |
| 6222 | return count; |
| 6223 | } |
| 6224 | |
| 6225 | static ssize_t show_retry_rate(struct device *d, |
| 6226 | struct device_attribute *attr, char *buf) |
| 6227 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6228 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6229 | return sprintf(buf, "%d", priv->retry_rate); |
| 6230 | } |
| 6231 | |
| 6232 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 6233 | store_retry_rate); |
| 6234 | |
| 6235 | static ssize_t store_power_level(struct device *d, |
| 6236 | struct device_attribute *attr, |
| 6237 | const char *buf, size_t count) |
| 6238 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6239 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6240 | int rc; |
| 6241 | int mode; |
| 6242 | |
| 6243 | mode = simple_strtoul(buf, NULL, 0); |
| 6244 | mutex_lock(&priv->mutex); |
| 6245 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6246 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6247 | rc = -EAGAIN; |
| 6248 | goto out; |
| 6249 | } |
| 6250 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 6251 | rc = iwl_power_set_user_mode(priv, mode); |
| 6252 | if (rc) { |
| 6253 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 6254 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6255 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6256 | rc = count; |
| 6257 | |
| 6258 | out: |
| 6259 | mutex_unlock(&priv->mutex); |
| 6260 | return rc; |
| 6261 | } |
| 6262 | |
| 6263 | #define MAX_WX_STRING 80 |
| 6264 | |
| 6265 | /* Values are in microsecond */ |
| 6266 | static const s32 timeout_duration[] = { |
| 6267 | 350000, |
| 6268 | 250000, |
| 6269 | 75000, |
| 6270 | 37000, |
| 6271 | 25000, |
| 6272 | }; |
| 6273 | static const s32 period_duration[] = { |
| 6274 | 400000, |
| 6275 | 700000, |
| 6276 | 1000000, |
| 6277 | 1000000, |
| 6278 | 1000000 |
| 6279 | }; |
| 6280 | |
| 6281 | static ssize_t show_power_level(struct device *d, |
| 6282 | struct device_attribute *attr, char *buf) |
| 6283 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6284 | struct iwl_priv *priv = dev_get_drvdata(d); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 6285 | int level = priv->power_data.power_mode; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6286 | char *p = buf; |
| 6287 | |
| 6288 | p += sprintf(p, "%d ", level); |
| 6289 | switch (level) { |
| 6290 | case IWL_POWER_MODE_CAM: |
| 6291 | case IWL_POWER_AC: |
| 6292 | p += sprintf(p, "(AC)"); |
| 6293 | break; |
| 6294 | case IWL_POWER_BATTERY: |
| 6295 | p += sprintf(p, "(BATTERY)"); |
| 6296 | break; |
| 6297 | default: |
| 6298 | p += sprintf(p, |
| 6299 | "(Timeout %dms, Period %dms)", |
| 6300 | timeout_duration[level - 1] / 1000, |
| 6301 | period_duration[level - 1] / 1000); |
| 6302 | } |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 6303 | /* |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6304 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 6305 | p += sprintf(p, " OFF\n"); |
| 6306 | else |
| 6307 | p += sprintf(p, " \n"); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 6308 | */ |
| 6309 | p += sprintf(p, " \n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6310 | return (p - buf + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6311 | } |
| 6312 | |
| 6313 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 6314 | store_power_level); |
| 6315 | |
| 6316 | static ssize_t show_channels(struct device *d, |
| 6317 | struct device_attribute *attr, char *buf) |
| 6318 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6319 | /* all this shit doesn't belong into sysfs anyway */ |
| 6320 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6321 | } |
| 6322 | |
| 6323 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 6324 | |
| 6325 | static ssize_t show_statistics(struct device *d, |
| 6326 | struct device_attribute *attr, char *buf) |
| 6327 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6328 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6329 | u32 size = sizeof(struct iwl4965_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6330 | u32 len = 0, ofs = 0; |
| 6331 | u8 *data = (u8 *) & priv->statistics; |
| 6332 | int rc = 0; |
| 6333 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6334 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6335 | return -EAGAIN; |
| 6336 | |
| 6337 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 6338 | rc = iwl_send_statistics_request(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6339 | mutex_unlock(&priv->mutex); |
| 6340 | |
| 6341 | if (rc) { |
| 6342 | len = sprintf(buf, |
| 6343 | "Error sending statistics request: 0x%08X\n", rc); |
| 6344 | return len; |
| 6345 | } |
| 6346 | |
| 6347 | while (size && (PAGE_SIZE - len)) { |
| 6348 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 6349 | PAGE_SIZE - len, 1); |
| 6350 | len = strlen(buf); |
| 6351 | if (PAGE_SIZE - len) |
| 6352 | buf[len++] = '\n'; |
| 6353 | |
| 6354 | ofs += 16; |
| 6355 | size -= min(size, 16U); |
| 6356 | } |
| 6357 | |
| 6358 | return len; |
| 6359 | } |
| 6360 | |
| 6361 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 6362 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6363 | static ssize_t show_status(struct device *d, |
| 6364 | struct device_attribute *attr, char *buf) |
| 6365 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6366 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6367 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6368 | return -EAGAIN; |
| 6369 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 6370 | } |
| 6371 | |
| 6372 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 6373 | |
| 6374 | static ssize_t dump_error_log(struct device *d, |
| 6375 | struct device_attribute *attr, |
| 6376 | const char *buf, size_t count) |
| 6377 | { |
| 6378 | char *p = (char *)buf; |
| 6379 | |
| 6380 | if (p[0] == '1') |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6381 | iwl4965_dump_nic_error_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6382 | |
| 6383 | return strnlen(buf, count); |
| 6384 | } |
| 6385 | |
| 6386 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 6387 | |
| 6388 | static ssize_t dump_event_log(struct device *d, |
| 6389 | struct device_attribute *attr, |
| 6390 | const char *buf, size_t count) |
| 6391 | { |
| 6392 | char *p = (char *)buf; |
| 6393 | |
| 6394 | if (p[0] == '1') |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6395 | iwl4965_dump_nic_event_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6396 | |
| 6397 | return strnlen(buf, count); |
| 6398 | } |
| 6399 | |
| 6400 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 6401 | |
| 6402 | /***************************************************************************** |
| 6403 | * |
| 6404 | * driver setup and teardown |
| 6405 | * |
| 6406 | *****************************************************************************/ |
| 6407 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6408 | static void iwl4965_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6409 | { |
| 6410 | priv->workqueue = create_workqueue(DRV_NAME); |
| 6411 | |
| 6412 | init_waitqueue_head(&priv->wait_command_queue); |
| 6413 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6414 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 6415 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 6416 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
| 6417 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); |
| 6418 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); |
| 6419 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); |
| 6420 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 6421 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 6422 | INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6423 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
| 6424 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start); |
| 6425 | INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start); |
| 6426 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6427 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6428 | iwl4965_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6429 | |
| 6430 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6431 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6432 | } |
| 6433 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6434 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6435 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6436 | iwl4965_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6437 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 6438 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6439 | cancel_delayed_work(&priv->scan_check); |
| 6440 | cancel_delayed_work(&priv->alive_start); |
| 6441 | cancel_delayed_work(&priv->post_associate); |
| 6442 | cancel_work_sync(&priv->beacon_update); |
| 6443 | } |
| 6444 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6445 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6446 | &dev_attr_channels.attr, |
| 6447 | &dev_attr_dump_errors.attr, |
| 6448 | &dev_attr_dump_events.attr, |
| 6449 | &dev_attr_flags.attr, |
| 6450 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6451 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6452 | &dev_attr_measurement.attr, |
| 6453 | #endif |
| 6454 | &dev_attr_power_level.attr, |
| 6455 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6456 | &dev_attr_rs_window.attr, |
| 6457 | &dev_attr_statistics.attr, |
| 6458 | &dev_attr_status.attr, |
| 6459 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6460 | &dev_attr_tx_power.attr, |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 6461 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 6462 | &dev_attr_debug_level.attr, |
| 6463 | #endif |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 6464 | &dev_attr_version.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6465 | |
| 6466 | NULL |
| 6467 | }; |
| 6468 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6469 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6470 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6471 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6472 | }; |
| 6473 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6474 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 6475 | .tx = iwl4965_mac_tx, |
| 6476 | .start = iwl4965_mac_start, |
| 6477 | .stop = iwl4965_mac_stop, |
| 6478 | .add_interface = iwl4965_mac_add_interface, |
| 6479 | .remove_interface = iwl4965_mac_remove_interface, |
| 6480 | .config = iwl4965_mac_config, |
| 6481 | .config_interface = iwl4965_mac_config_interface, |
| 6482 | .configure_filter = iwl4965_configure_filter, |
| 6483 | .set_key = iwl4965_mac_set_key, |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 6484 | .update_tkip_key = iwl4965_mac_update_tkip_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6485 | .get_stats = iwl4965_mac_get_stats, |
| 6486 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 6487 | .conf_tx = iwl4965_mac_conf_tx, |
| 6488 | .get_tsf = iwl4965_mac_get_tsf, |
| 6489 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 6490 | .beacon_update = iwl4965_mac_beacon_update, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 6491 | .bss_info_changed = iwl4965_bss_info_changed, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6492 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | 9ab4617 | 2007-12-25 17:00:38 +0200 | [diff] [blame] | 6493 | .ampdu_action = iwl4965_mac_ampdu_action, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6494 | #endif /* CONFIG_IWL4965_HT */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6495 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6496 | }; |
| 6497 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6498 | static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6499 | { |
| 6500 | int err = 0; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6501 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6502 | struct ieee80211_hw *hw; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 6503 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6504 | unsigned long flags; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6505 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6506 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6507 | /************************ |
| 6508 | * 1. Allocating HW data |
| 6509 | ************************/ |
| 6510 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 6511 | /* Disabling hardware scan means that mac80211 will perform scans |
| 6512 | * "the hard way", rather than using device's scan. */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 6513 | if (cfg->mod_params->disable_hw_scan) { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 6514 | if (cfg->mod_params->debug & IWL_DL_INFO) |
| 6515 | dev_printk(KERN_DEBUG, &(pdev->dev), |
| 6516 | "Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6517 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6518 | } |
| 6519 | |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 6520 | hw = iwl_alloc_all(cfg, &iwl4965_hw_ops); |
| 6521 | if (!hw) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6522 | err = -ENOMEM; |
| 6523 | goto out; |
| 6524 | } |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 6525 | priv = hw->priv; |
| 6526 | /* At this point both hw and priv are allocated. */ |
| 6527 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6528 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 6529 | |
| 6530 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 6531 | priv->cfg = cfg; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6532 | priv->pci_dev = pdev; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6533 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 6534 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 6535 | priv->debug_level = priv->cfg->mod_params->debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6536 | atomic_set(&priv->restrict_refcnt, 0); |
| 6537 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6538 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6539 | /************************** |
| 6540 | * 2. Initializing PCI bus |
| 6541 | **************************/ |
| 6542 | if (pci_enable_device(pdev)) { |
| 6543 | err = -ENODEV; |
| 6544 | goto out_ieee80211_free_hw; |
| 6545 | } |
| 6546 | |
| 6547 | pci_set_master(pdev); |
| 6548 | |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 6549 | err = pci_set_dma_mask(pdev, DMA_64BIT_MASK); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6550 | if (!err) |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 6551 | err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); |
| 6552 | if (err) { |
| 6553 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 6554 | if (!err) |
| 6555 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 6556 | /* both attempts failed: */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6557 | if (err) { |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 6558 | printk(KERN_WARNING "%s: No suitable DMA available.\n", |
| 6559 | DRV_NAME); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6560 | goto out_pci_disable_device; |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 6561 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6562 | } |
| 6563 | |
| 6564 | err = pci_request_regions(pdev, DRV_NAME); |
| 6565 | if (err) |
| 6566 | goto out_pci_disable_device; |
| 6567 | |
| 6568 | pci_set_drvdata(pdev, priv); |
| 6569 | |
| 6570 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 6571 | * PCI Tx retries from interfering with C3 CPU state */ |
| 6572 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 6573 | |
| 6574 | /*********************** |
| 6575 | * 3. Read REV register |
| 6576 | ***********************/ |
| 6577 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 6578 | if (!priv->hw_base) { |
| 6579 | err = -ENODEV; |
| 6580 | goto out_pci_release_regions; |
| 6581 | } |
| 6582 | |
| 6583 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 6584 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 6585 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 6586 | |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 6587 | iwl_hw_detect(priv); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6588 | printk(KERN_INFO DRV_NAME |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 6589 | ": Detected Intel Wireless WiFi Link %s REV=0x%X\n", |
| 6590 | priv->cfg->name, priv->hw_rev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6591 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 6592 | /* amp init */ |
| 6593 | err = priv->cfg->ops->lib->apm_ops.init(priv); |
| 6594 | if (err < 0) { |
| 6595 | IWL_DEBUG_INFO("Failed to init APMG\n"); |
| 6596 | goto out_iounmap; |
| 6597 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6598 | /***************** |
| 6599 | * 4. Read EEPROM |
| 6600 | *****************/ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6601 | /* Read the EEPROM */ |
| 6602 | err = iwl_eeprom_init(priv); |
| 6603 | if (err) { |
| 6604 | IWL_ERROR("Unable to init EEPROM\n"); |
| 6605 | goto out_iounmap; |
| 6606 | } |
Tomas Winkler | 8614f36 | 2008-04-23 17:14:55 -0700 | [diff] [blame] | 6607 | err = iwl_eeprom_check_version(priv); |
| 6608 | if (err) |
| 6609 | goto out_iounmap; |
| 6610 | |
Ron Rindjunsky | 0288301 | 2008-05-15 13:53:53 +0800 | [diff] [blame] | 6611 | /* extract MAC Address */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6612 | iwl_eeprom_get_mac(priv, priv->mac_addr); |
| 6613 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); |
| 6614 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 6615 | |
| 6616 | /************************ |
| 6617 | * 5. Setup HW constants |
| 6618 | ************************/ |
| 6619 | /* Device-specific setup */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 6620 | if (priv->cfg->ops->lib->set_hw_params(priv)) { |
| 6621 | IWL_ERROR("failed to set hw parameters\n"); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 6622 | goto out_free_eeprom; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6623 | } |
| 6624 | |
| 6625 | /******************* |
| 6626 | * 6. Setup hw/priv |
| 6627 | *******************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6628 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6629 | err = iwl_setup(priv); |
| 6630 | if (err) |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 6631 | goto out_free_eeprom; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6632 | /* At this point both hw and priv are initialized. */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6633 | |
| 6634 | /********************************** |
| 6635 | * 7. Initialize module parameters |
| 6636 | **********************************/ |
| 6637 | |
| 6638 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 6639 | if (priv->cfg->mod_params->disable) { |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6640 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 6641 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 6642 | } |
| 6643 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 6644 | if (priv->cfg->mod_params->enable_qos) |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6645 | priv->qos_data.qos_enable = 1; |
| 6646 | |
| 6647 | /******************** |
| 6648 | * 8. Setup services |
| 6649 | ********************/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6650 | spin_lock_irqsave(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6651 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6652 | spin_unlock_irqrestore(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6653 | |
| 6654 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
| 6655 | if (err) { |
| 6656 | IWL_ERROR("failed to create sysfs device attributes\n"); |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 6657 | goto out_free_eeprom; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6658 | } |
| 6659 | |
| 6660 | err = iwl_dbgfs_register(priv, DRV_NAME); |
| 6661 | if (err) { |
| 6662 | IWL_ERROR("failed to create debugfs files\n"); |
| 6663 | goto out_remove_sysfs; |
| 6664 | } |
| 6665 | |
| 6666 | iwl4965_setup_deferred_work(priv); |
| 6667 | iwl4965_setup_rx_handlers(priv); |
| 6668 | |
| 6669 | /******************** |
| 6670 | * 9. Conclude |
| 6671 | ********************/ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6672 | pci_save_state(pdev); |
| 6673 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6674 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 6675 | /* notify iwlcore to init */ |
| 6676 | iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6677 | return 0; |
| 6678 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6679 | out_remove_sysfs: |
| 6680 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 6681 | out_free_eeprom: |
| 6682 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6683 | out_iounmap: |
| 6684 | pci_iounmap(pdev, priv->hw_base); |
| 6685 | out_pci_release_regions: |
| 6686 | pci_release_regions(pdev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6687 | pci_set_drvdata(pdev, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6688 | out_pci_disable_device: |
| 6689 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6690 | out_ieee80211_free_hw: |
| 6691 | ieee80211_free_hw(priv->hw); |
| 6692 | out: |
| 6693 | return err; |
| 6694 | } |
| 6695 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 6696 | static void __devexit iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6697 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6698 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6699 | struct list_head *p, *q; |
| 6700 | int i; |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6701 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6702 | |
| 6703 | if (!priv) |
| 6704 | return; |
| 6705 | |
| 6706 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 6707 | |
Ron Rindjunsky | c4f5523 | 2008-03-28 16:21:10 -0700 | [diff] [blame] | 6708 | if (priv->mac80211_registered) { |
| 6709 | ieee80211_unregister_hw(priv->hw); |
| 6710 | priv->mac80211_registered = 0; |
| 6711 | } |
| 6712 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6713 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 6714 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6715 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6716 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6717 | /* make sure we flush any pending irq or |
| 6718 | * tasklet for the driver |
| 6719 | */ |
| 6720 | spin_lock_irqsave(&priv->lock, flags); |
| 6721 | iwl4965_disable_interrupts(priv); |
| 6722 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6723 | |
| 6724 | iwl_synchronize_irq(priv); |
| 6725 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6726 | /* Free MAC hash list for ADHOC */ |
| 6727 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 6728 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 6729 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6730 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6731 | } |
| 6732 | } |
| 6733 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 6734 | iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 6735 | iwl_dbgfs_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6736 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6737 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6738 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6739 | |
| 6740 | if (priv->rxq.bd) |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 6741 | iwl_rx_queue_free(priv, &priv->rxq); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 6742 | iwl_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6743 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6744 | iwlcore_clear_stations_table(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 6745 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6746 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6747 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 6748 | /*netif_stop_queue(dev); */ |
| 6749 | flush_workqueue(priv->workqueue); |
| 6750 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6751 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6752 | * priv->workqueue... so we can't take down the workqueue |
| 6753 | * until now... */ |
| 6754 | destroy_workqueue(priv->workqueue); |
| 6755 | priv->workqueue = NULL; |
| 6756 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6757 | pci_iounmap(pdev, priv->hw_base); |
| 6758 | pci_release_regions(pdev); |
| 6759 | pci_disable_device(pdev); |
| 6760 | pci_set_drvdata(pdev, NULL); |
| 6761 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6762 | iwl_free_channel_map(priv); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 6763 | iwlcore_free_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6764 | |
| 6765 | if (priv->ibss_beacon) |
| 6766 | dev_kfree_skb(priv->ibss_beacon); |
| 6767 | |
| 6768 | ieee80211_free_hw(priv->hw); |
| 6769 | } |
| 6770 | |
| 6771 | #ifdef CONFIG_PM |
| 6772 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6773 | static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6774 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6775 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6776 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6777 | if (priv->is_open) { |
| 6778 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 6779 | iwl4965_mac_stop(priv->hw); |
| 6780 | priv->is_open = 1; |
| 6781 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6782 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6783 | pci_set_power_state(pdev, PCI_D3hot); |
| 6784 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6785 | return 0; |
| 6786 | } |
| 6787 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6788 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6789 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6790 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6791 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6792 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6793 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6794 | if (priv->is_open) |
| 6795 | iwl4965_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6796 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6797 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6798 | return 0; |
| 6799 | } |
| 6800 | |
| 6801 | #endif /* CONFIG_PM */ |
| 6802 | |
| 6803 | /***************************************************************************** |
| 6804 | * |
| 6805 | * driver and module entry point |
| 6806 | * |
| 6807 | *****************************************************************************/ |
| 6808 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 6809 | /* Hardware specific file defines the PCI IDs table for that hardware module */ |
| 6810 | static struct pci_device_id iwl_hw_card_ids[] = { |
| 6811 | {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)}, |
| 6812 | {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)}, |
Tomas Winkler | 5a6a256 | 2008-04-24 11:55:23 -0700 | [diff] [blame] | 6813 | #ifdef CONFIG_IWL5000 |
| 6814 | {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)}, |
| 6815 | {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)}, |
| 6816 | {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)}, |
| 6817 | #endif /* CONFIG_IWL5000 */ |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 6818 | {0} |
| 6819 | }; |
| 6820 | MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); |
| 6821 | |
| 6822 | static struct pci_driver iwl_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6823 | .name = DRV_NAME, |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 6824 | .id_table = iwl_hw_card_ids, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6825 | .probe = iwl4965_pci_probe, |
| 6826 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6827 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6828 | .suspend = iwl4965_pci_suspend, |
| 6829 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6830 | #endif |
| 6831 | }; |
| 6832 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6833 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6834 | { |
| 6835 | |
| 6836 | int ret; |
| 6837 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 6838 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 6839 | |
| 6840 | ret = iwl4965_rate_control_register(); |
| 6841 | if (ret) { |
| 6842 | IWL_ERROR("Unable to register rate control algorithm: %d\n", ret); |
| 6843 | return ret; |
| 6844 | } |
| 6845 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 6846 | ret = pci_register_driver(&iwl_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6847 | if (ret) { |
| 6848 | IWL_ERROR("Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 6849 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6850 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6851 | |
| 6852 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 6853 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 6854 | error_register: |
| 6855 | iwl4965_rate_control_unregister(); |
| 6856 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6857 | } |
| 6858 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6859 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6860 | { |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 6861 | pci_unregister_driver(&iwl_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 6862 | iwl4965_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6863 | } |
| 6864 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6865 | module_exit(iwl4965_exit); |
| 6866 | module_init(iwl4965_init); |