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 | |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 56 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 57 | /****************************************************************************** |
| 58 | * |
| 59 | * module boiler plate |
| 60 | * |
| 61 | ******************************************************************************/ |
| 62 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 63 | /* |
| 64 | * module name, copyright, version, etc. |
| 65 | * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk |
| 66 | */ |
| 67 | |
| 68 | #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux" |
| 69 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 70 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 71 | #define VD "d" |
| 72 | #else |
| 73 | #define VD |
| 74 | #endif |
| 75 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 76 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 77 | #define VS "s" |
| 78 | #else |
| 79 | #define VS |
| 80 | #endif |
| 81 | |
Tomas Winkler | df48c32 | 2008-03-06 10:40:19 -0800 | [diff] [blame] | 82 | #define DRV_VERSION IWLWIFI_VERSION VD VS |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 83 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 84 | |
| 85 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 86 | MODULE_VERSION(DRV_VERSION); |
| 87 | MODULE_AUTHOR(DRV_COPYRIGHT); |
| 88 | MODULE_LICENSE("GPL"); |
| 89 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 90 | static const struct ieee80211_supported_band *iwl_get_hw_mode( |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 91 | struct iwl_priv *priv, enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 92 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 93 | return priv->hw->wiphy->bands[band]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 96 | static int iwl4965_is_empty_essid(const char *essid, int essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 97 | { |
| 98 | /* Single white space is for Linksys APs */ |
| 99 | if (essid_len == 1 && essid[0] == ' ') |
| 100 | return 1; |
| 101 | |
| 102 | /* Otherwise, if the entire essid is 0, we assume it is hidden */ |
| 103 | while (essid_len) { |
| 104 | essid_len--; |
| 105 | if (essid[essid_len] != '\0') |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | return 1; |
| 110 | } |
| 111 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 112 | static const char *iwl4965_escape_essid(const char *essid, u8 essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 113 | { |
| 114 | static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
| 115 | const char *s = essid; |
| 116 | char *d = escaped; |
| 117 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 118 | if (iwl4965_is_empty_essid(essid, essid_len)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 119 | memcpy(escaped, "<hidden>", sizeof("<hidden>")); |
| 120 | return escaped; |
| 121 | } |
| 122 | |
| 123 | essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE); |
| 124 | while (essid_len--) { |
| 125 | if (*s == '\0') { |
| 126 | *d++ = '\\'; |
| 127 | *d++ = '0'; |
| 128 | s++; |
| 129 | } else |
| 130 | *d++ = *s++; |
| 131 | } |
| 132 | *d = '\0'; |
| 133 | return escaped; |
| 134 | } |
| 135 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 136 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 137 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 138 | * the functionality provided here |
| 139 | */ |
| 140 | |
| 141 | /**************************************************************/ |
| 142 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 143 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 144 | /** |
| 145 | * iwl4965_remove_station - Remove driver's knowledge of station. |
| 146 | * |
| 147 | * NOTE: This does not remove station from device's station table. |
| 148 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 149 | 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] | 150 | { |
| 151 | int index = IWL_INVALID_STATION; |
| 152 | int i; |
| 153 | unsigned long flags; |
| 154 | |
| 155 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 156 | |
| 157 | if (is_ap) |
| 158 | index = IWL_AP_ID; |
| 159 | else if (is_broadcast_ether_addr(addr)) |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 160 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 161 | else |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 162 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 163 | if (priv->stations[i].used && |
| 164 | !compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 165 | addr)) { |
| 166 | index = i; |
| 167 | break; |
| 168 | } |
| 169 | |
| 170 | if (unlikely(index == IWL_INVALID_STATION)) |
| 171 | goto out; |
| 172 | |
| 173 | if (priv->stations[index].used) { |
| 174 | priv->stations[index].used = 0; |
| 175 | priv->num_stations--; |
| 176 | } |
| 177 | |
| 178 | BUG_ON(priv->num_stations < 0); |
| 179 | |
| 180 | out: |
| 181 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 182 | return 0; |
| 183 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 184 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 185 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 186 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 187 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 188 | static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) |
| 189 | { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 190 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 191 | |
| 192 | if (hw_decrypt) |
| 193 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 194 | else |
| 195 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 196 | |
| 197 | } |
| 198 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 199 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 200 | * iwl4965_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 201 | * |
| 202 | * NOTE: This is really only useful during development and can eventually |
| 203 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 204 | * making changes |
| 205 | */ |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 206 | static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 207 | { |
| 208 | int error = 0; |
| 209 | int counter = 1; |
| 210 | |
| 211 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 212 | error |= le32_to_cpu(rxon->flags & |
| 213 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 214 | RXON_FLG_RADAR_DETECT_MSK)); |
| 215 | if (error) |
| 216 | IWL_WARNING("check 24G fields %d | %d\n", |
| 217 | counter++, error); |
| 218 | } else { |
| 219 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 220 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 221 | if (error) |
| 222 | IWL_WARNING("check 52 fields %d | %d\n", |
| 223 | counter++, error); |
| 224 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 225 | if (error) |
| 226 | IWL_WARNING("check 52 CCK %d | %d\n", |
| 227 | counter++, error); |
| 228 | } |
| 229 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 230 | if (error) |
| 231 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); |
| 232 | |
| 233 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 234 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 235 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 236 | if (error) |
| 237 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); |
| 238 | |
| 239 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 240 | if (error) |
| 241 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); |
| 242 | |
| 243 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 244 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 245 | if (error) |
| 246 | IWL_WARNING("check CCK and short slot %d | %d\n", |
| 247 | counter++, error); |
| 248 | |
| 249 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 250 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 251 | if (error) |
| 252 | IWL_WARNING("check CCK & auto detect %d | %d\n", |
| 253 | counter++, error); |
| 254 | |
| 255 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 256 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 257 | if (error) |
| 258 | IWL_WARNING("check TGG and auto detect %d | %d\n", |
| 259 | counter++, error); |
| 260 | |
| 261 | if (error) |
| 262 | IWL_WARNING("Tuning to channel %d\n", |
| 263 | le16_to_cpu(rxon->channel)); |
| 264 | |
| 265 | if (error) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 266 | IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 267 | return -1; |
| 268 | } |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 273 | * 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] | 274 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 275 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 276 | * If the RXON structure is changing enough to require a new tune, |
| 277 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 278 | * 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] | 279 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 280 | static int iwl4965_full_rxon_required(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 281 | { |
| 282 | |
| 283 | /* These items are only settable from the full RXON command */ |
| 284 | if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || |
| 285 | compare_ether_addr(priv->staging_rxon.bssid_addr, |
| 286 | priv->active_rxon.bssid_addr) || |
| 287 | compare_ether_addr(priv->staging_rxon.node_addr, |
| 288 | priv->active_rxon.node_addr) || |
| 289 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, |
| 290 | priv->active_rxon.wlap_bssid_addr) || |
| 291 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || |
| 292 | (priv->staging_rxon.channel != priv->active_rxon.channel) || |
| 293 | (priv->staging_rxon.air_propagation != |
| 294 | priv->active_rxon.air_propagation) || |
| 295 | (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != |
| 296 | priv->active_rxon.ofdm_ht_single_stream_basic_rates) || |
| 297 | (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != |
| 298 | priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || |
| 299 | (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) || |
| 300 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) |
| 301 | return 1; |
| 302 | |
| 303 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 304 | * be updated with the RXON_ASSOC command -- however only some |
| 305 | * flag transitions are allowed using RXON_ASSOC */ |
| 306 | |
| 307 | /* Check if we are not switching bands */ |
| 308 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 309 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
| 310 | return 1; |
| 311 | |
| 312 | /* Check if we are switching association toggle */ |
| 313 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 314 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
| 315 | return 1; |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 320 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 321 | * iwl4965_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 322 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 323 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 324 | * the active_rxon structure is updated with the new data. This |
| 325 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 326 | * a HW tune is required based on the RXON structure changes. |
| 327 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 328 | static int iwl4965_commit_rxon(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 329 | { |
| 330 | /* cast away the const for active_rxon in this function */ |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 331 | struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 332 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 333 | int rc = 0; |
| 334 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 335 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 336 | return -1; |
| 337 | |
| 338 | /* always get timestamp with Rx frame */ |
| 339 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
| 340 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 341 | rc = iwl4965_check_rxon_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 342 | if (rc) { |
| 343 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); |
| 344 | return -EINVAL; |
| 345 | } |
| 346 | |
| 347 | /* 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] | 348 | * iwl4965_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 349 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 350 | if (!iwl4965_full_rxon_required(priv)) { |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 351 | rc = iwl_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 352 | if (rc) { |
| 353 | IWL_ERROR("Error setting RXON_ASSOC " |
| 354 | "configuration (%d).\n", rc); |
| 355 | return rc; |
| 356 | } |
| 357 | |
| 358 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | /* station table will be cleared */ |
| 364 | priv->assoc_station_added = 0; |
| 365 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 366 | /* If we are currently associated and the new config requires |
| 367 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 368 | * we must clear the associated from the active configuration |
| 369 | * before we apply the new config */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 370 | if (iwl_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 371 | (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
| 372 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 373 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 374 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 375 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 376 | sizeof(struct iwl_rxon_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 377 | &priv->active_rxon); |
| 378 | |
| 379 | /* If the mask clearing failed then we set |
| 380 | * active_rxon back to what it was previously */ |
| 381 | if (rc) { |
| 382 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 383 | IWL_ERROR("Error clearing ASSOC_MSK on current " |
| 384 | "configuration (%d).\n", rc); |
| 385 | return rc; |
| 386 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | IWL_DEBUG_INFO("Sending RXON\n" |
| 390 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 391 | "* channel = %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 392 | "* bssid = %s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 393 | ((priv->staging_rxon.filter_flags & |
| 394 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
| 395 | le16_to_cpu(priv->staging_rxon.channel), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 396 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 397 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 398 | iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 399 | /* Apply the new configuration */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 400 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 401 | sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 402 | if (rc) { |
| 403 | IWL_ERROR("Error setting new configuration (%d).\n", rc); |
| 404 | return rc; |
| 405 | } |
| 406 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 407 | iwlcore_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 408 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 409 | if (!priv->error_recovering) |
| 410 | priv->start_calib = 0; |
| 411 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 412 | iwl_init_sensitivity(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 413 | |
| 414 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 415 | |
| 416 | /* If we issue a new RXON command which required a tune then we must |
| 417 | * 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] | 418 | rc = iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 419 | if (rc) { |
| 420 | IWL_ERROR("Error setting Tx power (%d).\n", rc); |
| 421 | return rc; |
| 422 | } |
| 423 | |
| 424 | /* Add the broadcast address so we can send broadcast frames */ |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 425 | if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 426 | IWL_INVALID_STATION) { |
| 427 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); |
| 428 | return -EIO; |
| 429 | } |
| 430 | |
| 431 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 432 | * add the IWL_AP_ID to the station rate table */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 433 | if (iwl_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 434 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 435 | if (iwl_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 436 | == IWL_INVALID_STATION) { |
| 437 | IWL_ERROR("Error adding AP address for transmit.\n"); |
| 438 | return -EIO; |
| 439 | } |
| 440 | priv->assoc_station_added = 1; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 441 | if (priv->default_wep_key && |
| 442 | iwl_send_static_wepkey_cmd(priv, 0)) |
| 443 | IWL_ERROR("Could not send WEP static key.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | return 0; |
| 447 | } |
| 448 | |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 449 | void iwl4965_update_chain_flags(struct iwl_priv *priv) |
| 450 | { |
| 451 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 452 | iwl_set_rxon_chain(priv); |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 453 | iwl4965_commit_rxon(priv); |
| 454 | } |
| 455 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 456 | static int iwl4965_send_bt_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 457 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 458 | struct iwl4965_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 459 | .flags = 3, |
| 460 | .lead_time = 0xAA, |
| 461 | .max_kill = 1, |
| 462 | .kill_ack_mask = 0, |
| 463 | .kill_cts_mask = 0, |
| 464 | }; |
| 465 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 466 | return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 467 | sizeof(struct iwl4965_bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 470 | static int iwl4965_send_scan_abort(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 471 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 472 | int ret = 0; |
| 473 | struct iwl_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 474 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 475 | .id = REPLY_SCAN_ABORT_CMD, |
| 476 | .meta.flags = CMD_WANT_SKB, |
| 477 | }; |
| 478 | |
| 479 | /* If there isn't a scan actively going on in the hardware |
| 480 | * then we are in between scan bands and not actually |
| 481 | * actively scanning, so don't send the abort command */ |
| 482 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 483 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 484 | return 0; |
| 485 | } |
| 486 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 487 | ret = iwl_send_cmd_sync(priv, &cmd); |
| 488 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 489 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 490 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 491 | } |
| 492 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 493 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 494 | if (res->u.status != CAN_ABORT_STATUS) { |
| 495 | /* The scan abort will return 1 for success or |
| 496 | * 2 for "failure". A failure condition can be |
| 497 | * due to simply not being in an active scan which |
| 498 | * can occur if we send the scan abort before we |
| 499 | * the microcode has notified us that a scan is |
| 500 | * completed. */ |
| 501 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 502 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 503 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 504 | } |
| 505 | |
| 506 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 507 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 508 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 511 | /* |
| 512 | * CARD_STATE_CMD |
| 513 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 514 | * 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] | 515 | * |
| 516 | * When in the 'enable' state the card operates as normal. |
| 517 | * When in the 'disable' state, the card enters into a low power mode. |
| 518 | * When in the 'halt' state, the card is shut down and must be fully |
| 519 | * restarted to come back on. |
| 520 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 521 | 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] | 522 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 523 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 524 | .id = REPLY_CARD_STATE_CMD, |
| 525 | .len = sizeof(u32), |
| 526 | .data = &flags, |
| 527 | .meta.flags = meta_flag, |
| 528 | }; |
| 529 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 530 | return iwl_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 533 | static void iwl_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 534 | { |
| 535 | struct list_head *element; |
| 536 | |
| 537 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 538 | priv->frames_count); |
| 539 | |
| 540 | while (!list_empty(&priv->free_frames)) { |
| 541 | element = priv->free_frames.next; |
| 542 | list_del(element); |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 543 | kfree(list_entry(element, struct iwl_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 544 | priv->frames_count--; |
| 545 | } |
| 546 | |
| 547 | if (priv->frames_count) { |
| 548 | IWL_WARNING("%d frames still in use. Did we lose one?\n", |
| 549 | priv->frames_count); |
| 550 | priv->frames_count = 0; |
| 551 | } |
| 552 | } |
| 553 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 554 | static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 555 | { |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 556 | struct iwl_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 557 | struct list_head *element; |
| 558 | if (list_empty(&priv->free_frames)) { |
| 559 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 560 | if (!frame) { |
| 561 | IWL_ERROR("Could not allocate frame!\n"); |
| 562 | return NULL; |
| 563 | } |
| 564 | |
| 565 | priv->frames_count++; |
| 566 | return frame; |
| 567 | } |
| 568 | |
| 569 | element = priv->free_frames.next; |
| 570 | list_del(element); |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 571 | return list_entry(element, struct iwl_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 574 | 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] | 575 | { |
| 576 | memset(frame, 0, sizeof(*frame)); |
| 577 | list_add(&frame->list, &priv->free_frames); |
| 578 | } |
| 579 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 580 | unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 581 | struct ieee80211_hdr *hdr, |
| 582 | const u8 *dest, int left) |
| 583 | { |
| 584 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 585 | if (!iwl_is_associated(priv) || !priv->ibss_beacon || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 586 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
| 587 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) |
| 588 | return 0; |
| 589 | |
| 590 | if (priv->ibss_beacon->len > left) |
| 591 | return 0; |
| 592 | |
| 593 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 594 | |
| 595 | return priv->ibss_beacon->len; |
| 596 | } |
| 597 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 598 | static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 599 | { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 600 | int i; |
| 601 | int rate_mask; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 602 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 603 | /* Set rate mask*/ |
| 604 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 605 | rate_mask = priv->active_rate_basic & 0xF; |
| 606 | else |
| 607 | rate_mask = priv->active_rate_basic & 0xFF0; |
| 608 | |
| 609 | /* Find lowest valid rate */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 610 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 611 | i = iwl_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 612 | if (rate_mask & (1 << i)) |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 613 | return iwl_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 616 | /* No valid rate was found. Assign the lowest one */ |
| 617 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 618 | return IWL_RATE_1M_PLCP; |
| 619 | else |
| 620 | return IWL_RATE_6M_PLCP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 623 | static int iwl4965_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 624 | { |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 625 | struct iwl_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 626 | unsigned int frame_size; |
| 627 | int rc; |
| 628 | u8 rate; |
| 629 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 630 | frame = iwl_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 631 | |
| 632 | if (!frame) { |
| 633 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 634 | "command.\n"); |
| 635 | return -ENOMEM; |
| 636 | } |
| 637 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 638 | rate = iwl4965_rate_get_lowest_plcp(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 639 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 640 | frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 641 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 642 | rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 643 | &frame->u.cmd[0]); |
| 644 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 645 | iwl_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 646 | |
| 647 | return rc; |
| 648 | } |
| 649 | |
| 650 | /****************************************************************************** |
| 651 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 652 | * Misc. internal state and helper functions |
| 653 | * |
| 654 | ******************************************************************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 655 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 656 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 657 | * 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] | 658 | * |
| 659 | * return : set the bit for each supported rate insert in ie |
| 660 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 661 | static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 662 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 663 | { |
| 664 | u16 ret_rates = 0, bit; |
| 665 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 666 | u8 *cnt = ie; |
| 667 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 668 | |
| 669 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 670 | if (bit & supported_rate) { |
| 671 | ret_rates |= bit; |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 672 | rates[*cnt] = iwl_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 673 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 674 | (*cnt)++; |
| 675 | (*left)--; |
| 676 | if ((*left <= 0) || |
| 677 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 678 | break; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | return ret_rates; |
| 683 | } |
| 684 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 685 | #ifdef CONFIG_IWL4965_HT |
| 686 | static void iwl4965_ht_conf(struct iwl_priv *priv, |
| 687 | struct ieee80211_bss_conf *bss_conf) |
| 688 | { |
| 689 | struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf; |
| 690 | struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf; |
| 691 | struct iwl_ht_info *iwl_conf = &priv->current_ht_config; |
| 692 | |
| 693 | IWL_DEBUG_MAC80211("enter: \n"); |
| 694 | |
| 695 | iwl_conf->is_ht = bss_conf->assoc_ht; |
| 696 | |
| 697 | if (!iwl_conf->is_ht) |
| 698 | return; |
| 699 | |
| 700 | priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 701 | |
| 702 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) |
Emmanuel Grumbach | a984101 | 2008-05-15 13:54:08 +0800 | [diff] [blame] | 703 | iwl_conf->sgf |= HT_SHORT_GI_20MHZ; |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 704 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) |
Emmanuel Grumbach | a984101 | 2008-05-15 13:54:08 +0800 | [diff] [blame] | 705 | iwl_conf->sgf |= HT_SHORT_GI_40MHZ; |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 706 | |
| 707 | iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); |
| 708 | iwl_conf->max_amsdu_size = |
| 709 | !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); |
| 710 | |
| 711 | iwl_conf->supported_chan_width = |
| 712 | !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); |
| 713 | iwl_conf->extension_chan_offset = |
| 714 | ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; |
| 715 | /* If no above or below channel supplied disable FAT channel */ |
| 716 | if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE && |
| 717 | iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW) |
| 718 | iwl_conf->supported_chan_width = 0; |
| 719 | |
| 720 | iwl_conf->tx_mimo_ps_mode = |
| 721 | (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 722 | memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); |
| 723 | |
| 724 | iwl_conf->control_channel = ht_bss_conf->primary_channel; |
| 725 | iwl_conf->tx_chan_width = |
| 726 | !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); |
| 727 | iwl_conf->ht_protection = |
| 728 | ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; |
| 729 | iwl_conf->non_GF_STA_present = |
| 730 | !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT); |
| 731 | |
| 732 | IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel); |
| 733 | IWL_DEBUG_MAC80211("leave\n"); |
| 734 | } |
| 735 | |
| 736 | static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband, |
| 737 | u8 *pos, int *left) |
| 738 | { |
| 739 | struct ieee80211_ht_cap *ht_cap; |
| 740 | |
| 741 | if (!sband || !sband->ht_info.ht_supported) |
| 742 | return; |
| 743 | |
| 744 | if (*left < sizeof(struct ieee80211_ht_cap)) |
| 745 | return; |
| 746 | |
| 747 | *pos++ = sizeof(struct ieee80211_ht_cap); |
| 748 | ht_cap = (struct ieee80211_ht_cap *) pos; |
| 749 | |
| 750 | ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap); |
| 751 | memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16); |
| 752 | ht_cap->ampdu_params_info = |
| 753 | (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) | |
| 754 | ((sband->ht_info.ampdu_density << 2) & |
| 755 | IEEE80211_HT_CAP_AMPDU_DENSITY); |
| 756 | *left -= sizeof(struct ieee80211_ht_cap); |
| 757 | } |
| 758 | #else |
| 759 | static inline void iwl4965_ht_conf(struct iwl_priv *priv, |
| 760 | struct ieee80211_bss_conf *bss_conf) |
| 761 | { |
| 762 | } |
| 763 | static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband, |
| 764 | u8 *pos, int *left) |
| 765 | { |
| 766 | } |
| 767 | #endif |
| 768 | |
| 769 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 770 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 771 | * 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] | 772 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 773 | static u16 iwl4965_fill_probe_req(struct iwl_priv *priv, |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 774 | enum ieee80211_band band, |
| 775 | struct ieee80211_mgmt *frame, |
| 776 | int left, int is_direct) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 777 | { |
| 778 | int len = 0; |
| 779 | u8 *pos = NULL; |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 780 | u16 active_rates, ret_rates, cck_rates, active_rate_basic; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 781 | const struct ieee80211_supported_band *sband = |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 782 | iwl_get_hw_mode(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 783 | |
| 784 | /* Make sure there is enough space for the probe request, |
| 785 | * two mandatory IEs and the data */ |
| 786 | left -= 24; |
| 787 | if (left < 0) |
| 788 | return 0; |
| 789 | len += 24; |
| 790 | |
| 791 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Tomas Winkler | 57bd1be | 2008-05-15 13:54:03 +0800 | [diff] [blame] | 792 | memcpy(frame->da, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 793 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Tomas Winkler | 57bd1be | 2008-05-15 13:54:03 +0800 | [diff] [blame] | 794 | memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 795 | frame->seq_ctrl = 0; |
| 796 | |
| 797 | /* fill in our indirect SSID IE */ |
| 798 | /* ...next IE... */ |
| 799 | |
| 800 | left -= 2; |
| 801 | if (left < 0) |
| 802 | return 0; |
| 803 | len += 2; |
| 804 | pos = &(frame->u.probe_req.variable[0]); |
| 805 | *pos++ = WLAN_EID_SSID; |
| 806 | *pos++ = 0; |
| 807 | |
| 808 | /* fill in our direct SSID IE... */ |
| 809 | if (is_direct) { |
| 810 | /* ...next IE... */ |
| 811 | left -= 2 + priv->essid_len; |
| 812 | if (left < 0) |
| 813 | return 0; |
| 814 | /* ... fill it in... */ |
| 815 | *pos++ = WLAN_EID_SSID; |
| 816 | *pos++ = priv->essid_len; |
| 817 | memcpy(pos, priv->essid, priv->essid_len); |
| 818 | pos += priv->essid_len; |
| 819 | len += 2 + priv->essid_len; |
| 820 | } |
| 821 | |
| 822 | /* fill in supported rate */ |
| 823 | /* ...next IE... */ |
| 824 | left -= 2; |
| 825 | if (left < 0) |
| 826 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 827 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 828 | /* ... fill it in... */ |
| 829 | *pos++ = WLAN_EID_SUPP_RATES; |
| 830 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 831 | |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 832 | /* exclude 60M rate */ |
| 833 | active_rates = priv->rates_mask; |
| 834 | active_rates &= ~IWL_RATE_60M_MASK; |
| 835 | |
| 836 | active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 837 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 838 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 839 | ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 840 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 841 | active_rates &= ~ret_rates; |
| 842 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 843 | ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 844 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 845 | active_rates &= ~ret_rates; |
| 846 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 847 | len += 2 + *pos; |
| 848 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 849 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 850 | goto fill_end; |
| 851 | |
| 852 | /* fill in supported extended rate */ |
| 853 | /* ...next IE... */ |
| 854 | left -= 2; |
| 855 | if (left < 0) |
| 856 | return 0; |
| 857 | /* ... fill it in... */ |
| 858 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 859 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 860 | iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 861 | active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 862 | if (*pos > 0) |
| 863 | len += 2 + *pos; |
| 864 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 865 | fill_end: |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 866 | /* fill in HT IE */ |
| 867 | left -= 2; |
| 868 | if (left < 0) |
| 869 | return 0; |
| 870 | |
| 871 | *pos++ = WLAN_EID_HT_CAPABILITY; |
| 872 | *pos = 0; |
| 873 | |
| 874 | iwl_ht_cap_to_ie(sband, pos, &left); |
| 875 | |
| 876 | if (*pos > 0) |
| 877 | len += 2 + *pos; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 878 | return (u16)len; |
| 879 | } |
| 880 | |
| 881 | /* |
| 882 | * QoS support |
| 883 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 884 | static int iwl4965_send_qos_params_command(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 885 | struct iwl4965_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 886 | { |
| 887 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 888 | return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 889 | sizeof(struct iwl4965_qosparam_cmd), qos); |
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 void iwl4965_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 893 | { |
| 894 | unsigned long flags; |
| 895 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 896 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 897 | return; |
| 898 | |
| 899 | if (!priv->qos_data.qos_enable) |
| 900 | return; |
| 901 | |
| 902 | spin_lock_irqsave(&priv->lock, flags); |
| 903 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 904 | |
| 905 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 906 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 907 | priv->qos_data.def_qos_parm.qos_flags |= |
| 908 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 909 | if (priv->qos_data.qos_active) |
| 910 | priv->qos_data.def_qos_parm.qos_flags |= |
| 911 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 912 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 913 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 914 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 915 | 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] | 916 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 917 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 918 | spin_unlock_irqrestore(&priv->lock, flags); |
| 919 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 920 | if (force || iwl_is_associated(priv)) { |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 921 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 922 | priv->qos_data.qos_active, |
| 923 | priv->qos_data.def_qos_parm.qos_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 924 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 925 | iwl4965_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 926 | &(priv->qos_data.def_qos_parm)); |
| 927 | } |
| 928 | } |
| 929 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 930 | 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] | 931 | { |
| 932 | /* Filter incoming packets to determine if they are targeted toward |
| 933 | * this network, discarding packets coming from ourselves */ |
| 934 | switch (priv->iw_mode) { |
| 935 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 936 | /* packets from our adapter are dropped (echo) */ |
| 937 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 938 | return 0; |
| 939 | /* {broad,multi}cast packets to our IBSS go through */ |
| 940 | if (is_multicast_ether_addr(header->addr1)) |
| 941 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 942 | /* packets to our adapter go through */ |
| 943 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 944 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 945 | /* packets from our adapter are dropped (echo) */ |
| 946 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 947 | return 0; |
| 948 | /* {broad,multi}cast packets to our BSS go through */ |
| 949 | if (is_multicast_ether_addr(header->addr1)) |
| 950 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 951 | /* packets to our adapter go through */ |
| 952 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 953 | default: |
| 954 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | return 1; |
| 958 | } |
| 959 | |
| 960 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 961 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 962 | static const char *iwl4965_get_tx_fail_reason(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 963 | { |
| 964 | switch (status & TX_STATUS_MSK) { |
| 965 | case TX_STATUS_SUCCESS: |
| 966 | return "SUCCESS"; |
| 967 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 968 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 969 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 970 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 971 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 972 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 973 | TX_STATUS_ENTRY(DEST_PS); |
| 974 | TX_STATUS_ENTRY(ABORTED); |
| 975 | TX_STATUS_ENTRY(BT_RETRY); |
| 976 | TX_STATUS_ENTRY(STA_INVALID); |
| 977 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 978 | TX_STATUS_ENTRY(TID_DISABLE); |
| 979 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 980 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 981 | TX_STATUS_ENTRY(TX_LOCKED); |
| 982 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 983 | } |
| 984 | |
| 985 | return "UNKNOWN"; |
| 986 | } |
| 987 | |
| 988 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 989 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 990 | * |
| 991 | * NOTE: priv->mutex is not required before calling this function |
| 992 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 993 | static int iwl4965_scan_cancel(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 994 | { |
| 995 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 996 | clear_bit(STATUS_SCANNING, &priv->status); |
| 997 | return 0; |
| 998 | } |
| 999 | |
| 1000 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1001 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1002 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 1003 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1004 | queue_work(priv->workqueue, &priv->abort_scan); |
| 1005 | |
| 1006 | } else |
| 1007 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 1008 | |
| 1009 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1010 | } |
| 1011 | |
| 1012 | return 0; |
| 1013 | } |
| 1014 | |
| 1015 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1016 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1017 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 1018 | * |
| 1019 | * NOTE: priv->mutex must be held before calling this function |
| 1020 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1021 | 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] | 1022 | { |
| 1023 | unsigned long now = jiffies; |
| 1024 | int ret; |
| 1025 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1026 | ret = iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1027 | if (ret && ms) { |
| 1028 | mutex_unlock(&priv->mutex); |
| 1029 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 1030 | test_bit(STATUS_SCANNING, &priv->status)) |
| 1031 | msleep(1); |
| 1032 | mutex_lock(&priv->mutex); |
| 1033 | |
| 1034 | return test_bit(STATUS_SCANNING, &priv->status); |
| 1035 | } |
| 1036 | |
| 1037 | return ret; |
| 1038 | } |
| 1039 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1040 | static void iwl4965_sequence_reset(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1041 | { |
| 1042 | /* Reset ieee stats */ |
| 1043 | |
| 1044 | /* We don't reset the net_device_stats (ieee->stats) on |
| 1045 | * re-association */ |
| 1046 | |
| 1047 | priv->last_seq_num = -1; |
| 1048 | priv->last_frag_num = -1; |
| 1049 | priv->last_packet_time = 0; |
| 1050 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1051 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 1055 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 1056 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1057 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1058 | { |
| 1059 | u16 new_val = 0; |
| 1060 | u16 beacon_factor = 0; |
| 1061 | |
| 1062 | beacon_factor = |
| 1063 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 1064 | / MAX_UCODE_BEACON_INTERVAL; |
| 1065 | new_val = beacon_val / beacon_factor; |
| 1066 | |
| 1067 | return cpu_to_le16(new_val); |
| 1068 | } |
| 1069 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1070 | static void iwl4965_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1071 | { |
| 1072 | u64 interval_tm_unit; |
| 1073 | u64 tsf, result; |
| 1074 | unsigned long flags; |
| 1075 | struct ieee80211_conf *conf = NULL; |
| 1076 | u16 beacon_int = 0; |
| 1077 | |
| 1078 | conf = ieee80211_get_hw_conf(priv->hw); |
| 1079 | |
| 1080 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1081 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32); |
| 1082 | priv->rxon_timing.timestamp.dw[0] = |
| 1083 | cpu_to_le32(priv->timestamp & 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1084 | |
| 1085 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 1086 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1087 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1088 | |
| 1089 | beacon_int = priv->beacon_int; |
| 1090 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1091 | |
| 1092 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 1093 | if (beacon_int == 0) { |
| 1094 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 1095 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 1096 | } else { |
| 1097 | priv->rxon_timing.beacon_interval = |
| 1098 | cpu_to_le16(beacon_int); |
| 1099 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1100 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1101 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1102 | } |
| 1103 | |
| 1104 | priv->rxon_timing.atim_window = 0; |
| 1105 | } else { |
| 1106 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1107 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1108 | /* TODO: we need to get atim_window from upper stack |
| 1109 | * for now we set to 0 */ |
| 1110 | priv->rxon_timing.atim_window = 0; |
| 1111 | } |
| 1112 | |
| 1113 | interval_tm_unit = |
| 1114 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 1115 | result = do_div(tsf, interval_tm_unit); |
| 1116 | priv->rxon_timing.beacon_init_val = |
| 1117 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 1118 | |
| 1119 | IWL_DEBUG_ASSOC |
| 1120 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 1121 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 1122 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 1123 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 1124 | } |
| 1125 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1126 | static int iwl4965_scan_initiate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1127 | { |
| 1128 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 1129 | IWL_ERROR("APs don't scan.\n"); |
| 1130 | return 0; |
| 1131 | } |
| 1132 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1133 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1134 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 1135 | return -EIO; |
| 1136 | } |
| 1137 | |
| 1138 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1139 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 1140 | return -EAGAIN; |
| 1141 | } |
| 1142 | |
| 1143 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1144 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 1145 | "Queuing.\n"); |
| 1146 | return -EAGAIN; |
| 1147 | } |
| 1148 | |
| 1149 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 1150 | priv->scan_bands = 2; |
| 1151 | set_bit(STATUS_SCANNING, &priv->status); |
| 1152 | priv->scan_start = jiffies; |
| 1153 | priv->scan_pass_start = priv->scan_start; |
| 1154 | |
| 1155 | queue_work(priv->workqueue, &priv->request_scan); |
| 1156 | |
| 1157 | return 0; |
| 1158 | } |
| 1159 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1160 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1161 | static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1162 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1163 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1164 | if (band == IEEE80211_BAND_5GHZ) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1165 | priv->staging_rxon.flags &= |
| 1166 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 1167 | | RXON_FLG_CCK_MSK); |
| 1168 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1169 | } else { |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 1170 | /* Copied from iwl4965_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1171 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 1172 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1173 | else |
| 1174 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1175 | |
| 1176 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 1177 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1178 | |
| 1179 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 1180 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 1181 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1186 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1187 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1188 | static void iwl4965_connection_init_rx_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1189 | { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1190 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1191 | |
| 1192 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 1193 | |
| 1194 | switch (priv->iw_mode) { |
| 1195 | case IEEE80211_IF_TYPE_AP: |
| 1196 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 1197 | break; |
| 1198 | |
| 1199 | case IEEE80211_IF_TYPE_STA: |
| 1200 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 1201 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 1202 | break; |
| 1203 | |
| 1204 | case IEEE80211_IF_TYPE_IBSS: |
| 1205 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 1206 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1207 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 1208 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1209 | break; |
| 1210 | |
| 1211 | case IEEE80211_IF_TYPE_MNTR: |
| 1212 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 1213 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 1214 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1215 | break; |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1216 | default: |
| 1217 | IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode); |
| 1218 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | #if 0 |
| 1222 | /* TODO: Figure out when short_preamble would be set and cache from |
| 1223 | * that */ |
| 1224 | if (!hw_to_local(priv->hw)->short_preamble) |
| 1225 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1226 | else |
| 1227 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1228 | #endif |
| 1229 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1230 | ch_info = iwl_get_channel_info(priv, priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1231 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1232 | |
| 1233 | if (!ch_info) |
| 1234 | ch_info = &priv->channel_info[0]; |
| 1235 | |
| 1236 | /* |
| 1237 | * in some case A channels are all non IBSS |
| 1238 | * in this case force B/G channel |
| 1239 | */ |
| 1240 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 1241 | !(is_channel_ibss(ch_info))) |
| 1242 | ch_info = &priv->channel_info[0]; |
| 1243 | |
| 1244 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1245 | priv->band = ch_info->band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1246 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1247 | iwl4965_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1248 | |
| 1249 | priv->staging_rxon.ofdm_basic_rates = |
| 1250 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1251 | priv->staging_rxon.cck_basic_rates = |
| 1252 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1253 | |
| 1254 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 1255 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 1256 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1257 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 1258 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 1259 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 1260 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1263 | static int iwl4965_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1264 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1265 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1266 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1267 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1268 | ch_info = iwl_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1269 | priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1270 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1271 | |
| 1272 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 1273 | IWL_ERROR("channel %d not IBSS channel\n", |
| 1274 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1275 | return -EINVAL; |
| 1276 | } |
| 1277 | } |
| 1278 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1279 | priv->iw_mode = mode; |
| 1280 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1281 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1282 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1283 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1284 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1285 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1286 | /* dont commit rxon if rf-kill is on*/ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1287 | if (!iwl_is_ready_rf(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1288 | return -EAGAIN; |
| 1289 | |
| 1290 | cancel_delayed_work(&priv->scan_check); |
| 1291 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
| 1292 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 1293 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 1294 | return -EAGAIN; |
| 1295 | } |
| 1296 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1297 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1298 | |
| 1299 | return 0; |
| 1300 | } |
| 1301 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1302 | static void iwl4965_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1303 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1304 | const struct ieee80211_supported_band *hw = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1305 | struct ieee80211_rate *rate; |
| 1306 | int i; |
| 1307 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 1308 | hw = iwl_get_hw_mode(priv, priv->band); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 1309 | if (!hw) { |
| 1310 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 1311 | return; |
| 1312 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1313 | |
| 1314 | priv->active_rate = 0; |
| 1315 | priv->active_rate_basic = 0; |
| 1316 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1317 | for (i = 0; i < hw->n_bitrates; i++) { |
| 1318 | rate = &(hw->bitrates[i]); |
| 1319 | if (rate->hw_value < IWL_RATE_COUNT) |
| 1320 | priv->active_rate |= (1 << rate->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 1324 | priv->active_rate, priv->active_rate_basic); |
| 1325 | |
| 1326 | /* |
| 1327 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 1328 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 1329 | * OFDM |
| 1330 | */ |
| 1331 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 1332 | priv->staging_rxon.cck_basic_rates = |
| 1333 | ((priv->active_rate_basic & |
| 1334 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1335 | else |
| 1336 | priv->staging_rxon.cck_basic_rates = |
| 1337 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1338 | |
| 1339 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 1340 | priv->staging_rxon.ofdm_basic_rates = |
| 1341 | ((priv->active_rate_basic & |
| 1342 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 1343 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1344 | else |
| 1345 | priv->staging_rxon.ofdm_basic_rates = |
| 1346 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1347 | } |
| 1348 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1349 | void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1350 | { |
| 1351 | unsigned long flags; |
| 1352 | |
| 1353 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 1354 | return; |
| 1355 | |
| 1356 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 1357 | disable_radio ? "OFF" : "ON"); |
| 1358 | |
| 1359 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1360 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1361 | /* FIXME: This is a workaround for AP */ |
| 1362 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 1363 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1364 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1365 | CSR_UCODE_SW_BIT_RFKILL); |
| 1366 | spin_unlock_irqrestore(&priv->lock, flags); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1367 | /* call the host command only if no hw rf-kill set */ |
Mohamed Abbas | 5900383 | 2008-04-15 16:01:46 -0700 | [diff] [blame] | 1368 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status) && |
| 1369 | iwl_is_ready(priv)) |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1370 | iwl4965_send_card_state(priv, |
| 1371 | CARD_STATE_CMD_DISABLE, |
| 1372 | 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1373 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1374 | |
| 1375 | /* make sure mac80211 stop sending Tx frame */ |
| 1376 | if (priv->mac80211_registered) |
| 1377 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1378 | } |
| 1379 | return; |
| 1380 | } |
| 1381 | |
| 1382 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1383 | 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] | 1384 | |
| 1385 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 1386 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1387 | |
| 1388 | /* wake up ucode */ |
| 1389 | msleep(10); |
| 1390 | |
| 1391 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1392 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 1393 | if (!iwl_grab_nic_access(priv)) |
| 1394 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1395 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1396 | |
| 1397 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 1398 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 1399 | "disabled by HW switch\n"); |
| 1400 | return; |
| 1401 | } |
| 1402 | |
| 1403 | queue_work(priv->workqueue, &priv->restart); |
| 1404 | return; |
| 1405 | } |
| 1406 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1407 | #define IWL_PACKET_RETRY_TIME HZ |
| 1408 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1409 | 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] | 1410 | { |
| 1411 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 1412 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 1413 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 1414 | u16 *last_seq, *last_frag; |
| 1415 | unsigned long *last_time; |
| 1416 | |
| 1417 | switch (priv->iw_mode) { |
| 1418 | case IEEE80211_IF_TYPE_IBSS:{ |
| 1419 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1420 | struct iwl4965_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1421 | u8 *mac = header->addr2; |
| 1422 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 1423 | |
| 1424 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1425 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1426 | if (!compare_ether_addr(entry->mac, mac)) |
| 1427 | break; |
| 1428 | } |
| 1429 | if (p == &priv->ibss_mac_hash[index]) { |
| 1430 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 1431 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1432 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1433 | return 0; |
| 1434 | } |
| 1435 | memcpy(entry->mac, mac, ETH_ALEN); |
| 1436 | entry->seq_num = seq; |
| 1437 | entry->frag_num = frag; |
| 1438 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1439 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1440 | return 0; |
| 1441 | } |
| 1442 | last_seq = &entry->seq_num; |
| 1443 | last_frag = &entry->frag_num; |
| 1444 | last_time = &entry->packet_time; |
| 1445 | break; |
| 1446 | } |
| 1447 | case IEEE80211_IF_TYPE_STA: |
| 1448 | last_seq = &priv->last_seq_num; |
| 1449 | last_frag = &priv->last_frag_num; |
| 1450 | last_time = &priv->last_packet_time; |
| 1451 | break; |
| 1452 | default: |
| 1453 | return 0; |
| 1454 | } |
| 1455 | if ((*last_seq == seq) && |
| 1456 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 1457 | if (*last_frag == frag) |
| 1458 | goto drop; |
| 1459 | if (*last_frag + 1 != frag) |
| 1460 | /* out-of-order fragment */ |
| 1461 | goto drop; |
| 1462 | } else |
| 1463 | *last_seq = seq; |
| 1464 | |
| 1465 | *last_frag = frag; |
| 1466 | *last_time = jiffies; |
| 1467 | return 0; |
| 1468 | |
| 1469 | drop: |
| 1470 | return 1; |
| 1471 | } |
| 1472 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1473 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1474 | |
| 1475 | #include "iwl-spectrum.h" |
| 1476 | |
| 1477 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 1478 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 1479 | #define TIME_UNIT 1024 |
| 1480 | |
| 1481 | /* |
| 1482 | * extended beacon time format |
| 1483 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 1484 | * the high 1 byte is the beacon counts |
| 1485 | * the lower 3 bytes is the time in usec within one beacon interval |
| 1486 | */ |
| 1487 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1488 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1489 | { |
| 1490 | u32 quot; |
| 1491 | u32 rem; |
| 1492 | u32 interval = beacon_interval * 1024; |
| 1493 | |
| 1494 | if (!interval || !usec) |
| 1495 | return 0; |
| 1496 | |
| 1497 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 1498 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 1499 | |
| 1500 | return (quot << 24) + rem; |
| 1501 | } |
| 1502 | |
| 1503 | /* base is usually what we get from ucode with each received frame, |
| 1504 | * the same as HW timer counter counting down |
| 1505 | */ |
| 1506 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1507 | 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] | 1508 | { |
| 1509 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 1510 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 1511 | u32 interval = beacon_interval * TIME_UNIT; |
| 1512 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 1513 | (addon & BEACON_TIME_MASK_HIGH); |
| 1514 | |
| 1515 | if (base_low > addon_low) |
| 1516 | res += base_low - addon_low; |
| 1517 | else if (base_low < addon_low) { |
| 1518 | res += interval + base_low - addon_low; |
| 1519 | res += (1 << 24); |
| 1520 | } else |
| 1521 | res += (1 << 24); |
| 1522 | |
| 1523 | return cpu_to_le32(res); |
| 1524 | } |
| 1525 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1526 | static int iwl4965_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1527 | struct ieee80211_measurement_params *params, |
| 1528 | u8 type) |
| 1529 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1530 | struct iwl4965_spectrum_cmd spectrum; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1531 | struct iwl_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1532 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1533 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 1534 | .data = (void *)&spectrum, |
| 1535 | .meta.flags = CMD_WANT_SKB, |
| 1536 | }; |
| 1537 | u32 add_time = le64_to_cpu(params->start_time); |
| 1538 | int rc; |
| 1539 | int spectrum_resp_status; |
| 1540 | int duration = le16_to_cpu(params->duration); |
| 1541 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1542 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1543 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1544 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1545 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 1546 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1547 | |
| 1548 | memset(&spectrum, 0, sizeof(spectrum)); |
| 1549 | |
| 1550 | spectrum.channel_count = cpu_to_le16(1); |
| 1551 | spectrum.flags = |
| 1552 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 1553 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 1554 | cmd.len = sizeof(spectrum); |
| 1555 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 1556 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1557 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1558 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1559 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1560 | add_time, |
| 1561 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1562 | else |
| 1563 | spectrum.start_time = 0; |
| 1564 | |
| 1565 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 1566 | spectrum.channels[0].channel = params->channel; |
| 1567 | spectrum.channels[0].type = type; |
| 1568 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 1569 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 1570 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 1571 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1572 | rc = iwl_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1573 | if (rc) |
| 1574 | return rc; |
| 1575 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1576 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1577 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1578 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 1579 | rc = -EIO; |
| 1580 | } |
| 1581 | |
| 1582 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 1583 | switch (spectrum_resp_status) { |
| 1584 | case 0: /* Command will be handled */ |
| 1585 | if (res->u.spectrum.id != 0xff) { |
| 1586 | IWL_DEBUG_INFO |
| 1587 | ("Replaced existing measurement: %d\n", |
| 1588 | res->u.spectrum.id); |
| 1589 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 1590 | } |
| 1591 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 1592 | rc = 0; |
| 1593 | break; |
| 1594 | |
| 1595 | case 1: /* Command will not be handled */ |
| 1596 | rc = -EAGAIN; |
| 1597 | break; |
| 1598 | } |
| 1599 | |
| 1600 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1601 | |
| 1602 | return rc; |
| 1603 | } |
| 1604 | #endif |
| 1605 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1606 | static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv, |
Tomas Winkler | 8567c63 | 2008-05-15 13:53:58 +0800 | [diff] [blame] | 1607 | struct iwl_tx_info *tx_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1608 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1609 | ieee80211_tx_status_irqsafe(priv->hw, tx_sta->skb[0]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1610 | tx_sta->skb[0] = NULL; |
| 1611 | } |
| 1612 | |
| 1613 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1614 | * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1615 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1616 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 1617 | * need to be reclaimed. As result, some free space forms. If there is |
| 1618 | * enough free space (> low mark), wake the stack that feeds us. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1619 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1620 | 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] | 1621 | { |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 1622 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 1623 | struct iwl_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1624 | int nfreed = 0; |
| 1625 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 1626 | if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1627 | IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " |
| 1628 | "is out of range [0-%d] %d %d.\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1629 | index, q->n_bd, q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1630 | return 0; |
| 1631 | } |
| 1632 | |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 1633 | for (index = iwl_queue_inc_wrap(index, q->n_bd); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1634 | q->read_ptr != index; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 1635 | 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] | 1636 | if (txq_id != IWL_CMD_QUEUE_NUM) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1637 | iwl4965_txstatus_to_ieee(priv, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1638 | &(txq->txb[txq->q.read_ptr])); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 1639 | iwl_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1640 | } else if (nfreed > 1) { |
| 1641 | IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1642 | q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1643 | queue_work(priv->workqueue, &priv->restart); |
| 1644 | } |
| 1645 | nfreed++; |
| 1646 | } |
| 1647 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1648 | return nfreed; |
| 1649 | } |
| 1650 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1651 | static int iwl4965_is_tx_success(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1652 | { |
| 1653 | status &= TX_STATUS_MSK; |
| 1654 | return (status == TX_STATUS_SUCCESS) |
| 1655 | || (status == TX_STATUS_DIRECT_DONE); |
| 1656 | } |
| 1657 | |
| 1658 | /****************************************************************************** |
| 1659 | * |
| 1660 | * Generic RX handler implementations |
| 1661 | * |
| 1662 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1663 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1664 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1665 | static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1666 | struct ieee80211_hdr *hdr) |
| 1667 | { |
| 1668 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) |
| 1669 | return IWL_AP_ID; |
| 1670 | else { |
| 1671 | u8 *da = ieee80211_get_DA(hdr); |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 1672 | return iwl_find_station(priv, da); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1673 | } |
| 1674 | } |
| 1675 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1676 | static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr( |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1677 | struct iwl_priv *priv, int txq_id, int idx) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1678 | { |
| 1679 | if (priv->txq[txq_id].txb[idx].skb[0]) |
| 1680 | return (struct ieee80211_hdr *)priv->txq[txq_id]. |
| 1681 | txb[idx].skb[0]->data; |
| 1682 | return NULL; |
| 1683 | } |
| 1684 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1685 | 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] | 1686 | { |
| 1687 | __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + |
| 1688 | tx_resp->frame_count); |
| 1689 | return le32_to_cpu(*scd_ssn) & MAX_SN; |
| 1690 | |
| 1691 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1692 | |
| 1693 | /** |
| 1694 | * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue |
| 1695 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1696 | static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv, |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 1697 | struct iwl_ht_agg *agg, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1698 | struct iwl4965_tx_resp_agg *tx_resp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1699 | u16 start_idx) |
| 1700 | { |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1701 | u16 status; |
| 1702 | struct agg_tx_status *frame_status = &tx_resp->status; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1703 | struct ieee80211_tx_info *info = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1704 | struct ieee80211_hdr *hdr = NULL; |
| 1705 | int i, sh; |
| 1706 | int txq_id, idx; |
| 1707 | u16 seq; |
| 1708 | |
| 1709 | if (agg->wait_for_ba) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1710 | IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1711 | |
| 1712 | agg->frame_count = tx_resp->frame_count; |
| 1713 | agg->start_idx = start_idx; |
| 1714 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1715 | agg->bitmap = 0; |
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 | /* # frames attempted by Tx command */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1718 | if (agg->frame_count == 1) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1719 | /* Only one frame was attempted; no block-ack will arrive */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1720 | status = le16_to_cpu(frame_status[0].status); |
| 1721 | seq = le16_to_cpu(frame_status[0].sequence); |
| 1722 | idx = SEQ_TO_INDEX(seq); |
| 1723 | txq_id = SEQ_TO_QUEUE(seq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1724 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1725 | /* FIXME: code repetition */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1726 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n", |
| 1727 | agg->frame_count, agg->start_idx, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1728 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1729 | info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]); |
| 1730 | info->status.retry_count = tx_resp->failure_frame; |
| 1731 | info->flags &= ~IEEE80211_TX_CTL_AMPDU; |
| 1732 | info->flags |= iwl4965_is_tx_success(status)? |
| 1733 | IEEE80211_TX_STAT_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 1734 | iwl4965_hwrate_to_tx_control(priv, |
| 1735 | le32_to_cpu(tx_resp->rate_n_flags), |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1736 | info); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1737 | /* FIXME: code repetition end */ |
| 1738 | |
| 1739 | IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", |
| 1740 | status & 0xff, tx_resp->failure_frame); |
| 1741 | IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1742 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1743 | |
| 1744 | agg->wait_for_ba = 0; |
| 1745 | } else { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1746 | /* Two or more frames were attempted; expect block-ack */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1747 | u64 bitmap = 0; |
| 1748 | int start = agg->start_idx; |
| 1749 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1750 | /* Construct bit-map of pending frames within Tx window */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1751 | for (i = 0; i < agg->frame_count; i++) { |
| 1752 | u16 sc; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1753 | status = le16_to_cpu(frame_status[i].status); |
| 1754 | seq = le16_to_cpu(frame_status[i].sequence); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1755 | idx = SEQ_TO_INDEX(seq); |
| 1756 | txq_id = SEQ_TO_QUEUE(seq); |
| 1757 | |
| 1758 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 1759 | AGG_TX_STATE_ABORT_MSK)) |
| 1760 | continue; |
| 1761 | |
| 1762 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
| 1763 | agg->frame_count, txq_id, idx); |
| 1764 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1765 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1766 | |
| 1767 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 1768 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
| 1769 | IWL_ERROR("BUG_ON idx doesn't match seq control" |
| 1770 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 1771 | idx, SEQ_TO_SN(sc), |
| 1772 | hdr->seq_ctrl); |
| 1773 | return -1; |
| 1774 | } |
| 1775 | |
| 1776 | IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
| 1777 | i, idx, SEQ_TO_SN(sc)); |
| 1778 | |
| 1779 | sh = idx - start; |
| 1780 | if (sh > 64) { |
| 1781 | sh = (start - idx) + 0xff; |
| 1782 | bitmap = bitmap << sh; |
| 1783 | sh = 0; |
| 1784 | start = idx; |
| 1785 | } else if (sh < -64) |
| 1786 | sh = 0xff - (start - idx); |
| 1787 | else if (sh < 0) { |
| 1788 | sh = start - idx; |
| 1789 | start = idx; |
| 1790 | bitmap = bitmap << sh; |
| 1791 | sh = 0; |
| 1792 | } |
| 1793 | bitmap |= (1 << sh); |
| 1794 | IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n", |
| 1795 | start, (u32)(bitmap & 0xFFFFFFFF)); |
| 1796 | } |
| 1797 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1798 | agg->bitmap = bitmap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1799 | agg->start_idx = start; |
| 1800 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1801 | 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] | 1802 | agg->frame_count, agg->start_idx, |
John W. Linville | 06501d2 | 2008-04-01 17:38:47 -0400 | [diff] [blame] | 1803 | (unsigned long long)agg->bitmap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1804 | |
| 1805 | if (bitmap) |
| 1806 | agg->wait_for_ba = 1; |
| 1807 | } |
| 1808 | return 0; |
| 1809 | } |
| 1810 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1811 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1812 | /** |
| 1813 | * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response |
| 1814 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1815 | static void iwl4965_rx_reply_tx(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1816 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1817 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1818 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1819 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 1820 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 1821 | int index = SEQ_TO_INDEX(sequence); |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 1822 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1823 | struct ieee80211_tx_info *info; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1824 | struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1825 | u32 status = le32_to_cpu(tx_resp->status); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1826 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1827 | int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 1828 | u16 fc; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1829 | struct ieee80211_hdr *hdr; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 1830 | u8 *qc = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1831 | #endif |
| 1832 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 1833 | 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] | 1834 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 1835 | "is out of range [0-%d] %d %d\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1836 | index, txq->q.n_bd, txq->q.write_ptr, |
| 1837 | txq->q.read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1838 | return; |
| 1839 | } |
| 1840 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1841 | info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]); |
| 1842 | memset(&info->status, 0, sizeof(info->status)); |
| 1843 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1844 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1845 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index); |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 1846 | fc = le16_to_cpu(hdr->frame_control); |
| 1847 | if (ieee80211_is_qos_data(fc)) { |
| 1848 | qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc)); |
| 1849 | tid = qc[0] & 0xf; |
| 1850 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1851 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1852 | sta_id = iwl4965_get_ra_sta_id(priv, hdr); |
| 1853 | if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) { |
| 1854 | IWL_ERROR("Station not known\n"); |
| 1855 | return; |
| 1856 | } |
| 1857 | |
| 1858 | if (txq->sched_retry) { |
| 1859 | const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp); |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 1860 | struct iwl_ht_agg *agg = NULL; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1861 | |
| 1862 | if (!qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1863 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1864 | |
| 1865 | agg = &priv->stations[sta_id].tid[tid].agg; |
| 1866 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1867 | iwl4965_tx_status_reply_tx(priv, agg, |
| 1868 | (struct iwl4965_tx_resp_agg *)tx_resp, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1869 | |
| 1870 | if ((tx_resp->frame_count == 1) && |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1871 | !iwl4965_is_tx_success(status)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1872 | /* TODO: send BAR */ |
| 1873 | } |
| 1874 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1875 | if (txq->q.read_ptr != (scd_ssn & 0xff)) { |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 1876 | int freed, ampdu_q; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 1877 | index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1878 | IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " |
| 1879 | "%d index %d\n", scd_ssn , index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1880 | freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
| 1881 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 1882 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 1883 | if (iwl_queue_space(&txq->q) > txq->q.low_mark && |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1884 | txq_id >= 0 && priv->mac80211_registered && |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 1885 | agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) { |
| 1886 | /* calculate mac80211 ampdu sw queue to wake */ |
| 1887 | ampdu_q = txq_id - IWL_BACK_QUEUE_FIRST_ID + |
| 1888 | priv->hw->queues; |
| 1889 | if (agg->state == IWL_AGG_OFF) |
| 1890 | ieee80211_wake_queue(priv->hw, txq_id); |
| 1891 | else |
| 1892 | ieee80211_wake_queue(priv->hw, ampdu_q); |
| 1893 | } |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1894 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1895 | } |
| 1896 | } else { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1897 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1898 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1899 | info->status.retry_count = tx_resp->failure_frame; |
| 1900 | info->flags |= |
| 1901 | iwl4965_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 1902 | iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags), |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1903 | info); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1904 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1905 | 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] | 1906 | "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1907 | status, le32_to_cpu(tx_resp->rate_n_flags), |
| 1908 | tx_resp->failure_frame); |
| 1909 | |
| 1910 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 1911 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1912 | if (index != -1) { |
| 1913 | int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1914 | if (tid != MAX_TID_COUNT) |
| 1915 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 1916 | if (iwl_queue_space(&txq->q) > txq->q.low_mark && |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 1917 | (txq_id >= 0) && priv->mac80211_registered) |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1918 | ieee80211_wake_queue(priv->hw, txq_id); |
| 1919 | if (tid != MAX_TID_COUNT) |
| 1920 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1921 | } |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1922 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1923 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1924 | |
| 1925 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 1926 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 1927 | } |
| 1928 | |
| 1929 | |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1930 | static void iwl_rx_reply_alive(struct iwl_priv *priv, |
| 1931 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1932 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1933 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1934 | struct iwl_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1935 | struct delayed_work *pwork; |
| 1936 | |
| 1937 | palive = &pkt->u.alive_frame; |
| 1938 | |
| 1939 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 1940 | "0x%01X 0x%01X\n", |
| 1941 | palive->is_valid, palive->ver_type, |
| 1942 | palive->ver_subtype); |
| 1943 | |
| 1944 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 1945 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 1946 | memcpy(&priv->card_alive_init, |
| 1947 | &pkt->u.alive_frame, |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1948 | sizeof(struct iwl_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1949 | pwork = &priv->init_alive_start; |
| 1950 | } else { |
| 1951 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 1952 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1953 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1954 | pwork = &priv->alive_start; |
| 1955 | } |
| 1956 | |
| 1957 | /* We delay the ALIVE response by 5ms to |
| 1958 | * give the HW RF Kill time to activate... */ |
| 1959 | if (palive->is_valid == UCODE_VALID_OK) |
| 1960 | queue_delayed_work(priv->workqueue, pwork, |
| 1961 | msecs_to_jiffies(5)); |
| 1962 | else |
| 1963 | IWL_WARNING("uCode did not respond OK.\n"); |
| 1964 | } |
| 1965 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1966 | static void iwl4965_rx_reply_add_sta(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1967 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1968 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1969 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1970 | |
| 1971 | IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
| 1972 | return; |
| 1973 | } |
| 1974 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1975 | static void iwl4965_rx_reply_error(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1976 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1977 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1978 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1979 | |
| 1980 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 1981 | "seq 0x%04X ser 0x%08X\n", |
| 1982 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 1983 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 1984 | pkt->u.err_resp.cmd_id, |
| 1985 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 1986 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 1987 | } |
| 1988 | |
| 1989 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 1990 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1991 | 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] | 1992 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1993 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 1994 | struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1995 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1996 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 1997 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 1998 | rxon->channel = csa->channel; |
| 1999 | priv->staging_rxon.channel = csa->channel; |
| 2000 | } |
| 2001 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2002 | static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2003 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2004 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 2005 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2006 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2007 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2008 | |
| 2009 | if (!report->state) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2010 | IWL_DEBUG(IWL_DL_11H, |
| 2011 | "Spectrum Measure Notification: Start\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2012 | return; |
| 2013 | } |
| 2014 | |
| 2015 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 2016 | priv->measurement_status |= MEASUREMENT_READY; |
| 2017 | #endif |
| 2018 | } |
| 2019 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2020 | static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2021 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2022 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2023 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2024 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2025 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2026 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 2027 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 2028 | #endif |
| 2029 | } |
| 2030 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2031 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2032 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2033 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2034 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2035 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 2036 | "notification for %s:\n", |
| 2037 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2038 | 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] | 2039 | } |
| 2040 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2041 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2042 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2043 | struct iwl_priv *priv = |
| 2044 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2045 | struct sk_buff *beacon; |
| 2046 | |
| 2047 | /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2048 | beacon = ieee80211_beacon_get(priv->hw, priv->vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2049 | |
| 2050 | if (!beacon) { |
| 2051 | IWL_ERROR("update beacon failed\n"); |
| 2052 | return; |
| 2053 | } |
| 2054 | |
| 2055 | mutex_lock(&priv->mutex); |
| 2056 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 2057 | if (priv->ibss_beacon) |
| 2058 | dev_kfree_skb(priv->ibss_beacon); |
| 2059 | |
| 2060 | priv->ibss_beacon = beacon; |
| 2061 | mutex_unlock(&priv->mutex); |
| 2062 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2063 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2066 | static void iwl4965_rx_beacon_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2067 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2068 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2069 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2070 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2071 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 2072 | 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] | 2073 | |
| 2074 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 2075 | "tsf %d %d rate %d\n", |
| 2076 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 2077 | beacon->beacon_notify_hdr.failure_frame, |
| 2078 | le32_to_cpu(beacon->ibss_mgr_status), |
| 2079 | le32_to_cpu(beacon->high_tsf), |
| 2080 | le32_to_cpu(beacon->low_tsf), rate); |
| 2081 | #endif |
| 2082 | |
| 2083 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 2084 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 2085 | queue_work(priv->workqueue, &priv->beacon_update); |
| 2086 | } |
| 2087 | |
| 2088 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2089 | static void iwl4965_rx_reply_scan(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2090 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2091 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2092 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2093 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2094 | struct iwl4965_scanreq_notification *notif = |
| 2095 | (struct iwl4965_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2096 | |
| 2097 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 2098 | #endif |
| 2099 | } |
| 2100 | |
| 2101 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2102 | static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2103 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2104 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2105 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2106 | struct iwl4965_scanstart_notification *notif = |
| 2107 | (struct iwl4965_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2108 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 2109 | IWL_DEBUG_SCAN("Scan start: " |
| 2110 | "%d [802.11%s] " |
| 2111 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 2112 | notif->channel, |
| 2113 | notif->band ? "bg" : "a", |
| 2114 | notif->tsf_high, |
| 2115 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 2116 | } |
| 2117 | |
| 2118 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2119 | static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2120 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2121 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2122 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2123 | struct iwl4965_scanresults_notification *notif = |
| 2124 | (struct iwl4965_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2125 | |
| 2126 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 2127 | "%d [802.11%s] " |
| 2128 | "(TSF: 0x%08X:%08X) - %d " |
| 2129 | "elapsed=%lu usec (%dms since last)\n", |
| 2130 | notif->channel, |
| 2131 | notif->band ? "bg" : "a", |
| 2132 | le32_to_cpu(notif->tsf_high), |
| 2133 | le32_to_cpu(notif->tsf_low), |
| 2134 | le32_to_cpu(notif->statistics[0]), |
| 2135 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 2136 | jiffies_to_msecs(elapsed_jiffies |
| 2137 | (priv->last_scan_jiffies, jiffies))); |
| 2138 | |
| 2139 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2140 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2144 | static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2145 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2146 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2147 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2148 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2149 | |
| 2150 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 2151 | scan_notif->scanned_channels, |
| 2152 | scan_notif->tsf_low, |
| 2153 | scan_notif->tsf_high, scan_notif->status); |
| 2154 | |
| 2155 | /* The HW is no longer scanning */ |
| 2156 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 2157 | |
| 2158 | /* The scan completion notification came in, so kill that timer... */ |
| 2159 | cancel_delayed_work(&priv->scan_check); |
| 2160 | |
| 2161 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 2162 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 2163 | jiffies_to_msecs(elapsed_jiffies |
| 2164 | (priv->scan_pass_start, jiffies))); |
| 2165 | |
| 2166 | /* Remove this scanned band from the list |
| 2167 | * of pending bands to scan */ |
| 2168 | priv->scan_bands--; |
| 2169 | |
| 2170 | /* If a request to abort was given, or the scan did not succeed |
| 2171 | * then we reset the scan state machine and terminate, |
| 2172 | * re-queuing another scan if one has been requested */ |
| 2173 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2174 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 2175 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2176 | } else { |
| 2177 | /* If there are more bands on this scan pass reschedule */ |
| 2178 | if (priv->scan_bands > 0) |
| 2179 | goto reschedule; |
| 2180 | } |
| 2181 | |
| 2182 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2183 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2184 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 2185 | |
| 2186 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2187 | |
| 2188 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 2189 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 2190 | |
| 2191 | queue_work(priv->workqueue, &priv->scan_completed); |
| 2192 | |
| 2193 | return; |
| 2194 | |
| 2195 | reschedule: |
| 2196 | priv->scan_pass_start = jiffies; |
| 2197 | queue_work(priv->workqueue, &priv->request_scan); |
| 2198 | } |
| 2199 | |
| 2200 | /* Handle notification from uCode that card's power state is changing |
| 2201 | * due to software, hardware, or critical temperature RFKILL */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2202 | static void iwl4965_rx_card_state_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2203 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2204 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2205 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2206 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 2207 | unsigned long status = priv->status; |
| 2208 | |
| 2209 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 2210 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 2211 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 2212 | |
| 2213 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 2214 | RF_CARD_DISABLED)) { |
| 2215 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2216 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2217 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 2218 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2219 | if (!iwl_grab_nic_access(priv)) { |
| 2220 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2221 | priv, HBUS_TARG_MBX_C, |
| 2222 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 2223 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2224 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2225 | } |
| 2226 | |
| 2227 | if (!(flags & RXON_CARD_DISABLED)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2228 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2229 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2230 | if (!iwl_grab_nic_access(priv)) { |
| 2231 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2232 | priv, HBUS_TARG_MBX_C, |
| 2233 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 2234 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2235 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2236 | } |
| 2237 | } |
| 2238 | |
| 2239 | if (flags & RF_CARD_DISABLED) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2240 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2241 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2242 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 2243 | if (!iwl_grab_nic_access(priv)) |
| 2244 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2245 | } |
| 2246 | } |
| 2247 | |
| 2248 | if (flags & HW_CARD_DISABLED) |
| 2249 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2250 | else |
| 2251 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2252 | |
| 2253 | |
| 2254 | if (flags & SW_CARD_DISABLED) |
| 2255 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2256 | else |
| 2257 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2258 | |
| 2259 | if (!(flags & RXON_CARD_DISABLED)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2260 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2261 | |
| 2262 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 2263 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 2264 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 2265 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 2266 | queue_work(priv->workqueue, &priv->rf_kill); |
| 2267 | else |
| 2268 | wake_up_interruptible(&priv->wait_command_queue); |
| 2269 | } |
| 2270 | |
| 2271 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2272 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2273 | * |
| 2274 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 2275 | * to the host. |
| 2276 | * |
| 2277 | * This function chains into the hardware specific files for them to setup |
| 2278 | * any hardware specific handlers as well. |
| 2279 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2280 | static void iwl4965_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2281 | { |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 2282 | priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2283 | priv->rx_handlers[REPLY_ADD_STA] = iwl4965_rx_reply_add_sta; |
| 2284 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 2285 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2286 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2287 | iwl4965_rx_spectrum_measure_notif; |
| 2288 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2289 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2290 | iwl4965_rx_pm_debug_statistics_notif; |
| 2291 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2292 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2293 | /* |
| 2294 | * The same handler is used for both the REPLY to a discrete |
| 2295 | * statistics request from the host as well as for the periodic |
| 2296 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2297 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2298 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
| 2299 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2300 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2301 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
| 2302 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2303 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2304 | iwl4965_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2305 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2306 | iwl4965_rx_scan_complete_notif; |
| 2307 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
| 2308 | priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2309 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2310 | /* Set up hardware specific Rx handlers */ |
Emmanuel Grumbach | d4789ef | 2008-04-24 11:55:20 -0700 | [diff] [blame] | 2311 | priv->cfg->ops->lib->rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2312 | } |
| 2313 | |
| 2314 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2315 | * 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] | 2316 | * @rxb: Rx buffer to reclaim |
| 2317 | * |
| 2318 | * If an Rx buffer has an async callback associated with it the callback |
| 2319 | * will be executed. The attached skb (if present) will only be freed |
| 2320 | * if the callback returns 1 |
| 2321 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2322 | static void iwl4965_tx_cmd_complete(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2323 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2324 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2325 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2326 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 2327 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 2328 | int index = SEQ_TO_INDEX(sequence); |
| 2329 | int huge = sequence & SEQ_HUGE_FRAME; |
| 2330 | int cmd_index; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2331 | struct iwl_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2332 | |
| 2333 | /* If a Tx command is being handled and it isn't in the actual |
| 2334 | * command queue then there a command routing bug has been introduced |
| 2335 | * in the queue management code. */ |
| 2336 | if (txq_id != IWL_CMD_QUEUE_NUM) |
| 2337 | IWL_ERROR("Error wrong command queue %d command id 0x%X\n", |
| 2338 | txq_id, pkt->hdr.cmd); |
| 2339 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 2340 | |
| 2341 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 2342 | cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
| 2343 | |
| 2344 | /* Input error checking is done when commands are added to queue. */ |
| 2345 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 2346 | cmd->meta.source->u.skb = rxb->skb; |
| 2347 | rxb->skb = NULL; |
| 2348 | } else if (cmd->meta.u.callback && |
| 2349 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 2350 | rxb->skb = NULL; |
| 2351 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2352 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2353 | |
| 2354 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 2355 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 2356 | wake_up_interruptible(&priv->wait_command_queue); |
| 2357 | } |
| 2358 | } |
| 2359 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2360 | /* |
| 2361 | * this should be called while priv->lock is locked |
| 2362 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2363 | static void __iwl_rx_replenish(struct iwl_priv *priv) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2364 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2365 | iwl_rx_allocate(priv); |
| 2366 | iwl_rx_queue_restock(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2370 | /** |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2371 | * iwl_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2372 | * |
| 2373 | * Uses the priv->rx_handlers callback function array to invoke |
| 2374 | * the appropriate handlers, including command responses, |
| 2375 | * frame-received notifications, and other notifications. |
| 2376 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2377 | void iwl_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2378 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2379 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2380 | struct iwl_rx_packet *pkt; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2381 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2382 | u32 r, i; |
| 2383 | int reclaim; |
| 2384 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2385 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 2386 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2387 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2388 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 2389 | * buffer that the driver may process (last buffer filled by ucode). */ |
Ron Rindjunsky | d67f548 | 2008-05-05 10:22:49 +0800 | [diff] [blame] | 2390 | r = priv->cfg->ops->lib->shared_mem_rx_idx(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2391 | i = rxq->read; |
| 2392 | |
| 2393 | /* Rx interrupt, but nothing sent from uCode */ |
| 2394 | if (i == r) |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2395 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2396 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2397 | if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2398 | fill_rx = 1; |
| 2399 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2400 | while (i != r) { |
| 2401 | rxb = rxq->queue[i]; |
| 2402 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2403 | /* 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] | 2404 | * then a bug has been introduced in the queue refilling |
| 2405 | * routines -- catch it here */ |
| 2406 | BUG_ON(rxb == NULL); |
| 2407 | |
| 2408 | rxq->queue[i] = NULL; |
| 2409 | |
| 2410 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 2411 | priv->hw_params.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2412 | PCI_DMA_FROMDEVICE); |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2413 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2414 | |
| 2415 | /* Reclaim a command buffer only if this packet is a response |
| 2416 | * to a (driver-originated) command. |
| 2417 | * If the packet (e.g. Rx frame) originated from uCode, |
| 2418 | * there is no command buffer to reclaim. |
| 2419 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 2420 | * but apparently a few don't get set; catch them here. */ |
| 2421 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 2422 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2423 | (pkt->hdr.cmd != REPLY_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 2424 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2425 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 2426 | (pkt->hdr.cmd != REPLY_TX); |
| 2427 | |
| 2428 | /* Based on type of command response or notification, |
| 2429 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2430 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2431 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2432 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r, |
| 2433 | i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2434 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 2435 | } else { |
| 2436 | /* No handling needed */ |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2437 | IWL_DEBUG(IWL_DL_RX, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2438 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 2439 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 2440 | pkt->hdr.cmd); |
| 2441 | } |
| 2442 | |
| 2443 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2444 | /* Invoke any callbacks, transfer the skb to caller, and |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2445 | * fire off the (possibly) blocking iwl_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2446 | * as we reclaim the driver command queue */ |
| 2447 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2448 | iwl4965_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2449 | else |
| 2450 | IWL_WARNING("Claim null rxb?\n"); |
| 2451 | } |
| 2452 | |
| 2453 | /* For now we just don't re-use anything. We can tweak this |
| 2454 | * later to try and re-use notification packets and SKBs that |
| 2455 | * fail to Rx correctly */ |
| 2456 | if (rxb->skb != NULL) { |
| 2457 | priv->alloc_rxb_skb--; |
| 2458 | dev_kfree_skb_any(rxb->skb); |
| 2459 | rxb->skb = NULL; |
| 2460 | } |
| 2461 | |
| 2462 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 2463 | priv->hw_params.rx_buf_size, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 2464 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2465 | spin_lock_irqsave(&rxq->lock, flags); |
| 2466 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 2467 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 2468 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2469 | /* If there are a lot of unused frames, |
| 2470 | * restock the Rx queue so ucode wont assert. */ |
| 2471 | if (fill_rx) { |
| 2472 | count++; |
| 2473 | if (count >= 8) { |
| 2474 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2475 | __iwl_rx_replenish(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2476 | count = 0; |
| 2477 | } |
| 2478 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | /* Backtrack one entry */ |
| 2482 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2483 | iwl_rx_queue_restock(priv); |
| 2484 | } |
| 2485 | /* Convert linear signal-to-noise ratio into dB */ |
| 2486 | static u8 ratio2dB[100] = { |
| 2487 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 2488 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 2489 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 2490 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 2491 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 2492 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 2493 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 2494 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 2495 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 2496 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 2497 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 2498 | }; |
| 2499 | |
| 2500 | /* Calculates a relative dB value from a ratio of linear |
| 2501 | * (i.e. not dB) signal levels. |
| 2502 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
| 2503 | int iwl4965_calc_db_from_ratio(int sig_ratio) |
| 2504 | { |
| 2505 | /* 1000:1 or higher just report as 60 dB */ |
| 2506 | if (sig_ratio >= 1000) |
| 2507 | return 60; |
| 2508 | |
| 2509 | /* 100:1 or higher, divide by 10 and use table, |
| 2510 | * add 20 dB to make up for divide by 10 */ |
| 2511 | if (sig_ratio >= 100) |
| 2512 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 2513 | |
| 2514 | /* We shouldn't see this */ |
| 2515 | if (sig_ratio < 1) |
| 2516 | return 0; |
| 2517 | |
| 2518 | /* Use table for ratios 1:1 - 99:1 */ |
| 2519 | return (int)ratio2dB[sig_ratio]; |
| 2520 | } |
| 2521 | |
| 2522 | #define PERFECT_RSSI (-20) /* dBm */ |
| 2523 | #define WORST_RSSI (-95) /* dBm */ |
| 2524 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 2525 | |
| 2526 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 2527 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 2528 | * about formulas used below. */ |
| 2529 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) |
| 2530 | { |
| 2531 | int sig_qual; |
| 2532 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 2533 | |
| 2534 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 2535 | * as indicator; formula is (signal dbm - noise dbm). |
| 2536 | * SNR at or above 40 is a great signal (100%). |
| 2537 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 2538 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 2539 | if (noise_dbm) { |
| 2540 | if (rssi_dbm - noise_dbm >= 40) |
| 2541 | return 100; |
| 2542 | else if (rssi_dbm < noise_dbm) |
| 2543 | return 0; |
| 2544 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 2545 | |
| 2546 | /* Else use just the signal level. |
| 2547 | * This formula is a least squares fit of data points collected and |
| 2548 | * compared with a reference system that had a percentage (%) display |
| 2549 | * for signal quality. */ |
| 2550 | } else |
| 2551 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 2552 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 2553 | (RSSI_RANGE * RSSI_RANGE); |
| 2554 | |
| 2555 | if (sig_qual > 100) |
| 2556 | sig_qual = 100; |
| 2557 | else if (sig_qual < 1) |
| 2558 | sig_qual = 0; |
| 2559 | |
| 2560 | return sig_qual; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2561 | } |
| 2562 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2563 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2564 | static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2565 | { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 2566 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2567 | DECLARE_MAC_BUF(mac); |
| 2568 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2569 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2570 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2571 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 2572 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 2573 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 2574 | le32_to_cpu(rxon->filter_flags)); |
| 2575 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 2576 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 2577 | rxon->ofdm_basic_rates); |
| 2578 | 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] | 2579 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 2580 | print_mac(mac, rxon->node_addr)); |
| 2581 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 2582 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2583 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 2584 | } |
| 2585 | #endif |
| 2586 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2587 | static void iwl4965_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2588 | { |
| 2589 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 2590 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2591 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2594 | /* call this function to flush any scheduled tasklet */ |
| 2595 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
| 2596 | { |
| 2597 | /* wait to make sure we flush pedding tasklet*/ |
| 2598 | synchronize_irq(priv->pci_dev->irq); |
| 2599 | tasklet_kill(&priv->irq_tasklet); |
| 2600 | } |
| 2601 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2602 | static inline void iwl4965_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2603 | { |
| 2604 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 2605 | |
| 2606 | /* disable interrupts from uCode/NIC to host */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2607 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2608 | |
| 2609 | /* acknowledge/clear/reset any interrupts still pending |
| 2610 | * from uCode or flow handler (Rx/Tx DMA) */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2611 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 2612 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2613 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 2614 | } |
| 2615 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2616 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2617 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2618 | * 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] | 2619 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2620 | static void iwl4965_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2621 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2622 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2623 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 2624 | |
| 2625 | /* Cancel currently queued command. */ |
| 2626 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 2627 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2628 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2629 | if (priv->debug_level & IWL_DL_FW_ERRORS) { |
Ester Kummer | ede0cba | 2008-05-29 16:34:46 +0800 | [diff] [blame] | 2630 | iwl_dump_nic_error_log(priv); |
Ester Kummer | 189a2b5 | 2008-05-15 13:54:18 +0800 | [diff] [blame] | 2631 | iwl_dump_nic_event_log(priv); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2632 | iwl4965_print_rx_config_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2633 | } |
| 2634 | #endif |
| 2635 | |
| 2636 | wake_up_interruptible(&priv->wait_command_queue); |
| 2637 | |
| 2638 | /* Keep the restart process from trying to send host |
| 2639 | * commands by clearing the INIT status bit */ |
| 2640 | clear_bit(STATUS_READY, &priv->status); |
| 2641 | |
| 2642 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2643 | IWL_DEBUG(IWL_DL_FW_ERRORS, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2644 | "Restarting adapter due to uCode error.\n"); |
| 2645 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2646 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2647 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 2648 | sizeof(priv->recovery_rxon)); |
| 2649 | priv->error_recovering = 1; |
| 2650 | } |
Ester Kummer | 3a1081e | 2008-05-06 11:05:14 +0800 | [diff] [blame] | 2651 | if (priv->cfg->mod_params->restart_fw) |
| 2652 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2653 | } |
| 2654 | } |
| 2655 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2656 | static void iwl4965_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2657 | { |
| 2658 | unsigned long flags; |
| 2659 | |
| 2660 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 2661 | sizeof(priv->staging_rxon)); |
| 2662 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2663 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2664 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 2665 | iwl_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2666 | |
| 2667 | spin_lock_irqsave(&priv->lock, flags); |
| 2668 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 2669 | priv->error_recovering = 0; |
| 2670 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2671 | } |
| 2672 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2673 | static void iwl4965_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2674 | { |
| 2675 | u32 inta, handled = 0; |
| 2676 | u32 inta_fh; |
| 2677 | unsigned long flags; |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2678 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2679 | u32 inta_mask; |
| 2680 | #endif |
| 2681 | |
| 2682 | spin_lock_irqsave(&priv->lock, flags); |
| 2683 | |
| 2684 | /* Ack/clear/reset pending uCode interrupts. |
| 2685 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 2686 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2687 | inta = iwl_read32(priv, CSR_INT); |
| 2688 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2689 | |
| 2690 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 2691 | * Any new interrupts that happen after this, either while we're |
| 2692 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2693 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 2694 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2695 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2696 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2697 | if (priv->debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2698 | /* just for debug */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2699 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2700 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 2701 | inta, inta_mask, inta_fh); |
| 2702 | } |
| 2703 | #endif |
| 2704 | |
| 2705 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 2706 | * atomic, make sure that inta covers all the interrupts that |
| 2707 | * we've discovered, even if FH interrupt came in just after |
| 2708 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 2709 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2710 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 2711 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2712 | inta |= CSR_INT_BIT_FH_TX; |
| 2713 | |
| 2714 | /* Now service all interrupt bits discovered above. */ |
| 2715 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 2716 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 2717 | |
| 2718 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2719 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2720 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2721 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2722 | |
| 2723 | handled |= CSR_INT_BIT_HW_ERR; |
| 2724 | |
| 2725 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2726 | |
| 2727 | return; |
| 2728 | } |
| 2729 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2730 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2731 | if (priv->debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2732 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2733 | if (inta & CSR_INT_BIT_SCD) |
| 2734 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 2735 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2736 | |
| 2737 | /* Alive notification via Rx interrupt will do the real work */ |
| 2738 | if (inta & CSR_INT_BIT_ALIVE) |
| 2739 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 2740 | } |
| 2741 | #endif |
| 2742 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2743 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2744 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2745 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2746 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 2747 | int hw_rf_kill = 0; |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2748 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2749 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 2750 | hw_rf_kill = 1; |
| 2751 | |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2752 | 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] | 2753 | hw_rf_kill ? "disable radio":"enable radio"); |
| 2754 | |
| 2755 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 2756 | * when we loaded driver, and is now set to "enable". |
| 2757 | * After we're Alive, RF_KILL gets handled by |
Reinette Chatre | 3230455 | 2008-02-15 14:34:37 -0800 | [diff] [blame] | 2758 | * iwl4965_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 2759 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 2760 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2761 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 2762 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2763 | |
| 2764 | handled |= CSR_INT_BIT_RF_KILL; |
| 2765 | } |
| 2766 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2767 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2768 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 2769 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 2770 | handled |= CSR_INT_BIT_CT_KILL; |
| 2771 | } |
| 2772 | |
| 2773 | /* Error detected by uCode */ |
| 2774 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 2775 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 2776 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2777 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2778 | handled |= CSR_INT_BIT_SW_ERR; |
| 2779 | } |
| 2780 | |
| 2781 | /* uCode wakes up after power-down sleep */ |
| 2782 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 2783 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2784 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 2785 | iwl_txq_update_write_ptr(priv, &priv->txq[0]); |
| 2786 | iwl_txq_update_write_ptr(priv, &priv->txq[1]); |
| 2787 | iwl_txq_update_write_ptr(priv, &priv->txq[2]); |
| 2788 | iwl_txq_update_write_ptr(priv, &priv->txq[3]); |
| 2789 | iwl_txq_update_write_ptr(priv, &priv->txq[4]); |
| 2790 | iwl_txq_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2791 | |
| 2792 | handled |= CSR_INT_BIT_WAKEUP; |
| 2793 | } |
| 2794 | |
| 2795 | /* All uCode command responses, including Tx command responses, |
| 2796 | * Rx "responses" (frame-received notification), and other |
| 2797 | * notifications from uCode come through here*/ |
| 2798 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2799 | iwl_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2800 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 2801 | } |
| 2802 | |
| 2803 | if (inta & CSR_INT_BIT_FH_TX) { |
| 2804 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 2805 | handled |= CSR_INT_BIT_FH_TX; |
Ron Rindjunsky | dbb983b | 2008-05-15 13:54:12 +0800 | [diff] [blame] | 2806 | /* FH finished to write, send event */ |
| 2807 | priv->ucode_write_complete = 1; |
| 2808 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2809 | } |
| 2810 | |
| 2811 | if (inta & ~handled) |
| 2812 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 2813 | |
| 2814 | if (inta & ~CSR_INI_SET_MASK) { |
| 2815 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 2816 | inta & ~CSR_INI_SET_MASK); |
| 2817 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 2818 | } |
| 2819 | |
| 2820 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2821 | /* only Re-enable if diabled by irq */ |
| 2822 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 2823 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2824 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2825 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2826 | if (priv->debug_level & (IWL_DL_ISR)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2827 | inta = iwl_read32(priv, CSR_INT); |
| 2828 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 2829 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2830 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 2831 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 2832 | } |
| 2833 | #endif |
| 2834 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2835 | } |
| 2836 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2837 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2838 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2839 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2840 | u32 inta, inta_mask; |
| 2841 | u32 inta_fh; |
| 2842 | if (!priv) |
| 2843 | return IRQ_NONE; |
| 2844 | |
| 2845 | spin_lock(&priv->lock); |
| 2846 | |
| 2847 | /* Disable (but don't clear!) interrupts here to avoid |
| 2848 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 2849 | * If we have something to service, the tasklet will re-enable ints. |
| 2850 | * 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] | 2851 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 2852 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2853 | |
| 2854 | /* Discover which interrupts are active/pending */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2855 | inta = iwl_read32(priv, CSR_INT); |
| 2856 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2857 | |
| 2858 | /* Ignore interrupt if there's nothing in NIC to service. |
| 2859 | * This may be due to IRQ shared with another device, |
| 2860 | * or due to sporadic interrupts thrown from our NIC. */ |
| 2861 | if (!inta && !inta_fh) { |
| 2862 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 2863 | goto none; |
| 2864 | } |
| 2865 | |
| 2866 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 2867 | /* Hardware disappeared. It might have already raised |
| 2868 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2869 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 2870 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 2874 | inta, inta_mask, inta_fh); |
| 2875 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2876 | inta &= ~CSR_INT_BIT_SCD; |
| 2877 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2878 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2879 | if (likely(inta || inta_fh)) |
| 2880 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2881 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 2882 | unplugged: |
| 2883 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2884 | return IRQ_HANDLED; |
| 2885 | |
| 2886 | none: |
| 2887 | /* re-enable interrupts here since we don't have anything to service. */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2888 | /* only Re-enable if diabled by irq */ |
| 2889 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 2890 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2891 | spin_unlock(&priv->lock); |
| 2892 | return IRQ_NONE; |
| 2893 | } |
| 2894 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2895 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 2896 | * sending probe req. This should be set long enough to hear probe responses |
| 2897 | * from more than one AP. */ |
| 2898 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 2899 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 2900 | |
| 2901 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 2902 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 2903 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 2904 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 2905 | * no other traffic). |
| 2906 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 2907 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 2908 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 2909 | |
| 2910 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 2911 | * Must be set longer than active dwell time. |
| 2912 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 2913 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 2914 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 2915 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 2916 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 2917 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2918 | static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2919 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2920 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2921 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2922 | return IWL_ACTIVE_DWELL_TIME_52; |
| 2923 | else |
| 2924 | return IWL_ACTIVE_DWELL_TIME_24; |
| 2925 | } |
| 2926 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2927 | static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2928 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2929 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2930 | u16 active = iwl4965_get_active_dwell_time(priv, band); |
| 2931 | u16 passive = (band != IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2932 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 2933 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 2934 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2935 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2936 | /* If we're associated, we clamp the maximum passive |
| 2937 | * dwell time to be 98% of the beacon interval (minus |
| 2938 | * 2 * channel tune time) */ |
| 2939 | passive = priv->beacon_int; |
| 2940 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 2941 | passive = IWL_PASSIVE_DWELL_BASE; |
| 2942 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 2943 | } |
| 2944 | |
| 2945 | if (passive <= active) |
| 2946 | passive = active + 1; |
| 2947 | |
| 2948 | return passive; |
| 2949 | } |
| 2950 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2951 | static int iwl4965_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2952 | enum ieee80211_band band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2953 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2954 | struct iwl4965_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2955 | { |
| 2956 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2957 | const struct ieee80211_supported_band *sband; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 2958 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2959 | u16 passive_dwell = 0; |
| 2960 | u16 active_dwell = 0; |
| 2961 | int added, i; |
| 2962 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 2963 | sband = iwl_get_hw_mode(priv, band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2964 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2965 | return 0; |
| 2966 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2967 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2968 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2969 | active_dwell = iwl4965_get_active_dwell_time(priv, band); |
| 2970 | passive_dwell = iwl4965_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2971 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2972 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 2973 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 2974 | continue; |
| 2975 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2976 | scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2977 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 2978 | ch_info = iwl_get_channel_info(priv, band, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2979 | scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2980 | if (!is_channel_valid(ch_info)) { |
| 2981 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 2982 | scan_ch->channel); |
| 2983 | continue; |
| 2984 | } |
| 2985 | |
| 2986 | if (!is_active || is_channel_passive(ch_info) || |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2987 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2988 | scan_ch->type = 0; /* passive */ |
| 2989 | else |
| 2990 | scan_ch->type = 1; /* active */ |
| 2991 | |
| 2992 | if (scan_ch->type & 1) |
| 2993 | scan_ch->type |= (direct_mask << 1); |
| 2994 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2995 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 2996 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 2997 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2998 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2999 | scan_ch->tpc.dsp_atten = 110; |
| 3000 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 3001 | |
| 3002 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3003 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3004 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 3005 | else { |
| 3006 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 3007 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3008 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 3009 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3010 | */ |
| 3011 | } |
| 3012 | |
| 3013 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 3014 | scan_ch->channel, |
| 3015 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 3016 | (scan_ch->type & 1) ? |
| 3017 | active_dwell : passive_dwell); |
| 3018 | |
| 3019 | scan_ch++; |
| 3020 | added++; |
| 3021 | } |
| 3022 | |
| 3023 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 3024 | return added; |
| 3025 | } |
| 3026 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3027 | /****************************************************************************** |
| 3028 | * |
| 3029 | * uCode download functions |
| 3030 | * |
| 3031 | ******************************************************************************/ |
| 3032 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3033 | static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3034 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3035 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 3036 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 3037 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 3038 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 3039 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 3040 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3041 | } |
| 3042 | |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 3043 | static void iwl4965_nic_start(struct iwl_priv *priv) |
| 3044 | { |
| 3045 | /* Remove all resets to allow NIC to operate */ |
| 3046 | iwl_write32(priv, CSR_RESET, 0); |
| 3047 | } |
| 3048 | |
| 3049 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3050 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3051 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3052 | * |
| 3053 | * Copy into buffers for card to fetch via bus-mastering |
| 3054 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3055 | static int iwl4965_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3056 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3057 | struct iwl4965_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3058 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3059 | const struct firmware *ucode_raw; |
Tomas Winkler | 4bf775cd | 2008-03-04 18:09:31 -0800 | [diff] [blame] | 3060 | const char *name = priv->cfg->fw_name; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3061 | u8 *src; |
| 3062 | size_t len; |
| 3063 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 3064 | |
| 3065 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 3066 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3067 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 3068 | if (ret < 0) { |
| 3069 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 3070 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3071 | goto error; |
| 3072 | } |
| 3073 | |
| 3074 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 3075 | name, ucode_raw->size); |
| 3076 | |
| 3077 | /* Make sure that we got at least our header! */ |
| 3078 | if (ucode_raw->size < sizeof(*ucode)) { |
| 3079 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3080 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3081 | goto err_release; |
| 3082 | } |
| 3083 | |
| 3084 | /* Data from ucode file: header followed by uCode images */ |
| 3085 | ucode = (void *)ucode_raw->data; |
| 3086 | |
| 3087 | ver = le32_to_cpu(ucode->ver); |
| 3088 | inst_size = le32_to_cpu(ucode->inst_size); |
| 3089 | data_size = le32_to_cpu(ucode->data_size); |
| 3090 | init_size = le32_to_cpu(ucode->init_size); |
| 3091 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 3092 | boot_size = le32_to_cpu(ucode->boot_size); |
| 3093 | |
| 3094 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 3095 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 3096 | inst_size); |
| 3097 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 3098 | data_size); |
| 3099 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 3100 | init_size); |
| 3101 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 3102 | init_data_size); |
| 3103 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 3104 | boot_size); |
| 3105 | |
| 3106 | /* Verify size of file vs. image size info in file's header */ |
| 3107 | if (ucode_raw->size < sizeof(*ucode) + |
| 3108 | inst_size + data_size + init_size + |
| 3109 | init_data_size + boot_size) { |
| 3110 | |
| 3111 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 3112 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3113 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3114 | goto err_release; |
| 3115 | } |
| 3116 | |
| 3117 | /* Verify that uCode images will fit in card's SRAM */ |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 3118 | if (inst_size > priv->hw_params.max_inst_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3119 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 3120 | inst_size); |
| 3121 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3122 | goto err_release; |
| 3123 | } |
| 3124 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 3125 | if (data_size > priv->hw_params.max_data_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3126 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 3127 | data_size); |
| 3128 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3129 | goto err_release; |
| 3130 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 3131 | if (init_size > priv->hw_params.max_inst_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3132 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3133 | ("uCode init instr len %d too large to fit in\n", |
| 3134 | init_size); |
| 3135 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3136 | goto err_release; |
| 3137 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 3138 | if (init_data_size > priv->hw_params.max_data_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3139 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3140 | ("uCode init data len %d too large to fit in\n", |
| 3141 | init_data_size); |
| 3142 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3143 | goto err_release; |
| 3144 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 3145 | if (boot_size > priv->hw_params.max_bsm_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3146 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3147 | ("uCode boot instr len %d too large to fit in\n", |
| 3148 | boot_size); |
| 3149 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3150 | goto err_release; |
| 3151 | } |
| 3152 | |
| 3153 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 3154 | |
| 3155 | /* Runtime instructions and 2 copies of data: |
| 3156 | * 1) unmodified from disk |
| 3157 | * 2) backup cache for save/restore during power-downs */ |
| 3158 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3159 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3160 | |
| 3161 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3162 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3163 | |
| 3164 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3165 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3166 | |
| 3167 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3168 | if (init_size && init_data_size) { |
| 3169 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3170 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3171 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3172 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3173 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3174 | |
| 3175 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 3176 | goto err_pci_alloc; |
| 3177 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3178 | |
| 3179 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3180 | if (boot_size) { |
| 3181 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3182 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3183 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3184 | if (!priv->ucode_boot.v_addr) |
| 3185 | goto err_pci_alloc; |
| 3186 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3187 | |
| 3188 | /* Copy images into buffers for card's bus-master reads ... */ |
| 3189 | |
| 3190 | /* Runtime instructions (first block of data in file) */ |
| 3191 | src = &ucode->data[0]; |
| 3192 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3193 | 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] | 3194 | memcpy(priv->ucode_code.v_addr, src, len); |
| 3195 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 3196 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 3197 | |
| 3198 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3199 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3200 | src = &ucode->data[inst_size]; |
| 3201 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3202 | 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] | 3203 | memcpy(priv->ucode_data.v_addr, src, len); |
| 3204 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 3205 | |
| 3206 | /* Initialization instructions (3rd block) */ |
| 3207 | if (init_size) { |
| 3208 | src = &ucode->data[inst_size + data_size]; |
| 3209 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3210 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 3211 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3212 | memcpy(priv->ucode_init.v_addr, src, len); |
| 3213 | } |
| 3214 | |
| 3215 | /* Initialization data (4th block) */ |
| 3216 | if (init_data_size) { |
| 3217 | src = &ucode->data[inst_size + data_size + init_size]; |
| 3218 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3219 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 3220 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3221 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 3222 | } |
| 3223 | |
| 3224 | /* Bootstrap instructions (5th block) */ |
| 3225 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 3226 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3227 | 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] | 3228 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 3229 | |
| 3230 | /* We have our copies now, allow OS release its copies */ |
| 3231 | release_firmware(ucode_raw); |
| 3232 | return 0; |
| 3233 | |
| 3234 | err_pci_alloc: |
| 3235 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3236 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3237 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3238 | |
| 3239 | err_release: |
| 3240 | release_firmware(ucode_raw); |
| 3241 | |
| 3242 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3243 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3244 | } |
| 3245 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3246 | /** |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3247 | * iwl_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3248 | * from protocol/runtime uCode (initialization uCode's |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3249 | * Alive gets handled by iwl_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3250 | */ |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3251 | static void iwl_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3252 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3253 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3254 | |
| 3255 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 3256 | |
| 3257 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 3258 | /* We had an error bringing up the hardware, so take it |
| 3259 | * all the way back down so we can try again */ |
| 3260 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 3261 | goto restart; |
| 3262 | } |
| 3263 | |
| 3264 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 3265 | * This is a paranoid check, because we would not have gotten the |
| 3266 | * "runtime" alive if code weren't properly loaded. */ |
Emmanuel Grumbach | b0692f2 | 2008-04-24 11:55:18 -0700 | [diff] [blame] | 3267 | if (iwl_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3268 | /* Runtime instruction load was bad; |
| 3269 | * take it all the way back down so we can try again */ |
| 3270 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 3271 | goto restart; |
| 3272 | } |
| 3273 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3274 | iwlcore_clear_stations_table(priv); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3275 | ret = priv->cfg->ops->lib->alive_notify(priv); |
| 3276 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3277 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3278 | ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3279 | goto restart; |
| 3280 | } |
| 3281 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3282 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3283 | set_bit(STATUS_ALIVE, &priv->status); |
| 3284 | |
| 3285 | /* Clear out the uCode error bit if it is set */ |
| 3286 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 3287 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3288 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3289 | return; |
| 3290 | |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 3291 | ieee80211_wake_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3292 | |
| 3293 | priv->active_rate = priv->rates_mask; |
| 3294 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 3295 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3296 | if (iwl_is_associated(priv)) { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 3297 | struct iwl_rxon_cmd *active_rxon = |
| 3298 | (struct iwl_rxon_cmd *)&priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3299 | |
| 3300 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 3301 | sizeof(priv->staging_rxon)); |
| 3302 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 3303 | } else { |
| 3304 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3305 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3306 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 3307 | } |
| 3308 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3309 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3310 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3311 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3312 | iwl_reset_run_time_calib(priv); |
| 3313 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3314 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3315 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3316 | |
| 3317 | /* At this point, the NIC is initialized and operational */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3318 | iwl4965_rf_kill_ct_config(priv); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3319 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 3320 | iwl_leds_register(priv); |
| 3321 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3322 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 3323 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3324 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3325 | |
| 3326 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3327 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3328 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 3329 | iwlcore_low_level_notify(priv, IWLCORE_START_EVT); |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 3330 | ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3331 | return; |
| 3332 | |
| 3333 | restart: |
| 3334 | queue_work(priv->workqueue, &priv->restart); |
| 3335 | } |
| 3336 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3337 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3338 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3339 | static void __iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3340 | { |
| 3341 | unsigned long flags; |
| 3342 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3343 | |
| 3344 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 3345 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3346 | if (!exit_pending) |
| 3347 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 3348 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 3349 | iwl_leds_unregister(priv); |
| 3350 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 3351 | iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT); |
| 3352 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3353 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3354 | |
| 3355 | /* Unblock any waiting calls */ |
| 3356 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 3357 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3358 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 3359 | * exiting the module */ |
| 3360 | if (!exit_pending) |
| 3361 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 3362 | |
| 3363 | /* stop and reset the on-board processor */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3364 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3365 | |
| 3366 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3367 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3368 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3369 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3370 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3371 | |
| 3372 | if (priv->mac80211_registered) |
| 3373 | ieee80211_stop_queues(priv->hw); |
| 3374 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3375 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3376 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3377 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3378 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 3379 | STATUS_RF_KILL_HW | |
| 3380 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 3381 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 3382 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 3383 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3384 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 3385 | STATUS_IN_SUSPEND; |
| 3386 | goto exit; |
| 3387 | } |
| 3388 | |
| 3389 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 3390 | * SUSPEND bits and continue taking the NIC down. */ |
| 3391 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 3392 | STATUS_RF_KILL_HW | |
| 3393 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 3394 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 3395 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 3396 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3397 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 3398 | STATUS_IN_SUSPEND | |
| 3399 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 3400 | STATUS_FW_ERROR; |
| 3401 | |
| 3402 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3403 | iwl_clear_bit(priv, CSR_GP_CNTRL, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3404 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3405 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3406 | |
Tomas Winkler | da1bc45 | 2008-05-29 16:35:00 +0800 | [diff] [blame^] | 3407 | iwl_txq_ctx_stop(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3408 | iwl4965_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3409 | |
| 3410 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3411 | if (!iwl_grab_nic_access(priv)) { |
| 3412 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3413 | APMG_CLK_VAL_DMA_CLK_RQT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3414 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3415 | } |
| 3416 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3417 | |
| 3418 | udelay(5); |
| 3419 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 3420 | /* FIXME: apm_ops.suspend(priv) */ |
| 3421 | priv->cfg->ops->lib->apm_ops.reset(priv); |
Ron Rindjunsky | 399f4900 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 3422 | priv->cfg->ops->lib->free_shared_mem(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3423 | |
| 3424 | exit: |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 3425 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3426 | |
| 3427 | if (priv->ibss_beacon) |
| 3428 | dev_kfree_skb(priv->ibss_beacon); |
| 3429 | priv->ibss_beacon = NULL; |
| 3430 | |
| 3431 | /* clear out any free frames */ |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 3432 | iwl_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3433 | } |
| 3434 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3435 | static void iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3436 | { |
| 3437 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3438 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3439 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 3440 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3441 | iwl4965_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3442 | } |
| 3443 | |
| 3444 | #define MAX_HW_RESTARTS 5 |
| 3445 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3446 | static int __iwl4965_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3447 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3448 | int i; |
| 3449 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3450 | |
| 3451 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 3452 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 3453 | return -EIO; |
| 3454 | } |
| 3455 | |
| 3456 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 3457 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 3458 | "parameter)\n"); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3459 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3460 | return -ENODEV; |
| 3461 | } |
| 3462 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 3463 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 3464 | IWL_ERROR("ucode not available for device bringup\n"); |
| 3465 | return -EIO; |
| 3466 | } |
| 3467 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3468 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3469 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3470 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 3471 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3472 | else { |
| 3473 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3474 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3475 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3476 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 3477 | return -ENODEV; |
| 3478 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3479 | } |
| 3480 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3481 | iwl_rfkill_set_hw_state(priv); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3482 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3483 | |
Ron Rindjunsky | 399f4900 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 3484 | ret = priv->cfg->ops->lib->alloc_shared_mem(priv); |
| 3485 | if (ret) { |
| 3486 | IWL_ERROR("Unable to allocate shared memory\n"); |
| 3487 | return ret; |
| 3488 | } |
| 3489 | |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 3490 | ret = iwl_hw_nic_init(priv); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3491 | if (ret) { |
| 3492 | IWL_ERROR("Unable to init nic\n"); |
| 3493 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3494 | } |
| 3495 | |
| 3496 | /* make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3497 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 3498 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3499 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 3500 | |
| 3501 | /* clear (again), then enable host interrupts */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3502 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3503 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3504 | |
| 3505 | /* really make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3506 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 3507 | 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] | 3508 | |
| 3509 | /* Copy original ucode data image from disk into backup cache. |
| 3510 | * This will be used to initialize the on-board processor's |
| 3511 | * data SRAM for a clean start when the runtime program first loads. */ |
| 3512 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3513 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3514 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3515 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 3516 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3517 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3518 | |
| 3519 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 3520 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3521 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3522 | |
| 3523 | /* load bootstrap state machine, |
| 3524 | * load bootstrap program into processor's memory, |
| 3525 | * prepare to load the "initialize" uCode */ |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3526 | ret = priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3527 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3528 | if (ret) { |
| 3529 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3530 | continue; |
| 3531 | } |
| 3532 | |
| 3533 | /* start card; "initialize" will load runtime ucode */ |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 3534 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3535 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3536 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 3537 | |
| 3538 | return 0; |
| 3539 | } |
| 3540 | |
| 3541 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3542 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3543 | |
| 3544 | /* tried to restart and config the device for as long as our |
| 3545 | * patience could withstand */ |
| 3546 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 3547 | return -EIO; |
| 3548 | } |
| 3549 | |
| 3550 | |
| 3551 | /***************************************************************************** |
| 3552 | * |
| 3553 | * Workqueue callbacks |
| 3554 | * |
| 3555 | *****************************************************************************/ |
| 3556 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3557 | static void iwl_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3558 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3559 | struct iwl_priv *priv = |
| 3560 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3561 | |
| 3562 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3563 | return; |
| 3564 | |
| 3565 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | f3ccc08 | 2008-05-05 10:22:45 +0800 | [diff] [blame] | 3566 | priv->cfg->ops->lib->init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3567 | mutex_unlock(&priv->mutex); |
| 3568 | } |
| 3569 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3570 | static void iwl_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3571 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3572 | struct iwl_priv *priv = |
| 3573 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3574 | |
| 3575 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3576 | return; |
| 3577 | |
| 3578 | mutex_lock(&priv->mutex); |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3579 | iwl_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3580 | mutex_unlock(&priv->mutex); |
| 3581 | } |
| 3582 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3583 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3584 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3585 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3586 | |
| 3587 | wake_up_interruptible(&priv->wait_command_queue); |
| 3588 | |
| 3589 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3590 | return; |
| 3591 | |
| 3592 | mutex_lock(&priv->mutex); |
| 3593 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3594 | if (!iwl_is_rfkill(priv)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3595 | IWL_DEBUG(IWL_DL_RF_KILL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3596 | "HW and/or SW RF Kill no longer active, restarting " |
| 3597 | "device\n"); |
| 3598 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3599 | queue_work(priv->workqueue, &priv->restart); |
| 3600 | } else { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3601 | /* make sure mac80211 stop sending Tx frame */ |
| 3602 | if (priv->mac80211_registered) |
| 3603 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3604 | |
| 3605 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 3606 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 3607 | "disabled by SW switch\n"); |
| 3608 | else |
| 3609 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 3610 | "Kill switch must be turned off for " |
| 3611 | "wireless networking to work.\n"); |
| 3612 | } |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3613 | iwl_rfkill_set_hw_state(priv); |
| 3614 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3615 | mutex_unlock(&priv->mutex); |
| 3616 | } |
| 3617 | |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 3618 | static void iwl4965_bg_set_monitor(struct work_struct *work) |
| 3619 | { |
| 3620 | struct iwl_priv *priv = container_of(work, |
| 3621 | struct iwl_priv, set_monitor); |
| 3622 | |
| 3623 | IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n"); |
| 3624 | |
| 3625 | mutex_lock(&priv->mutex); |
| 3626 | |
| 3627 | if (!iwl_is_ready(priv)) |
| 3628 | IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n"); |
| 3629 | else |
| 3630 | if (iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR) != 0) |
| 3631 | IWL_ERROR("iwl4965_set_mode() failed\n"); |
| 3632 | |
| 3633 | mutex_unlock(&priv->mutex); |
| 3634 | } |
| 3635 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3636 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 3637 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3638 | static void iwl4965_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3639 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3640 | struct iwl_priv *priv = |
| 3641 | container_of(data, struct iwl_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3642 | |
| 3643 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3644 | return; |
| 3645 | |
| 3646 | mutex_lock(&priv->mutex); |
| 3647 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 3648 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3649 | IWL_DEBUG(IWL_DL_SCAN, "Scan completion watchdog resetting " |
| 3650 | "adapter (%dms)\n", |
| 3651 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3652 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3653 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3654 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3655 | } |
| 3656 | mutex_unlock(&priv->mutex); |
| 3657 | } |
| 3658 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3659 | static void iwl4965_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3660 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3661 | struct iwl_priv *priv = |
| 3662 | container_of(data, struct iwl_priv, request_scan); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3663 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3664 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3665 | .len = sizeof(struct iwl4965_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3666 | .meta.flags = CMD_SIZE_HUGE, |
| 3667 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3668 | struct iwl4965_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3669 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3670 | u16 cmd_len; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3671 | enum ieee80211_band band; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3672 | u8 direct_mask; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3673 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3674 | |
| 3675 | conf = ieee80211_get_hw_conf(priv->hw); |
| 3676 | |
| 3677 | mutex_lock(&priv->mutex); |
| 3678 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3679 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3680 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 3681 | goto done; |
| 3682 | } |
| 3683 | |
| 3684 | /* Make sure the scan wasn't cancelled before this queued work |
| 3685 | * was given the chance to run... */ |
| 3686 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 3687 | goto done; |
| 3688 | |
| 3689 | /* This should never be called or scheduled if there is currently |
| 3690 | * a scan active in the hardware. */ |
| 3691 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 3692 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 3693 | "Ignoring second request.\n"); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3694 | ret = -EIO; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3695 | goto done; |
| 3696 | } |
| 3697 | |
| 3698 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 3699 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 3700 | goto done; |
| 3701 | } |
| 3702 | |
| 3703 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 3704 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 3705 | goto done; |
| 3706 | } |
| 3707 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3708 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3709 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 3710 | goto done; |
| 3711 | } |
| 3712 | |
| 3713 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 3714 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 3715 | goto done; |
| 3716 | } |
| 3717 | |
| 3718 | if (!priv->scan_bands) { |
| 3719 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 3720 | goto done; |
| 3721 | } |
| 3722 | |
| 3723 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3724 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3725 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 3726 | if (!priv->scan) { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3727 | ret = -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3728 | goto done; |
| 3729 | } |
| 3730 | } |
| 3731 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3732 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3733 | |
| 3734 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 3735 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 3736 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3737 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3738 | u16 interval = 0; |
| 3739 | u32 extra; |
| 3740 | u32 suspend_time = 100; |
| 3741 | u32 scan_suspend_time = 100; |
| 3742 | unsigned long flags; |
| 3743 | |
| 3744 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 3745 | |
| 3746 | spin_lock_irqsave(&priv->lock, flags); |
| 3747 | interval = priv->beacon_int; |
| 3748 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3749 | |
| 3750 | scan->suspend_time = 0; |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3751 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3752 | if (!interval) |
| 3753 | interval = suspend_time; |
| 3754 | |
| 3755 | extra = (suspend_time / interval) << 22; |
| 3756 | scan_suspend_time = (extra | |
| 3757 | ((suspend_time % interval) * 1024)); |
| 3758 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 3759 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 3760 | scan_suspend_time, interval); |
| 3761 | } |
| 3762 | |
| 3763 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 3764 | if (priv->one_direct_scan) { |
| 3765 | IWL_DEBUG_SCAN |
| 3766 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3767 | iwl4965_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3768 | priv->direct_ssid_len)); |
| 3769 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 3770 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 3771 | memcpy(scan->direct_scan[0].ssid, |
| 3772 | priv->direct_ssid, priv->direct_ssid_len); |
| 3773 | direct_mask = 1; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3774 | } else if (!iwl_is_associated(priv) && priv->essid_len) { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3775 | IWL_DEBUG_SCAN |
| 3776 | ("Kicking off one direct scan for '%s' when not associated\n", |
| 3777 | iwl4965_escape_essid(priv->essid, priv->essid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3778 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 3779 | scan->direct_scan[0].len = priv->essid_len; |
| 3780 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 3781 | direct_mask = 1; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3782 | } else { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3783 | IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3784 | direct_mask = 0; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3785 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3786 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3787 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3788 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3789 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 3790 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3791 | |
| 3792 | switch (priv->scan_bands) { |
| 3793 | case 2: |
| 3794 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 3795 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3796 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3797 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 3798 | |
| 3799 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3800 | band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3801 | break; |
| 3802 | |
| 3803 | case 1: |
| 3804 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3805 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3806 | RATE_MCS_ANT_B_MSK); |
| 3807 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3808 | band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3809 | break; |
| 3810 | |
| 3811 | default: |
| 3812 | IWL_WARNING("Invalid scan band count\n"); |
| 3813 | goto done; |
| 3814 | } |
| 3815 | |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3816 | /* We don't build a direct scan probe request; the uCode will do |
| 3817 | * that based on the direct_mask added to each channel entry */ |
| 3818 | cmd_len = iwl4965_fill_probe_req(priv, band, |
| 3819 | (struct ieee80211_mgmt *)scan->data, |
| 3820 | IWL_MAX_SCAN_SIZE - sizeof(*scan), 0); |
| 3821 | |
| 3822 | scan->tx_cmd.len = cpu_to_le16(cmd_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3823 | /* select Rx chains */ |
| 3824 | |
| 3825 | /* Force use of chains B and C (0x6) for scan Rx. |
| 3826 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 3827 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 3828 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 3829 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 3830 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 3831 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 3832 | |
| 3833 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 3834 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 3835 | |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3836 | if (direct_mask) |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 3837 | scan->channel_count = |
| 3838 | iwl4965_get_channels_for_scan( |
| 3839 | priv, band, 1, /* active */ |
| 3840 | direct_mask, |
| 3841 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3842 | else |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 3843 | scan->channel_count = |
| 3844 | iwl4965_get_channels_for_scan( |
| 3845 | priv, band, 0, /* passive */ |
| 3846 | direct_mask, |
| 3847 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3848 | |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 3849 | scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | |
| 3850 | RXON_FILTER_BCON_AWARE_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3851 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3852 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3853 | cmd.data = scan; |
| 3854 | scan->len = cpu_to_le16(cmd.len); |
| 3855 | |
| 3856 | set_bit(STATUS_SCAN_HW, &priv->status); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3857 | ret = iwl_send_cmd_sync(priv, &cmd); |
| 3858 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3859 | goto done; |
| 3860 | |
| 3861 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 3862 | IWL_SCAN_CHECK_WATCHDOG); |
| 3863 | |
| 3864 | mutex_unlock(&priv->mutex); |
| 3865 | return; |
| 3866 | |
| 3867 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3868 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3869 | queue_work(priv->workqueue, &priv->scan_completed); |
| 3870 | mutex_unlock(&priv->mutex); |
| 3871 | } |
| 3872 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3873 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3874 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3875 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3876 | |
| 3877 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3878 | return; |
| 3879 | |
| 3880 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3881 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3882 | mutex_unlock(&priv->mutex); |
| 3883 | } |
| 3884 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3885 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3886 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3887 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3888 | |
| 3889 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3890 | return; |
| 3891 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3892 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3893 | queue_work(priv->workqueue, &priv->up); |
| 3894 | } |
| 3895 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3896 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3897 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3898 | struct iwl_priv *priv = |
| 3899 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3900 | |
| 3901 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3902 | return; |
| 3903 | |
| 3904 | mutex_lock(&priv->mutex); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3905 | iwl_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3906 | mutex_unlock(&priv->mutex); |
| 3907 | } |
| 3908 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3909 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 3910 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3911 | static void iwl4965_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3912 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3913 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3914 | int ret = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3915 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3916 | |
| 3917 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 3918 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 3919 | return; |
| 3920 | } |
| 3921 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3922 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 3923 | priv->assoc_id, |
| 3924 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3925 | |
| 3926 | |
| 3927 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3928 | return; |
| 3929 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3930 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3931 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 3932 | return; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3933 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3934 | iwl4965_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3935 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3936 | conf = ieee80211_get_hw_conf(priv->hw); |
| 3937 | |
| 3938 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3939 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3940 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3941 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 3942 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3943 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3944 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3945 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3946 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 3947 | "Attempting to continue.\n"); |
| 3948 | |
| 3949 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 3950 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3951 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 3952 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 3953 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3954 | #endif /* CONFIG_IWL4965_HT*/ |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 3955 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3956 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 3957 | |
| 3958 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 3959 | priv->assoc_id, priv->beacon_int); |
| 3960 | |
| 3961 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 3962 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3963 | else |
| 3964 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3965 | |
| 3966 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 3967 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 3968 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 3969 | else |
| 3970 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 3971 | |
| 3972 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 3973 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 3974 | |
| 3975 | } |
| 3976 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3977 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3978 | |
| 3979 | switch (priv->iw_mode) { |
| 3980 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3981 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3982 | break; |
| 3983 | |
| 3984 | case IEEE80211_IF_TYPE_IBSS: |
| 3985 | |
| 3986 | /* clear out the station table */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3987 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3988 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 3989 | iwl_rxon_add_station(priv, iwl_bcast_addr, 0); |
| 3990 | iwl_rxon_add_station(priv, priv->bssid, 0); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3991 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
| 3992 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3993 | |
| 3994 | break; |
| 3995 | |
| 3996 | default: |
| 3997 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 3998 | __FUNCTION__, priv->iw_mode); |
| 3999 | break; |
| 4000 | } |
| 4001 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4002 | iwl4965_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4003 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4004 | /* Enable Rx differential gain and sensitivity calibrations */ |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 4005 | iwl_chain_noise_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4006 | priv->start_calib = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4007 | |
| 4008 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 4009 | priv->assoc_station_added = 1; |
| 4010 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4011 | iwl4965_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 4012 | |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4013 | iwl_power_update_mode(priv, 0); |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4014 | /* we have just associated, don't start scan too early */ |
| 4015 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | |
| 4019 | static void iwl4965_bg_post_associate(struct work_struct *data) |
| 4020 | { |
| 4021 | struct iwl_priv *priv = container_of(data, struct iwl_priv, |
| 4022 | post_associate.work); |
| 4023 | |
| 4024 | mutex_lock(&priv->mutex); |
| 4025 | iwl4965_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4026 | mutex_unlock(&priv->mutex); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4027 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4028 | } |
| 4029 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4030 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4031 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4032 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4033 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4034 | if (!iwl_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4035 | return; |
| 4036 | |
| 4037 | mutex_lock(&priv->mutex); |
| 4038 | |
| 4039 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4040 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4041 | |
| 4042 | mutex_unlock(&priv->mutex); |
| 4043 | } |
| 4044 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4045 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 4046 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4047 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4048 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4049 | struct iwl_priv *priv = |
| 4050 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4051 | |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 4052 | IWL_DEBUG(IWL_DL_SCAN, "SCAN complete scan\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4053 | |
| 4054 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4055 | return; |
| 4056 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 4057 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
| 4058 | iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4059 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4060 | ieee80211_scan_completed(priv->hw); |
| 4061 | |
| 4062 | /* Since setting the TXPOWER may have been deferred while |
| 4063 | * performing the scan, fire one off */ |
| 4064 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4065 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4066 | mutex_unlock(&priv->mutex); |
| 4067 | } |
| 4068 | |
| 4069 | /***************************************************************************** |
| 4070 | * |
| 4071 | * mac80211 entry point functions |
| 4072 | * |
| 4073 | *****************************************************************************/ |
| 4074 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4075 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 4076 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4077 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4078 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4079 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4080 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4081 | |
| 4082 | IWL_DEBUG_MAC80211("enter\n"); |
| 4083 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4084 | if (pci_enable_device(priv->pci_dev)) { |
| 4085 | IWL_ERROR("Fail to pci_enable_device\n"); |
| 4086 | return -ENODEV; |
| 4087 | } |
| 4088 | pci_restore_state(priv->pci_dev); |
| 4089 | pci_enable_msi(priv->pci_dev); |
| 4090 | |
| 4091 | ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, |
| 4092 | DRV_NAME, priv); |
| 4093 | if (ret) { |
| 4094 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 4095 | goto out_disable_msi; |
| 4096 | } |
| 4097 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4098 | /* we should be verifying the device is ready to be opened */ |
| 4099 | mutex_lock(&priv->mutex); |
| 4100 | |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 4101 | memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd)); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4102 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 4103 | * ucode filename and max sizes are card-specific. */ |
| 4104 | |
| 4105 | if (!priv->ucode_code.len) { |
| 4106 | ret = iwl4965_read_ucode(priv); |
| 4107 | if (ret) { |
| 4108 | IWL_ERROR("Could not read microcode: %d\n", ret); |
| 4109 | mutex_unlock(&priv->mutex); |
| 4110 | goto out_release_irq; |
| 4111 | } |
| 4112 | } |
| 4113 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4114 | ret = __iwl4965_up(priv); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4115 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4116 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4117 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4118 | if (ret) |
| 4119 | goto out_release_irq; |
| 4120 | |
| 4121 | IWL_DEBUG_INFO("Start UP work done.\n"); |
| 4122 | |
| 4123 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 4124 | return 0; |
| 4125 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4126 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 4127 | * mac80211 will not be run successfully. */ |
| 4128 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 4129 | test_bit(STATUS_READY, &priv->status), |
| 4130 | UCODE_READY_TIMEOUT); |
| 4131 | if (!ret) { |
| 4132 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 4133 | IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n", |
| 4134 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 4135 | ret = -ETIMEDOUT; |
| 4136 | goto out_release_irq; |
| 4137 | } |
| 4138 | } |
| 4139 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4140 | priv->is_open = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4141 | IWL_DEBUG_MAC80211("leave\n"); |
| 4142 | return 0; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4143 | |
| 4144 | out_release_irq: |
| 4145 | free_irq(priv->pci_dev->irq, priv); |
| 4146 | out_disable_msi: |
| 4147 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4148 | pci_disable_device(priv->pci_dev); |
| 4149 | priv->is_open = 0; |
| 4150 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4151 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4152 | } |
| 4153 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4154 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4155 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4156 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4157 | |
| 4158 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4159 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4160 | if (!priv->is_open) { |
| 4161 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 4162 | return; |
| 4163 | } |
| 4164 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4165 | priv->is_open = 0; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4166 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4167 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4168 | /* stop mac, cancel any scan request and clear |
| 4169 | * RXON_FILTER_ASSOC_MSK BIT |
| 4170 | */ |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4171 | mutex_lock(&priv->mutex); |
| 4172 | iwl4965_scan_cancel_timeout(priv, 100); |
| 4173 | cancel_delayed_work(&priv->post_associate); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4174 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4175 | } |
| 4176 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4177 | iwl4965_down(priv); |
| 4178 | |
| 4179 | flush_workqueue(priv->workqueue); |
| 4180 | free_irq(priv->pci_dev->irq, priv); |
| 4181 | pci_disable_msi(priv->pci_dev); |
| 4182 | pci_save_state(priv->pci_dev); |
| 4183 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4184 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4185 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4186 | } |
| 4187 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 4188 | 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] | 4189 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4190 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4191 | |
| 4192 | IWL_DEBUG_MAC80211("enter\n"); |
| 4193 | |
| 4194 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 4195 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 4196 | return -1; |
| 4197 | } |
| 4198 | |
| 4199 | IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 4200 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4201 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 4202 | if (iwl_tx_skb(priv, skb)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4203 | dev_kfree_skb_any(skb); |
| 4204 | |
| 4205 | IWL_DEBUG_MAC80211("leave\n"); |
| 4206 | return 0; |
| 4207 | } |
| 4208 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4209 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4210 | struct ieee80211_if_init_conf *conf) |
| 4211 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4212 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4213 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4214 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4215 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 4216 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4217 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 4218 | if (priv->vif) { |
| 4219 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Reinette Chatre | 75849d2 | 2008-01-23 10:15:17 -0800 | [diff] [blame] | 4220 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 4224 | priv->vif = conf->vif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4225 | |
| 4226 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4227 | |
| 4228 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 4229 | |
| 4230 | if (conf->mac_addr) { |
| 4231 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 4232 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 4233 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4234 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4235 | if (iwl_is_ready(priv)) |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4236 | iwl4965_set_mode(priv, conf->type); |
| 4237 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4238 | mutex_unlock(&priv->mutex); |
| 4239 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4240 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4241 | return 0; |
| 4242 | } |
| 4243 | |
| 4244 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4245 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4246 | * |
| 4247 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 4248 | * be set inappropriately and the driver currently sets the hardware up to |
| 4249 | * use it whenever needed. |
| 4250 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4251 | 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] | 4252 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4253 | struct iwl_priv *priv = hw->priv; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4254 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4255 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4256 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4257 | |
| 4258 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4259 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4260 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 4261 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
| 4262 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4263 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4264 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4265 | ret = -EIO; |
| 4266 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4267 | } |
| 4268 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 4269 | if (unlikely(!priv->cfg->mod_params->disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4270 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 4271 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 4272 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4273 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 4274 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4275 | } |
| 4276 | |
| 4277 | spin_lock_irqsave(&priv->lock, flags); |
| 4278 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 4279 | ch_info = iwl_get_channel_info(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4280 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4281 | if (!is_channel_valid(ch_info)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4282 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 4283 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4284 | ret = -EINVAL; |
| 4285 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4286 | } |
| 4287 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4288 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 4289 | /* if we are switching from ht to 2.4 clear flags |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4290 | * from any ht related info since 2.4 does not |
| 4291 | * support ht */ |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 4292 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4293 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 4294 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 4295 | #endif |
| 4296 | ) |
| 4297 | priv->staging_rxon.flags = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4298 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4299 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4300 | iwl_set_rxon_channel(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4301 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4302 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4303 | iwl4965_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4304 | |
| 4305 | /* The list of supported rates and rate mask can be different |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4306 | * for each band; since the band may have changed, reset |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4307 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4308 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4309 | |
| 4310 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4311 | |
| 4312 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 4313 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4314 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4315 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4316 | } |
| 4317 | #endif |
| 4318 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4319 | if (priv->cfg->ops->lib->radio_kill_sw) |
| 4320 | priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4321 | |
| 4322 | if (!conf->radio_enabled) { |
| 4323 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4324 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4325 | } |
| 4326 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4327 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4328 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4329 | ret = -EIO; |
| 4330 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4331 | } |
| 4332 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4333 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4334 | |
| 4335 | if (memcmp(&priv->active_rxon, |
| 4336 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4337 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4338 | else |
| 4339 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 4340 | |
| 4341 | IWL_DEBUG_MAC80211("leave\n"); |
| 4342 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 4343 | out: |
| 4344 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4345 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4346 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4347 | } |
| 4348 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4349 | static void iwl4965_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4350 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4351 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4352 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 4353 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4354 | return; |
| 4355 | |
| 4356 | /* The following should be done only at AP bring up */ |
| 4357 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 4358 | |
| 4359 | /* RXON - unassoc (to set timing command) */ |
| 4360 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4361 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4362 | |
| 4363 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4364 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 4365 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4366 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4367 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4368 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4369 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 4370 | "Attempting to continue.\n"); |
| 4371 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4372 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4373 | |
| 4374 | /* FIXME: what should be the assoc_id for AP? */ |
| 4375 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 4376 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 4377 | priv->staging_rxon.flags |= |
| 4378 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4379 | else |
| 4380 | priv->staging_rxon.flags &= |
| 4381 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4382 | |
| 4383 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 4384 | if (priv->assoc_capability & |
| 4385 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 4386 | priv->staging_rxon.flags |= |
| 4387 | RXON_FLG_SHORT_SLOT_MSK; |
| 4388 | else |
| 4389 | priv->staging_rxon.flags &= |
| 4390 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 4391 | |
| 4392 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 4393 | priv->staging_rxon.flags &= |
| 4394 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 4395 | } |
| 4396 | /* restore RXON assoc */ |
| 4397 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4398 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4399 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 4400 | iwl_rxon_add_station(priv, iwl_bcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 4401 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4402 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4403 | |
| 4404 | /* FIXME - we need to add code here to detect a totally new |
| 4405 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 4406 | * clear sta table, add BCAST sta... */ |
| 4407 | } |
| 4408 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 4409 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, |
| 4410 | struct ieee80211_vif *vif, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4411 | struct ieee80211_if_conf *conf) |
| 4412 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4413 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4414 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4415 | unsigned long flags; |
| 4416 | int rc; |
| 4417 | |
| 4418 | if (conf == NULL) |
| 4419 | return -EIO; |
| 4420 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 4421 | if (priv->vif != vif) { |
| 4422 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 4423 | return 0; |
| 4424 | } |
| 4425 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4426 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 4427 | (!conf->beacon || !conf->ssid_len)) { |
| 4428 | IWL_DEBUG_MAC80211 |
| 4429 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 4430 | return 0; |
| 4431 | } |
| 4432 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4433 | if (!iwl_is_alive(priv)) |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4434 | return -EAGAIN; |
| 4435 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4436 | mutex_lock(&priv->mutex); |
| 4437 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4438 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4439 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 4440 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4441 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4442 | /* |
| 4443 | * very dubious code was here; the probe filtering flag is never set: |
| 4444 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4445 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 4446 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4447 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4448 | |
| 4449 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 4450 | if (!conf->bssid) { |
| 4451 | conf->bssid = priv->mac_addr; |
| 4452 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4453 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 4454 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4455 | } |
| 4456 | if (priv->ibss_beacon) |
| 4457 | dev_kfree_skb(priv->ibss_beacon); |
| 4458 | |
| 4459 | priv->ibss_beacon = conf->beacon; |
| 4460 | } |
| 4461 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4462 | if (iwl_is_rfkill(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4463 | goto done; |
| 4464 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4465 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 4466 | !is_multicast_ether_addr(conf->bssid)) { |
| 4467 | /* If there is currently a HW scan going on in the background |
| 4468 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4469 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4470 | IWL_WARNING("Aborted scan still in progress " |
| 4471 | "after 100ms\n"); |
| 4472 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 4473 | mutex_unlock(&priv->mutex); |
| 4474 | return -EAGAIN; |
| 4475 | } |
| 4476 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 4477 | |
| 4478 | /* TODO: Audit driver for usage of these members and see |
| 4479 | * if mac80211 deprecates them (priv->bssid looks like it |
| 4480 | * shouldn't be there, but I haven't scanned the IBSS code |
| 4481 | * to verify) - jpk */ |
| 4482 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 4483 | |
| 4484 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4485 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4486 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4487 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4488 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 4489 | iwl_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4490 | priv, priv->active_rxon.bssid_addr, 1); |
| 4491 | } |
| 4492 | |
| 4493 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4494 | iwl4965_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4495 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4496 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4497 | } |
| 4498 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4499 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4500 | spin_lock_irqsave(&priv->lock, flags); |
| 4501 | if (!conf->ssid_len) |
| 4502 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 4503 | else |
| 4504 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 4505 | |
| 4506 | priv->essid_len = conf->ssid_len; |
| 4507 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4508 | |
| 4509 | IWL_DEBUG_MAC80211("leave\n"); |
| 4510 | mutex_unlock(&priv->mutex); |
| 4511 | |
| 4512 | return 0; |
| 4513 | } |
| 4514 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4515 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4516 | unsigned int changed_flags, |
| 4517 | unsigned int *total_flags, |
| 4518 | int mc_count, struct dev_addr_list *mc_list) |
| 4519 | { |
| 4520 | /* |
| 4521 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4522 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4523 | */ |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 4524 | struct iwl_priv *priv = hw->priv; |
| 4525 | int new_flags = 0; |
| 4526 | if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { |
| 4527 | if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { |
| 4528 | IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n", |
| 4529 | IEEE80211_IF_TYPE_MNTR, |
| 4530 | changed_flags, *total_flags); |
| 4531 | /* queue work 'cuz mac80211 is holding a lock which |
| 4532 | * prevents us from issuing (synchronous) f/w cmds */ |
| 4533 | queue_work(priv->workqueue, &priv->set_monitor); |
| 4534 | new_flags &= FIF_PROMISC_IN_BSS | |
| 4535 | FIF_OTHER_BSS | |
| 4536 | FIF_ALLMULTI; |
| 4537 | } |
| 4538 | } |
| 4539 | *total_flags = new_flags; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4540 | } |
| 4541 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4542 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4543 | struct ieee80211_if_init_conf *conf) |
| 4544 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4545 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4546 | |
| 4547 | IWL_DEBUG_MAC80211("enter\n"); |
| 4548 | |
| 4549 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4550 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4551 | if (iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4552 | iwl4965_scan_cancel_timeout(priv, 100); |
| 4553 | cancel_delayed_work(&priv->post_associate); |
| 4554 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 4555 | iwl4965_commit_rxon(priv); |
| 4556 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 4557 | if (priv->vif == conf->vif) { |
| 4558 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4559 | memset(priv->bssid, 0, ETH_ALEN); |
| 4560 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 4561 | priv->essid_len = 0; |
| 4562 | } |
| 4563 | mutex_unlock(&priv->mutex); |
| 4564 | |
| 4565 | IWL_DEBUG_MAC80211("leave\n"); |
| 4566 | |
| 4567 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4568 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4569 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4570 | static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, |
| 4571 | struct ieee80211_vif *vif, |
| 4572 | struct ieee80211_bss_conf *bss_conf, |
| 4573 | u32 changes) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4574 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4575 | struct iwl_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4576 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4577 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
| 4578 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4579 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4580 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
| 4581 | bss_conf->use_short_preamble); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4582 | if (bss_conf->use_short_preamble) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4583 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4584 | else |
| 4585 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4586 | } |
| 4587 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4588 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4589 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4590 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4591 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 4592 | else |
| 4593 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 4594 | } |
| 4595 | |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 4596 | if (changes & BSS_CHANGED_HT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4597 | IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 4598 | iwl4965_ht_conf(priv, bss_conf); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4599 | iwl_set_rxon_chain(priv); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 4600 | } |
| 4601 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4602 | if (changes & BSS_CHANGED_ASSOC) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4603 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4604 | /* This should never happen as this function should |
| 4605 | * never be called from interrupt context. */ |
| 4606 | if (WARN_ON_ONCE(in_interrupt())) |
| 4607 | return; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4608 | if (bss_conf->assoc) { |
| 4609 | priv->assoc_id = bss_conf->aid; |
| 4610 | priv->beacon_int = bss_conf->beacon_int; |
| 4611 | priv->timestamp = bss_conf->timestamp; |
| 4612 | priv->assoc_capability = bss_conf->assoc_capability; |
| 4613 | priv->next_scan_jiffies = jiffies + |
| 4614 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4615 | mutex_lock(&priv->mutex); |
| 4616 | iwl4965_post_associate(priv); |
| 4617 | mutex_unlock(&priv->mutex); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4618 | } else { |
| 4619 | priv->assoc_id = 0; |
| 4620 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); |
| 4621 | } |
| 4622 | } else if (changes && iwl_is_associated(priv) && priv->assoc_id) { |
| 4623 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 4624 | iwl_send_rxon_assoc(priv); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4625 | } |
| 4626 | |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4627 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4628 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4629 | 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] | 4630 | { |
| 4631 | int rc = 0; |
| 4632 | unsigned long flags; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4633 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4634 | |
| 4635 | IWL_DEBUG_MAC80211("enter\n"); |
| 4636 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4637 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4638 | spin_lock_irqsave(&priv->lock, flags); |
| 4639 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4640 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4641 | rc = -EIO; |
| 4642 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 4643 | goto out_unlock; |
| 4644 | } |
| 4645 | |
| 4646 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 4647 | rc = -EIO; |
| 4648 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 4649 | goto out_unlock; |
| 4650 | } |
| 4651 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4652 | /* we don't schedule scan within next_scan_jiffies period */ |
| 4653 | if (priv->next_scan_jiffies && |
| 4654 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 4655 | rc = -EAGAIN; |
| 4656 | goto out_unlock; |
| 4657 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4658 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4659 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 4660 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4661 | rc = -EAGAIN; |
| 4662 | goto out_unlock; |
| 4663 | } |
| 4664 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4665 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4666 | iwl4965_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4667 | |
| 4668 | priv->one_direct_scan = 1; |
| 4669 | priv->direct_ssid_len = (u8) |
| 4670 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 4671 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4672 | } else |
| 4673 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4674 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4675 | rc = iwl4965_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4676 | |
| 4677 | IWL_DEBUG_MAC80211("leave\n"); |
| 4678 | |
| 4679 | out_unlock: |
| 4680 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4681 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4682 | |
| 4683 | return rc; |
| 4684 | } |
| 4685 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4686 | static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 4687 | struct ieee80211_key_conf *keyconf, const u8 *addr, |
| 4688 | u32 iv32, u16 *phase1key) |
| 4689 | { |
| 4690 | struct iwl_priv *priv = hw->priv; |
| 4691 | u8 sta_id = IWL_INVALID_STATION; |
| 4692 | unsigned long flags; |
| 4693 | __le16 key_flags = 0; |
| 4694 | int i; |
| 4695 | DECLARE_MAC_BUF(mac); |
| 4696 | |
| 4697 | IWL_DEBUG_MAC80211("enter\n"); |
| 4698 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 4699 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4700 | if (sta_id == IWL_INVALID_STATION) { |
| 4701 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 4702 | print_mac(mac, addr)); |
| 4703 | return; |
| 4704 | } |
| 4705 | |
| 4706 | iwl4965_scan_cancel_timeout(priv, 100); |
| 4707 | |
| 4708 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); |
| 4709 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 4710 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 4711 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 4712 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4713 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 4714 | |
| 4715 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 4716 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4717 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 4718 | priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; |
| 4719 | |
| 4720 | for (i = 0; i < 5; i++) |
| 4721 | priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = |
| 4722 | cpu_to_le16(phase1key[i]); |
| 4723 | |
| 4724 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 4725 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 4726 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 4727 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4728 | |
| 4729 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 4730 | |
| 4731 | IWL_DEBUG_MAC80211("leave\n"); |
| 4732 | } |
| 4733 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4734 | 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] | 4735 | const u8 *local_addr, const u8 *addr, |
| 4736 | struct ieee80211_key_conf *key) |
| 4737 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4738 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4739 | DECLARE_MAC_BUF(mac); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4740 | int ret = 0; |
| 4741 | u8 sta_id = IWL_INVALID_STATION; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4742 | u8 is_default_wep_key = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4743 | |
| 4744 | IWL_DEBUG_MAC80211("enter\n"); |
| 4745 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4746 | if (priv->hw_params.sw_crypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4747 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 4748 | return -EOPNOTSUPP; |
| 4749 | } |
| 4750 | |
| 4751 | if (is_zero_ether_addr(addr)) |
| 4752 | /* only support pairwise keys */ |
| 4753 | return -EOPNOTSUPP; |
| 4754 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 4755 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4756 | if (sta_id == IWL_INVALID_STATION) { |
| 4757 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 4758 | print_mac(mac, addr)); |
| 4759 | return -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4760 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4761 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4762 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4763 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4764 | iwl4965_scan_cancel_timeout(priv, 100); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4765 | mutex_unlock(&priv->mutex); |
| 4766 | |
| 4767 | /* If we are getting WEP group key and we didn't receive any key mapping |
| 4768 | * so far, we are in legacy wep mode (group key only), otherwise we are |
| 4769 | * in 1X mode. |
| 4770 | * In legacy wep mode, we use another host command to the uCode */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 4771 | 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] | 4772 | priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 4773 | if (cmd == SET_KEY) |
| 4774 | is_default_wep_key = !priv->key_mapping_key; |
| 4775 | else |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 4776 | is_default_wep_key = |
| 4777 | (key->hw_key_idx == HW_KEY_DEFAULT); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4778 | } |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4779 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4780 | switch (cmd) { |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4781 | case SET_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4782 | if (is_default_wep_key) |
| 4783 | ret = iwl_set_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4784 | else |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 4785 | ret = iwl_set_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4786 | |
| 4787 | IWL_DEBUG_MAC80211("enable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4788 | break; |
| 4789 | case DISABLE_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4790 | if (is_default_wep_key) |
| 4791 | ret = iwl_remove_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4792 | else |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 4793 | ret = iwl_remove_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4794 | |
| 4795 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4796 | break; |
| 4797 | default: |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4798 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4799 | } |
| 4800 | |
| 4801 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4802 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4803 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4804 | } |
| 4805 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 4806 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4807 | const struct ieee80211_tx_queue_params *params) |
| 4808 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4809 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4810 | unsigned long flags; |
| 4811 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4812 | |
| 4813 | IWL_DEBUG_MAC80211("enter\n"); |
| 4814 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4815 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4816 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 4817 | return -EIO; |
| 4818 | } |
| 4819 | |
| 4820 | if (queue >= AC_NUM) { |
| 4821 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 4822 | return 0; |
| 4823 | } |
| 4824 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4825 | if (!priv->qos_data.qos_enable) { |
| 4826 | priv->qos_data.qos_active = 0; |
| 4827 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 4828 | return 0; |
| 4829 | } |
| 4830 | q = AC_NUM - 1 - queue; |
| 4831 | |
| 4832 | spin_lock_irqsave(&priv->lock, flags); |
| 4833 | |
| 4834 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 4835 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 4836 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 4837 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 4838 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4839 | |
| 4840 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 4841 | priv->qos_data.qos_active = 1; |
| 4842 | |
| 4843 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4844 | |
| 4845 | mutex_lock(&priv->mutex); |
| 4846 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4847 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4848 | else if (priv->assoc_id && iwl_is_associated(priv)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4849 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4850 | |
| 4851 | mutex_unlock(&priv->mutex); |
| 4852 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4853 | IWL_DEBUG_MAC80211("leave\n"); |
| 4854 | return 0; |
| 4855 | } |
| 4856 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4857 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4858 | struct ieee80211_tx_queue_stats *stats) |
| 4859 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4860 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4861 | int i, avail; |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 4862 | struct iwl_tx_queue *txq; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 4863 | struct iwl_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4864 | unsigned long flags; |
| 4865 | |
| 4866 | IWL_DEBUG_MAC80211("enter\n"); |
| 4867 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4868 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4869 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 4870 | return -EIO; |
| 4871 | } |
| 4872 | |
| 4873 | spin_lock_irqsave(&priv->lock, flags); |
| 4874 | |
| 4875 | for (i = 0; i < AC_NUM; i++) { |
| 4876 | txq = &priv->txq[i]; |
| 4877 | q = &txq->q; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 4878 | avail = iwl_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4879 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 4880 | stats[i].len = q->n_window - avail; |
| 4881 | stats[i].limit = q->n_window - q->high_mark; |
| 4882 | stats[i].count = q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4883 | |
| 4884 | } |
| 4885 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4886 | |
| 4887 | IWL_DEBUG_MAC80211("leave\n"); |
| 4888 | |
| 4889 | return 0; |
| 4890 | } |
| 4891 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4892 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4893 | struct ieee80211_low_level_stats *stats) |
| 4894 | { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 4895 | struct iwl_priv *priv = hw->priv; |
| 4896 | |
| 4897 | priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4898 | IWL_DEBUG_MAC80211("enter\n"); |
| 4899 | IWL_DEBUG_MAC80211("leave\n"); |
| 4900 | |
| 4901 | return 0; |
| 4902 | } |
| 4903 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4904 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4905 | { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 4906 | struct iwl_priv *priv; |
| 4907 | |
| 4908 | priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4909 | IWL_DEBUG_MAC80211("enter\n"); |
| 4910 | IWL_DEBUG_MAC80211("leave\n"); |
| 4911 | |
| 4912 | return 0; |
| 4913 | } |
| 4914 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4915 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4916 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4917 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4918 | unsigned long flags; |
| 4919 | |
| 4920 | mutex_lock(&priv->mutex); |
| 4921 | IWL_DEBUG_MAC80211("enter\n"); |
| 4922 | |
| 4923 | priv->lq_mngr.lq_ready = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4924 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4925 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 4926 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4927 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4928 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4929 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4930 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4931 | |
| 4932 | cancel_delayed_work(&priv->post_associate); |
| 4933 | |
| 4934 | spin_lock_irqsave(&priv->lock, flags); |
| 4935 | priv->assoc_id = 0; |
| 4936 | priv->assoc_capability = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4937 | priv->assoc_station_added = 0; |
| 4938 | |
| 4939 | /* new association get rid of ibss beacon skb */ |
| 4940 | if (priv->ibss_beacon) |
| 4941 | dev_kfree_skb(priv->ibss_beacon); |
| 4942 | |
| 4943 | priv->ibss_beacon = NULL; |
| 4944 | |
| 4945 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4946 | priv->timestamp = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4947 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 4948 | priv->beacon_int = 0; |
| 4949 | |
| 4950 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4951 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4952 | if (!iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4953 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 4954 | mutex_unlock(&priv->mutex); |
| 4955 | return; |
| 4956 | } |
| 4957 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4958 | /* we are restarting association process |
| 4959 | * clear RXON_FILTER_ASSOC_MSK bit |
| 4960 | */ |
| 4961 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4962 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4963 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4964 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4965 | } |
| 4966 | |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4967 | iwl_power_update_mode(priv, 0); |
| 4968 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4969 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 4970 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4971 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4972 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 4973 | mutex_unlock(&priv->mutex); |
| 4974 | return; |
| 4975 | } |
| 4976 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4977 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4978 | |
| 4979 | mutex_unlock(&priv->mutex); |
| 4980 | |
| 4981 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4982 | } |
| 4983 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 4984 | 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] | 4985 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4986 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4987 | unsigned long flags; |
| 4988 | |
| 4989 | mutex_lock(&priv->mutex); |
| 4990 | IWL_DEBUG_MAC80211("enter\n"); |
| 4991 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4992 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4993 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 4994 | mutex_unlock(&priv->mutex); |
| 4995 | return -EIO; |
| 4996 | } |
| 4997 | |
| 4998 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 4999 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 5000 | mutex_unlock(&priv->mutex); |
| 5001 | return -EIO; |
| 5002 | } |
| 5003 | |
| 5004 | spin_lock_irqsave(&priv->lock, flags); |
| 5005 | |
| 5006 | if (priv->ibss_beacon) |
| 5007 | dev_kfree_skb(priv->ibss_beacon); |
| 5008 | |
| 5009 | priv->ibss_beacon = skb; |
| 5010 | |
| 5011 | priv->assoc_id = 0; |
| 5012 | |
| 5013 | IWL_DEBUG_MAC80211("leave\n"); |
| 5014 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5015 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 5016 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5017 | |
| 5018 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 5019 | |
| 5020 | mutex_unlock(&priv->mutex); |
| 5021 | |
| 5022 | return 0; |
| 5023 | } |
| 5024 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5025 | /***************************************************************************** |
| 5026 | * |
| 5027 | * sysfs attributes |
| 5028 | * |
| 5029 | *****************************************************************************/ |
| 5030 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 5031 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5032 | |
| 5033 | /* |
| 5034 | * The following adds a new attribute to the sysfs representation |
| 5035 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 5036 | * used for controlling the debug level. |
| 5037 | * |
| 5038 | * See the level definitions in iwl for details. |
| 5039 | */ |
| 5040 | |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5041 | static ssize_t show_debug_level(struct device *d, |
| 5042 | struct device_attribute *attr, char *buf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5043 | { |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5044 | struct iwl_priv *priv = d->driver_data; |
| 5045 | |
| 5046 | return sprintf(buf, "0x%08X\n", priv->debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5047 | } |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5048 | static ssize_t store_debug_level(struct device *d, |
| 5049 | struct device_attribute *attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5050 | const char *buf, size_t count) |
| 5051 | { |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5052 | struct iwl_priv *priv = d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5053 | char *p = (char *)buf; |
| 5054 | u32 val; |
| 5055 | |
| 5056 | val = simple_strtoul(p, &p, 0); |
| 5057 | if (p == buf) |
| 5058 | printk(KERN_INFO DRV_NAME |
| 5059 | ": %s is not in hex or decimal form.\n", buf); |
| 5060 | else |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5061 | priv->debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5062 | |
| 5063 | return strnlen(buf, count); |
| 5064 | } |
| 5065 | |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5066 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 5067 | show_debug_level, store_debug_level); |
| 5068 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5069 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 5070 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5071 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5072 | |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 5073 | static ssize_t show_version(struct device *d, |
| 5074 | struct device_attribute *attr, char *buf) |
| 5075 | { |
| 5076 | struct iwl_priv *priv = d->driver_data; |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 5077 | struct iwl_alive_resp *palive = &priv->card_alive; |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 5078 | |
| 5079 | if (palive->is_valid) |
| 5080 | return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n" |
| 5081 | "fw type: 0x%01X 0x%01X\n", |
| 5082 | palive->ucode_major, palive->ucode_minor, |
| 5083 | palive->sw_rev[0], palive->sw_rev[1], |
| 5084 | palive->ver_type, palive->ver_subtype); |
| 5085 | |
| 5086 | else |
| 5087 | return sprintf(buf, "fw not loaded\n"); |
| 5088 | } |
| 5089 | |
| 5090 | static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL); |
| 5091 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5092 | static ssize_t show_temperature(struct device *d, |
| 5093 | struct device_attribute *attr, char *buf) |
| 5094 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5095 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5096 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5097 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5098 | return -EAGAIN; |
| 5099 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5100 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5101 | } |
| 5102 | |
| 5103 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 5104 | |
| 5105 | static ssize_t show_rs_window(struct device *d, |
| 5106 | struct device_attribute *attr, |
| 5107 | char *buf) |
| 5108 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5109 | struct iwl_priv *priv = d->driver_data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5110 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5111 | } |
| 5112 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 5113 | |
| 5114 | static ssize_t show_tx_power(struct device *d, |
| 5115 | struct device_attribute *attr, char *buf) |
| 5116 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5117 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5118 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 5119 | } |
| 5120 | |
| 5121 | static ssize_t store_tx_power(struct device *d, |
| 5122 | struct device_attribute *attr, |
| 5123 | const char *buf, size_t count) |
| 5124 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5125 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5126 | char *p = (char *)buf; |
| 5127 | u32 val; |
| 5128 | |
| 5129 | val = simple_strtoul(p, &p, 10); |
| 5130 | if (p == buf) |
| 5131 | printk(KERN_INFO DRV_NAME |
| 5132 | ": %s is not in decimal form.\n", buf); |
| 5133 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5134 | iwl4965_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5135 | |
| 5136 | return count; |
| 5137 | } |
| 5138 | |
| 5139 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 5140 | |
| 5141 | static ssize_t show_flags(struct device *d, |
| 5142 | struct device_attribute *attr, char *buf) |
| 5143 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5144 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5145 | |
| 5146 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 5147 | } |
| 5148 | |
| 5149 | static ssize_t store_flags(struct device *d, |
| 5150 | struct device_attribute *attr, |
| 5151 | const char *buf, size_t count) |
| 5152 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5153 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5154 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 5155 | |
| 5156 | mutex_lock(&priv->mutex); |
| 5157 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 5158 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5159 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5160 | IWL_WARNING("Could not cancel scan.\n"); |
| 5161 | else { |
| 5162 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 5163 | flags); |
| 5164 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5165 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5166 | } |
| 5167 | } |
| 5168 | mutex_unlock(&priv->mutex); |
| 5169 | |
| 5170 | return count; |
| 5171 | } |
| 5172 | |
| 5173 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 5174 | |
| 5175 | static ssize_t show_filter_flags(struct device *d, |
| 5176 | struct device_attribute *attr, char *buf) |
| 5177 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5178 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5179 | |
| 5180 | return sprintf(buf, "0x%04X\n", |
| 5181 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 5182 | } |
| 5183 | |
| 5184 | static ssize_t store_filter_flags(struct device *d, |
| 5185 | struct device_attribute *attr, |
| 5186 | const char *buf, size_t count) |
| 5187 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5188 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5189 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 5190 | |
| 5191 | mutex_lock(&priv->mutex); |
| 5192 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 5193 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5194 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5195 | IWL_WARNING("Could not cancel scan.\n"); |
| 5196 | else { |
| 5197 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 5198 | "0x%04X\n", filter_flags); |
| 5199 | priv->staging_rxon.filter_flags = |
| 5200 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5201 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5202 | } |
| 5203 | } |
| 5204 | mutex_unlock(&priv->mutex); |
| 5205 | |
| 5206 | return count; |
| 5207 | } |
| 5208 | |
| 5209 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 5210 | store_filter_flags); |
| 5211 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5212 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5213 | |
| 5214 | static ssize_t show_measurement(struct device *d, |
| 5215 | struct device_attribute *attr, char *buf) |
| 5216 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5217 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5218 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5219 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 5220 | u8 *data = (u8 *) & measure_report; |
| 5221 | unsigned long flags; |
| 5222 | |
| 5223 | spin_lock_irqsave(&priv->lock, flags); |
| 5224 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 5225 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5226 | return 0; |
| 5227 | } |
| 5228 | memcpy(&measure_report, &priv->measure_report, size); |
| 5229 | priv->measurement_status = 0; |
| 5230 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5231 | |
| 5232 | while (size && (PAGE_SIZE - len)) { |
| 5233 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 5234 | PAGE_SIZE - len, 1); |
| 5235 | len = strlen(buf); |
| 5236 | if (PAGE_SIZE - len) |
| 5237 | buf[len++] = '\n'; |
| 5238 | |
| 5239 | ofs += 16; |
| 5240 | size -= min(size, 16U); |
| 5241 | } |
| 5242 | |
| 5243 | return len; |
| 5244 | } |
| 5245 | |
| 5246 | static ssize_t store_measurement(struct device *d, |
| 5247 | struct device_attribute *attr, |
| 5248 | const char *buf, size_t count) |
| 5249 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5250 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5251 | struct ieee80211_measurement_params params = { |
| 5252 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 5253 | .start_time = cpu_to_le64(priv->last_tsf), |
| 5254 | .duration = cpu_to_le16(1), |
| 5255 | }; |
| 5256 | u8 type = IWL_MEASURE_BASIC; |
| 5257 | u8 buffer[32]; |
| 5258 | u8 channel; |
| 5259 | |
| 5260 | if (count) { |
| 5261 | char *p = buffer; |
| 5262 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 5263 | channel = simple_strtoul(p, NULL, 0); |
| 5264 | if (channel) |
| 5265 | params.channel = channel; |
| 5266 | |
| 5267 | p = buffer; |
| 5268 | while (*p && *p != ' ') |
| 5269 | p++; |
| 5270 | if (*p) |
| 5271 | type = simple_strtoul(p + 1, NULL, 0); |
| 5272 | } |
| 5273 | |
| 5274 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 5275 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5276 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5277 | |
| 5278 | return count; |
| 5279 | } |
| 5280 | |
| 5281 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 5282 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5283 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5284 | |
| 5285 | static ssize_t store_retry_rate(struct device *d, |
| 5286 | struct device_attribute *attr, |
| 5287 | const char *buf, size_t count) |
| 5288 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5289 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5290 | |
| 5291 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 5292 | if (priv->retry_rate <= 0) |
| 5293 | priv->retry_rate = 1; |
| 5294 | |
| 5295 | return count; |
| 5296 | } |
| 5297 | |
| 5298 | static ssize_t show_retry_rate(struct device *d, |
| 5299 | struct device_attribute *attr, char *buf) |
| 5300 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5301 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5302 | return sprintf(buf, "%d", priv->retry_rate); |
| 5303 | } |
| 5304 | |
| 5305 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 5306 | store_retry_rate); |
| 5307 | |
| 5308 | static ssize_t store_power_level(struct device *d, |
| 5309 | struct device_attribute *attr, |
| 5310 | const char *buf, size_t count) |
| 5311 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5312 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5313 | int rc; |
| 5314 | int mode; |
| 5315 | |
| 5316 | mode = simple_strtoul(buf, NULL, 0); |
| 5317 | mutex_lock(&priv->mutex); |
| 5318 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5319 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5320 | rc = -EAGAIN; |
| 5321 | goto out; |
| 5322 | } |
| 5323 | |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 5324 | rc = iwl_power_set_user_mode(priv, mode); |
| 5325 | if (rc) { |
| 5326 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 5327 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5328 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5329 | rc = count; |
| 5330 | |
| 5331 | out: |
| 5332 | mutex_unlock(&priv->mutex); |
| 5333 | return rc; |
| 5334 | } |
| 5335 | |
| 5336 | #define MAX_WX_STRING 80 |
| 5337 | |
| 5338 | /* Values are in microsecond */ |
| 5339 | static const s32 timeout_duration[] = { |
| 5340 | 350000, |
| 5341 | 250000, |
| 5342 | 75000, |
| 5343 | 37000, |
| 5344 | 25000, |
| 5345 | }; |
| 5346 | static const s32 period_duration[] = { |
| 5347 | 400000, |
| 5348 | 700000, |
| 5349 | 1000000, |
| 5350 | 1000000, |
| 5351 | 1000000 |
| 5352 | }; |
| 5353 | |
| 5354 | static ssize_t show_power_level(struct device *d, |
| 5355 | struct device_attribute *attr, char *buf) |
| 5356 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5357 | struct iwl_priv *priv = dev_get_drvdata(d); |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 5358 | int level = priv->power_data.power_mode; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5359 | char *p = buf; |
| 5360 | |
| 5361 | p += sprintf(p, "%d ", level); |
| 5362 | switch (level) { |
| 5363 | case IWL_POWER_MODE_CAM: |
| 5364 | case IWL_POWER_AC: |
| 5365 | p += sprintf(p, "(AC)"); |
| 5366 | break; |
| 5367 | case IWL_POWER_BATTERY: |
| 5368 | p += sprintf(p, "(BATTERY)"); |
| 5369 | break; |
| 5370 | default: |
| 5371 | p += sprintf(p, |
| 5372 | "(Timeout %dms, Period %dms)", |
| 5373 | timeout_duration[level - 1] / 1000, |
| 5374 | period_duration[level - 1] / 1000); |
| 5375 | } |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 5376 | /* |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5377 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 5378 | p += sprintf(p, " OFF\n"); |
| 5379 | else |
| 5380 | p += sprintf(p, " \n"); |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 5381 | */ |
| 5382 | p += sprintf(p, " \n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5383 | return (p - buf + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5384 | } |
| 5385 | |
| 5386 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 5387 | store_power_level); |
| 5388 | |
| 5389 | static ssize_t show_channels(struct device *d, |
| 5390 | struct device_attribute *attr, char *buf) |
| 5391 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5392 | /* all this shit doesn't belong into sysfs anyway */ |
| 5393 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5394 | } |
| 5395 | |
| 5396 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 5397 | |
| 5398 | static ssize_t show_statistics(struct device *d, |
| 5399 | struct device_attribute *attr, char *buf) |
| 5400 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5401 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5402 | u32 size = sizeof(struct iwl4965_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5403 | u32 len = 0, ofs = 0; |
| 5404 | u8 *data = (u8 *) & priv->statistics; |
| 5405 | int rc = 0; |
| 5406 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5407 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5408 | return -EAGAIN; |
| 5409 | |
| 5410 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 5411 | rc = iwl_send_statistics_request(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5412 | mutex_unlock(&priv->mutex); |
| 5413 | |
| 5414 | if (rc) { |
| 5415 | len = sprintf(buf, |
| 5416 | "Error sending statistics request: 0x%08X\n", rc); |
| 5417 | return len; |
| 5418 | } |
| 5419 | |
| 5420 | while (size && (PAGE_SIZE - len)) { |
| 5421 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 5422 | PAGE_SIZE - len, 1); |
| 5423 | len = strlen(buf); |
| 5424 | if (PAGE_SIZE - len) |
| 5425 | buf[len++] = '\n'; |
| 5426 | |
| 5427 | ofs += 16; |
| 5428 | size -= min(size, 16U); |
| 5429 | } |
| 5430 | |
| 5431 | return len; |
| 5432 | } |
| 5433 | |
| 5434 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 5435 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5436 | static ssize_t show_status(struct device *d, |
| 5437 | struct device_attribute *attr, char *buf) |
| 5438 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5439 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5440 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5441 | return -EAGAIN; |
| 5442 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 5443 | } |
| 5444 | |
| 5445 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 5446 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5447 | /***************************************************************************** |
| 5448 | * |
| 5449 | * driver setup and teardown |
| 5450 | * |
| 5451 | *****************************************************************************/ |
| 5452 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5453 | static void iwl4965_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5454 | { |
| 5455 | priv->workqueue = create_workqueue(DRV_NAME); |
| 5456 | |
| 5457 | init_waitqueue_head(&priv->wait_command_queue); |
| 5458 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5459 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 5460 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 5461 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
| 5462 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); |
| 5463 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); |
| 5464 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); |
| 5465 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 5466 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 5467 | INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5468 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 5469 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start); |
| 5470 | INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5471 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5472 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5473 | iwl4965_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5474 | |
| 5475 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5476 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5477 | } |
| 5478 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5479 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5480 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5481 | iwl4965_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5482 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 5483 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5484 | cancel_delayed_work(&priv->scan_check); |
| 5485 | cancel_delayed_work(&priv->alive_start); |
| 5486 | cancel_delayed_work(&priv->post_associate); |
| 5487 | cancel_work_sync(&priv->beacon_update); |
| 5488 | } |
| 5489 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5490 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5491 | &dev_attr_channels.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5492 | &dev_attr_flags.attr, |
| 5493 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5494 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5495 | &dev_attr_measurement.attr, |
| 5496 | #endif |
| 5497 | &dev_attr_power_level.attr, |
| 5498 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5499 | &dev_attr_rs_window.attr, |
| 5500 | &dev_attr_statistics.attr, |
| 5501 | &dev_attr_status.attr, |
| 5502 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5503 | &dev_attr_tx_power.attr, |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5504 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 5505 | &dev_attr_debug_level.attr, |
| 5506 | #endif |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 5507 | &dev_attr_version.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5508 | |
| 5509 | NULL |
| 5510 | }; |
| 5511 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5512 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5513 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5514 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5515 | }; |
| 5516 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5517 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 5518 | .tx = iwl4965_mac_tx, |
| 5519 | .start = iwl4965_mac_start, |
| 5520 | .stop = iwl4965_mac_stop, |
| 5521 | .add_interface = iwl4965_mac_add_interface, |
| 5522 | .remove_interface = iwl4965_mac_remove_interface, |
| 5523 | .config = iwl4965_mac_config, |
| 5524 | .config_interface = iwl4965_mac_config_interface, |
| 5525 | .configure_filter = iwl4965_configure_filter, |
| 5526 | .set_key = iwl4965_mac_set_key, |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5527 | .update_tkip_key = iwl4965_mac_update_tkip_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5528 | .get_stats = iwl4965_mac_get_stats, |
| 5529 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 5530 | .conf_tx = iwl4965_mac_conf_tx, |
| 5531 | .get_tsf = iwl4965_mac_get_tsf, |
| 5532 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 5533 | .beacon_update = iwl4965_mac_beacon_update, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5534 | .bss_info_changed = iwl4965_bss_info_changed, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5535 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | 9ab4617 | 2007-12-25 17:00:38 +0200 | [diff] [blame] | 5536 | .ampdu_action = iwl4965_mac_ampdu_action, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5537 | #endif /* CONFIG_IWL4965_HT */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5538 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5539 | }; |
| 5540 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5541 | 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] | 5542 | { |
| 5543 | int err = 0; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5544 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5545 | struct ieee80211_hw *hw; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 5546 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5547 | unsigned long flags; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5548 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5549 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5550 | /************************ |
| 5551 | * 1. Allocating HW data |
| 5552 | ************************/ |
| 5553 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5554 | /* Disabling hardware scan means that mac80211 will perform scans |
| 5555 | * "the hard way", rather than using device's scan. */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 5556 | if (cfg->mod_params->disable_hw_scan) { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 5557 | if (cfg->mod_params->debug & IWL_DL_INFO) |
| 5558 | dev_printk(KERN_DEBUG, &(pdev->dev), |
| 5559 | "Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5560 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5561 | } |
| 5562 | |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 5563 | hw = iwl_alloc_all(cfg, &iwl4965_hw_ops); |
| 5564 | if (!hw) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5565 | err = -ENOMEM; |
| 5566 | goto out; |
| 5567 | } |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 5568 | priv = hw->priv; |
| 5569 | /* At this point both hw and priv are allocated. */ |
| 5570 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5571 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 5572 | |
| 5573 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 5574 | priv->cfg = cfg; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5575 | priv->pci_dev = pdev; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5576 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 5577 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 5578 | priv->debug_level = priv->cfg->mod_params->debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5579 | atomic_set(&priv->restrict_refcnt, 0); |
| 5580 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5581 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5582 | /************************** |
| 5583 | * 2. Initializing PCI bus |
| 5584 | **************************/ |
| 5585 | if (pci_enable_device(pdev)) { |
| 5586 | err = -ENODEV; |
| 5587 | goto out_ieee80211_free_hw; |
| 5588 | } |
| 5589 | |
| 5590 | pci_set_master(pdev); |
| 5591 | |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5592 | err = pci_set_dma_mask(pdev, DMA_64BIT_MASK); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5593 | if (!err) |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5594 | err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); |
| 5595 | if (err) { |
| 5596 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 5597 | if (!err) |
| 5598 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 5599 | /* both attempts failed: */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5600 | if (err) { |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5601 | printk(KERN_WARNING "%s: No suitable DMA available.\n", |
| 5602 | DRV_NAME); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5603 | goto out_pci_disable_device; |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5604 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5605 | } |
| 5606 | |
| 5607 | err = pci_request_regions(pdev, DRV_NAME); |
| 5608 | if (err) |
| 5609 | goto out_pci_disable_device; |
| 5610 | |
| 5611 | pci_set_drvdata(pdev, priv); |
| 5612 | |
| 5613 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 5614 | * PCI Tx retries from interfering with C3 CPU state */ |
| 5615 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 5616 | |
| 5617 | /*********************** |
| 5618 | * 3. Read REV register |
| 5619 | ***********************/ |
| 5620 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 5621 | if (!priv->hw_base) { |
| 5622 | err = -ENODEV; |
| 5623 | goto out_pci_release_regions; |
| 5624 | } |
| 5625 | |
| 5626 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 5627 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 5628 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 5629 | |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 5630 | iwl_hw_detect(priv); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5631 | printk(KERN_INFO DRV_NAME |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 5632 | ": Detected Intel Wireless WiFi Link %s REV=0x%X\n", |
| 5633 | priv->cfg->name, priv->hw_rev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5634 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 5635 | /* amp init */ |
| 5636 | err = priv->cfg->ops->lib->apm_ops.init(priv); |
| 5637 | if (err < 0) { |
| 5638 | IWL_DEBUG_INFO("Failed to init APMG\n"); |
| 5639 | goto out_iounmap; |
| 5640 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5641 | /***************** |
| 5642 | * 4. Read EEPROM |
| 5643 | *****************/ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5644 | /* Read the EEPROM */ |
| 5645 | err = iwl_eeprom_init(priv); |
| 5646 | if (err) { |
| 5647 | IWL_ERROR("Unable to init EEPROM\n"); |
| 5648 | goto out_iounmap; |
| 5649 | } |
Tomas Winkler | 8614f36 | 2008-04-23 17:14:55 -0700 | [diff] [blame] | 5650 | err = iwl_eeprom_check_version(priv); |
| 5651 | if (err) |
| 5652 | goto out_iounmap; |
| 5653 | |
Ron Rindjunsky | 0288301 | 2008-05-15 13:53:53 +0800 | [diff] [blame] | 5654 | /* extract MAC Address */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5655 | iwl_eeprom_get_mac(priv, priv->mac_addr); |
| 5656 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); |
| 5657 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 5658 | |
| 5659 | /************************ |
| 5660 | * 5. Setup HW constants |
| 5661 | ************************/ |
| 5662 | /* Device-specific setup */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 5663 | if (priv->cfg->ops->lib->set_hw_params(priv)) { |
| 5664 | IWL_ERROR("failed to set hw parameters\n"); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 5665 | goto out_free_eeprom; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5666 | } |
| 5667 | |
| 5668 | /******************* |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5669 | * 6. Setup priv |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5670 | *******************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5671 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5672 | err = iwl_init_drv(priv); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5673 | if (err) |
Ron Rindjunsky | 399f4900 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 5674 | goto out_free_eeprom; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5675 | /* At this point both hw and priv are initialized. */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5676 | |
| 5677 | /********************************** |
| 5678 | * 7. Initialize module parameters |
| 5679 | **********************************/ |
| 5680 | |
| 5681 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 5682 | if (priv->cfg->mod_params->disable) { |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5683 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 5684 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 5685 | } |
| 5686 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5687 | /******************** |
| 5688 | * 8. Setup services |
| 5689 | ********************/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5690 | spin_lock_irqsave(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5691 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5692 | spin_unlock_irqrestore(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5693 | |
| 5694 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
| 5695 | if (err) { |
| 5696 | IWL_ERROR("failed to create sysfs device attributes\n"); |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5697 | goto out_uninit_drv; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5698 | } |
| 5699 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5700 | |
| 5701 | iwl4965_setup_deferred_work(priv); |
| 5702 | iwl4965_setup_rx_handlers(priv); |
| 5703 | |
| 5704 | /******************** |
| 5705 | * 9. Conclude |
| 5706 | ********************/ |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5707 | pci_save_state(pdev); |
| 5708 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5709 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5710 | /********************************** |
| 5711 | * 10. Setup and register mac80211 |
| 5712 | **********************************/ |
| 5713 | |
| 5714 | err = iwl_setup_mac(priv); |
| 5715 | if (err) |
| 5716 | goto out_remove_sysfs; |
| 5717 | |
| 5718 | err = iwl_dbgfs_register(priv, DRV_NAME); |
| 5719 | if (err) |
| 5720 | IWL_ERROR("failed to create debugfs files\n"); |
| 5721 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 5722 | /* notify iwlcore to init */ |
| 5723 | iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5724 | return 0; |
| 5725 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5726 | out_remove_sysfs: |
| 5727 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5728 | out_uninit_drv: |
| 5729 | iwl_uninit_drv(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 5730 | out_free_eeprom: |
| 5731 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5732 | out_iounmap: |
| 5733 | pci_iounmap(pdev, priv->hw_base); |
| 5734 | out_pci_release_regions: |
| 5735 | pci_release_regions(pdev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5736 | pci_set_drvdata(pdev, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5737 | out_pci_disable_device: |
| 5738 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5739 | out_ieee80211_free_hw: |
| 5740 | ieee80211_free_hw(priv->hw); |
| 5741 | out: |
| 5742 | return err; |
| 5743 | } |
| 5744 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 5745 | static void __devexit iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5746 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5747 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5748 | struct list_head *p, *q; |
| 5749 | int i; |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5750 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5751 | |
| 5752 | if (!priv) |
| 5753 | return; |
| 5754 | |
| 5755 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 5756 | |
Ron Rindjunsky | c4f5523 | 2008-03-28 16:21:10 -0700 | [diff] [blame] | 5757 | if (priv->mac80211_registered) { |
| 5758 | ieee80211_unregister_hw(priv->hw); |
| 5759 | priv->mac80211_registered = 0; |
| 5760 | } |
| 5761 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5762 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 5763 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5764 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5765 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5766 | /* make sure we flush any pending irq or |
| 5767 | * tasklet for the driver |
| 5768 | */ |
| 5769 | spin_lock_irqsave(&priv->lock, flags); |
| 5770 | iwl4965_disable_interrupts(priv); |
| 5771 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5772 | |
| 5773 | iwl_synchronize_irq(priv); |
| 5774 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5775 | /* Free MAC hash list for ADHOC */ |
| 5776 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 5777 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 5778 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5779 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5780 | } |
| 5781 | } |
| 5782 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 5783 | iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 5784 | iwl_dbgfs_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5785 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5786 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5787 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5788 | |
| 5789 | if (priv->rxq.bd) |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 5790 | iwl_rx_queue_free(priv, &priv->rxq); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 5791 | iwl_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5792 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5793 | iwlcore_clear_stations_table(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 5794 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5795 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5796 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5797 | /*netif_stop_queue(dev); */ |
| 5798 | flush_workqueue(priv->workqueue); |
| 5799 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5800 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5801 | * priv->workqueue... so we can't take down the workqueue |
| 5802 | * until now... */ |
| 5803 | destroy_workqueue(priv->workqueue); |
| 5804 | priv->workqueue = NULL; |
| 5805 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5806 | pci_iounmap(pdev, priv->hw_base); |
| 5807 | pci_release_regions(pdev); |
| 5808 | pci_disable_device(pdev); |
| 5809 | pci_set_drvdata(pdev, NULL); |
| 5810 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5811 | iwl_uninit_drv(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5812 | |
| 5813 | if (priv->ibss_beacon) |
| 5814 | dev_kfree_skb(priv->ibss_beacon); |
| 5815 | |
| 5816 | ieee80211_free_hw(priv->hw); |
| 5817 | } |
| 5818 | |
| 5819 | #ifdef CONFIG_PM |
| 5820 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5821 | 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] | 5822 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5823 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5824 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5825 | if (priv->is_open) { |
| 5826 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 5827 | iwl4965_mac_stop(priv->hw); |
| 5828 | priv->is_open = 1; |
| 5829 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5830 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5831 | pci_set_power_state(pdev, PCI_D3hot); |
| 5832 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5833 | return 0; |
| 5834 | } |
| 5835 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5836 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5837 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5838 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5839 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5840 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5841 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5842 | if (priv->is_open) |
| 5843 | iwl4965_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5844 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5845 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5846 | return 0; |
| 5847 | } |
| 5848 | |
| 5849 | #endif /* CONFIG_PM */ |
| 5850 | |
| 5851 | /***************************************************************************** |
| 5852 | * |
| 5853 | * driver and module entry point |
| 5854 | * |
| 5855 | *****************************************************************************/ |
| 5856 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5857 | /* Hardware specific file defines the PCI IDs table for that hardware module */ |
| 5858 | static struct pci_device_id iwl_hw_card_ids[] = { |
| 5859 | {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)}, |
| 5860 | {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)}, |
Tomas Winkler | 5a6a256 | 2008-04-24 11:55:23 -0700 | [diff] [blame] | 5861 | #ifdef CONFIG_IWL5000 |
| 5862 | {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)}, |
| 5863 | {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)}, |
| 5864 | {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)}, |
| 5865 | #endif /* CONFIG_IWL5000 */ |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5866 | {0} |
| 5867 | }; |
| 5868 | MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); |
| 5869 | |
| 5870 | static struct pci_driver iwl_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5871 | .name = DRV_NAME, |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5872 | .id_table = iwl_hw_card_ids, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5873 | .probe = iwl4965_pci_probe, |
| 5874 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5875 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5876 | .suspend = iwl4965_pci_suspend, |
| 5877 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5878 | #endif |
| 5879 | }; |
| 5880 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5881 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5882 | { |
| 5883 | |
| 5884 | int ret; |
| 5885 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 5886 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5887 | |
| 5888 | ret = iwl4965_rate_control_register(); |
| 5889 | if (ret) { |
| 5890 | IWL_ERROR("Unable to register rate control algorithm: %d\n", ret); |
| 5891 | return ret; |
| 5892 | } |
| 5893 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5894 | ret = pci_register_driver(&iwl_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5895 | if (ret) { |
| 5896 | IWL_ERROR("Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5897 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5898 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5899 | |
| 5900 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5901 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5902 | error_register: |
| 5903 | iwl4965_rate_control_unregister(); |
| 5904 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5905 | } |
| 5906 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5907 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5908 | { |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5909 | pci_unregister_driver(&iwl_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5910 | iwl4965_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5911 | } |
| 5912 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5913 | module_exit(iwl4965_exit); |
| 5914 | module_init(iwl4965_init); |