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 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 210 | |
| 211 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 212 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 213 | * the functionality provided here |
| 214 | */ |
| 215 | |
| 216 | /**************************************************************/ |
| 217 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 218 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 219 | /** |
| 220 | * iwl4965_remove_station - Remove driver's knowledge of station. |
| 221 | * |
| 222 | * NOTE: This does not remove station from device's station table. |
| 223 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 224 | 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] | 225 | { |
| 226 | int index = IWL_INVALID_STATION; |
| 227 | int i; |
| 228 | unsigned long flags; |
| 229 | |
| 230 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 231 | |
| 232 | if (is_ap) |
| 233 | index = IWL_AP_ID; |
| 234 | else if (is_broadcast_ether_addr(addr)) |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 235 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 236 | else |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 237 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 238 | if (priv->stations[i].used && |
| 239 | !compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 240 | addr)) { |
| 241 | index = i; |
| 242 | break; |
| 243 | } |
| 244 | |
| 245 | if (unlikely(index == IWL_INVALID_STATION)) |
| 246 | goto out; |
| 247 | |
| 248 | if (priv->stations[index].used) { |
| 249 | priv->stations[index].used = 0; |
| 250 | priv->num_stations--; |
| 251 | } |
| 252 | |
| 253 | BUG_ON(priv->num_stations < 0); |
| 254 | |
| 255 | out: |
| 256 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 257 | return 0; |
| 258 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 259 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 260 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 261 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 262 | * iwl4965_add_station_flags - Add station to tables in driver and device |
| 263 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 264 | u8 iwl4965_add_station_flags(struct iwl_priv *priv, const u8 *addr, |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 265 | int is_ap, u8 flags, void *ht_data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 266 | { |
| 267 | int i; |
| 268 | int index = IWL_INVALID_STATION; |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 269 | struct iwl_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 270 | unsigned long flags_spin; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 271 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 272 | |
| 273 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 274 | if (is_ap) |
| 275 | index = IWL_AP_ID; |
| 276 | else if (is_broadcast_ether_addr(addr)) |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 277 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 278 | else |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 279 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 280 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 281 | addr)) { |
| 282 | index = i; |
| 283 | break; |
| 284 | } |
| 285 | |
| 286 | if (!priv->stations[i].used && |
| 287 | index == IWL_INVALID_STATION) |
| 288 | index = i; |
| 289 | } |
| 290 | |
| 291 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 292 | /* These two conditions have the same outcome, but keep them separate |
| 293 | since they have different meanings */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 294 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 295 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 296 | return index; |
| 297 | } |
| 298 | |
| 299 | if (priv->stations[index].used && |
| 300 | !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) { |
| 301 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 302 | return index; |
| 303 | } |
| 304 | |
| 305 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 306 | 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] | 307 | station = &priv->stations[index]; |
| 308 | station->used = 1; |
| 309 | priv->num_stations++; |
| 310 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 311 | /* Set up the REPLY_ADD_STA command to send to device */ |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 312 | memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 313 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 314 | station->sta.mode = 0; |
| 315 | station->sta.sta.sta_id = index; |
| 316 | station->sta.station_flags = 0; |
| 317 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 318 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 319 | /* BCAST station and IBSS stations do not work in HT mode */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 320 | if (index != priv->hw_params.bcast_sta_id && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 321 | priv->iw_mode != IEEE80211_IF_TYPE_IBSS) |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 322 | iwl4965_set_ht_add_station(priv, index, |
| 323 | (struct ieee80211_ht_info *) ht_data); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 324 | #endif /*CONFIG_IWL4965_HT*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 325 | |
| 326 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 327 | |
| 328 | /* Add station to device's station table */ |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 329 | iwl_send_add_sta(priv, &station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 330 | return index; |
| 331 | |
| 332 | } |
| 333 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 334 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 335 | |
| 336 | /*************** HOST COMMAND QUEUE FUNCTIONS *****/ |
| 337 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 338 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 339 | * iwl4965_enqueue_hcmd - enqueue a uCode command |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 340 | * @priv: device private data point |
| 341 | * @cmd: a point to the ucode command structure |
| 342 | * |
| 343 | * The function returns < 0 values to indicate the operation is |
| 344 | * failed. On success, it turns the index (> 0) of command in the |
| 345 | * command queue. |
| 346 | */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 347 | 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] | 348 | { |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 349 | struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 350 | struct iwl_queue *q = &txq->q; |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 351 | struct iwl_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 352 | u32 *control_flags; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 353 | struct iwl_cmd *out_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 354 | u32 idx; |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 355 | u16 fix_size; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 356 | dma_addr_t phys_addr; |
| 357 | int ret; |
| 358 | unsigned long flags; |
| 359 | |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 360 | cmd->len = priv->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len); |
| 361 | fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr)); |
| 362 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 363 | /* If any of the command structures end up being larger than |
| 364 | * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then |
| 365 | * we will need to increase the size of the TFD entries */ |
| 366 | BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) && |
| 367 | !(cmd->meta.flags & CMD_SIZE_HUGE)); |
| 368 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 369 | if (iwl_is_rfkill(priv)) { |
Gregory Greenman | c342a1b | 2008-02-06 11:20:40 -0800 | [diff] [blame] | 370 | IWL_DEBUG_INFO("Not sending command - RF KILL"); |
| 371 | return -EIO; |
| 372 | } |
| 373 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 374 | if (iwl_queue_space(q) < ((cmd->meta.flags & CMD_ASYNC) ? 2 : 1)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 375 | IWL_ERROR("No space for Tx\n"); |
| 376 | return -ENOSPC; |
| 377 | } |
| 378 | |
| 379 | spin_lock_irqsave(&priv->hcmd_lock, flags); |
| 380 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 381 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 382 | memset(tfd, 0, sizeof(*tfd)); |
| 383 | |
| 384 | control_flags = (u32 *) tfd; |
| 385 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 386 | 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] | 387 | out_cmd = &txq->cmd[idx]; |
| 388 | |
| 389 | out_cmd->hdr.cmd = cmd->id; |
| 390 | memcpy(&out_cmd->meta, &cmd->meta, sizeof(cmd->meta)); |
| 391 | memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len); |
| 392 | |
| 393 | /* At this point, the out_cmd now has all of the incoming cmd |
| 394 | * information */ |
| 395 | |
| 396 | out_cmd->hdr.flags = 0; |
| 397 | 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] | 398 | INDEX_TO_SEQ(q->write_ptr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 399 | if (out_cmd->meta.flags & CMD_SIZE_HUGE) |
| 400 | out_cmd->hdr.sequence |= cpu_to_le16(SEQ_HUGE_FRAME); |
| 401 | |
| 402 | phys_addr = txq->dma_addr_cmd + sizeof(txq->cmd[0]) * idx + |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 403 | offsetof(struct iwl_cmd, hdr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 404 | 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] | 405 | |
| 406 | IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, " |
| 407 | "%d bytes at %d[%d]:%d\n", |
| 408 | get_cmd_string(out_cmd->hdr.cmd), |
| 409 | out_cmd->hdr.cmd, le16_to_cpu(out_cmd->hdr.sequence), |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 410 | fix_size, q->write_ptr, idx, IWL_CMD_QUEUE_NUM); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 411 | |
| 412 | txq->need_update = 1; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 413 | |
| 414 | /* Set up entry in queue's byte count circular buffer */ |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 415 | 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] | 416 | |
| 417 | /* Increment and update queue's write index */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 418 | 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] | 419 | ret = iwl_txq_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 420 | |
| 421 | spin_unlock_irqrestore(&priv->hcmd_lock, flags); |
| 422 | return ret ? ret : idx; |
| 423 | } |
| 424 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 425 | static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) |
| 426 | { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 427 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 428 | |
| 429 | if (hw_decrypt) |
| 430 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 431 | else |
| 432 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 433 | |
| 434 | } |
| 435 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 436 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 437 | * iwl4965_rxon_add_station - add station into station table. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 438 | * |
| 439 | * there is only one AP station with id= IWL_AP_ID |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 440 | * NOTE: mutex must be held before calling this fnction |
| 441 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 442 | static int iwl4965_rxon_add_station(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 443 | const u8 *addr, int is_ap) |
| 444 | { |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 445 | u8 sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 446 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 447 | /* Add station to device's station table */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 448 | #ifdef CONFIG_IWL4965_HT |
| 449 | struct ieee80211_conf *conf = &priv->hw->conf; |
| 450 | struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf; |
| 451 | |
| 452 | if ((is_ap) && |
| 453 | (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) && |
| 454 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 455 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, |
| 456 | 0, cur_ht_config); |
| 457 | else |
| 458 | #endif /* CONFIG_IWL4965_HT */ |
| 459 | sta_id = iwl4965_add_station_flags(priv, addr, is_ap, |
| 460 | 0, NULL); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 461 | |
| 462 | /* Set up default rate scaling table in device's station table */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 463 | iwl4965_add_station(priv, addr, is_ap); |
| 464 | |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 465 | return sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 469 | * iwl4965_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 470 | * |
| 471 | * NOTE: This is really only useful during development and can eventually |
| 472 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 473 | * making changes |
| 474 | */ |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 475 | static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 476 | { |
| 477 | int error = 0; |
| 478 | int counter = 1; |
| 479 | |
| 480 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 481 | error |= le32_to_cpu(rxon->flags & |
| 482 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 483 | RXON_FLG_RADAR_DETECT_MSK)); |
| 484 | if (error) |
| 485 | IWL_WARNING("check 24G fields %d | %d\n", |
| 486 | counter++, error); |
| 487 | } else { |
| 488 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 489 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 490 | if (error) |
| 491 | IWL_WARNING("check 52 fields %d | %d\n", |
| 492 | counter++, error); |
| 493 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 494 | if (error) |
| 495 | IWL_WARNING("check 52 CCK %d | %d\n", |
| 496 | counter++, error); |
| 497 | } |
| 498 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 499 | if (error) |
| 500 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); |
| 501 | |
| 502 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 503 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 504 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 505 | if (error) |
| 506 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); |
| 507 | |
| 508 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 509 | if (error) |
| 510 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); |
| 511 | |
| 512 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 513 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 514 | if (error) |
| 515 | IWL_WARNING("check CCK and short slot %d | %d\n", |
| 516 | counter++, error); |
| 517 | |
| 518 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 519 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 520 | if (error) |
| 521 | IWL_WARNING("check CCK & auto detect %d | %d\n", |
| 522 | counter++, error); |
| 523 | |
| 524 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 525 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 526 | if (error) |
| 527 | IWL_WARNING("check TGG and auto detect %d | %d\n", |
| 528 | counter++, error); |
| 529 | |
| 530 | if (error) |
| 531 | IWL_WARNING("Tuning to channel %d\n", |
| 532 | le16_to_cpu(rxon->channel)); |
| 533 | |
| 534 | if (error) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 535 | IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 536 | return -1; |
| 537 | } |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 542 | * 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] | 543 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 544 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 545 | * If the RXON structure is changing enough to require a new tune, |
| 546 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 547 | * 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] | 548 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 549 | static int iwl4965_full_rxon_required(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 550 | { |
| 551 | |
| 552 | /* These items are only settable from the full RXON command */ |
| 553 | if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || |
| 554 | compare_ether_addr(priv->staging_rxon.bssid_addr, |
| 555 | priv->active_rxon.bssid_addr) || |
| 556 | compare_ether_addr(priv->staging_rxon.node_addr, |
| 557 | priv->active_rxon.node_addr) || |
| 558 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, |
| 559 | priv->active_rxon.wlap_bssid_addr) || |
| 560 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || |
| 561 | (priv->staging_rxon.channel != priv->active_rxon.channel) || |
| 562 | (priv->staging_rxon.air_propagation != |
| 563 | priv->active_rxon.air_propagation) || |
| 564 | (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != |
| 565 | priv->active_rxon.ofdm_ht_single_stream_basic_rates) || |
| 566 | (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != |
| 567 | priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || |
| 568 | (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) || |
| 569 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) |
| 570 | return 1; |
| 571 | |
| 572 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 573 | * be updated with the RXON_ASSOC command -- however only some |
| 574 | * flag transitions are allowed using RXON_ASSOC */ |
| 575 | |
| 576 | /* Check if we are not switching bands */ |
| 577 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 578 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
| 579 | return 1; |
| 580 | |
| 581 | /* Check if we are switching association toggle */ |
| 582 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 583 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
| 584 | return 1; |
| 585 | |
| 586 | return 0; |
| 587 | } |
| 588 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 589 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 590 | * iwl4965_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 591 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 592 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 593 | * the active_rxon structure is updated with the new data. This |
| 594 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 595 | * a HW tune is required based on the RXON structure changes. |
| 596 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 597 | static int iwl4965_commit_rxon(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 598 | { |
| 599 | /* cast away the const for active_rxon in this function */ |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 600 | struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 601 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 602 | int rc = 0; |
| 603 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 604 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 605 | return -1; |
| 606 | |
| 607 | /* always get timestamp with Rx frame */ |
| 608 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
| 609 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 610 | rc = iwl4965_check_rxon_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 611 | if (rc) { |
| 612 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); |
| 613 | return -EINVAL; |
| 614 | } |
| 615 | |
| 616 | /* 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] | 617 | * iwl4965_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 618 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 619 | if (!iwl4965_full_rxon_required(priv)) { |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 620 | rc = iwl_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 621 | if (rc) { |
| 622 | IWL_ERROR("Error setting RXON_ASSOC " |
| 623 | "configuration (%d).\n", rc); |
| 624 | return rc; |
| 625 | } |
| 626 | |
| 627 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 628 | |
| 629 | return 0; |
| 630 | } |
| 631 | |
| 632 | /* station table will be cleared */ |
| 633 | priv->assoc_station_added = 0; |
| 634 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 635 | /* If we are currently associated and the new config requires |
| 636 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 637 | * we must clear the associated from the active configuration |
| 638 | * before we apply the new config */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 639 | if (iwl_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 640 | (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
| 641 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 642 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 643 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 644 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 645 | sizeof(struct iwl_rxon_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 646 | &priv->active_rxon); |
| 647 | |
| 648 | /* If the mask clearing failed then we set |
| 649 | * active_rxon back to what it was previously */ |
| 650 | if (rc) { |
| 651 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 652 | IWL_ERROR("Error clearing ASSOC_MSK on current " |
| 653 | "configuration (%d).\n", rc); |
| 654 | return rc; |
| 655 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | IWL_DEBUG_INFO("Sending RXON\n" |
| 659 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 660 | "* channel = %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 661 | "* bssid = %s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 662 | ((priv->staging_rxon.filter_flags & |
| 663 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
| 664 | le16_to_cpu(priv->staging_rxon.channel), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 665 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 666 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 667 | iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 668 | /* Apply the new configuration */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 669 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 670 | sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 671 | if (rc) { |
| 672 | IWL_ERROR("Error setting new configuration (%d).\n", rc); |
| 673 | return rc; |
| 674 | } |
| 675 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 676 | iwlcore_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 677 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 678 | if (!priv->error_recovering) |
| 679 | priv->start_calib = 0; |
| 680 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 681 | iwl_init_sensitivity(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 682 | |
| 683 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 684 | |
| 685 | /* If we issue a new RXON command which required a tune then we must |
| 686 | * 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] | 687 | rc = iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 688 | if (rc) { |
| 689 | IWL_ERROR("Error setting Tx power (%d).\n", rc); |
| 690 | return rc; |
| 691 | } |
| 692 | |
| 693 | /* Add the broadcast address so we can send broadcast frames */ |
Tomas Winkler | 57bd1be | 2008-05-15 13:54:03 +0800 | [diff] [blame^] | 694 | if (iwl4965_rxon_add_station(priv, iwl_bcast_addr, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 695 | IWL_INVALID_STATION) { |
| 696 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); |
| 697 | return -EIO; |
| 698 | } |
| 699 | |
| 700 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 701 | * add the IWL_AP_ID to the station rate table */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 702 | if (iwl_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 703 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 704 | if (iwl4965_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 705 | == IWL_INVALID_STATION) { |
| 706 | IWL_ERROR("Error adding AP address for transmit.\n"); |
| 707 | return -EIO; |
| 708 | } |
| 709 | priv->assoc_station_added = 1; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 710 | if (priv->default_wep_key && |
| 711 | iwl_send_static_wepkey_cmd(priv, 0)) |
| 712 | IWL_ERROR("Could not send WEP static key.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 718 | void iwl4965_update_chain_flags(struct iwl_priv *priv) |
| 719 | { |
| 720 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 721 | iwl_set_rxon_chain(priv); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 722 | iwl4965_commit_rxon(priv); |
| 723 | } |
| 724 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 725 | static int iwl4965_send_bt_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 726 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 727 | struct iwl4965_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 728 | .flags = 3, |
| 729 | .lead_time = 0xAA, |
| 730 | .max_kill = 1, |
| 731 | .kill_ack_mask = 0, |
| 732 | .kill_cts_mask = 0, |
| 733 | }; |
| 734 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 735 | return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 736 | sizeof(struct iwl4965_bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 737 | } |
| 738 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 739 | static int iwl4965_send_scan_abort(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 740 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 741 | int ret = 0; |
| 742 | struct iwl_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 743 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 744 | .id = REPLY_SCAN_ABORT_CMD, |
| 745 | .meta.flags = CMD_WANT_SKB, |
| 746 | }; |
| 747 | |
| 748 | /* If there isn't a scan actively going on in the hardware |
| 749 | * then we are in between scan bands and not actually |
| 750 | * actively scanning, so don't send the abort command */ |
| 751 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 752 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 753 | return 0; |
| 754 | } |
| 755 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 756 | ret = iwl_send_cmd_sync(priv, &cmd); |
| 757 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 758 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 759 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 762 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 763 | if (res->u.status != CAN_ABORT_STATUS) { |
| 764 | /* The scan abort will return 1 for success or |
| 765 | * 2 for "failure". A failure condition can be |
| 766 | * due to simply not being in an active scan which |
| 767 | * can occur if we send the scan abort before we |
| 768 | * the microcode has notified us that a scan is |
| 769 | * completed. */ |
| 770 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 771 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 772 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 773 | } |
| 774 | |
| 775 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 776 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 777 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 780 | /* |
| 781 | * CARD_STATE_CMD |
| 782 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 783 | * 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] | 784 | * |
| 785 | * When in the 'enable' state the card operates as normal. |
| 786 | * When in the 'disable' state, the card enters into a low power mode. |
| 787 | * When in the 'halt' state, the card is shut down and must be fully |
| 788 | * restarted to come back on. |
| 789 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 790 | 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] | 791 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 792 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 793 | .id = REPLY_CARD_STATE_CMD, |
| 794 | .len = sizeof(u32), |
| 795 | .data = &flags, |
| 796 | .meta.flags = meta_flag, |
| 797 | }; |
| 798 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 799 | return iwl_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 800 | } |
| 801 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 802 | static void iwl_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 803 | { |
| 804 | struct list_head *element; |
| 805 | |
| 806 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 807 | priv->frames_count); |
| 808 | |
| 809 | while (!list_empty(&priv->free_frames)) { |
| 810 | element = priv->free_frames.next; |
| 811 | list_del(element); |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 812 | kfree(list_entry(element, struct iwl_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 813 | priv->frames_count--; |
| 814 | } |
| 815 | |
| 816 | if (priv->frames_count) { |
| 817 | IWL_WARNING("%d frames still in use. Did we lose one?\n", |
| 818 | priv->frames_count); |
| 819 | priv->frames_count = 0; |
| 820 | } |
| 821 | } |
| 822 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 823 | static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 824 | { |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 825 | struct iwl_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 826 | struct list_head *element; |
| 827 | if (list_empty(&priv->free_frames)) { |
| 828 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 829 | if (!frame) { |
| 830 | IWL_ERROR("Could not allocate frame!\n"); |
| 831 | return NULL; |
| 832 | } |
| 833 | |
| 834 | priv->frames_count++; |
| 835 | return frame; |
| 836 | } |
| 837 | |
| 838 | element = priv->free_frames.next; |
| 839 | list_del(element); |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 840 | return list_entry(element, struct iwl_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 843 | 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] | 844 | { |
| 845 | memset(frame, 0, sizeof(*frame)); |
| 846 | list_add(&frame->list, &priv->free_frames); |
| 847 | } |
| 848 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 849 | unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 850 | struct ieee80211_hdr *hdr, |
| 851 | const u8 *dest, int left) |
| 852 | { |
| 853 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 854 | if (!iwl_is_associated(priv) || !priv->ibss_beacon || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 855 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
| 856 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) |
| 857 | return 0; |
| 858 | |
| 859 | if (priv->ibss_beacon->len > left) |
| 860 | return 0; |
| 861 | |
| 862 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 863 | |
| 864 | return priv->ibss_beacon->len; |
| 865 | } |
| 866 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 867 | static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 868 | { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 869 | int i; |
| 870 | int rate_mask; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 871 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 872 | /* Set rate mask*/ |
| 873 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 874 | rate_mask = priv->active_rate_basic & 0xF; |
| 875 | else |
| 876 | rate_mask = priv->active_rate_basic & 0xFF0; |
| 877 | |
| 878 | /* Find lowest valid rate */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 879 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 880 | i = iwl_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 881 | if (rate_mask & (1 << i)) |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 882 | return iwl_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 883 | } |
| 884 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 885 | /* No valid rate was found. Assign the lowest one */ |
| 886 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 887 | return IWL_RATE_1M_PLCP; |
| 888 | else |
| 889 | return IWL_RATE_6M_PLCP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 892 | static int iwl4965_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 893 | { |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 894 | struct iwl_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 895 | unsigned int frame_size; |
| 896 | int rc; |
| 897 | u8 rate; |
| 898 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 899 | frame = iwl_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 900 | |
| 901 | if (!frame) { |
| 902 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 903 | "command.\n"); |
| 904 | return -ENOMEM; |
| 905 | } |
| 906 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 907 | rate = iwl4965_rate_get_lowest_plcp(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 908 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 909 | frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 910 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 911 | rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 912 | &frame->u.cmd[0]); |
| 913 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 914 | iwl_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 915 | |
| 916 | return rc; |
| 917 | } |
| 918 | |
| 919 | /****************************************************************************** |
| 920 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 921 | * Misc. internal state and helper functions |
| 922 | * |
| 923 | ******************************************************************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 924 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 925 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 926 | * 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] | 927 | * |
| 928 | * return : set the bit for each supported rate insert in ie |
| 929 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 930 | static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 931 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 932 | { |
| 933 | u16 ret_rates = 0, bit; |
| 934 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 935 | u8 *cnt = ie; |
| 936 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 937 | |
| 938 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 939 | if (bit & supported_rate) { |
| 940 | ret_rates |= bit; |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 941 | rates[*cnt] = iwl_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 942 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 943 | (*cnt)++; |
| 944 | (*left)--; |
| 945 | if ((*left <= 0) || |
| 946 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 947 | break; |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | return ret_rates; |
| 952 | } |
| 953 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 954 | #ifdef CONFIG_IWL4965_HT |
| 955 | static void iwl4965_ht_conf(struct iwl_priv *priv, |
| 956 | struct ieee80211_bss_conf *bss_conf) |
| 957 | { |
| 958 | struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf; |
| 959 | struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf; |
| 960 | struct iwl_ht_info *iwl_conf = &priv->current_ht_config; |
| 961 | |
| 962 | IWL_DEBUG_MAC80211("enter: \n"); |
| 963 | |
| 964 | iwl_conf->is_ht = bss_conf->assoc_ht; |
| 965 | |
| 966 | if (!iwl_conf->is_ht) |
| 967 | return; |
| 968 | |
| 969 | priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 970 | |
| 971 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) |
| 972 | iwl_conf->sgf |= 0x1; |
| 973 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) |
| 974 | iwl_conf->sgf |= 0x2; |
| 975 | |
| 976 | iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); |
| 977 | iwl_conf->max_amsdu_size = |
| 978 | !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); |
| 979 | |
| 980 | iwl_conf->supported_chan_width = |
| 981 | !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); |
| 982 | iwl_conf->extension_chan_offset = |
| 983 | ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; |
| 984 | /* If no above or below channel supplied disable FAT channel */ |
| 985 | if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE && |
| 986 | iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW) |
| 987 | iwl_conf->supported_chan_width = 0; |
| 988 | |
| 989 | iwl_conf->tx_mimo_ps_mode = |
| 990 | (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 991 | memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); |
| 992 | |
| 993 | iwl_conf->control_channel = ht_bss_conf->primary_channel; |
| 994 | iwl_conf->tx_chan_width = |
| 995 | !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); |
| 996 | iwl_conf->ht_protection = |
| 997 | ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; |
| 998 | iwl_conf->non_GF_STA_present = |
| 999 | !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT); |
| 1000 | |
| 1001 | IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel); |
| 1002 | IWL_DEBUG_MAC80211("leave\n"); |
| 1003 | } |
| 1004 | |
| 1005 | static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband, |
| 1006 | u8 *pos, int *left) |
| 1007 | { |
| 1008 | struct ieee80211_ht_cap *ht_cap; |
| 1009 | |
| 1010 | if (!sband || !sband->ht_info.ht_supported) |
| 1011 | return; |
| 1012 | |
| 1013 | if (*left < sizeof(struct ieee80211_ht_cap)) |
| 1014 | return; |
| 1015 | |
| 1016 | *pos++ = sizeof(struct ieee80211_ht_cap); |
| 1017 | ht_cap = (struct ieee80211_ht_cap *) pos; |
| 1018 | |
| 1019 | ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap); |
| 1020 | memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16); |
| 1021 | ht_cap->ampdu_params_info = |
| 1022 | (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) | |
| 1023 | ((sband->ht_info.ampdu_density << 2) & |
| 1024 | IEEE80211_HT_CAP_AMPDU_DENSITY); |
| 1025 | *left -= sizeof(struct ieee80211_ht_cap); |
| 1026 | } |
| 1027 | #else |
| 1028 | static inline void iwl4965_ht_conf(struct iwl_priv *priv, |
| 1029 | struct ieee80211_bss_conf *bss_conf) |
| 1030 | { |
| 1031 | } |
| 1032 | static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband, |
| 1033 | u8 *pos, int *left) |
| 1034 | { |
| 1035 | } |
| 1036 | #endif |
| 1037 | |
| 1038 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1039 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1040 | * 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] | 1041 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1042 | static u16 iwl4965_fill_probe_req(struct iwl_priv *priv, |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1043 | enum ieee80211_band band, |
| 1044 | struct ieee80211_mgmt *frame, |
| 1045 | int left, int is_direct) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1046 | { |
| 1047 | int len = 0; |
| 1048 | u8 *pos = NULL; |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1049 | u16 active_rates, ret_rates, cck_rates, active_rate_basic; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 1050 | const struct ieee80211_supported_band *sband = |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 1051 | iwl_get_hw_mode(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1052 | |
| 1053 | /* Make sure there is enough space for the probe request, |
| 1054 | * two mandatory IEs and the data */ |
| 1055 | left -= 24; |
| 1056 | if (left < 0) |
| 1057 | return 0; |
| 1058 | len += 24; |
| 1059 | |
| 1060 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Tomas Winkler | 57bd1be | 2008-05-15 13:54:03 +0800 | [diff] [blame^] | 1061 | memcpy(frame->da, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1062 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Tomas Winkler | 57bd1be | 2008-05-15 13:54:03 +0800 | [diff] [blame^] | 1063 | memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1064 | frame->seq_ctrl = 0; |
| 1065 | |
| 1066 | /* fill in our indirect SSID IE */ |
| 1067 | /* ...next IE... */ |
| 1068 | |
| 1069 | left -= 2; |
| 1070 | if (left < 0) |
| 1071 | return 0; |
| 1072 | len += 2; |
| 1073 | pos = &(frame->u.probe_req.variable[0]); |
| 1074 | *pos++ = WLAN_EID_SSID; |
| 1075 | *pos++ = 0; |
| 1076 | |
| 1077 | /* fill in our direct SSID IE... */ |
| 1078 | if (is_direct) { |
| 1079 | /* ...next IE... */ |
| 1080 | left -= 2 + priv->essid_len; |
| 1081 | if (left < 0) |
| 1082 | return 0; |
| 1083 | /* ... fill it in... */ |
| 1084 | *pos++ = WLAN_EID_SSID; |
| 1085 | *pos++ = priv->essid_len; |
| 1086 | memcpy(pos, priv->essid, priv->essid_len); |
| 1087 | pos += priv->essid_len; |
| 1088 | len += 2 + priv->essid_len; |
| 1089 | } |
| 1090 | |
| 1091 | /* fill in supported rate */ |
| 1092 | /* ...next IE... */ |
| 1093 | left -= 2; |
| 1094 | if (left < 0) |
| 1095 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1096 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1097 | /* ... fill it in... */ |
| 1098 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1099 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1100 | |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1101 | /* exclude 60M rate */ |
| 1102 | active_rates = priv->rates_mask; |
| 1103 | active_rates &= ~IWL_RATE_60M_MASK; |
| 1104 | |
| 1105 | active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1106 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1107 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1108 | ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1109 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1110 | active_rates &= ~ret_rates; |
| 1111 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1112 | ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1113 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1114 | active_rates &= ~ret_rates; |
| 1115 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1116 | len += 2 + *pos; |
| 1117 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 1118 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1119 | goto fill_end; |
| 1120 | |
| 1121 | /* fill in supported extended rate */ |
| 1122 | /* ...next IE... */ |
| 1123 | left -= 2; |
| 1124 | if (left < 0) |
| 1125 | return 0; |
| 1126 | /* ... fill it in... */ |
| 1127 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1128 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1129 | iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 1130 | active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1131 | if (*pos > 0) |
| 1132 | len += 2 + *pos; |
| 1133 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1134 | fill_end: |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 1135 | /* fill in HT IE */ |
| 1136 | left -= 2; |
| 1137 | if (left < 0) |
| 1138 | return 0; |
| 1139 | |
| 1140 | *pos++ = WLAN_EID_HT_CAPABILITY; |
| 1141 | *pos = 0; |
| 1142 | |
| 1143 | iwl_ht_cap_to_ie(sband, pos, &left); |
| 1144 | |
| 1145 | if (*pos > 0) |
| 1146 | len += 2 + *pos; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1147 | return (u16)len; |
| 1148 | } |
| 1149 | |
| 1150 | /* |
| 1151 | * QoS support |
| 1152 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1153 | static int iwl4965_send_qos_params_command(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1154 | struct iwl4965_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1155 | { |
| 1156 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1157 | return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1158 | sizeof(struct iwl4965_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1161 | static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1162 | { |
| 1163 | unsigned long flags; |
| 1164 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1165 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 1166 | return; |
| 1167 | |
| 1168 | if (!priv->qos_data.qos_enable) |
| 1169 | return; |
| 1170 | |
| 1171 | spin_lock_irqsave(&priv->lock, flags); |
| 1172 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 1173 | |
| 1174 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 1175 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 1176 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1177 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1178 | if (priv->qos_data.qos_active) |
| 1179 | priv->qos_data.def_qos_parm.qos_flags |= |
| 1180 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 1181 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1182 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 1183 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1184 | 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] | 1185 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1186 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1187 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1188 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1189 | if (force || iwl_is_associated(priv)) { |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 1190 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 1191 | priv->qos_data.qos_active, |
| 1192 | priv->qos_data.def_qos_parm.qos_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1193 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1194 | iwl4965_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1195 | &(priv->qos_data.def_qos_parm)); |
| 1196 | } |
| 1197 | } |
| 1198 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1199 | 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] | 1200 | { |
| 1201 | /* Filter incoming packets to determine if they are targeted toward |
| 1202 | * this network, discarding packets coming from ourselves */ |
| 1203 | switch (priv->iw_mode) { |
| 1204 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 1205 | /* packets from our adapter are dropped (echo) */ |
| 1206 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 1207 | return 0; |
| 1208 | /* {broad,multi}cast packets to our IBSS go through */ |
| 1209 | if (is_multicast_ether_addr(header->addr1)) |
| 1210 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 1211 | /* packets to our adapter go through */ |
| 1212 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 1213 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 1214 | /* packets from our adapter are dropped (echo) */ |
| 1215 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 1216 | return 0; |
| 1217 | /* {broad,multi}cast packets to our BSS go through */ |
| 1218 | if (is_multicast_ether_addr(header->addr1)) |
| 1219 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 1220 | /* packets to our adapter go through */ |
| 1221 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1222 | default: |
| 1223 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | return 1; |
| 1227 | } |
| 1228 | |
| 1229 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 1230 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1231 | static const char *iwl4965_get_tx_fail_reason(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1232 | { |
| 1233 | switch (status & TX_STATUS_MSK) { |
| 1234 | case TX_STATUS_SUCCESS: |
| 1235 | return "SUCCESS"; |
| 1236 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 1237 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 1238 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 1239 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 1240 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 1241 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 1242 | TX_STATUS_ENTRY(DEST_PS); |
| 1243 | TX_STATUS_ENTRY(ABORTED); |
| 1244 | TX_STATUS_ENTRY(BT_RETRY); |
| 1245 | TX_STATUS_ENTRY(STA_INVALID); |
| 1246 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 1247 | TX_STATUS_ENTRY(TID_DISABLE); |
| 1248 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 1249 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 1250 | TX_STATUS_ENTRY(TX_LOCKED); |
| 1251 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 1252 | } |
| 1253 | |
| 1254 | return "UNKNOWN"; |
| 1255 | } |
| 1256 | |
| 1257 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1258 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1259 | * |
| 1260 | * NOTE: priv->mutex is not required before calling this function |
| 1261 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1262 | static int iwl4965_scan_cancel(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1263 | { |
| 1264 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 1265 | clear_bit(STATUS_SCANNING, &priv->status); |
| 1266 | return 0; |
| 1267 | } |
| 1268 | |
| 1269 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1270 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1271 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 1272 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1273 | queue_work(priv->workqueue, &priv->abort_scan); |
| 1274 | |
| 1275 | } else |
| 1276 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 1277 | |
| 1278 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1279 | } |
| 1280 | |
| 1281 | return 0; |
| 1282 | } |
| 1283 | |
| 1284 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1285 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1286 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 1287 | * |
| 1288 | * NOTE: priv->mutex must be held before calling this function |
| 1289 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1290 | 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] | 1291 | { |
| 1292 | unsigned long now = jiffies; |
| 1293 | int ret; |
| 1294 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1295 | ret = iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1296 | if (ret && ms) { |
| 1297 | mutex_unlock(&priv->mutex); |
| 1298 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 1299 | test_bit(STATUS_SCANNING, &priv->status)) |
| 1300 | msleep(1); |
| 1301 | mutex_lock(&priv->mutex); |
| 1302 | |
| 1303 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1304 | } |
| 1305 | |
| 1306 | return ret; |
| 1307 | } |
| 1308 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1309 | static void iwl4965_sequence_reset(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1310 | { |
| 1311 | /* Reset ieee stats */ |
| 1312 | |
| 1313 | /* We don't reset the net_device_stats (ieee->stats) on |
| 1314 | * re-association */ |
| 1315 | |
| 1316 | priv->last_seq_num = -1; |
| 1317 | priv->last_frag_num = -1; |
| 1318 | priv->last_packet_time = 0; |
| 1319 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1320 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 1324 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 1325 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1326 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1327 | { |
| 1328 | u16 new_val = 0; |
| 1329 | u16 beacon_factor = 0; |
| 1330 | |
| 1331 | beacon_factor = |
| 1332 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 1333 | / MAX_UCODE_BEACON_INTERVAL; |
| 1334 | new_val = beacon_val / beacon_factor; |
| 1335 | |
| 1336 | return cpu_to_le16(new_val); |
| 1337 | } |
| 1338 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1339 | static void iwl4965_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1340 | { |
| 1341 | u64 interval_tm_unit; |
| 1342 | u64 tsf, result; |
| 1343 | unsigned long flags; |
| 1344 | struct ieee80211_conf *conf = NULL; |
| 1345 | u16 beacon_int = 0; |
| 1346 | |
| 1347 | conf = ieee80211_get_hw_conf(priv->hw); |
| 1348 | |
| 1349 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1350 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32); |
| 1351 | priv->rxon_timing.timestamp.dw[0] = |
| 1352 | cpu_to_le32(priv->timestamp & 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1353 | |
| 1354 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 1355 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1356 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1357 | |
| 1358 | beacon_int = priv->beacon_int; |
| 1359 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1360 | |
| 1361 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 1362 | if (beacon_int == 0) { |
| 1363 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 1364 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 1365 | } else { |
| 1366 | priv->rxon_timing.beacon_interval = |
| 1367 | cpu_to_le16(beacon_int); |
| 1368 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1369 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1370 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1371 | } |
| 1372 | |
| 1373 | priv->rxon_timing.atim_window = 0; |
| 1374 | } else { |
| 1375 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1376 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1377 | /* TODO: we need to get atim_window from upper stack |
| 1378 | * for now we set to 0 */ |
| 1379 | priv->rxon_timing.atim_window = 0; |
| 1380 | } |
| 1381 | |
| 1382 | interval_tm_unit = |
| 1383 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 1384 | result = do_div(tsf, interval_tm_unit); |
| 1385 | priv->rxon_timing.beacon_init_val = |
| 1386 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 1387 | |
| 1388 | IWL_DEBUG_ASSOC |
| 1389 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 1390 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 1391 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 1392 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 1393 | } |
| 1394 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1395 | static int iwl4965_scan_initiate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1396 | { |
| 1397 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 1398 | IWL_ERROR("APs don't scan.\n"); |
| 1399 | return 0; |
| 1400 | } |
| 1401 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1402 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1403 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 1404 | return -EIO; |
| 1405 | } |
| 1406 | |
| 1407 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1408 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 1409 | return -EAGAIN; |
| 1410 | } |
| 1411 | |
| 1412 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1413 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 1414 | "Queuing.\n"); |
| 1415 | return -EAGAIN; |
| 1416 | } |
| 1417 | |
| 1418 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 1419 | priv->scan_bands = 2; |
| 1420 | set_bit(STATUS_SCANNING, &priv->status); |
| 1421 | priv->scan_start = jiffies; |
| 1422 | priv->scan_pass_start = priv->scan_start; |
| 1423 | |
| 1424 | queue_work(priv->workqueue, &priv->request_scan); |
| 1425 | |
| 1426 | return 0; |
| 1427 | } |
| 1428 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1429 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1430 | static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1431 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1432 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1433 | if (band == IEEE80211_BAND_5GHZ) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1434 | priv->staging_rxon.flags &= |
| 1435 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 1436 | | RXON_FLG_CCK_MSK); |
| 1437 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1438 | } else { |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 1439 | /* Copied from iwl4965_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1440 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 1441 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1442 | else |
| 1443 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1444 | |
| 1445 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 1446 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1447 | |
| 1448 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 1449 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 1450 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1455 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1456 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1457 | static void iwl4965_connection_init_rx_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1458 | { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1459 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1460 | |
| 1461 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 1462 | |
| 1463 | switch (priv->iw_mode) { |
| 1464 | case IEEE80211_IF_TYPE_AP: |
| 1465 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 1466 | break; |
| 1467 | |
| 1468 | case IEEE80211_IF_TYPE_STA: |
| 1469 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 1470 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 1471 | break; |
| 1472 | |
| 1473 | case IEEE80211_IF_TYPE_IBSS: |
| 1474 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 1475 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1476 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 1477 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1478 | break; |
| 1479 | |
| 1480 | case IEEE80211_IF_TYPE_MNTR: |
| 1481 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 1482 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 1483 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1484 | break; |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1485 | default: |
| 1486 | IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode); |
| 1487 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | #if 0 |
| 1491 | /* TODO: Figure out when short_preamble would be set and cache from |
| 1492 | * that */ |
| 1493 | if (!hw_to_local(priv->hw)->short_preamble) |
| 1494 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1495 | else |
| 1496 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1497 | #endif |
| 1498 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1499 | ch_info = iwl_get_channel_info(priv, priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1500 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1501 | |
| 1502 | if (!ch_info) |
| 1503 | ch_info = &priv->channel_info[0]; |
| 1504 | |
| 1505 | /* |
| 1506 | * in some case A channels are all non IBSS |
| 1507 | * in this case force B/G channel |
| 1508 | */ |
| 1509 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 1510 | !(is_channel_ibss(ch_info))) |
| 1511 | ch_info = &priv->channel_info[0]; |
| 1512 | |
| 1513 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1514 | priv->band = ch_info->band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1515 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1516 | iwl4965_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1517 | |
| 1518 | priv->staging_rxon.ofdm_basic_rates = |
| 1519 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1520 | priv->staging_rxon.cck_basic_rates = |
| 1521 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1522 | |
| 1523 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 1524 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 1525 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1526 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 1527 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 1528 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 1529 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1532 | static int iwl4965_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1533 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1534 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1535 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1536 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1537 | ch_info = iwl_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1538 | priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1539 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1540 | |
| 1541 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 1542 | IWL_ERROR("channel %d not IBSS channel\n", |
| 1543 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1544 | return -EINVAL; |
| 1545 | } |
| 1546 | } |
| 1547 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1548 | priv->iw_mode = mode; |
| 1549 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1550 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1551 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1552 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1553 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1554 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1555 | /* dont commit rxon if rf-kill is on*/ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1556 | if (!iwl_is_ready_rf(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1557 | return -EAGAIN; |
| 1558 | |
| 1559 | cancel_delayed_work(&priv->scan_check); |
| 1560 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
| 1561 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 1562 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 1563 | return -EAGAIN; |
| 1564 | } |
| 1565 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1566 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1567 | |
| 1568 | return 0; |
| 1569 | } |
| 1570 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1571 | static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1572 | struct ieee80211_tx_control *ctl, |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1573 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1574 | struct sk_buff *skb_frag, |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 1575 | int sta_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1576 | { |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 1577 | struct iwl_hw_key *keyinfo = &priv->stations[sta_id].keyinfo; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1578 | struct iwl_wep_key *wepkey; |
| 1579 | int keyidx = 0; |
| 1580 | |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 1581 | BUG_ON(ctl->hw_key->hw_key_idx > 3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1582 | |
| 1583 | switch (keyinfo->alg) { |
| 1584 | case ALG_CCMP: |
| 1585 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_CCM; |
| 1586 | memcpy(cmd->cmd.tx.key, keyinfo->key, keyinfo->keylen); |
Max Stepanov | 8236e18 | 2008-03-12 16:58:48 -0700 | [diff] [blame] | 1587 | if (ctl->flags & IEEE80211_TXCTL_AMPDU) |
| 1588 | cmd->cmd.tx.tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1589 | IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n"); |
| 1590 | break; |
| 1591 | |
| 1592 | case ALG_TKIP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1593 | cmd->cmd.tx.sec_ctl = TX_CMD_SEC_TKIP; |
Emmanuel Grumbach | 2bc7508 | 2008-03-19 16:41:45 -0700 | [diff] [blame] | 1594 | ieee80211_get_tkip_key(keyinfo->conf, skb_frag, |
| 1595 | IEEE80211_TKIP_P2_KEY, cmd->cmd.tx.key); |
| 1596 | IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1597 | break; |
| 1598 | |
| 1599 | case ALG_WEP: |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 1600 | wepkey = &priv->wep_keys[ctl->hw_key->hw_key_idx]; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1601 | cmd->cmd.tx.sec_ctl = 0; |
| 1602 | if (priv->default_wep_key) { |
| 1603 | /* the WEP key was sent as static */ |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 1604 | keyidx = ctl->hw_key->hw_key_idx; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1605 | memcpy(&cmd->cmd.tx.key[3], wepkey->key, |
| 1606 | wepkey->key_size); |
| 1607 | if (wepkey->key_size == WEP_KEY_LEN_128) |
| 1608 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
| 1609 | } else { |
Emmanuel Grumbach | 0211ddd | 2008-04-14 21:16:07 -0700 | [diff] [blame] | 1610 | /* the WEP key was sent as dynamic */ |
| 1611 | keyidx = keyinfo->keyidx; |
| 1612 | memcpy(&cmd->cmd.tx.key[3], keyinfo->key, |
| 1613 | keyinfo->keylen); |
| 1614 | if (keyinfo->keylen == WEP_KEY_LEN_128) |
| 1615 | cmd->cmd.tx.sec_ctl |= TX_CMD_SEC_KEY128; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1616 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1617 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1618 | cmd->cmd.tx.sec_ctl |= (TX_CMD_SEC_WEP | |
| 1619 | (keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1620 | |
| 1621 | IWL_DEBUG_TX("Configuring packet for WEP encryption " |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1622 | "with key %d\n", keyidx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1623 | break; |
| 1624 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1625 | default: |
| 1626 | printk(KERN_ERR "Unknown encode alg %d\n", keyinfo->alg); |
| 1627 | break; |
| 1628 | } |
| 1629 | } |
| 1630 | |
| 1631 | /* |
| 1632 | * handle build REPLY_TX command notification. |
| 1633 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1634 | static void iwl4965_build_tx_cmd_basic(struct iwl_priv *priv, |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1635 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1636 | struct ieee80211_tx_control *ctrl, |
| 1637 | struct ieee80211_hdr *hdr, |
| 1638 | int is_unicast, u8 std_id) |
| 1639 | { |
| 1640 | __le16 *qc; |
| 1641 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 1642 | __le32 tx_flags = cmd->cmd.tx.tx_flags; |
| 1643 | |
| 1644 | cmd->cmd.tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 1645 | if (!(ctrl->flags & IEEE80211_TXCTL_NO_ACK)) { |
| 1646 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
| 1647 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) |
| 1648 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1649 | if (ieee80211_is_probe_response(fc) && |
| 1650 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 1651 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 1652 | } else { |
| 1653 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 1654 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1655 | } |
| 1656 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 1657 | if (ieee80211_is_back_request(fc)) |
| 1658 | tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK; |
| 1659 | |
| 1660 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1661 | cmd->cmd.tx.sta_id = std_id; |
| 1662 | if (ieee80211_get_morefrag(hdr)) |
| 1663 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 1664 | |
| 1665 | qc = ieee80211_get_qos_ctrl(hdr); |
| 1666 | if (qc) { |
| 1667 | cmd->cmd.tx.tid_tspec = (u8) (le16_to_cpu(*qc) & 0xf); |
| 1668 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
| 1669 | } else |
| 1670 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 1671 | |
| 1672 | if (ctrl->flags & IEEE80211_TXCTL_USE_RTS_CTS) { |
| 1673 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 1674 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
| 1675 | } else if (ctrl->flags & IEEE80211_TXCTL_USE_CTS_PROTECT) { |
| 1676 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 1677 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 1678 | } |
| 1679 | |
| 1680 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 1681 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 1682 | |
| 1683 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
| 1684 | if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) { |
| 1685 | if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_ASSOC_REQ || |
| 1686 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_REASSOC_REQ) |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1687 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1688 | else |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1689 | cmd->cmd.tx.timeout.pm_frame_timeout = cpu_to_le16(2); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 1690 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1691 | cmd->cmd.tx.timeout.pm_frame_timeout = 0; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 1692 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1693 | |
| 1694 | cmd->cmd.tx.driver_txop = 0; |
| 1695 | cmd->cmd.tx.tx_flags = tx_flags; |
| 1696 | cmd->cmd.tx.next_frame_len = 0; |
| 1697 | } |
Tomas Winkler | 19758be | 2008-03-12 16:58:51 -0700 | [diff] [blame] | 1698 | static void iwl_update_tx_stats(struct iwl_priv *priv, u16 fc, u16 len) |
| 1699 | { |
| 1700 | /* 0 - mgmt, 1 - cnt, 2 - data */ |
| 1701 | int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2; |
| 1702 | priv->tx_stats[idx].cnt++; |
| 1703 | priv->tx_stats[idx].bytes += len; |
| 1704 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1705 | /** |
| 1706 | * iwl4965_get_sta_id - Find station's index within station table |
| 1707 | * |
| 1708 | * If new IBSS station, create new entry in station table |
| 1709 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1710 | static int iwl4965_get_sta_id(struct iwl_priv *priv, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1711 | struct ieee80211_hdr *hdr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1712 | { |
| 1713 | int sta_id; |
| 1714 | u16 fc = le16_to_cpu(hdr->frame_control); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1715 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1716 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1717 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1718 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 1719 | is_multicast_ether_addr(hdr->addr1)) |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1720 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1721 | |
| 1722 | switch (priv->iw_mode) { |
| 1723 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1724 | /* If we are a client station in a BSS network, use the special |
| 1725 | * AP station entry (that's the only station we communicate with) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1726 | case IEEE80211_IF_TYPE_STA: |
| 1727 | return IWL_AP_ID; |
| 1728 | |
| 1729 | /* If we are an AP, then find the station, or use BCAST */ |
| 1730 | case IEEE80211_IF_TYPE_AP: |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 1731 | sta_id = iwl_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1732 | if (sta_id != IWL_INVALID_STATION) |
| 1733 | return sta_id; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1734 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1735 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1736 | /* If this frame is going out to an IBSS network, find the station, |
| 1737 | * or create a new station table entry */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1738 | case IEEE80211_IF_TYPE_IBSS: |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 1739 | sta_id = iwl_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1740 | if (sta_id != IWL_INVALID_STATION) |
| 1741 | return sta_id; |
| 1742 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1743 | /* Create new station table entry */ |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 1744 | sta_id = iwl4965_add_station_flags(priv, hdr->addr1, |
| 1745 | 0, CMD_ASYNC, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1746 | |
| 1747 | if (sta_id != IWL_INVALID_STATION) |
| 1748 | return sta_id; |
| 1749 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1750 | IWL_DEBUG_DROP("Station %s not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1751 | "Defaulting to broadcast...\n", |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1752 | print_mac(mac, hdr->addr1)); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1753 | iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1754 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1755 | |
| 1756 | default: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1757 | IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode); |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1758 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | /* |
| 1763 | * start REPLY_TX command process |
| 1764 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1765 | static int iwl4965_tx_skb(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1766 | struct sk_buff *skb, struct ieee80211_tx_control *ctl) |
| 1767 | { |
| 1768 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 1769 | struct iwl_tfd_frame *tfd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1770 | u32 *control_flags; |
| 1771 | int txq_id = ctl->queue; |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 1772 | struct iwl_tx_queue *txq = NULL; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 1773 | struct iwl_queue *q = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1774 | dma_addr_t phys_addr; |
| 1775 | dma_addr_t txcmd_phys; |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 1776 | dma_addr_t scratch_phys; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1777 | struct iwl_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1778 | u16 len, idx, len_org; |
| 1779 | u8 id, hdr_len, unicast; |
| 1780 | u8 sta_id; |
| 1781 | u16 seq_number = 0; |
| 1782 | u16 fc; |
| 1783 | __le16 *qc; |
| 1784 | u8 wait_write_ptr = 0; |
| 1785 | unsigned long flags; |
| 1786 | int rc; |
| 1787 | |
| 1788 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1789 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1790 | IWL_DEBUG_DROP("Dropping - RF KILL\n"); |
| 1791 | goto drop_unlock; |
| 1792 | } |
| 1793 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 1794 | if (!priv->vif) { |
| 1795 | IWL_DEBUG_DROP("Dropping - !priv->vif\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1796 | goto drop_unlock; |
| 1797 | } |
| 1798 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1799 | if ((ctl->tx_rate->hw_value & 0xFF) == IWL_INVALID_RATE) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1800 | IWL_ERROR("ERROR: No TX rate available.\n"); |
| 1801 | goto drop_unlock; |
| 1802 | } |
| 1803 | |
| 1804 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 1805 | id = 0; |
| 1806 | |
| 1807 | fc = le16_to_cpu(hdr->frame_control); |
| 1808 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1809 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1810 | if (ieee80211_is_auth(fc)) |
| 1811 | IWL_DEBUG_TX("Sending AUTH frame\n"); |
| 1812 | else if (ieee80211_is_assoc_request(fc)) |
| 1813 | IWL_DEBUG_TX("Sending ASSOC frame\n"); |
| 1814 | else if (ieee80211_is_reassoc_request(fc)) |
| 1815 | IWL_DEBUG_TX("Sending REASSOC frame\n"); |
| 1816 | #endif |
| 1817 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 1818 | /* drop all data frame if we are not associated */ |
Gregory Greenman | 76f3915 | 2008-01-23 10:15:21 -0800 | [diff] [blame] | 1819 | if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) && |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1820 | (!iwl_is_associated(priv) || |
Reinette Chatre | a647724 | 2008-02-14 10:40:28 -0800 | [diff] [blame] | 1821 | ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && !priv->assoc_id) || |
Gregory Greenman | 76f3915 | 2008-01-23 10:15:21 -0800 | [diff] [blame] | 1822 | !priv->assoc_station_added)) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1823 | IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1824 | goto drop_unlock; |
| 1825 | } |
| 1826 | |
| 1827 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1828 | |
| 1829 | hdr_len = ieee80211_get_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1830 | |
| 1831 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1832 | sta_id = iwl4965_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1833 | if (sta_id == IWL_INVALID_STATION) { |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1834 | DECLARE_MAC_BUF(mac); |
| 1835 | |
| 1836 | IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n", |
| 1837 | print_mac(mac, hdr->addr1)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1838 | goto drop; |
| 1839 | } |
| 1840 | |
Guy Cohen | 07bc28e | 2008-04-23 17:15:03 -0700 | [diff] [blame] | 1841 | IWL_DEBUG_TX("station Id %d\n", sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1842 | |
| 1843 | qc = ieee80211_get_qos_ctrl(hdr); |
| 1844 | if (qc) { |
| 1845 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 1846 | seq_number = priv->stations[sta_id].tid[tid].seq_number & |
| 1847 | IEEE80211_SCTL_SEQ; |
| 1848 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 1849 | (hdr->seq_ctrl & |
| 1850 | __constant_cpu_to_le16(IEEE80211_SCTL_FRAG)); |
| 1851 | seq_number += 0x10; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1852 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1853 | /* aggregation is on for this <sta,tid> */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1854 | if (ctl->flags & IEEE80211_TXCTL_AMPDU) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1855 | txq_id = priv->stations[sta_id].tid[tid].agg.txq_id; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1856 | priv->stations[sta_id].tid[tid].tfds_in_queue++; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1857 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1858 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1859 | |
| 1860 | /* Descriptor for chosen Tx queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1861 | txq = &priv->txq[txq_id]; |
| 1862 | q = &txq->q; |
| 1863 | |
| 1864 | spin_lock_irqsave(&priv->lock, flags); |
| 1865 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1866 | /* Set up first empty TFD within this queue's circular TFD buffer */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1867 | tfd = &txq->bd[q->write_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1868 | memset(tfd, 0, sizeof(*tfd)); |
| 1869 | control_flags = (u32 *) tfd; |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1870 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1871 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1872 | /* Set up driver data for this TFD */ |
Tomas Winkler | 8567c63 | 2008-05-15 13:53:58 +0800 | [diff] [blame] | 1873 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1874 | txq->txb[q->write_ptr].skb[0] = skb; |
| 1875 | memcpy(&(txq->txb[q->write_ptr].status.control), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1876 | ctl, sizeof(struct ieee80211_tx_control)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1877 | |
| 1878 | /* 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] | 1879 | out_cmd = &txq->cmd[idx]; |
| 1880 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
| 1881 | memset(&out_cmd->cmd.tx, 0, sizeof(out_cmd->cmd.tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1882 | |
| 1883 | /* |
| 1884 | * Set up the Tx-command (not MAC!) header. |
| 1885 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 1886 | * after Tx, uCode's Tx response will return this value so driver can |
| 1887 | * locate the frame within the tx queue and do post-tx processing. |
| 1888 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1889 | out_cmd->hdr.cmd = REPLY_TX; |
| 1890 | 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] | 1891 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1892 | |
| 1893 | /* Copy MAC header from skb into command buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1894 | memcpy(out_cmd->cmd.tx.hdr, hdr, hdr_len); |
| 1895 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1896 | /* |
| 1897 | * Use the first empty entry in this queue's command buffer array |
| 1898 | * to contain the Tx command and MAC header concatenated together |
| 1899 | * (payload data will be in another buffer). |
| 1900 | * Size of this varies, due to varying MAC header length. |
| 1901 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 1902 | * of the MAC header (device reads on dword boundaries). |
| 1903 | * We'll tell device about this padding later. |
| 1904 | */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1905 | len = priv->hw_params.tx_cmd_len + |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1906 | sizeof(struct iwl_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1907 | |
| 1908 | len_org = len; |
| 1909 | len = (len + 3) & ~3; |
| 1910 | |
| 1911 | if (len_org != len) |
| 1912 | len_org = 1; |
| 1913 | else |
| 1914 | len_org = 0; |
| 1915 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1916 | /* Physical address of this Tx command's header (not MAC header!), |
| 1917 | * within command buffer array. */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1918 | txcmd_phys = txq->dma_addr_cmd + sizeof(struct iwl_cmd) * idx + |
| 1919 | offsetof(struct iwl_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1920 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1921 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 1922 | * first entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1923 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, txcmd_phys, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1924 | |
| 1925 | if (!(ctl->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT)) |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 1926 | iwl4965_build_tx_cmd_hwcrypto(priv, ctl, out_cmd, skb, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1927 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1928 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 1929 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1930 | len = skb->len - hdr_len; |
| 1931 | if (len) { |
| 1932 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 1933 | len, PCI_DMA_TODEVICE); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1934 | iwl4965_hw_txq_attach_buf_to_tfd(priv, tfd, phys_addr, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1937 | /* Tell 4965 about any 2-byte padding after MAC header */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1938 | if (len_org) |
| 1939 | out_cmd->cmd.tx.tx_flags |= TX_CMD_FLG_MH_PAD_MSK; |
| 1940 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1941 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1942 | len = (u16)skb->len; |
| 1943 | out_cmd->cmd.tx.len = cpu_to_le16(len); |
| 1944 | |
| 1945 | /* TODO need this for burst mode later on */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1946 | 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] | 1947 | |
| 1948 | /* set is_hcca to 0; it probably will never be implemented */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1949 | 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] | 1950 | |
Tomas Winkler | 19758be | 2008-03-12 16:58:51 -0700 | [diff] [blame] | 1951 | iwl_update_tx_stats(priv, fc, len); |
| 1952 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1953 | scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) + |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 1954 | offsetof(struct iwl4965_tx_cmd, scratch); |
| 1955 | out_cmd->cmd.tx.dram_lsb_ptr = cpu_to_le32(scratch_phys); |
| 1956 | out_cmd->cmd.tx.dram_msb_ptr = iwl_get_dma_hi_address(scratch_phys); |
| 1957 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1958 | if (!ieee80211_get_morefrag(hdr)) { |
| 1959 | txq->need_update = 1; |
| 1960 | if (qc) { |
| 1961 | u8 tid = (u8)(le16_to_cpu(*qc) & 0xf); |
| 1962 | priv->stations[sta_id].tid[tid].seq_number = seq_number; |
| 1963 | } |
| 1964 | } else { |
| 1965 | wait_write_ptr = 1; |
| 1966 | txq->need_update = 0; |
| 1967 | } |
| 1968 | |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1969 | iwl_print_hex_dump(priv, IWL_DL_TX, out_cmd->cmd.payload, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1970 | sizeof(out_cmd->cmd.tx)); |
| 1971 | |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1972 | 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] | 1973 | ieee80211_get_hdrlen(fc)); |
| 1974 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1975 | /* Set up entry for this TFD in Tx byte-count array */ |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 1976 | priv->cfg->ops->lib->txq_update_byte_cnt_tbl(priv, txq, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1977 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1978 | /* Tell device the write index *just past* this latest filled TFD */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 1979 | 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] | 1980 | rc = iwl_txq_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1981 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1982 | |
| 1983 | if (rc) |
| 1984 | return rc; |
| 1985 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 1986 | if ((iwl_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1987 | && priv->mac80211_registered) { |
| 1988 | if (wait_write_ptr) { |
| 1989 | spin_lock_irqsave(&priv->lock, flags); |
| 1990 | txq->need_update = 1; |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 1991 | iwl_txq_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1992 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1993 | } |
| 1994 | |
| 1995 | ieee80211_stop_queue(priv->hw, ctl->queue); |
| 1996 | } |
| 1997 | |
| 1998 | return 0; |
| 1999 | |
| 2000 | drop_unlock: |
| 2001 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2002 | drop: |
| 2003 | return -1; |
| 2004 | } |
| 2005 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2006 | static void iwl4965_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2007 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2008 | const struct ieee80211_supported_band *hw = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2009 | struct ieee80211_rate *rate; |
| 2010 | int i; |
| 2011 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 2012 | hw = iwl_get_hw_mode(priv, priv->band); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 2013 | if (!hw) { |
| 2014 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 2015 | return; |
| 2016 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2017 | |
| 2018 | priv->active_rate = 0; |
| 2019 | priv->active_rate_basic = 0; |
| 2020 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2021 | for (i = 0; i < hw->n_bitrates; i++) { |
| 2022 | rate = &(hw->bitrates[i]); |
| 2023 | if (rate->hw_value < IWL_RATE_COUNT) |
| 2024 | priv->active_rate |= (1 << rate->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 2028 | priv->active_rate, priv->active_rate_basic); |
| 2029 | |
| 2030 | /* |
| 2031 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 2032 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 2033 | * OFDM |
| 2034 | */ |
| 2035 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 2036 | priv->staging_rxon.cck_basic_rates = |
| 2037 | ((priv->active_rate_basic & |
| 2038 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2039 | else |
| 2040 | priv->staging_rxon.cck_basic_rates = |
| 2041 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 2042 | |
| 2043 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 2044 | priv->staging_rxon.ofdm_basic_rates = |
| 2045 | ((priv->active_rate_basic & |
| 2046 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 2047 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2048 | else |
| 2049 | priv->staging_rxon.ofdm_basic_rates = |
| 2050 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 2051 | } |
| 2052 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2053 | void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2054 | { |
| 2055 | unsigned long flags; |
| 2056 | |
| 2057 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 2058 | return; |
| 2059 | |
| 2060 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 2061 | disable_radio ? "OFF" : "ON"); |
| 2062 | |
| 2063 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2064 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2065 | /* FIXME: This is a workaround for AP */ |
| 2066 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 2067 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2068 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2069 | CSR_UCODE_SW_BIT_RFKILL); |
| 2070 | spin_unlock_irqrestore(&priv->lock, flags); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2071 | /* call the host command only if no hw rf-kill set */ |
Mohamed Abbas | 5900383 | 2008-04-15 16:01:46 -0700 | [diff] [blame] | 2072 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status) && |
| 2073 | iwl_is_ready(priv)) |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2074 | iwl4965_send_card_state(priv, |
| 2075 | CARD_STATE_CMD_DISABLE, |
| 2076 | 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2077 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2078 | |
| 2079 | /* make sure mac80211 stop sending Tx frame */ |
| 2080 | if (priv->mac80211_registered) |
| 2081 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2082 | } |
| 2083 | return; |
| 2084 | } |
| 2085 | |
| 2086 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2087 | 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] | 2088 | |
| 2089 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2090 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2091 | |
| 2092 | /* wake up ucode */ |
| 2093 | msleep(10); |
| 2094 | |
| 2095 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2096 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 2097 | if (!iwl_grab_nic_access(priv)) |
| 2098 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2099 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2100 | |
| 2101 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 2102 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 2103 | "disabled by HW switch\n"); |
| 2104 | return; |
| 2105 | } |
| 2106 | |
| 2107 | queue_work(priv->workqueue, &priv->restart); |
| 2108 | return; |
| 2109 | } |
| 2110 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2111 | #define IWL_PACKET_RETRY_TIME HZ |
| 2112 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2113 | 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] | 2114 | { |
| 2115 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 2116 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 2117 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 2118 | u16 *last_seq, *last_frag; |
| 2119 | unsigned long *last_time; |
| 2120 | |
| 2121 | switch (priv->iw_mode) { |
| 2122 | case IEEE80211_IF_TYPE_IBSS:{ |
| 2123 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2124 | struct iwl4965_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2125 | u8 *mac = header->addr2; |
| 2126 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 2127 | |
| 2128 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2129 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2130 | if (!compare_ether_addr(entry->mac, mac)) |
| 2131 | break; |
| 2132 | } |
| 2133 | if (p == &priv->ibss_mac_hash[index]) { |
| 2134 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 2135 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2136 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2137 | return 0; |
| 2138 | } |
| 2139 | memcpy(entry->mac, mac, ETH_ALEN); |
| 2140 | entry->seq_num = seq; |
| 2141 | entry->frag_num = frag; |
| 2142 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 2143 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2144 | return 0; |
| 2145 | } |
| 2146 | last_seq = &entry->seq_num; |
| 2147 | last_frag = &entry->frag_num; |
| 2148 | last_time = &entry->packet_time; |
| 2149 | break; |
| 2150 | } |
| 2151 | case IEEE80211_IF_TYPE_STA: |
| 2152 | last_seq = &priv->last_seq_num; |
| 2153 | last_frag = &priv->last_frag_num; |
| 2154 | last_time = &priv->last_packet_time; |
| 2155 | break; |
| 2156 | default: |
| 2157 | return 0; |
| 2158 | } |
| 2159 | if ((*last_seq == seq) && |
| 2160 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 2161 | if (*last_frag == frag) |
| 2162 | goto drop; |
| 2163 | if (*last_frag + 1 != frag) |
| 2164 | /* out-of-order fragment */ |
| 2165 | goto drop; |
| 2166 | } else |
| 2167 | *last_seq = seq; |
| 2168 | |
| 2169 | *last_frag = frag; |
| 2170 | *last_time = jiffies; |
| 2171 | return 0; |
| 2172 | |
| 2173 | drop: |
| 2174 | return 1; |
| 2175 | } |
| 2176 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2177 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2178 | |
| 2179 | #include "iwl-spectrum.h" |
| 2180 | |
| 2181 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 2182 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 2183 | #define TIME_UNIT 1024 |
| 2184 | |
| 2185 | /* |
| 2186 | * extended beacon time format |
| 2187 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 2188 | * the high 1 byte is the beacon counts |
| 2189 | * the lower 3 bytes is the time in usec within one beacon interval |
| 2190 | */ |
| 2191 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2192 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2193 | { |
| 2194 | u32 quot; |
| 2195 | u32 rem; |
| 2196 | u32 interval = beacon_interval * 1024; |
| 2197 | |
| 2198 | if (!interval || !usec) |
| 2199 | return 0; |
| 2200 | |
| 2201 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 2202 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 2203 | |
| 2204 | return (quot << 24) + rem; |
| 2205 | } |
| 2206 | |
| 2207 | /* base is usually what we get from ucode with each received frame, |
| 2208 | * the same as HW timer counter counting down |
| 2209 | */ |
| 2210 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2211 | 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] | 2212 | { |
| 2213 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 2214 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 2215 | u32 interval = beacon_interval * TIME_UNIT; |
| 2216 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 2217 | (addon & BEACON_TIME_MASK_HIGH); |
| 2218 | |
| 2219 | if (base_low > addon_low) |
| 2220 | res += base_low - addon_low; |
| 2221 | else if (base_low < addon_low) { |
| 2222 | res += interval + base_low - addon_low; |
| 2223 | res += (1 << 24); |
| 2224 | } else |
| 2225 | res += (1 << 24); |
| 2226 | |
| 2227 | return cpu_to_le32(res); |
| 2228 | } |
| 2229 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2230 | static int iwl4965_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2231 | struct ieee80211_measurement_params *params, |
| 2232 | u8 type) |
| 2233 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2234 | struct iwl4965_spectrum_cmd spectrum; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2235 | struct iwl_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2236 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2237 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 2238 | .data = (void *)&spectrum, |
| 2239 | .meta.flags = CMD_WANT_SKB, |
| 2240 | }; |
| 2241 | u32 add_time = le64_to_cpu(params->start_time); |
| 2242 | int rc; |
| 2243 | int spectrum_resp_status; |
| 2244 | int duration = le16_to_cpu(params->duration); |
| 2245 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2246 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2247 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2248 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2249 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 2250 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2251 | |
| 2252 | memset(&spectrum, 0, sizeof(spectrum)); |
| 2253 | |
| 2254 | spectrum.channel_count = cpu_to_le16(1); |
| 2255 | spectrum.flags = |
| 2256 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 2257 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 2258 | cmd.len = sizeof(spectrum); |
| 2259 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 2260 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2261 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2262 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2263 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2264 | add_time, |
| 2265 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 2266 | else |
| 2267 | spectrum.start_time = 0; |
| 2268 | |
| 2269 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 2270 | spectrum.channels[0].channel = params->channel; |
| 2271 | spectrum.channels[0].type = type; |
| 2272 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 2273 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 2274 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 2275 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2276 | rc = iwl_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2277 | if (rc) |
| 2278 | return rc; |
| 2279 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2280 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2281 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 2282 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 2283 | rc = -EIO; |
| 2284 | } |
| 2285 | |
| 2286 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 2287 | switch (spectrum_resp_status) { |
| 2288 | case 0: /* Command will be handled */ |
| 2289 | if (res->u.spectrum.id != 0xff) { |
| 2290 | IWL_DEBUG_INFO |
| 2291 | ("Replaced existing measurement: %d\n", |
| 2292 | res->u.spectrum.id); |
| 2293 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 2294 | } |
| 2295 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 2296 | rc = 0; |
| 2297 | break; |
| 2298 | |
| 2299 | case 1: /* Command will not be handled */ |
| 2300 | rc = -EAGAIN; |
| 2301 | break; |
| 2302 | } |
| 2303 | |
| 2304 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 2305 | |
| 2306 | return rc; |
| 2307 | } |
| 2308 | #endif |
| 2309 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2310 | static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv, |
Tomas Winkler | 8567c63 | 2008-05-15 13:53:58 +0800 | [diff] [blame] | 2311 | struct iwl_tx_info *tx_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2312 | { |
| 2313 | |
| 2314 | tx_sta->status.ack_signal = 0; |
| 2315 | tx_sta->status.excessive_retries = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2316 | |
| 2317 | if (in_interrupt()) |
| 2318 | ieee80211_tx_status_irqsafe(priv->hw, |
| 2319 | tx_sta->skb[0], &(tx_sta->status)); |
| 2320 | else |
| 2321 | ieee80211_tx_status(priv->hw, |
| 2322 | tx_sta->skb[0], &(tx_sta->status)); |
| 2323 | |
| 2324 | tx_sta->skb[0] = NULL; |
| 2325 | } |
| 2326 | |
| 2327 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2328 | * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2329 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2330 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 2331 | * need to be reclaimed. As result, some free space forms. If there is |
| 2332 | * enough free space (> low mark), wake the stack that feeds us. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2333 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2334 | 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] | 2335 | { |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 2336 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 2337 | struct iwl_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2338 | int nfreed = 0; |
| 2339 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 2340 | if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2341 | IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " |
| 2342 | "is out of range [0-%d] %d %d.\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2343 | index, q->n_bd, q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2344 | return 0; |
| 2345 | } |
| 2346 | |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2347 | for (index = iwl_queue_inc_wrap(index, q->n_bd); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2348 | q->read_ptr != index; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2349 | 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] | 2350 | if (txq_id != IWL_CMD_QUEUE_NUM) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2351 | iwl4965_txstatus_to_ieee(priv, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2352 | &(txq->txb[txq->q.read_ptr])); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 2353 | iwl_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2354 | } else if (nfreed > 1) { |
| 2355 | IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2356 | q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2357 | queue_work(priv->workqueue, &priv->restart); |
| 2358 | } |
| 2359 | nfreed++; |
| 2360 | } |
| 2361 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2362 | return nfreed; |
| 2363 | } |
| 2364 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2365 | static int iwl4965_is_tx_success(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2366 | { |
| 2367 | status &= TX_STATUS_MSK; |
| 2368 | return (status == TX_STATUS_SUCCESS) |
| 2369 | || (status == TX_STATUS_DIRECT_DONE); |
| 2370 | } |
| 2371 | |
| 2372 | /****************************************************************************** |
| 2373 | * |
| 2374 | * Generic RX handler implementations |
| 2375 | * |
| 2376 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2377 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2378 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2379 | static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2380 | struct ieee80211_hdr *hdr) |
| 2381 | { |
| 2382 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) |
| 2383 | return IWL_AP_ID; |
| 2384 | else { |
| 2385 | u8 *da = ieee80211_get_DA(hdr); |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 2386 | return iwl_find_station(priv, da); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2387 | } |
| 2388 | } |
| 2389 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2390 | static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr( |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2391 | struct iwl_priv *priv, int txq_id, int idx) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2392 | { |
| 2393 | if (priv->txq[txq_id].txb[idx].skb[0]) |
| 2394 | return (struct ieee80211_hdr *)priv->txq[txq_id]. |
| 2395 | txb[idx].skb[0]->data; |
| 2396 | return NULL; |
| 2397 | } |
| 2398 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2399 | 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] | 2400 | { |
| 2401 | __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + |
| 2402 | tx_resp->frame_count); |
| 2403 | return le32_to_cpu(*scd_ssn) & MAX_SN; |
| 2404 | |
| 2405 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2406 | |
| 2407 | /** |
| 2408 | * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue |
| 2409 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2410 | static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv, |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 2411 | struct iwl_ht_agg *agg, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2412 | struct iwl4965_tx_resp_agg *tx_resp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2413 | u16 start_idx) |
| 2414 | { |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2415 | u16 status; |
| 2416 | struct agg_tx_status *frame_status = &tx_resp->status; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2417 | struct ieee80211_tx_status *tx_status = NULL; |
| 2418 | struct ieee80211_hdr *hdr = NULL; |
| 2419 | int i, sh; |
| 2420 | int txq_id, idx; |
| 2421 | u16 seq; |
| 2422 | |
| 2423 | if (agg->wait_for_ba) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2424 | IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2425 | |
| 2426 | agg->frame_count = tx_resp->frame_count; |
| 2427 | agg->start_idx = start_idx; |
| 2428 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2429 | agg->bitmap = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2430 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2431 | /* # frames attempted by Tx command */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2432 | if (agg->frame_count == 1) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2433 | /* Only one frame was attempted; no block-ack will arrive */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2434 | status = le16_to_cpu(frame_status[0].status); |
| 2435 | seq = le16_to_cpu(frame_status[0].sequence); |
| 2436 | idx = SEQ_TO_INDEX(seq); |
| 2437 | txq_id = SEQ_TO_QUEUE(seq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2438 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2439 | /* FIXME: code repetition */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2440 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n", |
| 2441 | agg->frame_count, agg->start_idx, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2442 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2443 | tx_status = &(priv->txq[txq_id].txb[idx].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2444 | tx_status->retry_count = tx_resp->failure_frame; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2445 | tx_status->control.flags &= ~IEEE80211_TXCTL_AMPDU; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2446 | tx_status->flags = iwl4965_is_tx_success(status)? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2447 | IEEE80211_TX_STATUS_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 2448 | iwl4965_hwrate_to_tx_control(priv, |
| 2449 | le32_to_cpu(tx_resp->rate_n_flags), |
| 2450 | &tx_status->control); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2451 | /* FIXME: code repetition end */ |
| 2452 | |
| 2453 | IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", |
| 2454 | status & 0xff, tx_resp->failure_frame); |
| 2455 | IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2456 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2457 | |
| 2458 | agg->wait_for_ba = 0; |
| 2459 | } else { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2460 | /* Two or more frames were attempted; expect block-ack */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2461 | u64 bitmap = 0; |
| 2462 | int start = agg->start_idx; |
| 2463 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2464 | /* Construct bit-map of pending frames within Tx window */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2465 | for (i = 0; i < agg->frame_count; i++) { |
| 2466 | u16 sc; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2467 | status = le16_to_cpu(frame_status[i].status); |
| 2468 | seq = le16_to_cpu(frame_status[i].sequence); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2469 | idx = SEQ_TO_INDEX(seq); |
| 2470 | txq_id = SEQ_TO_QUEUE(seq); |
| 2471 | |
| 2472 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 2473 | AGG_TX_STATE_ABORT_MSK)) |
| 2474 | continue; |
| 2475 | |
| 2476 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
| 2477 | agg->frame_count, txq_id, idx); |
| 2478 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2479 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2480 | |
| 2481 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 2482 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
| 2483 | IWL_ERROR("BUG_ON idx doesn't match seq control" |
| 2484 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 2485 | idx, SEQ_TO_SN(sc), |
| 2486 | hdr->seq_ctrl); |
| 2487 | return -1; |
| 2488 | } |
| 2489 | |
| 2490 | IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
| 2491 | i, idx, SEQ_TO_SN(sc)); |
| 2492 | |
| 2493 | sh = idx - start; |
| 2494 | if (sh > 64) { |
| 2495 | sh = (start - idx) + 0xff; |
| 2496 | bitmap = bitmap << sh; |
| 2497 | sh = 0; |
| 2498 | start = idx; |
| 2499 | } else if (sh < -64) |
| 2500 | sh = 0xff - (start - idx); |
| 2501 | else if (sh < 0) { |
| 2502 | sh = start - idx; |
| 2503 | start = idx; |
| 2504 | bitmap = bitmap << sh; |
| 2505 | sh = 0; |
| 2506 | } |
| 2507 | bitmap |= (1 << sh); |
| 2508 | IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n", |
| 2509 | start, (u32)(bitmap & 0xFFFFFFFF)); |
| 2510 | } |
| 2511 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2512 | agg->bitmap = bitmap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2513 | agg->start_idx = start; |
| 2514 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2515 | 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] | 2516 | agg->frame_count, agg->start_idx, |
John W. Linville | 06501d2 | 2008-04-01 17:38:47 -0400 | [diff] [blame] | 2517 | (unsigned long long)agg->bitmap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2518 | |
| 2519 | if (bitmap) |
| 2520 | agg->wait_for_ba = 1; |
| 2521 | } |
| 2522 | return 0; |
| 2523 | } |
| 2524 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2525 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2526 | /** |
| 2527 | * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response |
| 2528 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2529 | static void iwl4965_rx_reply_tx(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2530 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2531 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2532 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2533 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 2534 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 2535 | int index = SEQ_TO_INDEX(sequence); |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 2536 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2537 | struct ieee80211_tx_status *tx_status; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2538 | struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2539 | u32 status = le32_to_cpu(tx_resp->status); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2540 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2541 | int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION; |
| 2542 | struct ieee80211_hdr *hdr; |
| 2543 | __le16 *qc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2544 | #endif |
| 2545 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 2546 | 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] | 2547 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 2548 | "is out of range [0-%d] %d %d\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2549 | index, txq->q.n_bd, txq->q.write_ptr, |
| 2550 | txq->q.read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2551 | return; |
| 2552 | } |
| 2553 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2554 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2555 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index); |
| 2556 | qc = ieee80211_get_qos_ctrl(hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2557 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2558 | if (qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2559 | tid = le16_to_cpu(*qc) & 0xf; |
| 2560 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2561 | sta_id = iwl4965_get_ra_sta_id(priv, hdr); |
| 2562 | if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) { |
| 2563 | IWL_ERROR("Station not known\n"); |
| 2564 | return; |
| 2565 | } |
| 2566 | |
| 2567 | if (txq->sched_retry) { |
| 2568 | const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp); |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 2569 | struct iwl_ht_agg *agg = NULL; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2570 | |
| 2571 | if (!qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2572 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2573 | |
| 2574 | agg = &priv->stations[sta_id].tid[tid].agg; |
| 2575 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2576 | iwl4965_tx_status_reply_tx(priv, agg, |
| 2577 | (struct iwl4965_tx_resp_agg *)tx_resp, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2578 | |
| 2579 | if ((tx_resp->frame_count == 1) && |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2580 | !iwl4965_is_tx_success(status)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2581 | /* TODO: send BAR */ |
| 2582 | } |
| 2583 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2584 | if (txq->q.read_ptr != (scd_ssn & 0xff)) { |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 2585 | int freed, ampdu_q; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 2586 | index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2587 | IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " |
| 2588 | "%d index %d\n", scd_ssn , index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2589 | freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
| 2590 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 2591 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 2592 | if (iwl_queue_space(&txq->q) > txq->q.low_mark && |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2593 | txq_id >= 0 && priv->mac80211_registered && |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 2594 | agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) { |
| 2595 | /* calculate mac80211 ampdu sw queue to wake */ |
| 2596 | ampdu_q = txq_id - IWL_BACK_QUEUE_FIRST_ID + |
| 2597 | priv->hw->queues; |
| 2598 | if (agg->state == IWL_AGG_OFF) |
| 2599 | ieee80211_wake_queue(priv->hw, txq_id); |
| 2600 | else |
| 2601 | ieee80211_wake_queue(priv->hw, ampdu_q); |
| 2602 | } |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2603 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2604 | } |
| 2605 | } else { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2606 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2607 | tx_status = &(txq->txb[txq->q.read_ptr].status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2608 | |
| 2609 | tx_status->retry_count = tx_resp->failure_frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2610 | tx_status->flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2611 | iwl4965_is_tx_success(status) ? IEEE80211_TX_STATUS_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 2612 | iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags), |
| 2613 | &tx_status->control); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2614 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2615 | 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] | 2616 | "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2617 | status, le32_to_cpu(tx_resp->rate_n_flags), |
| 2618 | tx_resp->failure_frame); |
| 2619 | |
| 2620 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 2621 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2622 | if (index != -1) { |
| 2623 | int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2624 | if (tid != MAX_TID_COUNT) |
| 2625 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 2626 | if (iwl_queue_space(&txq->q) > txq->q.low_mark && |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 2627 | (txq_id >= 0) && priv->mac80211_registered) |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2628 | ieee80211_wake_queue(priv->hw, txq_id); |
| 2629 | if (tid != MAX_TID_COUNT) |
| 2630 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2631 | } |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2632 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2633 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2634 | |
| 2635 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 2636 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 2637 | } |
| 2638 | |
| 2639 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2640 | static void iwl4965_rx_reply_alive(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2641 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2642 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2643 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2644 | struct iwl4965_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2645 | struct delayed_work *pwork; |
| 2646 | |
| 2647 | palive = &pkt->u.alive_frame; |
| 2648 | |
| 2649 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 2650 | "0x%01X 0x%01X\n", |
| 2651 | palive->is_valid, palive->ver_type, |
| 2652 | palive->ver_subtype); |
| 2653 | |
| 2654 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 2655 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 2656 | memcpy(&priv->card_alive_init, |
| 2657 | &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2658 | sizeof(struct iwl4965_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2659 | pwork = &priv->init_alive_start; |
| 2660 | } else { |
| 2661 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 2662 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2663 | sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2664 | pwork = &priv->alive_start; |
| 2665 | } |
| 2666 | |
| 2667 | /* We delay the ALIVE response by 5ms to |
| 2668 | * give the HW RF Kill time to activate... */ |
| 2669 | if (palive->is_valid == UCODE_VALID_OK) |
| 2670 | queue_delayed_work(priv->workqueue, pwork, |
| 2671 | msecs_to_jiffies(5)); |
| 2672 | else |
| 2673 | IWL_WARNING("uCode did not respond OK.\n"); |
| 2674 | } |
| 2675 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2676 | static void iwl4965_rx_reply_add_sta(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2677 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2678 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2679 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2680 | |
| 2681 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 2682 | return; |
| 2683 | } |
| 2684 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2685 | static void iwl4965_rx_reply_error(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2686 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2687 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2688 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2689 | |
| 2690 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 2691 | "seq 0x%04X ser 0x%08X\n", |
| 2692 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 2693 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 2694 | pkt->u.err_resp.cmd_id, |
| 2695 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 2696 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 2697 | } |
| 2698 | |
| 2699 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 2700 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2701 | 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] | 2702 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2703 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 2704 | struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2705 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2706 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 2707 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 2708 | rxon->channel = csa->channel; |
| 2709 | priv->staging_rxon.channel = csa->channel; |
| 2710 | } |
| 2711 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2712 | static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2713 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2714 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2715 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2716 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2717 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2718 | |
| 2719 | if (!report->state) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2720 | IWL_DEBUG(IWL_DL_11H, |
| 2721 | "Spectrum Measure Notification: Start\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2722 | return; |
| 2723 | } |
| 2724 | |
| 2725 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 2726 | priv->measurement_status |= MEASUREMENT_READY; |
| 2727 | #endif |
| 2728 | } |
| 2729 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2730 | static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2731 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2732 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2733 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2734 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2735 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2736 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 2737 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 2738 | #endif |
| 2739 | } |
| 2740 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2741 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2742 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2743 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2744 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2745 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 2746 | "notification for %s:\n", |
| 2747 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2748 | 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] | 2749 | } |
| 2750 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2751 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2752 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2753 | struct iwl_priv *priv = |
| 2754 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2755 | struct sk_buff *beacon; |
| 2756 | |
| 2757 | /* 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] | 2758 | beacon = ieee80211_beacon_get(priv->hw, priv->vif, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2759 | |
| 2760 | if (!beacon) { |
| 2761 | IWL_ERROR("update beacon failed\n"); |
| 2762 | return; |
| 2763 | } |
| 2764 | |
| 2765 | mutex_lock(&priv->mutex); |
| 2766 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 2767 | if (priv->ibss_beacon) |
| 2768 | dev_kfree_skb(priv->ibss_beacon); |
| 2769 | |
| 2770 | priv->ibss_beacon = beacon; |
| 2771 | mutex_unlock(&priv->mutex); |
| 2772 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2773 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2774 | } |
| 2775 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2776 | static void iwl4965_rx_beacon_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2777 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2778 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2779 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2780 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2781 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 2782 | 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] | 2783 | |
| 2784 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 2785 | "tsf %d %d rate %d\n", |
| 2786 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 2787 | beacon->beacon_notify_hdr.failure_frame, |
| 2788 | le32_to_cpu(beacon->ibss_mgr_status), |
| 2789 | le32_to_cpu(beacon->high_tsf), |
| 2790 | le32_to_cpu(beacon->low_tsf), rate); |
| 2791 | #endif |
| 2792 | |
| 2793 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 2794 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 2795 | queue_work(priv->workqueue, &priv->beacon_update); |
| 2796 | } |
| 2797 | |
| 2798 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2799 | static void iwl4965_rx_reply_scan(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2800 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2801 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2802 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2803 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2804 | struct iwl4965_scanreq_notification *notif = |
| 2805 | (struct iwl4965_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2806 | |
| 2807 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 2808 | #endif |
| 2809 | } |
| 2810 | |
| 2811 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2812 | static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2813 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2814 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2815 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2816 | struct iwl4965_scanstart_notification *notif = |
| 2817 | (struct iwl4965_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2818 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 2819 | IWL_DEBUG_SCAN("Scan start: " |
| 2820 | "%d [802.11%s] " |
| 2821 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 2822 | notif->channel, |
| 2823 | notif->band ? "bg" : "a", |
| 2824 | notif->tsf_high, |
| 2825 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 2826 | } |
| 2827 | |
| 2828 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2829 | static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2830 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2831 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2832 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2833 | struct iwl4965_scanresults_notification *notif = |
| 2834 | (struct iwl4965_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2835 | |
| 2836 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 2837 | "%d [802.11%s] " |
| 2838 | "(TSF: 0x%08X:%08X) - %d " |
| 2839 | "elapsed=%lu usec (%dms since last)\n", |
| 2840 | notif->channel, |
| 2841 | notif->band ? "bg" : "a", |
| 2842 | le32_to_cpu(notif->tsf_high), |
| 2843 | le32_to_cpu(notif->tsf_low), |
| 2844 | le32_to_cpu(notif->statistics[0]), |
| 2845 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 2846 | jiffies_to_msecs(elapsed_jiffies |
| 2847 | (priv->last_scan_jiffies, jiffies))); |
| 2848 | |
| 2849 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2850 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2854 | static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2855 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2856 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2857 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2858 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2859 | |
| 2860 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 2861 | scan_notif->scanned_channels, |
| 2862 | scan_notif->tsf_low, |
| 2863 | scan_notif->tsf_high, scan_notif->status); |
| 2864 | |
| 2865 | /* The HW is no longer scanning */ |
| 2866 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 2867 | |
| 2868 | /* The scan completion notification came in, so kill that timer... */ |
| 2869 | cancel_delayed_work(&priv->scan_check); |
| 2870 | |
| 2871 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 2872 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 2873 | jiffies_to_msecs(elapsed_jiffies |
| 2874 | (priv->scan_pass_start, jiffies))); |
| 2875 | |
| 2876 | /* Remove this scanned band from the list |
| 2877 | * of pending bands to scan */ |
| 2878 | priv->scan_bands--; |
| 2879 | |
| 2880 | /* If a request to abort was given, or the scan did not succeed |
| 2881 | * then we reset the scan state machine and terminate, |
| 2882 | * re-queuing another scan if one has been requested */ |
| 2883 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2884 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 2885 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2886 | } else { |
| 2887 | /* If there are more bands on this scan pass reschedule */ |
| 2888 | if (priv->scan_bands > 0) |
| 2889 | goto reschedule; |
| 2890 | } |
| 2891 | |
| 2892 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2893 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2894 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 2895 | |
| 2896 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2897 | |
| 2898 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 2899 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 2900 | |
| 2901 | queue_work(priv->workqueue, &priv->scan_completed); |
| 2902 | |
| 2903 | return; |
| 2904 | |
| 2905 | reschedule: |
| 2906 | priv->scan_pass_start = jiffies; |
| 2907 | queue_work(priv->workqueue, &priv->request_scan); |
| 2908 | } |
| 2909 | |
| 2910 | /* Handle notification from uCode that card's power state is changing |
| 2911 | * due to software, hardware, or critical temperature RFKILL */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2912 | static void iwl4965_rx_card_state_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2913 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2914 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2915 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2916 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 2917 | unsigned long status = priv->status; |
| 2918 | |
| 2919 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 2920 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 2921 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 2922 | |
| 2923 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 2924 | RF_CARD_DISABLED)) { |
| 2925 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2926 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2927 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 2928 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2929 | if (!iwl_grab_nic_access(priv)) { |
| 2930 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2931 | priv, HBUS_TARG_MBX_C, |
| 2932 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 2933 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2934 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2935 | } |
| 2936 | |
| 2937 | if (!(flags & RXON_CARD_DISABLED)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2938 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2939 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2940 | if (!iwl_grab_nic_access(priv)) { |
| 2941 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2942 | priv, HBUS_TARG_MBX_C, |
| 2943 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 2944 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2945 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2946 | } |
| 2947 | } |
| 2948 | |
| 2949 | if (flags & RF_CARD_DISABLED) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2950 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2951 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2952 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 2953 | if (!iwl_grab_nic_access(priv)) |
| 2954 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2955 | } |
| 2956 | } |
| 2957 | |
| 2958 | if (flags & HW_CARD_DISABLED) |
| 2959 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2960 | else |
| 2961 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2962 | |
| 2963 | |
| 2964 | if (flags & SW_CARD_DISABLED) |
| 2965 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2966 | else |
| 2967 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2968 | |
| 2969 | if (!(flags & RXON_CARD_DISABLED)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2970 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2971 | |
| 2972 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 2973 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 2974 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 2975 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 2976 | queue_work(priv->workqueue, &priv->rf_kill); |
| 2977 | else |
| 2978 | wake_up_interruptible(&priv->wait_command_queue); |
| 2979 | } |
| 2980 | |
| 2981 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2982 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2983 | * |
| 2984 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 2985 | * to the host. |
| 2986 | * |
| 2987 | * This function chains into the hardware specific files for them to setup |
| 2988 | * any hardware specific handlers as well. |
| 2989 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2990 | static void iwl4965_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2991 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2992 | priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive; |
| 2993 | priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta; |
| 2994 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 2995 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2996 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2997 | iwl4965_rx_spectrum_measure_notif; |
| 2998 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2999 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3000 | iwl4965_rx_pm_debug_statistics_notif; |
| 3001 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3002 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3003 | /* |
| 3004 | * The same handler is used for both the REPLY to a discrete |
| 3005 | * statistics request from the host as well as for the periodic |
| 3006 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3007 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3008 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
| 3009 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3010 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3011 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
| 3012 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3013 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3014 | iwl4965_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3015 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3016 | iwl4965_rx_scan_complete_notif; |
| 3017 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
| 3018 | priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3019 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3020 | /* Set up hardware specific Rx handlers */ |
Emmanuel Grumbach | d4789ef | 2008-04-24 11:55:20 -0700 | [diff] [blame] | 3021 | priv->cfg->ops->lib->rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3022 | } |
| 3023 | |
| 3024 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3025 | * 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] | 3026 | * @rxb: Rx buffer to reclaim |
| 3027 | * |
| 3028 | * If an Rx buffer has an async callback associated with it the callback |
| 3029 | * will be executed. The attached skb (if present) will only be freed |
| 3030 | * if the callback returns 1 |
| 3031 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3032 | static void iwl4965_tx_cmd_complete(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3033 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3034 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 3035 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3036 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3037 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3038 | int index = SEQ_TO_INDEX(sequence); |
| 3039 | int huge = sequence & SEQ_HUGE_FRAME; |
| 3040 | int cmd_index; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3041 | struct iwl_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3042 | |
| 3043 | /* If a Tx command is being handled and it isn't in the actual |
| 3044 | * command queue then there a command routing bug has been introduced |
| 3045 | * in the queue management code. */ |
| 3046 | if (txq_id != IWL_CMD_QUEUE_NUM) |
| 3047 | IWL_ERROR("Error wrong command queue %d command id 0x%X\n", |
| 3048 | txq_id, pkt->hdr.cmd); |
| 3049 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 3050 | |
| 3051 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 3052 | cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
| 3053 | |
| 3054 | /* Input error checking is done when commands are added to queue. */ |
| 3055 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 3056 | cmd->meta.source->u.skb = rxb->skb; |
| 3057 | rxb->skb = NULL; |
| 3058 | } else if (cmd->meta.u.callback && |
| 3059 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 3060 | rxb->skb = NULL; |
| 3061 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3062 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3063 | |
| 3064 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 3065 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3066 | wake_up_interruptible(&priv->wait_command_queue); |
| 3067 | } |
| 3068 | } |
| 3069 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3070 | /* |
| 3071 | * this should be called while priv->lock is locked |
| 3072 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3073 | static void __iwl_rx_replenish(struct iwl_priv *priv) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3074 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3075 | iwl_rx_allocate(priv); |
| 3076 | iwl_rx_queue_restock(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3077 | } |
| 3078 | |
| 3079 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3080 | /** |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3081 | * iwl_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3082 | * |
| 3083 | * Uses the priv->rx_handlers callback function array to invoke |
| 3084 | * the appropriate handlers, including command responses, |
| 3085 | * frame-received notifications, and other notifications. |
| 3086 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3087 | void iwl_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3088 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3089 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 3090 | struct iwl_rx_packet *pkt; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3091 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3092 | u32 r, i; |
| 3093 | int reclaim; |
| 3094 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3095 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 3096 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3097 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3098 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 3099 | * buffer that the driver may process (last buffer filled by ucode). */ |
Ron Rindjunsky | d67f548 | 2008-05-05 10:22:49 +0800 | [diff] [blame] | 3100 | r = priv->cfg->ops->lib->shared_mem_rx_idx(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3101 | i = rxq->read; |
| 3102 | |
| 3103 | /* Rx interrupt, but nothing sent from uCode */ |
| 3104 | if (i == r) |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3105 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3106 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3107 | if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3108 | fill_rx = 1; |
| 3109 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3110 | while (i != r) { |
| 3111 | rxb = rxq->queue[i]; |
| 3112 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3113 | /* 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] | 3114 | * then a bug has been introduced in the queue refilling |
| 3115 | * routines -- catch it here */ |
| 3116 | BUG_ON(rxb == NULL); |
| 3117 | |
| 3118 | rxq->queue[i] = NULL; |
| 3119 | |
| 3120 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3121 | priv->hw_params.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3122 | PCI_DMA_FROMDEVICE); |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 3123 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3124 | |
| 3125 | /* Reclaim a command buffer only if this packet is a response |
| 3126 | * to a (driver-originated) command. |
| 3127 | * If the packet (e.g. Rx frame) originated from uCode, |
| 3128 | * there is no command buffer to reclaim. |
| 3129 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 3130 | * but apparently a few don't get set; catch them here. */ |
| 3131 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 3132 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3133 | (pkt->hdr.cmd != REPLY_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 3134 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3135 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 3136 | (pkt->hdr.cmd != REPLY_TX); |
| 3137 | |
| 3138 | /* Based on type of command response or notification, |
| 3139 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3140 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3141 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3142 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r, |
| 3143 | i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3144 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 3145 | } else { |
| 3146 | /* No handling needed */ |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3147 | IWL_DEBUG(IWL_DL_RX, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3148 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 3149 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 3150 | pkt->hdr.cmd); |
| 3151 | } |
| 3152 | |
| 3153 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3154 | /* Invoke any callbacks, transfer the skb to caller, and |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3155 | * fire off the (possibly) blocking iwl_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3156 | * as we reclaim the driver command queue */ |
| 3157 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3158 | iwl4965_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3159 | else |
| 3160 | IWL_WARNING("Claim null rxb?\n"); |
| 3161 | } |
| 3162 | |
| 3163 | /* For now we just don't re-use anything. We can tweak this |
| 3164 | * later to try and re-use notification packets and SKBs that |
| 3165 | * fail to Rx correctly */ |
| 3166 | if (rxb->skb != NULL) { |
| 3167 | priv->alloc_rxb_skb--; |
| 3168 | dev_kfree_skb_any(rxb->skb); |
| 3169 | rxb->skb = NULL; |
| 3170 | } |
| 3171 | |
| 3172 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3173 | priv->hw_params.rx_buf_size, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 3174 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3175 | spin_lock_irqsave(&rxq->lock, flags); |
| 3176 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 3177 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 3178 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3179 | /* If there are a lot of unused frames, |
| 3180 | * restock the Rx queue so ucode wont assert. */ |
| 3181 | if (fill_rx) { |
| 3182 | count++; |
| 3183 | if (count >= 8) { |
| 3184 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3185 | __iwl_rx_replenish(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 3186 | count = 0; |
| 3187 | } |
| 3188 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | /* Backtrack one entry */ |
| 3192 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3193 | iwl_rx_queue_restock(priv); |
| 3194 | } |
| 3195 | /* Convert linear signal-to-noise ratio into dB */ |
| 3196 | static u8 ratio2dB[100] = { |
| 3197 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 3198 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 3199 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 3200 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 3201 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 3202 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 3203 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 3204 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 3205 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 3206 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 3207 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 3208 | }; |
| 3209 | |
| 3210 | /* Calculates a relative dB value from a ratio of linear |
| 3211 | * (i.e. not dB) signal levels. |
| 3212 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
| 3213 | int iwl4965_calc_db_from_ratio(int sig_ratio) |
| 3214 | { |
| 3215 | /* 1000:1 or higher just report as 60 dB */ |
| 3216 | if (sig_ratio >= 1000) |
| 3217 | return 60; |
| 3218 | |
| 3219 | /* 100:1 or higher, divide by 10 and use table, |
| 3220 | * add 20 dB to make up for divide by 10 */ |
| 3221 | if (sig_ratio >= 100) |
| 3222 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 3223 | |
| 3224 | /* We shouldn't see this */ |
| 3225 | if (sig_ratio < 1) |
| 3226 | return 0; |
| 3227 | |
| 3228 | /* Use table for ratios 1:1 - 99:1 */ |
| 3229 | return (int)ratio2dB[sig_ratio]; |
| 3230 | } |
| 3231 | |
| 3232 | #define PERFECT_RSSI (-20) /* dBm */ |
| 3233 | #define WORST_RSSI (-95) /* dBm */ |
| 3234 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 3235 | |
| 3236 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 3237 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 3238 | * about formulas used below. */ |
| 3239 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) |
| 3240 | { |
| 3241 | int sig_qual; |
| 3242 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 3243 | |
| 3244 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 3245 | * as indicator; formula is (signal dbm - noise dbm). |
| 3246 | * SNR at or above 40 is a great signal (100%). |
| 3247 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 3248 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 3249 | if (noise_dbm) { |
| 3250 | if (rssi_dbm - noise_dbm >= 40) |
| 3251 | return 100; |
| 3252 | else if (rssi_dbm < noise_dbm) |
| 3253 | return 0; |
| 3254 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 3255 | |
| 3256 | /* Else use just the signal level. |
| 3257 | * This formula is a least squares fit of data points collected and |
| 3258 | * compared with a reference system that had a percentage (%) display |
| 3259 | * for signal quality. */ |
| 3260 | } else |
| 3261 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 3262 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 3263 | (RSSI_RANGE * RSSI_RANGE); |
| 3264 | |
| 3265 | if (sig_qual > 100) |
| 3266 | sig_qual = 100; |
| 3267 | else if (sig_qual < 1) |
| 3268 | sig_qual = 0; |
| 3269 | |
| 3270 | return sig_qual; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3271 | } |
| 3272 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3273 | /** |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3274 | * iwl_txq_update_write_ptr - Send new write index to hardware |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3275 | */ |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3276 | static int iwl_txq_update_write_ptr(struct iwl_priv *priv, |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 3277 | struct iwl_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3278 | { |
| 3279 | u32 reg = 0; |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3280 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3281 | int txq_id = txq->q.id; |
| 3282 | |
| 3283 | if (txq->need_update == 0) |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3284 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3285 | |
| 3286 | /* if we're trying to save power */ |
| 3287 | if (test_bit(STATUS_POWER_PMI, &priv->status)) { |
| 3288 | /* wake up nic if it's powered down ... |
| 3289 | * uCode will wake up, and interrupt us again, so next |
| 3290 | * time we'll skip this part. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3291 | reg = iwl_read32(priv, CSR_UCODE_DRV_GP1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3292 | |
| 3293 | if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) { |
| 3294 | IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3295 | iwl_set_bit(priv, CSR_GP_CNTRL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3296 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3297 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3298 | } |
| 3299 | |
| 3300 | /* restore this queue's parameters in nic hardware. */ |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3301 | ret = iwl_grab_nic_access(priv); |
| 3302 | if (ret) |
| 3303 | return ret; |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3304 | iwl_write_direct32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3305 | txq->q.write_ptr | (txq_id << 8)); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3306 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3307 | |
| 3308 | /* else not in power-save mode, uCode will never sleep when we're |
| 3309 | * trying to tx (during RFKILL, we're not trying to tx). */ |
| 3310 | } else |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3311 | iwl_write32(priv, HBUS_TARG_WRPTR, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3312 | txq->q.write_ptr | (txq_id << 8)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3313 | |
| 3314 | txq->need_update = 0; |
| 3315 | |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3316 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3317 | } |
| 3318 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3319 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3320 | static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3321 | { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 3322 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3323 | DECLARE_MAC_BUF(mac); |
| 3324 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3325 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3326 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3327 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 3328 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 3329 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 3330 | le32_to_cpu(rxon->filter_flags)); |
| 3331 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 3332 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 3333 | rxon->ofdm_basic_rates); |
| 3334 | 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] | 3335 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 3336 | print_mac(mac, rxon->node_addr)); |
| 3337 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 3338 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3339 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 3340 | } |
| 3341 | #endif |
| 3342 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3343 | static void iwl4965_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3344 | { |
| 3345 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 3346 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3347 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3348 | } |
| 3349 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3350 | /* call this function to flush any scheduled tasklet */ |
| 3351 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
| 3352 | { |
| 3353 | /* wait to make sure we flush pedding tasklet*/ |
| 3354 | synchronize_irq(priv->pci_dev->irq); |
| 3355 | tasklet_kill(&priv->irq_tasklet); |
| 3356 | } |
| 3357 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3358 | static inline void iwl4965_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3359 | { |
| 3360 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 3361 | |
| 3362 | /* disable interrupts from uCode/NIC to host */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3363 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3364 | |
| 3365 | /* acknowledge/clear/reset any interrupts still pending |
| 3366 | * from uCode or flow handler (Rx/Tx DMA) */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3367 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 3368 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3369 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 3370 | } |
| 3371 | |
| 3372 | static const char *desc_lookup(int i) |
| 3373 | { |
| 3374 | switch (i) { |
| 3375 | case 1: |
| 3376 | return "FAIL"; |
| 3377 | case 2: |
| 3378 | return "BAD_PARAM"; |
| 3379 | case 3: |
| 3380 | return "BAD_CHECKSUM"; |
| 3381 | case 4: |
| 3382 | return "NMI_INTERRUPT"; |
| 3383 | case 5: |
| 3384 | return "SYSASSERT"; |
| 3385 | case 6: |
| 3386 | return "FATAL_ERROR"; |
| 3387 | } |
| 3388 | |
| 3389 | return "UNKNOWN"; |
| 3390 | } |
| 3391 | |
| 3392 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 3393 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 3394 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3395 | static void iwl4965_dump_nic_error_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3396 | { |
| 3397 | u32 data2, line; |
| 3398 | u32 desc, time, count, base, data1; |
| 3399 | u32 blink1, blink2, ilink1, ilink2; |
| 3400 | int rc; |
| 3401 | |
| 3402 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 3403 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3404 | if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3405 | IWL_ERROR("Not valid error log pointer 0x%08X\n", base); |
| 3406 | return; |
| 3407 | } |
| 3408 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3409 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3410 | if (rc) { |
| 3411 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 3412 | return; |
| 3413 | } |
| 3414 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3415 | count = iwl_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3416 | |
| 3417 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
| 3418 | IWL_ERROR("Start IWL Error Log Dump:\n"); |
Tomas Winkler | 2acae16 | 2008-03-02 01:25:59 +0200 | [diff] [blame] | 3419 | IWL_ERROR("Status: 0x%08lX, count: %d\n", priv->status, count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3420 | } |
| 3421 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3422 | desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32)); |
| 3423 | blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32)); |
| 3424 | blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32)); |
| 3425 | ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32)); |
| 3426 | ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32)); |
| 3427 | data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32)); |
| 3428 | data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32)); |
| 3429 | line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32)); |
| 3430 | time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3431 | |
| 3432 | IWL_ERROR("Desc Time " |
| 3433 | "data1 data2 line\n"); |
| 3434 | IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n", |
| 3435 | desc_lookup(desc), desc, time, data1, data2, line); |
| 3436 | IWL_ERROR("blink1 blink2 ilink1 ilink2\n"); |
| 3437 | IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2, |
| 3438 | ilink1, ilink2); |
| 3439 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3440 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3441 | } |
| 3442 | |
| 3443 | #define EVENT_START_OFFSET (4 * sizeof(u32)) |
| 3444 | |
| 3445 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3446 | * iwl4965_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3447 | * |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3448 | * NOTE: Must be called with iwl_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3449 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3450 | 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] | 3451 | u32 num_events, u32 mode) |
| 3452 | { |
| 3453 | u32 i; |
| 3454 | u32 base; /* SRAM byte address of event log header */ |
| 3455 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 3456 | u32 ptr; /* SRAM byte address of log data */ |
| 3457 | u32 ev, time, data; /* event log data */ |
| 3458 | |
| 3459 | if (num_events == 0) |
| 3460 | return; |
| 3461 | |
| 3462 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 3463 | |
| 3464 | if (mode == 0) |
| 3465 | event_size = 2 * sizeof(u32); |
| 3466 | else |
| 3467 | event_size = 3 * sizeof(u32); |
| 3468 | |
| 3469 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 3470 | |
| 3471 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 3472 | * place event id # at far right for easier visual parsing. */ |
| 3473 | for (i = 0; i < num_events; i++) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3474 | ev = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3475 | ptr += sizeof(u32); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3476 | time = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3477 | ptr += sizeof(u32); |
| 3478 | if (mode == 0) |
| 3479 | IWL_ERROR("0x%08x\t%04u\n", time, ev); /* data, ev */ |
| 3480 | else { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3481 | data = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3482 | ptr += sizeof(u32); |
| 3483 | IWL_ERROR("%010u\t0x%08x\t%04u\n", time, data, ev); |
| 3484 | } |
| 3485 | } |
| 3486 | } |
| 3487 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3488 | static void iwl4965_dump_nic_event_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3489 | { |
| 3490 | int rc; |
| 3491 | u32 base; /* SRAM byte address of event log header */ |
| 3492 | u32 capacity; /* event log capacity in # entries */ |
| 3493 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 3494 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 3495 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 3496 | u32 size; /* # entries that we'll print */ |
| 3497 | |
| 3498 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3499 | if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3500 | IWL_ERROR("Invalid event log pointer 0x%08X\n", base); |
| 3501 | return; |
| 3502 | } |
| 3503 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3504 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3505 | if (rc) { |
| 3506 | IWL_WARNING("Can not read from adapter at this time.\n"); |
| 3507 | return; |
| 3508 | } |
| 3509 | |
| 3510 | /* event log header */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3511 | capacity = iwl_read_targ_mem(priv, base); |
| 3512 | mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 3513 | num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 3514 | next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3515 | |
| 3516 | size = num_wraps ? capacity : next_entry; |
| 3517 | |
| 3518 | /* bail out if nothing in log */ |
| 3519 | if (size == 0) { |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 3520 | IWL_ERROR("Start IWL Event Log Dump: nothing in log\n"); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3521 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3522 | return; |
| 3523 | } |
| 3524 | |
Zhu Yi | 583fab3 | 2007-09-27 11:27:30 +0800 | [diff] [blame] | 3525 | 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] | 3526 | size, num_wraps); |
| 3527 | |
| 3528 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 3529 | * i.e the next one that uCode would fill. */ |
| 3530 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3531 | iwl4965_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3532 | capacity - next_entry, mode); |
| 3533 | |
| 3534 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3535 | iwl4965_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3536 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3537 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3538 | } |
| 3539 | |
| 3540 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3541 | * 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] | 3542 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3543 | static void iwl4965_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3544 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3545 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3546 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 3547 | |
| 3548 | /* Cancel currently queued command. */ |
| 3549 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 3550 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3551 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3552 | if (priv->debug_level & IWL_DL_FW_ERRORS) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3553 | iwl4965_dump_nic_error_log(priv); |
| 3554 | iwl4965_dump_nic_event_log(priv); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3555 | iwl4965_print_rx_config_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3556 | } |
| 3557 | #endif |
| 3558 | |
| 3559 | wake_up_interruptible(&priv->wait_command_queue); |
| 3560 | |
| 3561 | /* Keep the restart process from trying to send host |
| 3562 | * commands by clearing the INIT status bit */ |
| 3563 | clear_bit(STATUS_READY, &priv->status); |
| 3564 | |
| 3565 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3566 | IWL_DEBUG(IWL_DL_FW_ERRORS, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3567 | "Restarting adapter due to uCode error.\n"); |
| 3568 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3569 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3570 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 3571 | sizeof(priv->recovery_rxon)); |
| 3572 | priv->error_recovering = 1; |
| 3573 | } |
Ester Kummer | 3a1081e | 2008-05-06 11:05:14 +0800 | [diff] [blame] | 3574 | if (priv->cfg->mod_params->restart_fw) |
| 3575 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3576 | } |
| 3577 | } |
| 3578 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3579 | static void iwl4965_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3580 | { |
| 3581 | unsigned long flags; |
| 3582 | |
| 3583 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 3584 | sizeof(priv->staging_rxon)); |
| 3585 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3586 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3587 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3588 | iwl4965_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3589 | |
| 3590 | spin_lock_irqsave(&priv->lock, flags); |
| 3591 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 3592 | priv->error_recovering = 0; |
| 3593 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3594 | } |
| 3595 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3596 | static void iwl4965_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3597 | { |
| 3598 | u32 inta, handled = 0; |
| 3599 | u32 inta_fh; |
| 3600 | unsigned long flags; |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3601 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3602 | u32 inta_mask; |
| 3603 | #endif |
| 3604 | |
| 3605 | spin_lock_irqsave(&priv->lock, flags); |
| 3606 | |
| 3607 | /* Ack/clear/reset pending uCode interrupts. |
| 3608 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 3609 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3610 | inta = iwl_read32(priv, CSR_INT); |
| 3611 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3612 | |
| 3613 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 3614 | * Any new interrupts that happen after this, either while we're |
| 3615 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3616 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 3617 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3618 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3619 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3620 | if (priv->debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3621 | /* just for debug */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3622 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3623 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 3624 | inta, inta_mask, inta_fh); |
| 3625 | } |
| 3626 | #endif |
| 3627 | |
| 3628 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 3629 | * atomic, make sure that inta covers all the interrupts that |
| 3630 | * we've discovered, even if FH interrupt came in just after |
| 3631 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 3632 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3633 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 3634 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3635 | inta |= CSR_INT_BIT_FH_TX; |
| 3636 | |
| 3637 | /* Now service all interrupt bits discovered above. */ |
| 3638 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 3639 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 3640 | |
| 3641 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3642 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3643 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3644 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3645 | |
| 3646 | handled |= CSR_INT_BIT_HW_ERR; |
| 3647 | |
| 3648 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3649 | |
| 3650 | return; |
| 3651 | } |
| 3652 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3653 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3654 | if (priv->debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3655 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3656 | if (inta & CSR_INT_BIT_SCD) |
| 3657 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 3658 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3659 | |
| 3660 | /* Alive notification via Rx interrupt will do the real work */ |
| 3661 | if (inta & CSR_INT_BIT_ALIVE) |
| 3662 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 3663 | } |
| 3664 | #endif |
| 3665 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3666 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3667 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3668 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3669 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 3670 | int hw_rf_kill = 0; |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3671 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3672 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 3673 | hw_rf_kill = 1; |
| 3674 | |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3675 | 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] | 3676 | hw_rf_kill ? "disable radio":"enable radio"); |
| 3677 | |
| 3678 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 3679 | * when we loaded driver, and is now set to "enable". |
| 3680 | * After we're Alive, RF_KILL gets handled by |
Reinette Chatre | 3230455 | 2008-02-15 14:34:37 -0800 | [diff] [blame] | 3681 | * iwl4965_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 3682 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 3683 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3684 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 3685 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3686 | |
| 3687 | handled |= CSR_INT_BIT_RF_KILL; |
| 3688 | } |
| 3689 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3690 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3691 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 3692 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 3693 | handled |= CSR_INT_BIT_CT_KILL; |
| 3694 | } |
| 3695 | |
| 3696 | /* Error detected by uCode */ |
| 3697 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 3698 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 3699 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3700 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3701 | handled |= CSR_INT_BIT_SW_ERR; |
| 3702 | } |
| 3703 | |
| 3704 | /* uCode wakes up after power-down sleep */ |
| 3705 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 3706 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3707 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 3708 | iwl_txq_update_write_ptr(priv, &priv->txq[0]); |
| 3709 | iwl_txq_update_write_ptr(priv, &priv->txq[1]); |
| 3710 | iwl_txq_update_write_ptr(priv, &priv->txq[2]); |
| 3711 | iwl_txq_update_write_ptr(priv, &priv->txq[3]); |
| 3712 | iwl_txq_update_write_ptr(priv, &priv->txq[4]); |
| 3713 | iwl_txq_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3714 | |
| 3715 | handled |= CSR_INT_BIT_WAKEUP; |
| 3716 | } |
| 3717 | |
| 3718 | /* All uCode command responses, including Tx command responses, |
| 3719 | * Rx "responses" (frame-received notification), and other |
| 3720 | * notifications from uCode come through here*/ |
| 3721 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3722 | iwl_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3723 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 3724 | } |
| 3725 | |
| 3726 | if (inta & CSR_INT_BIT_FH_TX) { |
| 3727 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 3728 | handled |= CSR_INT_BIT_FH_TX; |
| 3729 | } |
| 3730 | |
| 3731 | if (inta & ~handled) |
| 3732 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 3733 | |
| 3734 | if (inta & ~CSR_INI_SET_MASK) { |
| 3735 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 3736 | inta & ~CSR_INI_SET_MASK); |
| 3737 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 3738 | } |
| 3739 | |
| 3740 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3741 | /* only Re-enable if diabled by irq */ |
| 3742 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 3743 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3744 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3745 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3746 | if (priv->debug_level & (IWL_DL_ISR)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3747 | inta = iwl_read32(priv, CSR_INT); |
| 3748 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 3749 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3750 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 3751 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 3752 | } |
| 3753 | #endif |
| 3754 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3755 | } |
| 3756 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3757 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3758 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3759 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3760 | u32 inta, inta_mask; |
| 3761 | u32 inta_fh; |
| 3762 | if (!priv) |
| 3763 | return IRQ_NONE; |
| 3764 | |
| 3765 | spin_lock(&priv->lock); |
| 3766 | |
| 3767 | /* Disable (but don't clear!) interrupts here to avoid |
| 3768 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 3769 | * If we have something to service, the tasklet will re-enable ints. |
| 3770 | * 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] | 3771 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 3772 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3773 | |
| 3774 | /* Discover which interrupts are active/pending */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3775 | inta = iwl_read32(priv, CSR_INT); |
| 3776 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3777 | |
| 3778 | /* Ignore interrupt if there's nothing in NIC to service. |
| 3779 | * This may be due to IRQ shared with another device, |
| 3780 | * or due to sporadic interrupts thrown from our NIC. */ |
| 3781 | if (!inta && !inta_fh) { |
| 3782 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 3783 | goto none; |
| 3784 | } |
| 3785 | |
| 3786 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 3787 | /* Hardware disappeared. It might have already raised |
| 3788 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3789 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 3790 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3791 | } |
| 3792 | |
| 3793 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 3794 | inta, inta_mask, inta_fh); |
| 3795 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3796 | inta &= ~CSR_INT_BIT_SCD; |
| 3797 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3798 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 3799 | if (likely(inta || inta_fh)) |
| 3800 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3801 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 3802 | unplugged: |
| 3803 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3804 | return IRQ_HANDLED; |
| 3805 | |
| 3806 | none: |
| 3807 | /* re-enable interrupts here since we don't have anything to service. */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3808 | /* only Re-enable if diabled by irq */ |
| 3809 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 3810 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3811 | spin_unlock(&priv->lock); |
| 3812 | return IRQ_NONE; |
| 3813 | } |
| 3814 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3815 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 3816 | * sending probe req. This should be set long enough to hear probe responses |
| 3817 | * from more than one AP. */ |
| 3818 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 3819 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 3820 | |
| 3821 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 3822 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 3823 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 3824 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 3825 | * no other traffic). |
| 3826 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 3827 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 3828 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 3829 | |
| 3830 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 3831 | * Must be set longer than active dwell time. |
| 3832 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 3833 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 3834 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 3835 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 3836 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 3837 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3838 | static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3839 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3840 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3841 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3842 | return IWL_ACTIVE_DWELL_TIME_52; |
| 3843 | else |
| 3844 | return IWL_ACTIVE_DWELL_TIME_24; |
| 3845 | } |
| 3846 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3847 | static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3848 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3849 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3850 | u16 active = iwl4965_get_active_dwell_time(priv, band); |
| 3851 | u16 passive = (band != IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3852 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 3853 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 3854 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3855 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3856 | /* If we're associated, we clamp the maximum passive |
| 3857 | * dwell time to be 98% of the beacon interval (minus |
| 3858 | * 2 * channel tune time) */ |
| 3859 | passive = priv->beacon_int; |
| 3860 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 3861 | passive = IWL_PASSIVE_DWELL_BASE; |
| 3862 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 3863 | } |
| 3864 | |
| 3865 | if (passive <= active) |
| 3866 | passive = active + 1; |
| 3867 | |
| 3868 | return passive; |
| 3869 | } |
| 3870 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3871 | static int iwl4965_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3872 | enum ieee80211_band band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3873 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3874 | struct iwl4965_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3875 | { |
| 3876 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3877 | const struct ieee80211_supported_band *sband; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3878 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3879 | u16 passive_dwell = 0; |
| 3880 | u16 active_dwell = 0; |
| 3881 | int added, i; |
| 3882 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 3883 | sband = iwl_get_hw_mode(priv, band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3884 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3885 | return 0; |
| 3886 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3887 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3888 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3889 | active_dwell = iwl4965_get_active_dwell_time(priv, band); |
| 3890 | passive_dwell = iwl4965_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3891 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3892 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 3893 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 3894 | continue; |
| 3895 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3896 | scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3897 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 3898 | ch_info = iwl_get_channel_info(priv, band, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3899 | scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3900 | if (!is_channel_valid(ch_info)) { |
| 3901 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 3902 | scan_ch->channel); |
| 3903 | continue; |
| 3904 | } |
| 3905 | |
| 3906 | if (!is_active || is_channel_passive(ch_info) || |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3907 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3908 | scan_ch->type = 0; /* passive */ |
| 3909 | else |
| 3910 | scan_ch->type = 1; /* active */ |
| 3911 | |
| 3912 | if (scan_ch->type & 1) |
| 3913 | scan_ch->type |= (direct_mask << 1); |
| 3914 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3915 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 3916 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 3917 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3918 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3919 | scan_ch->tpc.dsp_atten = 110; |
| 3920 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 3921 | |
| 3922 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3923 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3924 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 3925 | else { |
| 3926 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 3927 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3928 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 3929 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3930 | */ |
| 3931 | } |
| 3932 | |
| 3933 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 3934 | scan_ch->channel, |
| 3935 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 3936 | (scan_ch->type & 1) ? |
| 3937 | active_dwell : passive_dwell); |
| 3938 | |
| 3939 | scan_ch++; |
| 3940 | added++; |
| 3941 | } |
| 3942 | |
| 3943 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 3944 | return added; |
| 3945 | } |
| 3946 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3947 | /****************************************************************************** |
| 3948 | * |
| 3949 | * uCode download functions |
| 3950 | * |
| 3951 | ******************************************************************************/ |
| 3952 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3953 | static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3954 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3955 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 3956 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 3957 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 3958 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 3959 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 3960 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3961 | } |
| 3962 | |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 3963 | static void iwl4965_nic_start(struct iwl_priv *priv) |
| 3964 | { |
| 3965 | /* Remove all resets to allow NIC to operate */ |
| 3966 | iwl_write32(priv, CSR_RESET, 0); |
| 3967 | } |
| 3968 | |
| 3969 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3970 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3971 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3972 | * |
| 3973 | * Copy into buffers for card to fetch via bus-mastering |
| 3974 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3975 | static int iwl4965_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3976 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3977 | struct iwl4965_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3978 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3979 | const struct firmware *ucode_raw; |
Tomas Winkler | 4bf775c | 2008-03-04 18:09:31 -0800 | [diff] [blame] | 3980 | const char *name = priv->cfg->fw_name; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3981 | u8 *src; |
| 3982 | size_t len; |
| 3983 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 3984 | |
| 3985 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 3986 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3987 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 3988 | if (ret < 0) { |
| 3989 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 3990 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3991 | goto error; |
| 3992 | } |
| 3993 | |
| 3994 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 3995 | name, ucode_raw->size); |
| 3996 | |
| 3997 | /* Make sure that we got at least our header! */ |
| 3998 | if (ucode_raw->size < sizeof(*ucode)) { |
| 3999 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4000 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4001 | goto err_release; |
| 4002 | } |
| 4003 | |
| 4004 | /* Data from ucode file: header followed by uCode images */ |
| 4005 | ucode = (void *)ucode_raw->data; |
| 4006 | |
| 4007 | ver = le32_to_cpu(ucode->ver); |
| 4008 | inst_size = le32_to_cpu(ucode->inst_size); |
| 4009 | data_size = le32_to_cpu(ucode->data_size); |
| 4010 | init_size = le32_to_cpu(ucode->init_size); |
| 4011 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 4012 | boot_size = le32_to_cpu(ucode->boot_size); |
| 4013 | |
| 4014 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 4015 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 4016 | inst_size); |
| 4017 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 4018 | data_size); |
| 4019 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 4020 | init_size); |
| 4021 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 4022 | init_data_size); |
| 4023 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 4024 | boot_size); |
| 4025 | |
| 4026 | /* Verify size of file vs. image size info in file's header */ |
| 4027 | if (ucode_raw->size < sizeof(*ucode) + |
| 4028 | inst_size + data_size + init_size + |
| 4029 | init_data_size + boot_size) { |
| 4030 | |
| 4031 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 4032 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4033 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4034 | goto err_release; |
| 4035 | } |
| 4036 | |
| 4037 | /* Verify that uCode images will fit in card's SRAM */ |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4038 | if (inst_size > priv->hw_params.max_inst_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4039 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 4040 | inst_size); |
| 4041 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4042 | goto err_release; |
| 4043 | } |
| 4044 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4045 | if (data_size > priv->hw_params.max_data_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4046 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 4047 | data_size); |
| 4048 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4049 | goto err_release; |
| 4050 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4051 | if (init_size > priv->hw_params.max_inst_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4052 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4053 | ("uCode init instr len %d too large to fit in\n", |
| 4054 | init_size); |
| 4055 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4056 | goto err_release; |
| 4057 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4058 | if (init_data_size > priv->hw_params.max_data_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4059 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4060 | ("uCode init data len %d too large to fit in\n", |
| 4061 | init_data_size); |
| 4062 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4063 | goto err_release; |
| 4064 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4065 | if (boot_size > priv->hw_params.max_bsm_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4066 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4067 | ("uCode boot instr len %d too large to fit in\n", |
| 4068 | boot_size); |
| 4069 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4070 | goto err_release; |
| 4071 | } |
| 4072 | |
| 4073 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 4074 | |
| 4075 | /* Runtime instructions and 2 copies of data: |
| 4076 | * 1) unmodified from disk |
| 4077 | * 2) backup cache for save/restore during power-downs */ |
| 4078 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4079 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4080 | |
| 4081 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4082 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4083 | |
| 4084 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4085 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4086 | |
| 4087 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4088 | if (init_size && init_data_size) { |
| 4089 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4090 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4091 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4092 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4093 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4094 | |
| 4095 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 4096 | goto err_pci_alloc; |
| 4097 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4098 | |
| 4099 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4100 | if (boot_size) { |
| 4101 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 4102 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4103 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4104 | if (!priv->ucode_boot.v_addr) |
| 4105 | goto err_pci_alloc; |
| 4106 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4107 | |
| 4108 | /* Copy images into buffers for card's bus-master reads ... */ |
| 4109 | |
| 4110 | /* Runtime instructions (first block of data in file) */ |
| 4111 | src = &ucode->data[0]; |
| 4112 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4113 | 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] | 4114 | memcpy(priv->ucode_code.v_addr, src, len); |
| 4115 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 4116 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 4117 | |
| 4118 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4119 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4120 | src = &ucode->data[inst_size]; |
| 4121 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4122 | 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] | 4123 | memcpy(priv->ucode_data.v_addr, src, len); |
| 4124 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 4125 | |
| 4126 | /* Initialization instructions (3rd block) */ |
| 4127 | if (init_size) { |
| 4128 | src = &ucode->data[inst_size + data_size]; |
| 4129 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4130 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 4131 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4132 | memcpy(priv->ucode_init.v_addr, src, len); |
| 4133 | } |
| 4134 | |
| 4135 | /* Initialization data (4th block) */ |
| 4136 | if (init_data_size) { |
| 4137 | src = &ucode->data[inst_size + data_size + init_size]; |
| 4138 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4139 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 4140 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4141 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 4142 | } |
| 4143 | |
| 4144 | /* Bootstrap instructions (5th block) */ |
| 4145 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 4146 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4147 | 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] | 4148 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 4149 | |
| 4150 | /* We have our copies now, allow OS release its copies */ |
| 4151 | release_firmware(ucode_raw); |
| 4152 | return 0; |
| 4153 | |
| 4154 | err_pci_alloc: |
| 4155 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4156 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4157 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4158 | |
| 4159 | err_release: |
| 4160 | release_firmware(ucode_raw); |
| 4161 | |
| 4162 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 4163 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4164 | } |
| 4165 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4166 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4167 | * iwl4965_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4168 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4169 | * Alive gets handled by iwl4965_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4170 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4171 | static void iwl4965_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4172 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4173 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4174 | |
| 4175 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 4176 | |
| 4177 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 4178 | /* We had an error bringing up the hardware, so take it |
| 4179 | * all the way back down so we can try again */ |
| 4180 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 4181 | goto restart; |
| 4182 | } |
| 4183 | |
| 4184 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 4185 | * This is a paranoid check, because we would not have gotten the |
| 4186 | * "runtime" alive if code weren't properly loaded. */ |
Emmanuel Grumbach | b0692f2 | 2008-04-24 11:55:18 -0700 | [diff] [blame] | 4187 | if (iwl_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4188 | /* Runtime instruction load was bad; |
| 4189 | * take it all the way back down so we can try again */ |
| 4190 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 4191 | goto restart; |
| 4192 | } |
| 4193 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4194 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4195 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4196 | ret = priv->cfg->ops->lib->alive_notify(priv); |
| 4197 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4198 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4199 | ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4200 | goto restart; |
| 4201 | } |
| 4202 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4203 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4204 | set_bit(STATUS_ALIVE, &priv->status); |
| 4205 | |
| 4206 | /* Clear out the uCode error bit if it is set */ |
| 4207 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 4208 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4209 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4210 | return; |
| 4211 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4212 | ieee80211_start_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4213 | |
| 4214 | priv->active_rate = priv->rates_mask; |
| 4215 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 4216 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4217 | if (iwl_is_associated(priv)) { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 4218 | struct iwl_rxon_cmd *active_rxon = |
| 4219 | (struct iwl_rxon_cmd *)&priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4220 | |
| 4221 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 4222 | sizeof(priv->staging_rxon)); |
| 4223 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 4224 | } else { |
| 4225 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4226 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4227 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 4228 | } |
| 4229 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4230 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4231 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4232 | |
| 4233 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4234 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4235 | |
| 4236 | /* At this point, the NIC is initialized and operational */ |
| 4237 | priv->notif_missed_beacons = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4238 | |
| 4239 | iwl4965_rf_kill_ct_config(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4240 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 4241 | iwl_leds_register(priv); |
| 4242 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4243 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 4244 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4245 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4246 | |
| 4247 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4248 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4249 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 4250 | iwlcore_low_level_notify(priv, IWLCORE_START_EVT); |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 4251 | ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4252 | return; |
| 4253 | |
| 4254 | restart: |
| 4255 | queue_work(priv->workqueue, &priv->restart); |
| 4256 | } |
| 4257 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4258 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4259 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4260 | static void __iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4261 | { |
| 4262 | unsigned long flags; |
| 4263 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 4264 | struct ieee80211_conf *conf = NULL; |
| 4265 | |
| 4266 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 4267 | |
| 4268 | conf = ieee80211_get_hw_conf(priv->hw); |
| 4269 | |
| 4270 | if (!exit_pending) |
| 4271 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 4272 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 4273 | iwl_leds_unregister(priv); |
| 4274 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 4275 | iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT); |
| 4276 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4277 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4278 | |
| 4279 | /* Unblock any waiting calls */ |
| 4280 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 4281 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4282 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 4283 | * exiting the module */ |
| 4284 | if (!exit_pending) |
| 4285 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 4286 | |
| 4287 | /* stop and reset the on-board processor */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4288 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4289 | |
| 4290 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4291 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4292 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4293 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4294 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4295 | |
| 4296 | if (priv->mac80211_registered) |
| 4297 | ieee80211_stop_queues(priv->hw); |
| 4298 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4299 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4300 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4301 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4302 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 4303 | STATUS_RF_KILL_HW | |
| 4304 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 4305 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 4306 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 4307 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4308 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 4309 | STATUS_IN_SUSPEND; |
| 4310 | goto exit; |
| 4311 | } |
| 4312 | |
| 4313 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 4314 | * SUSPEND bits and continue taking the NIC down. */ |
| 4315 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 4316 | STATUS_RF_KILL_HW | |
| 4317 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 4318 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 4319 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 4320 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4321 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 4322 | STATUS_IN_SUSPEND | |
| 4323 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 4324 | STATUS_FW_ERROR; |
| 4325 | |
| 4326 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4327 | iwl_clear_bit(priv, CSR_GP_CNTRL, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 4328 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4329 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4330 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4331 | iwl4965_hw_txq_ctx_stop(priv); |
| 4332 | iwl4965_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4333 | |
| 4334 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4335 | if (!iwl_grab_nic_access(priv)) { |
| 4336 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4337 | APMG_CLK_VAL_DMA_CLK_RQT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4338 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4339 | } |
| 4340 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4341 | |
| 4342 | udelay(5); |
| 4343 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4344 | iwl4965_hw_nic_stop_master(priv); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4345 | iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4346 | iwl4965_hw_nic_reset(priv); |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 4347 | priv->cfg->ops->lib->free_shared_mem(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4348 | |
| 4349 | exit: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4350 | memset(&priv->card_alive, 0, sizeof(struct iwl4965_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4351 | |
| 4352 | if (priv->ibss_beacon) |
| 4353 | dev_kfree_skb(priv->ibss_beacon); |
| 4354 | priv->ibss_beacon = NULL; |
| 4355 | |
| 4356 | /* clear out any free frames */ |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 4357 | iwl_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4358 | } |
| 4359 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4360 | static void iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4361 | { |
| 4362 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4363 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4364 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 4365 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4366 | iwl4965_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4367 | } |
| 4368 | |
| 4369 | #define MAX_HW_RESTARTS 5 |
| 4370 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4371 | static int __iwl4965_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4372 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4373 | int i; |
| 4374 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4375 | |
| 4376 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 4377 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 4378 | return -EIO; |
| 4379 | } |
| 4380 | |
| 4381 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 4382 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 4383 | "parameter)\n"); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4384 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4385 | return -ENODEV; |
| 4386 | } |
| 4387 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 4388 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 4389 | IWL_ERROR("ucode not available for device bringup\n"); |
| 4390 | return -EIO; |
| 4391 | } |
| 4392 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4393 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4394 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4395 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 4396 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4397 | else { |
| 4398 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4399 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4400 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4401 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 4402 | return -ENODEV; |
| 4403 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4404 | } |
| 4405 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4406 | iwl_rfkill_set_hw_state(priv); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4407 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4408 | |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 4409 | ret = priv->cfg->ops->lib->alloc_shared_mem(priv); |
| 4410 | if (ret) { |
| 4411 | IWL_ERROR("Unable to allocate shared memory\n"); |
| 4412 | return ret; |
| 4413 | } |
| 4414 | |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 4415 | ret = iwl_hw_nic_init(priv); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4416 | if (ret) { |
| 4417 | IWL_ERROR("Unable to init nic\n"); |
| 4418 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4419 | } |
| 4420 | |
| 4421 | /* make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4422 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 4423 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4424 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 4425 | |
| 4426 | /* clear (again), then enable host interrupts */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4427 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4428 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4429 | |
| 4430 | /* really make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 4431 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 4432 | 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] | 4433 | |
| 4434 | /* Copy original ucode data image from disk into backup cache. |
| 4435 | * This will be used to initialize the on-board processor's |
| 4436 | * data SRAM for a clean start when the runtime program first loads. */ |
| 4437 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4438 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4439 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4440 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 4441 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4442 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4443 | |
| 4444 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 4445 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4446 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4447 | |
| 4448 | /* load bootstrap state machine, |
| 4449 | * load bootstrap program into processor's memory, |
| 4450 | * prepare to load the "initialize" uCode */ |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4451 | ret = priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4452 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4453 | if (ret) { |
| 4454 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4455 | continue; |
| 4456 | } |
| 4457 | |
| 4458 | /* start card; "initialize" will load runtime ucode */ |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 4459 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4460 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4461 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 4462 | |
| 4463 | return 0; |
| 4464 | } |
| 4465 | |
| 4466 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4467 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4468 | |
| 4469 | /* tried to restart and config the device for as long as our |
| 4470 | * patience could withstand */ |
| 4471 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 4472 | return -EIO; |
| 4473 | } |
| 4474 | |
| 4475 | |
| 4476 | /***************************************************************************** |
| 4477 | * |
| 4478 | * Workqueue callbacks |
| 4479 | * |
| 4480 | *****************************************************************************/ |
| 4481 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4482 | static void iwl4965_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4483 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4484 | struct iwl_priv *priv = |
| 4485 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4486 | |
| 4487 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4488 | return; |
| 4489 | |
| 4490 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | f3ccc08 | 2008-05-05 10:22:45 +0800 | [diff] [blame] | 4491 | priv->cfg->ops->lib->init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4492 | mutex_unlock(&priv->mutex); |
| 4493 | } |
| 4494 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4495 | static void iwl4965_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4496 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4497 | struct iwl_priv *priv = |
| 4498 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4499 | |
| 4500 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4501 | return; |
| 4502 | |
| 4503 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4504 | iwl4965_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4505 | mutex_unlock(&priv->mutex); |
| 4506 | } |
| 4507 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4508 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4509 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4510 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4511 | |
| 4512 | wake_up_interruptible(&priv->wait_command_queue); |
| 4513 | |
| 4514 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4515 | return; |
| 4516 | |
| 4517 | mutex_lock(&priv->mutex); |
| 4518 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4519 | if (!iwl_is_rfkill(priv)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 4520 | IWL_DEBUG(IWL_DL_RF_KILL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4521 | "HW and/or SW RF Kill no longer active, restarting " |
| 4522 | "device\n"); |
| 4523 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4524 | queue_work(priv->workqueue, &priv->restart); |
| 4525 | } else { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4526 | /* make sure mac80211 stop sending Tx frame */ |
| 4527 | if (priv->mac80211_registered) |
| 4528 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4529 | |
| 4530 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 4531 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 4532 | "disabled by SW switch\n"); |
| 4533 | else |
| 4534 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 4535 | "Kill switch must be turned off for " |
| 4536 | "wireless networking to work.\n"); |
| 4537 | } |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4538 | iwl_rfkill_set_hw_state(priv); |
| 4539 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4540 | mutex_unlock(&priv->mutex); |
| 4541 | } |
| 4542 | |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 4543 | static void iwl4965_bg_set_monitor(struct work_struct *work) |
| 4544 | { |
| 4545 | struct iwl_priv *priv = container_of(work, |
| 4546 | struct iwl_priv, set_monitor); |
| 4547 | |
| 4548 | IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n"); |
| 4549 | |
| 4550 | mutex_lock(&priv->mutex); |
| 4551 | |
| 4552 | if (!iwl_is_ready(priv)) |
| 4553 | IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n"); |
| 4554 | else |
| 4555 | if (iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR) != 0) |
| 4556 | IWL_ERROR("iwl4965_set_mode() failed\n"); |
| 4557 | |
| 4558 | mutex_unlock(&priv->mutex); |
| 4559 | } |
| 4560 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4561 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 4562 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4563 | static void iwl4965_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4564 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4565 | struct iwl_priv *priv = |
| 4566 | container_of(data, struct iwl_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4567 | |
| 4568 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4569 | return; |
| 4570 | |
| 4571 | mutex_lock(&priv->mutex); |
| 4572 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 4573 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 4574 | IWL_DEBUG(IWL_DL_SCAN, "Scan completion watchdog resetting " |
| 4575 | "adapter (%dms)\n", |
| 4576 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4577 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4578 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4579 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4580 | } |
| 4581 | mutex_unlock(&priv->mutex); |
| 4582 | } |
| 4583 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4584 | static void iwl4965_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4585 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4586 | struct iwl_priv *priv = |
| 4587 | container_of(data, struct iwl_priv, request_scan); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4588 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4589 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4590 | .len = sizeof(struct iwl4965_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4591 | .meta.flags = CMD_SIZE_HUGE, |
| 4592 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4593 | struct iwl4965_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4594 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 4595 | u16 cmd_len; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4596 | enum ieee80211_band band; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 4597 | u8 direct_mask; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4598 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4599 | |
| 4600 | conf = ieee80211_get_hw_conf(priv->hw); |
| 4601 | |
| 4602 | mutex_lock(&priv->mutex); |
| 4603 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4604 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4605 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 4606 | goto done; |
| 4607 | } |
| 4608 | |
| 4609 | /* Make sure the scan wasn't cancelled before this queued work |
| 4610 | * was given the chance to run... */ |
| 4611 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 4612 | goto done; |
| 4613 | |
| 4614 | /* This should never be called or scheduled if there is currently |
| 4615 | * a scan active in the hardware. */ |
| 4616 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 4617 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 4618 | "Ignoring second request.\n"); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4619 | ret = -EIO; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4620 | goto done; |
| 4621 | } |
| 4622 | |
| 4623 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 4624 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 4625 | goto done; |
| 4626 | } |
| 4627 | |
| 4628 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 4629 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 4630 | goto done; |
| 4631 | } |
| 4632 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4633 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4634 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 4635 | goto done; |
| 4636 | } |
| 4637 | |
| 4638 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 4639 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 4640 | goto done; |
| 4641 | } |
| 4642 | |
| 4643 | if (!priv->scan_bands) { |
| 4644 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 4645 | goto done; |
| 4646 | } |
| 4647 | |
| 4648 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4649 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4650 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 4651 | if (!priv->scan) { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4652 | ret = -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4653 | goto done; |
| 4654 | } |
| 4655 | } |
| 4656 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4657 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4658 | |
| 4659 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 4660 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 4661 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4662 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4663 | u16 interval = 0; |
| 4664 | u32 extra; |
| 4665 | u32 suspend_time = 100; |
| 4666 | u32 scan_suspend_time = 100; |
| 4667 | unsigned long flags; |
| 4668 | |
| 4669 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 4670 | |
| 4671 | spin_lock_irqsave(&priv->lock, flags); |
| 4672 | interval = priv->beacon_int; |
| 4673 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4674 | |
| 4675 | scan->suspend_time = 0; |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4676 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4677 | if (!interval) |
| 4678 | interval = suspend_time; |
| 4679 | |
| 4680 | extra = (suspend_time / interval) << 22; |
| 4681 | scan_suspend_time = (extra | |
| 4682 | ((suspend_time % interval) * 1024)); |
| 4683 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 4684 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 4685 | scan_suspend_time, interval); |
| 4686 | } |
| 4687 | |
| 4688 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 4689 | if (priv->one_direct_scan) { |
| 4690 | IWL_DEBUG_SCAN |
| 4691 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4692 | iwl4965_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4693 | priv->direct_ssid_len)); |
| 4694 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 4695 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 4696 | memcpy(scan->direct_scan[0].ssid, |
| 4697 | priv->direct_ssid, priv->direct_ssid_len); |
| 4698 | direct_mask = 1; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4699 | } else if (!iwl_is_associated(priv) && priv->essid_len) { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 4700 | IWL_DEBUG_SCAN |
| 4701 | ("Kicking off one direct scan for '%s' when not associated\n", |
| 4702 | iwl4965_escape_essid(priv->essid, priv->essid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4703 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 4704 | scan->direct_scan[0].len = priv->essid_len; |
| 4705 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 4706 | direct_mask = 1; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4707 | } else { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 4708 | IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4709 | direct_mask = 0; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4710 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4711 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4712 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 4713 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4714 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 4715 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4716 | |
| 4717 | switch (priv->scan_bands) { |
| 4718 | case 2: |
| 4719 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 4720 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4721 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4722 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 4723 | |
| 4724 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4725 | band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4726 | break; |
| 4727 | |
| 4728 | case 1: |
| 4729 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4730 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4731 | RATE_MCS_ANT_B_MSK); |
| 4732 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4733 | band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4734 | break; |
| 4735 | |
| 4736 | default: |
| 4737 | IWL_WARNING("Invalid scan band count\n"); |
| 4738 | goto done; |
| 4739 | } |
| 4740 | |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 4741 | /* We don't build a direct scan probe request; the uCode will do |
| 4742 | * that based on the direct_mask added to each channel entry */ |
| 4743 | cmd_len = iwl4965_fill_probe_req(priv, band, |
| 4744 | (struct ieee80211_mgmt *)scan->data, |
| 4745 | IWL_MAX_SCAN_SIZE - sizeof(*scan), 0); |
| 4746 | |
| 4747 | scan->tx_cmd.len = cpu_to_le16(cmd_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4748 | /* select Rx chains */ |
| 4749 | |
| 4750 | /* Force use of chains B and C (0x6) for scan Rx. |
| 4751 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 4752 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 4753 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 4754 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 4755 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 4756 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 4757 | |
| 4758 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 4759 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 4760 | |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 4761 | if (direct_mask) |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 4762 | scan->channel_count = |
| 4763 | iwl4965_get_channels_for_scan( |
| 4764 | priv, band, 1, /* active */ |
| 4765 | direct_mask, |
| 4766 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 4767 | else |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 4768 | scan->channel_count = |
| 4769 | iwl4965_get_channels_for_scan( |
| 4770 | priv, band, 0, /* passive */ |
| 4771 | direct_mask, |
| 4772 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4773 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4774 | scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | |
| 4775 | RXON_FILTER_BCON_AWARE_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4776 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4777 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4778 | cmd.data = scan; |
| 4779 | scan->len = cpu_to_le16(cmd.len); |
| 4780 | |
| 4781 | set_bit(STATUS_SCAN_HW, &priv->status); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4782 | ret = iwl_send_cmd_sync(priv, &cmd); |
| 4783 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4784 | goto done; |
| 4785 | |
| 4786 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 4787 | IWL_SCAN_CHECK_WATCHDOG); |
| 4788 | |
| 4789 | mutex_unlock(&priv->mutex); |
| 4790 | return; |
| 4791 | |
| 4792 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 4793 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4794 | queue_work(priv->workqueue, &priv->scan_completed); |
| 4795 | mutex_unlock(&priv->mutex); |
| 4796 | } |
| 4797 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4798 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4799 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4800 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4801 | |
| 4802 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4803 | return; |
| 4804 | |
| 4805 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4806 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4807 | mutex_unlock(&priv->mutex); |
| 4808 | } |
| 4809 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4810 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4811 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4812 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4813 | |
| 4814 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4815 | return; |
| 4816 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4817 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4818 | queue_work(priv->workqueue, &priv->up); |
| 4819 | } |
| 4820 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4821 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4822 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4823 | struct iwl_priv *priv = |
| 4824 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4825 | |
| 4826 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4827 | return; |
| 4828 | |
| 4829 | mutex_lock(&priv->mutex); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 4830 | iwl_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4831 | mutex_unlock(&priv->mutex); |
| 4832 | } |
| 4833 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4834 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 4835 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4836 | static void iwl4965_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4837 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4838 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4839 | int ret = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4840 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4841 | |
| 4842 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 4843 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 4844 | return; |
| 4845 | } |
| 4846 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4847 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 4848 | priv->assoc_id, |
| 4849 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4850 | |
| 4851 | |
| 4852 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4853 | return; |
| 4854 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4855 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4856 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4857 | return; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4858 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4859 | iwl4965_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4860 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4861 | conf = ieee80211_get_hw_conf(priv->hw); |
| 4862 | |
| 4863 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4864 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4865 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4866 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 4867 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4868 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4869 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4870 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4871 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 4872 | "Attempting to continue.\n"); |
| 4873 | |
| 4874 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 4875 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4876 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 4877 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 4878 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4879 | #endif /* CONFIG_IWL4965_HT*/ |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4880 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4881 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 4882 | |
| 4883 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 4884 | priv->assoc_id, priv->beacon_int); |
| 4885 | |
| 4886 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 4887 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4888 | else |
| 4889 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4890 | |
| 4891 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 4892 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 4893 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 4894 | else |
| 4895 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 4896 | |
| 4897 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 4898 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 4899 | |
| 4900 | } |
| 4901 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4902 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4903 | |
| 4904 | switch (priv->iw_mode) { |
| 4905 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4906 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4907 | break; |
| 4908 | |
| 4909 | case IEEE80211_IF_TYPE_IBSS: |
| 4910 | |
| 4911 | /* clear out the station table */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4912 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4913 | |
Tomas Winkler | 57bd1be | 2008-05-15 13:54:03 +0800 | [diff] [blame^] | 4914 | iwl4965_rxon_add_station(priv, iwl_bcast_addr, 0); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4915 | iwl4965_rxon_add_station(priv, priv->bssid, 0); |
| 4916 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
| 4917 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4918 | |
| 4919 | break; |
| 4920 | |
| 4921 | default: |
| 4922 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 4923 | __FUNCTION__, priv->iw_mode); |
| 4924 | break; |
| 4925 | } |
| 4926 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4927 | iwl4965_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4928 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4929 | /* Enable Rx differential gain and sensitivity calibrations */ |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 4930 | iwl_chain_noise_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4931 | priv->start_calib = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4932 | |
| 4933 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 4934 | priv->assoc_station_added = 1; |
| 4935 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4936 | iwl4965_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 4937 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4938 | iwl_power_update_mode(priv, 0); |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4939 | /* we have just associated, don't start scan too early */ |
| 4940 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4941 | } |
| 4942 | |
| 4943 | |
| 4944 | static void iwl4965_bg_post_associate(struct work_struct *data) |
| 4945 | { |
| 4946 | struct iwl_priv *priv = container_of(data, struct iwl_priv, |
| 4947 | post_associate.work); |
| 4948 | |
| 4949 | mutex_lock(&priv->mutex); |
| 4950 | iwl4965_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4951 | mutex_unlock(&priv->mutex); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4952 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4953 | } |
| 4954 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4955 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4956 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4957 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4958 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4959 | if (!iwl_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4960 | return; |
| 4961 | |
| 4962 | mutex_lock(&priv->mutex); |
| 4963 | |
| 4964 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4965 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4966 | |
| 4967 | mutex_unlock(&priv->mutex); |
| 4968 | } |
| 4969 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4970 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 4971 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4972 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4973 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4974 | struct iwl_priv *priv = |
| 4975 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4976 | |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 4977 | IWL_DEBUG(IWL_DL_SCAN, "SCAN complete scan\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4978 | |
| 4979 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4980 | return; |
| 4981 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 4982 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
| 4983 | iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4984 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4985 | ieee80211_scan_completed(priv->hw); |
| 4986 | |
| 4987 | /* Since setting the TXPOWER may have been deferred while |
| 4988 | * performing the scan, fire one off */ |
| 4989 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4990 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4991 | mutex_unlock(&priv->mutex); |
| 4992 | } |
| 4993 | |
| 4994 | /***************************************************************************** |
| 4995 | * |
| 4996 | * mac80211 entry point functions |
| 4997 | * |
| 4998 | *****************************************************************************/ |
| 4999 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5000 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 5001 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5002 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5003 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5004 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5005 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5006 | |
| 5007 | IWL_DEBUG_MAC80211("enter\n"); |
| 5008 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5009 | if (pci_enable_device(priv->pci_dev)) { |
| 5010 | IWL_ERROR("Fail to pci_enable_device\n"); |
| 5011 | return -ENODEV; |
| 5012 | } |
| 5013 | pci_restore_state(priv->pci_dev); |
| 5014 | pci_enable_msi(priv->pci_dev); |
| 5015 | |
| 5016 | ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, |
| 5017 | DRV_NAME, priv); |
| 5018 | if (ret) { |
| 5019 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 5020 | goto out_disable_msi; |
| 5021 | } |
| 5022 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5023 | /* we should be verifying the device is ready to be opened */ |
| 5024 | mutex_lock(&priv->mutex); |
| 5025 | |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 5026 | memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd)); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5027 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 5028 | * ucode filename and max sizes are card-specific. */ |
| 5029 | |
| 5030 | if (!priv->ucode_code.len) { |
| 5031 | ret = iwl4965_read_ucode(priv); |
| 5032 | if (ret) { |
| 5033 | IWL_ERROR("Could not read microcode: %d\n", ret); |
| 5034 | mutex_unlock(&priv->mutex); |
| 5035 | goto out_release_irq; |
| 5036 | } |
| 5037 | } |
| 5038 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5039 | ret = __iwl4965_up(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5040 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5041 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5042 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5043 | if (ret) |
| 5044 | goto out_release_irq; |
| 5045 | |
| 5046 | IWL_DEBUG_INFO("Start UP work done.\n"); |
| 5047 | |
| 5048 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 5049 | return 0; |
| 5050 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5051 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 5052 | * mac80211 will not be run successfully. */ |
| 5053 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 5054 | test_bit(STATUS_READY, &priv->status), |
| 5055 | UCODE_READY_TIMEOUT); |
| 5056 | if (!ret) { |
| 5057 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 5058 | IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n", |
| 5059 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 5060 | ret = -ETIMEDOUT; |
| 5061 | goto out_release_irq; |
| 5062 | } |
| 5063 | } |
| 5064 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5065 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5066 | IWL_DEBUG_MAC80211("leave\n"); |
| 5067 | return 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5068 | |
| 5069 | out_release_irq: |
| 5070 | free_irq(priv->pci_dev->irq, priv); |
| 5071 | out_disable_msi: |
| 5072 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5073 | pci_disable_device(priv->pci_dev); |
| 5074 | priv->is_open = 0; |
| 5075 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5076 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5077 | } |
| 5078 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5079 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5080 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5081 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5082 | |
| 5083 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5084 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5085 | if (!priv->is_open) { |
| 5086 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 5087 | return; |
| 5088 | } |
| 5089 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5090 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5091 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5092 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5093 | /* stop mac, cancel any scan request and clear |
| 5094 | * RXON_FILTER_ASSOC_MSK BIT |
| 5095 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5096 | mutex_lock(&priv->mutex); |
| 5097 | iwl4965_scan_cancel_timeout(priv, 100); |
| 5098 | cancel_delayed_work(&priv->post_associate); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5099 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5100 | } |
| 5101 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5102 | iwl4965_down(priv); |
| 5103 | |
| 5104 | flush_workqueue(priv->workqueue); |
| 5105 | free_irq(priv->pci_dev->irq, priv); |
| 5106 | pci_disable_msi(priv->pci_dev); |
| 5107 | pci_save_state(priv->pci_dev); |
| 5108 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5109 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5110 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5111 | } |
| 5112 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5113 | 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] | 5114 | struct ieee80211_tx_control *ctl) |
| 5115 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5116 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5117 | |
| 5118 | IWL_DEBUG_MAC80211("enter\n"); |
| 5119 | |
| 5120 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 5121 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 5122 | return -1; |
| 5123 | } |
| 5124 | |
| 5125 | 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] | 5126 | ctl->tx_rate->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5127 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5128 | if (iwl4965_tx_skb(priv, skb, ctl)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5129 | dev_kfree_skb_any(skb); |
| 5130 | |
| 5131 | IWL_DEBUG_MAC80211("leave\n"); |
| 5132 | return 0; |
| 5133 | } |
| 5134 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5135 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5136 | struct ieee80211_if_init_conf *conf) |
| 5137 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5138 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5139 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5140 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5141 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5142 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5143 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5144 | if (priv->vif) { |
| 5145 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Reinette Chatre | 75849d2 | 2008-01-23 10:15:17 -0800 | [diff] [blame] | 5146 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5147 | } |
| 5148 | |
| 5149 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5150 | priv->vif = conf->vif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5151 | |
| 5152 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5153 | |
| 5154 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 5155 | |
| 5156 | if (conf->mac_addr) { |
| 5157 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 5158 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 5159 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5160 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5161 | if (iwl_is_ready(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5162 | iwl4965_set_mode(priv, conf->type); |
| 5163 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5164 | mutex_unlock(&priv->mutex); |
| 5165 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5166 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5167 | return 0; |
| 5168 | } |
| 5169 | |
| 5170 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5171 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5172 | * |
| 5173 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 5174 | * be set inappropriately and the driver currently sets the hardware up to |
| 5175 | * use it whenever needed. |
| 5176 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5177 | 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] | 5178 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5179 | struct iwl_priv *priv = hw->priv; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5180 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5181 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5182 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5183 | |
| 5184 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5185 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5186 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 5187 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
| 5188 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5189 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5190 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5191 | ret = -EIO; |
| 5192 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5193 | } |
| 5194 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 5195 | if (unlikely(!priv->cfg->mod_params->disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5196 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 5197 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 5198 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5199 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 5200 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5201 | } |
| 5202 | |
| 5203 | spin_lock_irqsave(&priv->lock, flags); |
| 5204 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 5205 | ch_info = iwl_get_channel_info(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5206 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5207 | if (!is_channel_valid(ch_info)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5208 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 5209 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5210 | ret = -EINVAL; |
| 5211 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5212 | } |
| 5213 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5214 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5215 | /* if we are switching from ht to 2.4 clear flags |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5216 | * from any ht related info since 2.4 does not |
| 5217 | * support ht */ |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 5218 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5219 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 5220 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 5221 | #endif |
| 5222 | ) |
| 5223 | priv->staging_rxon.flags = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5224 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5225 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5226 | iwl_set_rxon_channel(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5227 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5228 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5229 | iwl4965_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5230 | |
| 5231 | /* The list of supported rates and rate mask can be different |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5232 | * for each band; since the band may have changed, reset |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5233 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5234 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5235 | |
| 5236 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5237 | |
| 5238 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 5239 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5240 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5241 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5242 | } |
| 5243 | #endif |
| 5244 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 5245 | if (priv->cfg->ops->lib->radio_kill_sw) |
| 5246 | priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5247 | |
| 5248 | if (!conf->radio_enabled) { |
| 5249 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5250 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5251 | } |
| 5252 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5253 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5254 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5255 | ret = -EIO; |
| 5256 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5257 | } |
| 5258 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5259 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5260 | |
| 5261 | if (memcmp(&priv->active_rxon, |
| 5262 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5263 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5264 | else |
| 5265 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 5266 | |
| 5267 | IWL_DEBUG_MAC80211("leave\n"); |
| 5268 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 5269 | out: |
| 5270 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5271 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 5272 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5273 | } |
| 5274 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5275 | static void iwl4965_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5276 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5277 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5278 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 5279 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5280 | return; |
| 5281 | |
| 5282 | /* The following should be done only at AP bring up */ |
| 5283 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 5284 | |
| 5285 | /* RXON - unassoc (to set timing command) */ |
| 5286 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5287 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5288 | |
| 5289 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5290 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 5291 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5292 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5293 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 5294 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5295 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 5296 | "Attempting to continue.\n"); |
| 5297 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5298 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5299 | |
| 5300 | /* FIXME: what should be the assoc_id for AP? */ |
| 5301 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 5302 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 5303 | priv->staging_rxon.flags |= |
| 5304 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5305 | else |
| 5306 | priv->staging_rxon.flags &= |
| 5307 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5308 | |
| 5309 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 5310 | if (priv->assoc_capability & |
| 5311 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 5312 | priv->staging_rxon.flags |= |
| 5313 | RXON_FLG_SHORT_SLOT_MSK; |
| 5314 | else |
| 5315 | priv->staging_rxon.flags &= |
| 5316 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 5317 | |
| 5318 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 5319 | priv->staging_rxon.flags &= |
| 5320 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 5321 | } |
| 5322 | /* restore RXON assoc */ |
| 5323 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5324 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5325 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 57bd1be | 2008-05-15 13:54:03 +0800 | [diff] [blame^] | 5326 | iwl4965_rxon_add_station(priv, iwl_bcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 5327 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5328 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5329 | |
| 5330 | /* FIXME - we need to add code here to detect a totally new |
| 5331 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 5332 | * clear sta table, add BCAST sta... */ |
| 5333 | } |
| 5334 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5335 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, |
| 5336 | struct ieee80211_vif *vif, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5337 | struct ieee80211_if_conf *conf) |
| 5338 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5339 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5340 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5341 | unsigned long flags; |
| 5342 | int rc; |
| 5343 | |
| 5344 | if (conf == NULL) |
| 5345 | return -EIO; |
| 5346 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 5347 | if (priv->vif != vif) { |
| 5348 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 5349 | return 0; |
| 5350 | } |
| 5351 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5352 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 5353 | (!conf->beacon || !conf->ssid_len)) { |
| 5354 | IWL_DEBUG_MAC80211 |
| 5355 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 5356 | return 0; |
| 5357 | } |
| 5358 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5359 | if (!iwl_is_alive(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5360 | return -EAGAIN; |
| 5361 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5362 | mutex_lock(&priv->mutex); |
| 5363 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5364 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5365 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 5366 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5367 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 5368 | /* |
| 5369 | * very dubious code was here; the probe filtering flag is never set: |
| 5370 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5371 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 5372 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 5373 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5374 | |
| 5375 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 5376 | if (!conf->bssid) { |
| 5377 | conf->bssid = priv->mac_addr; |
| 5378 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5379 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 5380 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5381 | } |
| 5382 | if (priv->ibss_beacon) |
| 5383 | dev_kfree_skb(priv->ibss_beacon); |
| 5384 | |
| 5385 | priv->ibss_beacon = conf->beacon; |
| 5386 | } |
| 5387 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5388 | if (iwl_is_rfkill(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5389 | goto done; |
| 5390 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5391 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 5392 | !is_multicast_ether_addr(conf->bssid)) { |
| 5393 | /* If there is currently a HW scan going on in the background |
| 5394 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5395 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5396 | IWL_WARNING("Aborted scan still in progress " |
| 5397 | "after 100ms\n"); |
| 5398 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 5399 | mutex_unlock(&priv->mutex); |
| 5400 | return -EAGAIN; |
| 5401 | } |
| 5402 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 5403 | |
| 5404 | /* TODO: Audit driver for usage of these members and see |
| 5405 | * if mac80211 deprecates them (priv->bssid looks like it |
| 5406 | * shouldn't be there, but I haven't scanned the IBSS code |
| 5407 | * to verify) - jpk */ |
| 5408 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 5409 | |
| 5410 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5411 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5412 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5413 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5414 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5415 | iwl4965_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5416 | priv, priv->active_rxon.bssid_addr, 1); |
| 5417 | } |
| 5418 | |
| 5419 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5420 | iwl4965_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5421 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5422 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5423 | } |
| 5424 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5425 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5426 | spin_lock_irqsave(&priv->lock, flags); |
| 5427 | if (!conf->ssid_len) |
| 5428 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 5429 | else |
| 5430 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 5431 | |
| 5432 | priv->essid_len = conf->ssid_len; |
| 5433 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5434 | |
| 5435 | IWL_DEBUG_MAC80211("leave\n"); |
| 5436 | mutex_unlock(&priv->mutex); |
| 5437 | |
| 5438 | return 0; |
| 5439 | } |
| 5440 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5441 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 5442 | unsigned int changed_flags, |
| 5443 | unsigned int *total_flags, |
| 5444 | int mc_count, struct dev_addr_list *mc_list) |
| 5445 | { |
| 5446 | /* |
| 5447 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5448 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 5449 | */ |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 5450 | struct iwl_priv *priv = hw->priv; |
| 5451 | int new_flags = 0; |
| 5452 | if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { |
| 5453 | if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { |
| 5454 | IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n", |
| 5455 | IEEE80211_IF_TYPE_MNTR, |
| 5456 | changed_flags, *total_flags); |
| 5457 | /* queue work 'cuz mac80211 is holding a lock which |
| 5458 | * prevents us from issuing (synchronous) f/w cmds */ |
| 5459 | queue_work(priv->workqueue, &priv->set_monitor); |
| 5460 | new_flags &= FIF_PROMISC_IN_BSS | |
| 5461 | FIF_OTHER_BSS | |
| 5462 | FIF_ALLMULTI; |
| 5463 | } |
| 5464 | } |
| 5465 | *total_flags = new_flags; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 5466 | } |
| 5467 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5468 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5469 | struct ieee80211_if_init_conf *conf) |
| 5470 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5471 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5472 | |
| 5473 | IWL_DEBUG_MAC80211("enter\n"); |
| 5474 | |
| 5475 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5476 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5477 | if (iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5478 | iwl4965_scan_cancel_timeout(priv, 100); |
| 5479 | cancel_delayed_work(&priv->post_associate); |
| 5480 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 5481 | iwl4965_commit_rxon(priv); |
| 5482 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5483 | if (priv->vif == conf->vif) { |
| 5484 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5485 | memset(priv->bssid, 0, ETH_ALEN); |
| 5486 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 5487 | priv->essid_len = 0; |
| 5488 | } |
| 5489 | mutex_unlock(&priv->mutex); |
| 5490 | |
| 5491 | IWL_DEBUG_MAC80211("leave\n"); |
| 5492 | |
| 5493 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5494 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5495 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5496 | static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, |
| 5497 | struct ieee80211_vif *vif, |
| 5498 | struct ieee80211_bss_conf *bss_conf, |
| 5499 | u32 changes) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5500 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5501 | struct iwl_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5502 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5503 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
| 5504 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5505 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5506 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
| 5507 | bss_conf->use_short_preamble); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5508 | if (bss_conf->use_short_preamble) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5509 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5510 | else |
| 5511 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 5512 | } |
| 5513 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5514 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5515 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5516 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5517 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 5518 | else |
| 5519 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 5520 | } |
| 5521 | |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 5522 | if (changes & BSS_CHANGED_HT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5523 | IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 5524 | iwl4965_ht_conf(priv, bss_conf); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5525 | iwl_set_rxon_chain(priv); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 5526 | } |
| 5527 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5528 | if (changes & BSS_CHANGED_ASSOC) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5529 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5530 | /* This should never happen as this function should |
| 5531 | * never be called from interrupt context. */ |
| 5532 | if (WARN_ON_ONCE(in_interrupt())) |
| 5533 | return; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5534 | if (bss_conf->assoc) { |
| 5535 | priv->assoc_id = bss_conf->aid; |
| 5536 | priv->beacon_int = bss_conf->beacon_int; |
| 5537 | priv->timestamp = bss_conf->timestamp; |
| 5538 | priv->assoc_capability = bss_conf->assoc_capability; |
| 5539 | priv->next_scan_jiffies = jiffies + |
| 5540 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 5541 | mutex_lock(&priv->mutex); |
| 5542 | iwl4965_post_associate(priv); |
| 5543 | mutex_unlock(&priv->mutex); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5544 | } else { |
| 5545 | priv->assoc_id = 0; |
| 5546 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); |
| 5547 | } |
| 5548 | } else if (changes && iwl_is_associated(priv) && priv->assoc_id) { |
| 5549 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 5550 | iwl_send_rxon_assoc(priv); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5551 | } |
| 5552 | |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 5553 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5554 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5555 | 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] | 5556 | { |
| 5557 | int rc = 0; |
| 5558 | unsigned long flags; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5559 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5560 | |
| 5561 | IWL_DEBUG_MAC80211("enter\n"); |
| 5562 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5563 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5564 | spin_lock_irqsave(&priv->lock, flags); |
| 5565 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5566 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5567 | rc = -EIO; |
| 5568 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 5569 | goto out_unlock; |
| 5570 | } |
| 5571 | |
| 5572 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 5573 | rc = -EIO; |
| 5574 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 5575 | goto out_unlock; |
| 5576 | } |
| 5577 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5578 | /* we don't schedule scan within next_scan_jiffies period */ |
| 5579 | if (priv->next_scan_jiffies && |
| 5580 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 5581 | rc = -EAGAIN; |
| 5582 | goto out_unlock; |
| 5583 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5584 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5585 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 5586 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5587 | rc = -EAGAIN; |
| 5588 | goto out_unlock; |
| 5589 | } |
| 5590 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 5591 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5592 | iwl4965_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5593 | |
| 5594 | priv->one_direct_scan = 1; |
| 5595 | priv->direct_ssid_len = (u8) |
| 5596 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 5597 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5598 | } else |
| 5599 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5600 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5601 | rc = iwl4965_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5602 | |
| 5603 | IWL_DEBUG_MAC80211("leave\n"); |
| 5604 | |
| 5605 | out_unlock: |
| 5606 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5607 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5608 | |
| 5609 | return rc; |
| 5610 | } |
| 5611 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5612 | static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 5613 | struct ieee80211_key_conf *keyconf, const u8 *addr, |
| 5614 | u32 iv32, u16 *phase1key) |
| 5615 | { |
| 5616 | struct iwl_priv *priv = hw->priv; |
| 5617 | u8 sta_id = IWL_INVALID_STATION; |
| 5618 | unsigned long flags; |
| 5619 | __le16 key_flags = 0; |
| 5620 | int i; |
| 5621 | DECLARE_MAC_BUF(mac); |
| 5622 | |
| 5623 | IWL_DEBUG_MAC80211("enter\n"); |
| 5624 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 5625 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5626 | if (sta_id == IWL_INVALID_STATION) { |
| 5627 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 5628 | print_mac(mac, addr)); |
| 5629 | return; |
| 5630 | } |
| 5631 | |
| 5632 | iwl4965_scan_cancel_timeout(priv, 100); |
| 5633 | |
| 5634 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); |
| 5635 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 5636 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 5637 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 5638 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5639 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 5640 | |
| 5641 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 5642 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5643 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 5644 | priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; |
| 5645 | |
| 5646 | for (i = 0; i < 5; i++) |
| 5647 | priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = |
| 5648 | cpu_to_le16(phase1key[i]); |
| 5649 | |
| 5650 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 5651 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 5652 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 5653 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5654 | |
| 5655 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 5656 | |
| 5657 | IWL_DEBUG_MAC80211("leave\n"); |
| 5658 | } |
| 5659 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5660 | 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] | 5661 | const u8 *local_addr, const u8 *addr, |
| 5662 | struct ieee80211_key_conf *key) |
| 5663 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5664 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 5665 | DECLARE_MAC_BUF(mac); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5666 | int ret = 0; |
| 5667 | u8 sta_id = IWL_INVALID_STATION; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5668 | u8 is_default_wep_key = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5669 | |
| 5670 | IWL_DEBUG_MAC80211("enter\n"); |
| 5671 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 5672 | if (priv->hw_params.sw_crypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5673 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 5674 | return -EOPNOTSUPP; |
| 5675 | } |
| 5676 | |
| 5677 | if (is_zero_ether_addr(addr)) |
| 5678 | /* only support pairwise keys */ |
| 5679 | return -EOPNOTSUPP; |
| 5680 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 5681 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5682 | if (sta_id == IWL_INVALID_STATION) { |
| 5683 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 5684 | print_mac(mac, addr)); |
| 5685 | return -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5686 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5687 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5688 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5689 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5690 | iwl4965_scan_cancel_timeout(priv, 100); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5691 | mutex_unlock(&priv->mutex); |
| 5692 | |
| 5693 | /* If we are getting WEP group key and we didn't receive any key mapping |
| 5694 | * so far, we are in legacy wep mode (group key only), otherwise we are |
| 5695 | * in 1X mode. |
| 5696 | * In legacy wep mode, we use another host command to the uCode */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 5697 | 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] | 5698 | priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 5699 | if (cmd == SET_KEY) |
| 5700 | is_default_wep_key = !priv->key_mapping_key; |
| 5701 | else |
| 5702 | is_default_wep_key = priv->default_wep_key; |
| 5703 | } |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5704 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5705 | switch (cmd) { |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5706 | case SET_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5707 | if (is_default_wep_key) |
| 5708 | ret = iwl_set_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5709 | else |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 5710 | ret = iwl_set_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5711 | |
| 5712 | IWL_DEBUG_MAC80211("enable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5713 | break; |
| 5714 | case DISABLE_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 5715 | if (is_default_wep_key) |
| 5716 | ret = iwl_remove_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5717 | else |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 5718 | ret = iwl_remove_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5719 | |
| 5720 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5721 | break; |
| 5722 | default: |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5723 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5724 | } |
| 5725 | |
| 5726 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5727 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 5728 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5729 | } |
| 5730 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 5731 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5732 | const struct ieee80211_tx_queue_params *params) |
| 5733 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5734 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5735 | unsigned long flags; |
| 5736 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5737 | |
| 5738 | IWL_DEBUG_MAC80211("enter\n"); |
| 5739 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5740 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5741 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 5742 | return -EIO; |
| 5743 | } |
| 5744 | |
| 5745 | if (queue >= AC_NUM) { |
| 5746 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 5747 | return 0; |
| 5748 | } |
| 5749 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5750 | if (!priv->qos_data.qos_enable) { |
| 5751 | priv->qos_data.qos_active = 0; |
| 5752 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 5753 | return 0; |
| 5754 | } |
| 5755 | q = AC_NUM - 1 - queue; |
| 5756 | |
| 5757 | spin_lock_irqsave(&priv->lock, flags); |
| 5758 | |
| 5759 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 5760 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 5761 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 5762 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 5763 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5764 | |
| 5765 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 5766 | priv->qos_data.qos_active = 1; |
| 5767 | |
| 5768 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5769 | |
| 5770 | mutex_lock(&priv->mutex); |
| 5771 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5772 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5773 | else if (priv->assoc_id && iwl_is_associated(priv)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5774 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5775 | |
| 5776 | mutex_unlock(&priv->mutex); |
| 5777 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5778 | IWL_DEBUG_MAC80211("leave\n"); |
| 5779 | return 0; |
| 5780 | } |
| 5781 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5782 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5783 | struct ieee80211_tx_queue_stats *stats) |
| 5784 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5785 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5786 | int i, avail; |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 5787 | struct iwl_tx_queue *txq; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 5788 | struct iwl_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5789 | unsigned long flags; |
| 5790 | |
| 5791 | IWL_DEBUG_MAC80211("enter\n"); |
| 5792 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5793 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5794 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 5795 | return -EIO; |
| 5796 | } |
| 5797 | |
| 5798 | spin_lock_irqsave(&priv->lock, flags); |
| 5799 | |
| 5800 | for (i = 0; i < AC_NUM; i++) { |
| 5801 | txq = &priv->txq[i]; |
| 5802 | q = &txq->q; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 5803 | avail = iwl_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5804 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 5805 | stats[i].len = q->n_window - avail; |
| 5806 | stats[i].limit = q->n_window - q->high_mark; |
| 5807 | stats[i].count = q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5808 | |
| 5809 | } |
| 5810 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5811 | |
| 5812 | IWL_DEBUG_MAC80211("leave\n"); |
| 5813 | |
| 5814 | return 0; |
| 5815 | } |
| 5816 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5817 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5818 | struct ieee80211_low_level_stats *stats) |
| 5819 | { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 5820 | struct iwl_priv *priv = hw->priv; |
| 5821 | |
| 5822 | priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5823 | IWL_DEBUG_MAC80211("enter\n"); |
| 5824 | IWL_DEBUG_MAC80211("leave\n"); |
| 5825 | |
| 5826 | return 0; |
| 5827 | } |
| 5828 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5829 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5830 | { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 5831 | struct iwl_priv *priv; |
| 5832 | |
| 5833 | priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5834 | IWL_DEBUG_MAC80211("enter\n"); |
| 5835 | IWL_DEBUG_MAC80211("leave\n"); |
| 5836 | |
| 5837 | return 0; |
| 5838 | } |
| 5839 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5840 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5841 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5842 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5843 | unsigned long flags; |
| 5844 | |
| 5845 | mutex_lock(&priv->mutex); |
| 5846 | IWL_DEBUG_MAC80211("enter\n"); |
| 5847 | |
| 5848 | priv->lq_mngr.lq_ready = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5849 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5850 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 5851 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5852 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5853 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5854 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5855 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5856 | |
| 5857 | cancel_delayed_work(&priv->post_associate); |
| 5858 | |
| 5859 | spin_lock_irqsave(&priv->lock, flags); |
| 5860 | priv->assoc_id = 0; |
| 5861 | priv->assoc_capability = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5862 | priv->assoc_station_added = 0; |
| 5863 | |
| 5864 | /* new association get rid of ibss beacon skb */ |
| 5865 | if (priv->ibss_beacon) |
| 5866 | dev_kfree_skb(priv->ibss_beacon); |
| 5867 | |
| 5868 | priv->ibss_beacon = NULL; |
| 5869 | |
| 5870 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 5871 | priv->timestamp = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5872 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 5873 | priv->beacon_int = 0; |
| 5874 | |
| 5875 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5876 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5877 | if (!iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 5878 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 5879 | mutex_unlock(&priv->mutex); |
| 5880 | return; |
| 5881 | } |
| 5882 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5883 | /* we are restarting association process |
| 5884 | * clear RXON_FILTER_ASSOC_MSK bit |
| 5885 | */ |
| 5886 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5887 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5888 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5889 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5890 | } |
| 5891 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 5892 | iwl_power_update_mode(priv, 0); |
| 5893 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5894 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 5895 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 5896 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5897 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 5898 | mutex_unlock(&priv->mutex); |
| 5899 | return; |
| 5900 | } |
| 5901 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5902 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5903 | |
| 5904 | mutex_unlock(&priv->mutex); |
| 5905 | |
| 5906 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5907 | } |
| 5908 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5909 | 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] | 5910 | struct ieee80211_tx_control *control) |
| 5911 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5912 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5913 | unsigned long flags; |
| 5914 | |
| 5915 | mutex_lock(&priv->mutex); |
| 5916 | IWL_DEBUG_MAC80211("enter\n"); |
| 5917 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5918 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5919 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 5920 | mutex_unlock(&priv->mutex); |
| 5921 | return -EIO; |
| 5922 | } |
| 5923 | |
| 5924 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 5925 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 5926 | mutex_unlock(&priv->mutex); |
| 5927 | return -EIO; |
| 5928 | } |
| 5929 | |
| 5930 | spin_lock_irqsave(&priv->lock, flags); |
| 5931 | |
| 5932 | if (priv->ibss_beacon) |
| 5933 | dev_kfree_skb(priv->ibss_beacon); |
| 5934 | |
| 5935 | priv->ibss_beacon = skb; |
| 5936 | |
| 5937 | priv->assoc_id = 0; |
| 5938 | |
| 5939 | IWL_DEBUG_MAC80211("leave\n"); |
| 5940 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5941 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5942 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5943 | |
| 5944 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 5945 | |
| 5946 | mutex_unlock(&priv->mutex); |
| 5947 | |
| 5948 | return 0; |
| 5949 | } |
| 5950 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5951 | /***************************************************************************** |
| 5952 | * |
| 5953 | * sysfs attributes |
| 5954 | * |
| 5955 | *****************************************************************************/ |
| 5956 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 5957 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5958 | |
| 5959 | /* |
| 5960 | * The following adds a new attribute to the sysfs representation |
| 5961 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 5962 | * used for controlling the debug level. |
| 5963 | * |
| 5964 | * See the level definitions in iwl for details. |
| 5965 | */ |
| 5966 | |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5967 | static ssize_t show_debug_level(struct device *d, |
| 5968 | struct device_attribute *attr, char *buf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5969 | { |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5970 | struct iwl_priv *priv = d->driver_data; |
| 5971 | |
| 5972 | return sprintf(buf, "0x%08X\n", priv->debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5973 | } |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5974 | static ssize_t store_debug_level(struct device *d, |
| 5975 | struct device_attribute *attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5976 | const char *buf, size_t count) |
| 5977 | { |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5978 | struct iwl_priv *priv = d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5979 | char *p = (char *)buf; |
| 5980 | u32 val; |
| 5981 | |
| 5982 | val = simple_strtoul(p, &p, 0); |
| 5983 | if (p == buf) |
| 5984 | printk(KERN_INFO DRV_NAME |
| 5985 | ": %s is not in hex or decimal form.\n", buf); |
| 5986 | else |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5987 | priv->debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5988 | |
| 5989 | return strnlen(buf, count); |
| 5990 | } |
| 5991 | |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5992 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 5993 | show_debug_level, store_debug_level); |
| 5994 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5995 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 5996 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5997 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5998 | |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 5999 | static ssize_t show_version(struct device *d, |
| 6000 | struct device_attribute *attr, char *buf) |
| 6001 | { |
| 6002 | struct iwl_priv *priv = d->driver_data; |
| 6003 | struct iwl4965_alive_resp *palive = &priv->card_alive; |
| 6004 | |
| 6005 | if (palive->is_valid) |
| 6006 | return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n" |
| 6007 | "fw type: 0x%01X 0x%01X\n", |
| 6008 | palive->ucode_major, palive->ucode_minor, |
| 6009 | palive->sw_rev[0], palive->sw_rev[1], |
| 6010 | palive->ver_type, palive->ver_subtype); |
| 6011 | |
| 6012 | else |
| 6013 | return sprintf(buf, "fw not loaded\n"); |
| 6014 | } |
| 6015 | |
| 6016 | static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL); |
| 6017 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6018 | static ssize_t show_temperature(struct device *d, |
| 6019 | struct device_attribute *attr, char *buf) |
| 6020 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6021 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6022 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6023 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6024 | return -EAGAIN; |
| 6025 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6026 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6027 | } |
| 6028 | |
| 6029 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 6030 | |
| 6031 | static ssize_t show_rs_window(struct device *d, |
| 6032 | struct device_attribute *attr, |
| 6033 | char *buf) |
| 6034 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6035 | struct iwl_priv *priv = d->driver_data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6036 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6037 | } |
| 6038 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 6039 | |
| 6040 | static ssize_t show_tx_power(struct device *d, |
| 6041 | struct device_attribute *attr, char *buf) |
| 6042 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6043 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6044 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 6045 | } |
| 6046 | |
| 6047 | static ssize_t store_tx_power(struct device *d, |
| 6048 | struct device_attribute *attr, |
| 6049 | const char *buf, size_t count) |
| 6050 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6051 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6052 | char *p = (char *)buf; |
| 6053 | u32 val; |
| 6054 | |
| 6055 | val = simple_strtoul(p, &p, 10); |
| 6056 | if (p == buf) |
| 6057 | printk(KERN_INFO DRV_NAME |
| 6058 | ": %s is not in decimal form.\n", buf); |
| 6059 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6060 | iwl4965_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6061 | |
| 6062 | return count; |
| 6063 | } |
| 6064 | |
| 6065 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 6066 | |
| 6067 | static ssize_t show_flags(struct device *d, |
| 6068 | struct device_attribute *attr, char *buf) |
| 6069 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6070 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6071 | |
| 6072 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 6073 | } |
| 6074 | |
| 6075 | static ssize_t store_flags(struct device *d, |
| 6076 | struct device_attribute *attr, |
| 6077 | const char *buf, size_t count) |
| 6078 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6079 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6080 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 6081 | |
| 6082 | mutex_lock(&priv->mutex); |
| 6083 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 6084 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6085 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6086 | IWL_WARNING("Could not cancel scan.\n"); |
| 6087 | else { |
| 6088 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 6089 | flags); |
| 6090 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6091 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6092 | } |
| 6093 | } |
| 6094 | mutex_unlock(&priv->mutex); |
| 6095 | |
| 6096 | return count; |
| 6097 | } |
| 6098 | |
| 6099 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 6100 | |
| 6101 | static ssize_t show_filter_flags(struct device *d, |
| 6102 | struct device_attribute *attr, char *buf) |
| 6103 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6104 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6105 | |
| 6106 | return sprintf(buf, "0x%04X\n", |
| 6107 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 6108 | } |
| 6109 | |
| 6110 | static ssize_t store_filter_flags(struct device *d, |
| 6111 | struct device_attribute *attr, |
| 6112 | const char *buf, size_t count) |
| 6113 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6114 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6115 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 6116 | |
| 6117 | mutex_lock(&priv->mutex); |
| 6118 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 6119 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6120 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6121 | IWL_WARNING("Could not cancel scan.\n"); |
| 6122 | else { |
| 6123 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 6124 | "0x%04X\n", filter_flags); |
| 6125 | priv->staging_rxon.filter_flags = |
| 6126 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6127 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6128 | } |
| 6129 | } |
| 6130 | mutex_unlock(&priv->mutex); |
| 6131 | |
| 6132 | return count; |
| 6133 | } |
| 6134 | |
| 6135 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 6136 | store_filter_flags); |
| 6137 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6138 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6139 | |
| 6140 | static ssize_t show_measurement(struct device *d, |
| 6141 | struct device_attribute *attr, char *buf) |
| 6142 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6143 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6144 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6145 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 6146 | u8 *data = (u8 *) & measure_report; |
| 6147 | unsigned long flags; |
| 6148 | |
| 6149 | spin_lock_irqsave(&priv->lock, flags); |
| 6150 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 6151 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6152 | return 0; |
| 6153 | } |
| 6154 | memcpy(&measure_report, &priv->measure_report, size); |
| 6155 | priv->measurement_status = 0; |
| 6156 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6157 | |
| 6158 | while (size && (PAGE_SIZE - len)) { |
| 6159 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 6160 | PAGE_SIZE - len, 1); |
| 6161 | len = strlen(buf); |
| 6162 | if (PAGE_SIZE - len) |
| 6163 | buf[len++] = '\n'; |
| 6164 | |
| 6165 | ofs += 16; |
| 6166 | size -= min(size, 16U); |
| 6167 | } |
| 6168 | |
| 6169 | return len; |
| 6170 | } |
| 6171 | |
| 6172 | static ssize_t store_measurement(struct device *d, |
| 6173 | struct device_attribute *attr, |
| 6174 | const char *buf, size_t count) |
| 6175 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6176 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6177 | struct ieee80211_measurement_params params = { |
| 6178 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 6179 | .start_time = cpu_to_le64(priv->last_tsf), |
| 6180 | .duration = cpu_to_le16(1), |
| 6181 | }; |
| 6182 | u8 type = IWL_MEASURE_BASIC; |
| 6183 | u8 buffer[32]; |
| 6184 | u8 channel; |
| 6185 | |
| 6186 | if (count) { |
| 6187 | char *p = buffer; |
| 6188 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 6189 | channel = simple_strtoul(p, NULL, 0); |
| 6190 | if (channel) |
| 6191 | params.channel = channel; |
| 6192 | |
| 6193 | p = buffer; |
| 6194 | while (*p && *p != ' ') |
| 6195 | p++; |
| 6196 | if (*p) |
| 6197 | type = simple_strtoul(p + 1, NULL, 0); |
| 6198 | } |
| 6199 | |
| 6200 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 6201 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6202 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6203 | |
| 6204 | return count; |
| 6205 | } |
| 6206 | |
| 6207 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 6208 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6209 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6210 | |
| 6211 | static ssize_t store_retry_rate(struct device *d, |
| 6212 | struct device_attribute *attr, |
| 6213 | const char *buf, size_t count) |
| 6214 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6215 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6216 | |
| 6217 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 6218 | if (priv->retry_rate <= 0) |
| 6219 | priv->retry_rate = 1; |
| 6220 | |
| 6221 | return count; |
| 6222 | } |
| 6223 | |
| 6224 | static ssize_t show_retry_rate(struct device *d, |
| 6225 | struct device_attribute *attr, char *buf) |
| 6226 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6227 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6228 | return sprintf(buf, "%d", priv->retry_rate); |
| 6229 | } |
| 6230 | |
| 6231 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 6232 | store_retry_rate); |
| 6233 | |
| 6234 | static ssize_t store_power_level(struct device *d, |
| 6235 | struct device_attribute *attr, |
| 6236 | const char *buf, size_t count) |
| 6237 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6238 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6239 | int rc; |
| 6240 | int mode; |
| 6241 | |
| 6242 | mode = simple_strtoul(buf, NULL, 0); |
| 6243 | mutex_lock(&priv->mutex); |
| 6244 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6245 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6246 | rc = -EAGAIN; |
| 6247 | goto out; |
| 6248 | } |
| 6249 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 6250 | rc = iwl_power_set_user_mode(priv, mode); |
| 6251 | if (rc) { |
| 6252 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 6253 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6254 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6255 | rc = count; |
| 6256 | |
| 6257 | out: |
| 6258 | mutex_unlock(&priv->mutex); |
| 6259 | return rc; |
| 6260 | } |
| 6261 | |
| 6262 | #define MAX_WX_STRING 80 |
| 6263 | |
| 6264 | /* Values are in microsecond */ |
| 6265 | static const s32 timeout_duration[] = { |
| 6266 | 350000, |
| 6267 | 250000, |
| 6268 | 75000, |
| 6269 | 37000, |
| 6270 | 25000, |
| 6271 | }; |
| 6272 | static const s32 period_duration[] = { |
| 6273 | 400000, |
| 6274 | 700000, |
| 6275 | 1000000, |
| 6276 | 1000000, |
| 6277 | 1000000 |
| 6278 | }; |
| 6279 | |
| 6280 | static ssize_t show_power_level(struct device *d, |
| 6281 | struct device_attribute *attr, char *buf) |
| 6282 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6283 | struct iwl_priv *priv = dev_get_drvdata(d); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 6284 | int level = priv->power_data.power_mode; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6285 | char *p = buf; |
| 6286 | |
| 6287 | p += sprintf(p, "%d ", level); |
| 6288 | switch (level) { |
| 6289 | case IWL_POWER_MODE_CAM: |
| 6290 | case IWL_POWER_AC: |
| 6291 | p += sprintf(p, "(AC)"); |
| 6292 | break; |
| 6293 | case IWL_POWER_BATTERY: |
| 6294 | p += sprintf(p, "(BATTERY)"); |
| 6295 | break; |
| 6296 | default: |
| 6297 | p += sprintf(p, |
| 6298 | "(Timeout %dms, Period %dms)", |
| 6299 | timeout_duration[level - 1] / 1000, |
| 6300 | period_duration[level - 1] / 1000); |
| 6301 | } |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 6302 | /* |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6303 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 6304 | p += sprintf(p, " OFF\n"); |
| 6305 | else |
| 6306 | p += sprintf(p, " \n"); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 6307 | */ |
| 6308 | p += sprintf(p, " \n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6309 | return (p - buf + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6310 | } |
| 6311 | |
| 6312 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 6313 | store_power_level); |
| 6314 | |
| 6315 | static ssize_t show_channels(struct device *d, |
| 6316 | struct device_attribute *attr, char *buf) |
| 6317 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 6318 | /* all this shit doesn't belong into sysfs anyway */ |
| 6319 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6320 | } |
| 6321 | |
| 6322 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 6323 | |
| 6324 | static ssize_t show_statistics(struct device *d, |
| 6325 | struct device_attribute *attr, char *buf) |
| 6326 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6327 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6328 | u32 size = sizeof(struct iwl4965_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6329 | u32 len = 0, ofs = 0; |
| 6330 | u8 *data = (u8 *) & priv->statistics; |
| 6331 | int rc = 0; |
| 6332 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6333 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6334 | return -EAGAIN; |
| 6335 | |
| 6336 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 6337 | rc = iwl_send_statistics_request(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6338 | mutex_unlock(&priv->mutex); |
| 6339 | |
| 6340 | if (rc) { |
| 6341 | len = sprintf(buf, |
| 6342 | "Error sending statistics request: 0x%08X\n", rc); |
| 6343 | return len; |
| 6344 | } |
| 6345 | |
| 6346 | while (size && (PAGE_SIZE - len)) { |
| 6347 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 6348 | PAGE_SIZE - len, 1); |
| 6349 | len = strlen(buf); |
| 6350 | if (PAGE_SIZE - len) |
| 6351 | buf[len++] = '\n'; |
| 6352 | |
| 6353 | ofs += 16; |
| 6354 | size -= min(size, 16U); |
| 6355 | } |
| 6356 | |
| 6357 | return len; |
| 6358 | } |
| 6359 | |
| 6360 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 6361 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6362 | static ssize_t show_status(struct device *d, |
| 6363 | struct device_attribute *attr, char *buf) |
| 6364 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6365 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 6366 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6367 | return -EAGAIN; |
| 6368 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 6369 | } |
| 6370 | |
| 6371 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 6372 | |
| 6373 | static ssize_t dump_error_log(struct device *d, |
| 6374 | struct device_attribute *attr, |
| 6375 | const char *buf, size_t count) |
| 6376 | { |
| 6377 | char *p = (char *)buf; |
| 6378 | |
| 6379 | if (p[0] == '1') |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6380 | iwl4965_dump_nic_error_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6381 | |
| 6382 | return strnlen(buf, count); |
| 6383 | } |
| 6384 | |
| 6385 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 6386 | |
| 6387 | static ssize_t dump_event_log(struct device *d, |
| 6388 | struct device_attribute *attr, |
| 6389 | const char *buf, size_t count) |
| 6390 | { |
| 6391 | char *p = (char *)buf; |
| 6392 | |
| 6393 | if (p[0] == '1') |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6394 | iwl4965_dump_nic_event_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6395 | |
| 6396 | return strnlen(buf, count); |
| 6397 | } |
| 6398 | |
| 6399 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 6400 | |
| 6401 | /***************************************************************************** |
| 6402 | * |
| 6403 | * driver setup and teardown |
| 6404 | * |
| 6405 | *****************************************************************************/ |
| 6406 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6407 | static void iwl4965_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6408 | { |
| 6409 | priv->workqueue = create_workqueue(DRV_NAME); |
| 6410 | |
| 6411 | init_waitqueue_head(&priv->wait_command_queue); |
| 6412 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6413 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 6414 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 6415 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
| 6416 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); |
| 6417 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); |
| 6418 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); |
| 6419 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 6420 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 6421 | INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6422 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
| 6423 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start); |
| 6424 | INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start); |
| 6425 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6426 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6427 | iwl4965_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6428 | |
| 6429 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6430 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6431 | } |
| 6432 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6433 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6434 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6435 | iwl4965_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6436 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 6437 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6438 | cancel_delayed_work(&priv->scan_check); |
| 6439 | cancel_delayed_work(&priv->alive_start); |
| 6440 | cancel_delayed_work(&priv->post_associate); |
| 6441 | cancel_work_sync(&priv->beacon_update); |
| 6442 | } |
| 6443 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6444 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6445 | &dev_attr_channels.attr, |
| 6446 | &dev_attr_dump_errors.attr, |
| 6447 | &dev_attr_dump_events.attr, |
| 6448 | &dev_attr_flags.attr, |
| 6449 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6450 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6451 | &dev_attr_measurement.attr, |
| 6452 | #endif |
| 6453 | &dev_attr_power_level.attr, |
| 6454 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6455 | &dev_attr_rs_window.attr, |
| 6456 | &dev_attr_statistics.attr, |
| 6457 | &dev_attr_status.attr, |
| 6458 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6459 | &dev_attr_tx_power.attr, |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 6460 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 6461 | &dev_attr_debug_level.attr, |
| 6462 | #endif |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 6463 | &dev_attr_version.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6464 | |
| 6465 | NULL |
| 6466 | }; |
| 6467 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6468 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6469 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6470 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6471 | }; |
| 6472 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6473 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 6474 | .tx = iwl4965_mac_tx, |
| 6475 | .start = iwl4965_mac_start, |
| 6476 | .stop = iwl4965_mac_stop, |
| 6477 | .add_interface = iwl4965_mac_add_interface, |
| 6478 | .remove_interface = iwl4965_mac_remove_interface, |
| 6479 | .config = iwl4965_mac_config, |
| 6480 | .config_interface = iwl4965_mac_config_interface, |
| 6481 | .configure_filter = iwl4965_configure_filter, |
| 6482 | .set_key = iwl4965_mac_set_key, |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 6483 | .update_tkip_key = iwl4965_mac_update_tkip_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6484 | .get_stats = iwl4965_mac_get_stats, |
| 6485 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 6486 | .conf_tx = iwl4965_mac_conf_tx, |
| 6487 | .get_tsf = iwl4965_mac_get_tsf, |
| 6488 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 6489 | .beacon_update = iwl4965_mac_beacon_update, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 6490 | .bss_info_changed = iwl4965_bss_info_changed, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6491 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | 9ab4617 | 2007-12-25 17:00:38 +0200 | [diff] [blame] | 6492 | .ampdu_action = iwl4965_mac_ampdu_action, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 6493 | #endif /* CONFIG_IWL4965_HT */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6494 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6495 | }; |
| 6496 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6497 | 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] | 6498 | { |
| 6499 | int err = 0; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6500 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6501 | struct ieee80211_hw *hw; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 6502 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6503 | unsigned long flags; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6504 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6505 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6506 | /************************ |
| 6507 | * 1. Allocating HW data |
| 6508 | ************************/ |
| 6509 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 6510 | /* Disabling hardware scan means that mac80211 will perform scans |
| 6511 | * "the hard way", rather than using device's scan. */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 6512 | if (cfg->mod_params->disable_hw_scan) { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 6513 | if (cfg->mod_params->debug & IWL_DL_INFO) |
| 6514 | dev_printk(KERN_DEBUG, &(pdev->dev), |
| 6515 | "Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6516 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6517 | } |
| 6518 | |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 6519 | hw = iwl_alloc_all(cfg, &iwl4965_hw_ops); |
| 6520 | if (!hw) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6521 | err = -ENOMEM; |
| 6522 | goto out; |
| 6523 | } |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 6524 | priv = hw->priv; |
| 6525 | /* At this point both hw and priv are allocated. */ |
| 6526 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6527 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 6528 | |
| 6529 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 6530 | priv->cfg = cfg; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6531 | priv->pci_dev = pdev; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6532 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 6533 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 6534 | priv->debug_level = priv->cfg->mod_params->debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6535 | atomic_set(&priv->restrict_refcnt, 0); |
| 6536 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6537 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6538 | /************************** |
| 6539 | * 2. Initializing PCI bus |
| 6540 | **************************/ |
| 6541 | if (pci_enable_device(pdev)) { |
| 6542 | err = -ENODEV; |
| 6543 | goto out_ieee80211_free_hw; |
| 6544 | } |
| 6545 | |
| 6546 | pci_set_master(pdev); |
| 6547 | |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 6548 | err = pci_set_dma_mask(pdev, DMA_64BIT_MASK); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6549 | if (!err) |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 6550 | err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); |
| 6551 | if (err) { |
| 6552 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 6553 | if (!err) |
| 6554 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 6555 | /* both attempts failed: */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6556 | if (err) { |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 6557 | printk(KERN_WARNING "%s: No suitable DMA available.\n", |
| 6558 | DRV_NAME); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6559 | goto out_pci_disable_device; |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 6560 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6561 | } |
| 6562 | |
| 6563 | err = pci_request_regions(pdev, DRV_NAME); |
| 6564 | if (err) |
| 6565 | goto out_pci_disable_device; |
| 6566 | |
| 6567 | pci_set_drvdata(pdev, priv); |
| 6568 | |
| 6569 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 6570 | * PCI Tx retries from interfering with C3 CPU state */ |
| 6571 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 6572 | |
| 6573 | /*********************** |
| 6574 | * 3. Read REV register |
| 6575 | ***********************/ |
| 6576 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 6577 | if (!priv->hw_base) { |
| 6578 | err = -ENODEV; |
| 6579 | goto out_pci_release_regions; |
| 6580 | } |
| 6581 | |
| 6582 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 6583 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 6584 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 6585 | |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 6586 | iwl_hw_detect(priv); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6587 | printk(KERN_INFO DRV_NAME |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 6588 | ": Detected Intel Wireless WiFi Link %s REV=0x%X\n", |
| 6589 | priv->cfg->name, priv->hw_rev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6590 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 6591 | /* amp init */ |
| 6592 | err = priv->cfg->ops->lib->apm_ops.init(priv); |
| 6593 | if (err < 0) { |
| 6594 | IWL_DEBUG_INFO("Failed to init APMG\n"); |
| 6595 | goto out_iounmap; |
| 6596 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6597 | /***************** |
| 6598 | * 4. Read EEPROM |
| 6599 | *****************/ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6600 | /* Read the EEPROM */ |
| 6601 | err = iwl_eeprom_init(priv); |
| 6602 | if (err) { |
| 6603 | IWL_ERROR("Unable to init EEPROM\n"); |
| 6604 | goto out_iounmap; |
| 6605 | } |
Tomas Winkler | 8614f36 | 2008-04-23 17:14:55 -0700 | [diff] [blame] | 6606 | err = iwl_eeprom_check_version(priv); |
| 6607 | if (err) |
| 6608 | goto out_iounmap; |
| 6609 | |
Ron Rindjunsky | 0288301 | 2008-05-15 13:53:53 +0800 | [diff] [blame] | 6610 | /* extract MAC Address */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6611 | iwl_eeprom_get_mac(priv, priv->mac_addr); |
| 6612 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); |
| 6613 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 6614 | |
| 6615 | /************************ |
| 6616 | * 5. Setup HW constants |
| 6617 | ************************/ |
| 6618 | /* Device-specific setup */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 6619 | if (priv->cfg->ops->lib->set_hw_params(priv)) { |
| 6620 | IWL_ERROR("failed to set hw parameters\n"); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 6621 | goto out_free_eeprom; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6622 | } |
| 6623 | |
| 6624 | /******************* |
| 6625 | * 6. Setup hw/priv |
| 6626 | *******************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6627 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6628 | err = iwl_setup(priv); |
| 6629 | if (err) |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 6630 | goto out_free_eeprom; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6631 | /* At this point both hw and priv are initialized. */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6632 | |
| 6633 | /********************************** |
| 6634 | * 7. Initialize module parameters |
| 6635 | **********************************/ |
| 6636 | |
| 6637 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 6638 | if (priv->cfg->mod_params->disable) { |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6639 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 6640 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 6641 | } |
| 6642 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 6643 | if (priv->cfg->mod_params->enable_qos) |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6644 | priv->qos_data.qos_enable = 1; |
| 6645 | |
| 6646 | /******************** |
| 6647 | * 8. Setup services |
| 6648 | ********************/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6649 | spin_lock_irqsave(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6650 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6651 | spin_unlock_irqrestore(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6652 | |
| 6653 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
| 6654 | if (err) { |
| 6655 | IWL_ERROR("failed to create sysfs device attributes\n"); |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 6656 | goto out_free_eeprom; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6657 | } |
| 6658 | |
| 6659 | err = iwl_dbgfs_register(priv, DRV_NAME); |
| 6660 | if (err) { |
| 6661 | IWL_ERROR("failed to create debugfs files\n"); |
| 6662 | goto out_remove_sysfs; |
| 6663 | } |
| 6664 | |
| 6665 | iwl4965_setup_deferred_work(priv); |
| 6666 | iwl4965_setup_rx_handlers(priv); |
| 6667 | |
| 6668 | /******************** |
| 6669 | * 9. Conclude |
| 6670 | ********************/ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 6671 | pci_save_state(pdev); |
| 6672 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6673 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 6674 | /* notify iwlcore to init */ |
| 6675 | iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6676 | return 0; |
| 6677 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6678 | out_remove_sysfs: |
| 6679 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 6680 | out_free_eeprom: |
| 6681 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6682 | out_iounmap: |
| 6683 | pci_iounmap(pdev, priv->hw_base); |
| 6684 | out_pci_release_regions: |
| 6685 | pci_release_regions(pdev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 6686 | pci_set_drvdata(pdev, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6687 | out_pci_disable_device: |
| 6688 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6689 | out_ieee80211_free_hw: |
| 6690 | ieee80211_free_hw(priv->hw); |
| 6691 | out: |
| 6692 | return err; |
| 6693 | } |
| 6694 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 6695 | static void __devexit iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6696 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6697 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6698 | struct list_head *p, *q; |
| 6699 | int i; |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6700 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6701 | |
| 6702 | if (!priv) |
| 6703 | return; |
| 6704 | |
| 6705 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 6706 | |
Ron Rindjunsky | c4f5523 | 2008-03-28 16:21:10 -0700 | [diff] [blame] | 6707 | if (priv->mac80211_registered) { |
| 6708 | ieee80211_unregister_hw(priv->hw); |
| 6709 | priv->mac80211_registered = 0; |
| 6710 | } |
| 6711 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6712 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 6713 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6714 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6715 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 6716 | /* make sure we flush any pending irq or |
| 6717 | * tasklet for the driver |
| 6718 | */ |
| 6719 | spin_lock_irqsave(&priv->lock, flags); |
| 6720 | iwl4965_disable_interrupts(priv); |
| 6721 | spin_unlock_irqrestore(&priv->lock, flags); |
| 6722 | |
| 6723 | iwl_synchronize_irq(priv); |
| 6724 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6725 | /* Free MAC hash list for ADHOC */ |
| 6726 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 6727 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 6728 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6729 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6730 | } |
| 6731 | } |
| 6732 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 6733 | iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 6734 | iwl_dbgfs_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6735 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6736 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6737 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6738 | |
| 6739 | if (priv->rxq.bd) |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 6740 | iwl_rx_queue_free(priv, &priv->rxq); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 6741 | iwl_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6742 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6743 | iwlcore_clear_stations_table(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 6744 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6745 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6746 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 6747 | /*netif_stop_queue(dev); */ |
| 6748 | flush_workqueue(priv->workqueue); |
| 6749 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6750 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6751 | * priv->workqueue... so we can't take down the workqueue |
| 6752 | * until now... */ |
| 6753 | destroy_workqueue(priv->workqueue); |
| 6754 | priv->workqueue = NULL; |
| 6755 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6756 | pci_iounmap(pdev, priv->hw_base); |
| 6757 | pci_release_regions(pdev); |
| 6758 | pci_disable_device(pdev); |
| 6759 | pci_set_drvdata(pdev, NULL); |
| 6760 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 6761 | iwl_free_channel_map(priv); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 6762 | iwlcore_free_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6763 | |
| 6764 | if (priv->ibss_beacon) |
| 6765 | dev_kfree_skb(priv->ibss_beacon); |
| 6766 | |
| 6767 | ieee80211_free_hw(priv->hw); |
| 6768 | } |
| 6769 | |
| 6770 | #ifdef CONFIG_PM |
| 6771 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6772 | 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] | 6773 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6774 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6775 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6776 | if (priv->is_open) { |
| 6777 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 6778 | iwl4965_mac_stop(priv->hw); |
| 6779 | priv->is_open = 1; |
| 6780 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6781 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6782 | pci_set_power_state(pdev, PCI_D3hot); |
| 6783 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6784 | return 0; |
| 6785 | } |
| 6786 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6787 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6788 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 6789 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6790 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6791 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6792 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6793 | if (priv->is_open) |
| 6794 | iwl4965_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6795 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 6796 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6797 | return 0; |
| 6798 | } |
| 6799 | |
| 6800 | #endif /* CONFIG_PM */ |
| 6801 | |
| 6802 | /***************************************************************************** |
| 6803 | * |
| 6804 | * driver and module entry point |
| 6805 | * |
| 6806 | *****************************************************************************/ |
| 6807 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 6808 | /* Hardware specific file defines the PCI IDs table for that hardware module */ |
| 6809 | static struct pci_device_id iwl_hw_card_ids[] = { |
| 6810 | {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)}, |
| 6811 | {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)}, |
Tomas Winkler | 5a6a256 | 2008-04-24 11:55:23 -0700 | [diff] [blame] | 6812 | #ifdef CONFIG_IWL5000 |
| 6813 | {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)}, |
| 6814 | {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)}, |
| 6815 | {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)}, |
| 6816 | #endif /* CONFIG_IWL5000 */ |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 6817 | {0} |
| 6818 | }; |
| 6819 | MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); |
| 6820 | |
| 6821 | static struct pci_driver iwl_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6822 | .name = DRV_NAME, |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 6823 | .id_table = iwl_hw_card_ids, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6824 | .probe = iwl4965_pci_probe, |
| 6825 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6826 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6827 | .suspend = iwl4965_pci_suspend, |
| 6828 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6829 | #endif |
| 6830 | }; |
| 6831 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6832 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6833 | { |
| 6834 | |
| 6835 | int ret; |
| 6836 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 6837 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 6838 | |
| 6839 | ret = iwl4965_rate_control_register(); |
| 6840 | if (ret) { |
| 6841 | IWL_ERROR("Unable to register rate control algorithm: %d\n", ret); |
| 6842 | return ret; |
| 6843 | } |
| 6844 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 6845 | ret = pci_register_driver(&iwl_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6846 | if (ret) { |
| 6847 | IWL_ERROR("Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 6848 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6849 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6850 | |
| 6851 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 6852 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 6853 | error_register: |
| 6854 | iwl4965_rate_control_unregister(); |
| 6855 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6856 | } |
| 6857 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6858 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6859 | { |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 6860 | pci_unregister_driver(&iwl_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 6861 | iwl4965_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 6862 | } |
| 6863 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 6864 | module_exit(iwl4965_exit); |
| 6865 | module_init(iwl4965_init); |