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 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 143 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 144 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 145 | static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) |
| 146 | { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 147 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 148 | |
| 149 | if (hw_decrypt) |
| 150 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 151 | else |
| 152 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 153 | |
| 154 | } |
| 155 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 156 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 157 | * iwl4965_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 158 | * |
| 159 | * NOTE: This is really only useful during development and can eventually |
| 160 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 161 | * making changes |
| 162 | */ |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 163 | static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 164 | { |
| 165 | int error = 0; |
| 166 | int counter = 1; |
| 167 | |
| 168 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 169 | error |= le32_to_cpu(rxon->flags & |
| 170 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 171 | RXON_FLG_RADAR_DETECT_MSK)); |
| 172 | if (error) |
| 173 | IWL_WARNING("check 24G fields %d | %d\n", |
| 174 | counter++, error); |
| 175 | } else { |
| 176 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 177 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 178 | if (error) |
| 179 | IWL_WARNING("check 52 fields %d | %d\n", |
| 180 | counter++, error); |
| 181 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 182 | if (error) |
| 183 | IWL_WARNING("check 52 CCK %d | %d\n", |
| 184 | counter++, error); |
| 185 | } |
| 186 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 187 | if (error) |
| 188 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); |
| 189 | |
| 190 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 191 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 192 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 193 | if (error) |
| 194 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); |
| 195 | |
| 196 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 197 | if (error) |
| 198 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); |
| 199 | |
| 200 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 201 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 202 | if (error) |
| 203 | IWL_WARNING("check CCK and short slot %d | %d\n", |
| 204 | counter++, error); |
| 205 | |
| 206 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 207 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 208 | if (error) |
| 209 | IWL_WARNING("check CCK & auto detect %d | %d\n", |
| 210 | counter++, error); |
| 211 | |
| 212 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 213 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 214 | if (error) |
| 215 | IWL_WARNING("check TGG and auto detect %d | %d\n", |
| 216 | counter++, error); |
| 217 | |
| 218 | if (error) |
| 219 | IWL_WARNING("Tuning to channel %d\n", |
| 220 | le16_to_cpu(rxon->channel)); |
| 221 | |
| 222 | if (error) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 223 | IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 224 | return -1; |
| 225 | } |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 230 | * 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] | 231 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 232 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 233 | * If the RXON structure is changing enough to require a new tune, |
| 234 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 235 | * 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] | 236 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 237 | static int iwl4965_full_rxon_required(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 238 | { |
| 239 | |
| 240 | /* These items are only settable from the full RXON command */ |
| 241 | if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || |
| 242 | compare_ether_addr(priv->staging_rxon.bssid_addr, |
| 243 | priv->active_rxon.bssid_addr) || |
| 244 | compare_ether_addr(priv->staging_rxon.node_addr, |
| 245 | priv->active_rxon.node_addr) || |
| 246 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, |
| 247 | priv->active_rxon.wlap_bssid_addr) || |
| 248 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || |
| 249 | (priv->staging_rxon.channel != priv->active_rxon.channel) || |
| 250 | (priv->staging_rxon.air_propagation != |
| 251 | priv->active_rxon.air_propagation) || |
| 252 | (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != |
| 253 | priv->active_rxon.ofdm_ht_single_stream_basic_rates) || |
| 254 | (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != |
| 255 | priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || |
| 256 | (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) || |
| 257 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) |
| 258 | return 1; |
| 259 | |
| 260 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 261 | * be updated with the RXON_ASSOC command -- however only some |
| 262 | * flag transitions are allowed using RXON_ASSOC */ |
| 263 | |
| 264 | /* Check if we are not switching bands */ |
| 265 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 266 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
| 267 | return 1; |
| 268 | |
| 269 | /* Check if we are switching association toggle */ |
| 270 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 271 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
| 272 | return 1; |
| 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 277 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 278 | * iwl4965_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 279 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 280 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 281 | * the active_rxon structure is updated with the new data. This |
| 282 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 283 | * a HW tune is required based on the RXON structure changes. |
| 284 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 285 | static int iwl4965_commit_rxon(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 286 | { |
| 287 | /* cast away the const for active_rxon in this function */ |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 288 | struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 289 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 290 | int rc = 0; |
| 291 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 292 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 293 | return -1; |
| 294 | |
| 295 | /* always get timestamp with Rx frame */ |
| 296 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
| 297 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 298 | rc = iwl4965_check_rxon_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 299 | if (rc) { |
| 300 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); |
| 301 | return -EINVAL; |
| 302 | } |
| 303 | |
| 304 | /* 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] | 305 | * iwl4965_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 306 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 307 | if (!iwl4965_full_rxon_required(priv)) { |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 308 | rc = iwl_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 309 | if (rc) { |
| 310 | IWL_ERROR("Error setting RXON_ASSOC " |
| 311 | "configuration (%d).\n", rc); |
| 312 | return rc; |
| 313 | } |
| 314 | |
| 315 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | /* station table will be cleared */ |
| 321 | priv->assoc_station_added = 0; |
| 322 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 323 | /* If we are currently associated and the new config requires |
| 324 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 325 | * we must clear the associated from the active configuration |
| 326 | * before we apply the new config */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 327 | if (iwl_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 328 | (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
| 329 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 330 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 331 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 332 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 333 | sizeof(struct iwl_rxon_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 334 | &priv->active_rxon); |
| 335 | |
| 336 | /* If the mask clearing failed then we set |
| 337 | * active_rxon back to what it was previously */ |
| 338 | if (rc) { |
| 339 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 340 | IWL_ERROR("Error clearing ASSOC_MSK on current " |
| 341 | "configuration (%d).\n", rc); |
| 342 | return rc; |
| 343 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | IWL_DEBUG_INFO("Sending RXON\n" |
| 347 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 348 | "* channel = %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 349 | "* bssid = %s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 350 | ((priv->staging_rxon.filter_flags & |
| 351 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
| 352 | le16_to_cpu(priv->staging_rxon.channel), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 353 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 354 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 355 | iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 356 | /* Apply the new configuration */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 357 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 358 | sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 359 | if (rc) { |
| 360 | IWL_ERROR("Error setting new configuration (%d).\n", rc); |
| 361 | return rc; |
| 362 | } |
| 363 | |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 364 | iwl_remove_station(priv, iwl_bcast_addr, 0); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 365 | iwlcore_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 366 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 367 | if (!priv->error_recovering) |
| 368 | priv->start_calib = 0; |
| 369 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 370 | iwl_init_sensitivity(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 371 | |
| 372 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 373 | |
| 374 | /* If we issue a new RXON command which required a tune then we must |
| 375 | * 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] | 376 | rc = iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 377 | if (rc) { |
| 378 | IWL_ERROR("Error setting Tx power (%d).\n", rc); |
| 379 | return rc; |
| 380 | } |
| 381 | |
| 382 | /* Add the broadcast address so we can send broadcast frames */ |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 383 | if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 384 | IWL_INVALID_STATION) { |
| 385 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); |
| 386 | return -EIO; |
| 387 | } |
| 388 | |
| 389 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 390 | * add the IWL_AP_ID to the station rate table */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 391 | if (iwl_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 392 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 393 | if (iwl_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 394 | == IWL_INVALID_STATION) { |
| 395 | IWL_ERROR("Error adding AP address for transmit.\n"); |
| 396 | return -EIO; |
| 397 | } |
| 398 | priv->assoc_station_added = 1; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 399 | if (priv->default_wep_key && |
| 400 | iwl_send_static_wepkey_cmd(priv, 0)) |
| 401 | IWL_ERROR("Could not send WEP static key.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | return 0; |
| 405 | } |
| 406 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 407 | void iwl4965_update_chain_flags(struct iwl_priv *priv) |
| 408 | { |
| 409 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 410 | iwl_set_rxon_chain(priv); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 411 | iwl4965_commit_rxon(priv); |
| 412 | } |
| 413 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 414 | static int iwl4965_send_bt_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 415 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 416 | struct iwl4965_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 417 | .flags = 3, |
| 418 | .lead_time = 0xAA, |
| 419 | .max_kill = 1, |
| 420 | .kill_ack_mask = 0, |
| 421 | .kill_cts_mask = 0, |
| 422 | }; |
| 423 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 424 | return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 425 | sizeof(struct iwl4965_bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 428 | static int iwl4965_send_scan_abort(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 429 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 430 | int ret = 0; |
| 431 | struct iwl_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 432 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 433 | .id = REPLY_SCAN_ABORT_CMD, |
| 434 | .meta.flags = CMD_WANT_SKB, |
| 435 | }; |
| 436 | |
| 437 | /* If there isn't a scan actively going on in the hardware |
| 438 | * then we are in between scan bands and not actually |
| 439 | * actively scanning, so don't send the abort command */ |
| 440 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 441 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 442 | return 0; |
| 443 | } |
| 444 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 445 | ret = iwl_send_cmd_sync(priv, &cmd); |
| 446 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 447 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 448 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 451 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 452 | if (res->u.status != CAN_ABORT_STATUS) { |
| 453 | /* The scan abort will return 1 for success or |
| 454 | * 2 for "failure". A failure condition can be |
| 455 | * due to simply not being in an active scan which |
| 456 | * can occur if we send the scan abort before we |
| 457 | * the microcode has notified us that a scan is |
| 458 | * completed. */ |
| 459 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 460 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 461 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 462 | } |
| 463 | |
| 464 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 465 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 466 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 469 | /* |
| 470 | * CARD_STATE_CMD |
| 471 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 472 | * 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] | 473 | * |
| 474 | * When in the 'enable' state the card operates as normal. |
| 475 | * When in the 'disable' state, the card enters into a low power mode. |
| 476 | * When in the 'halt' state, the card is shut down and must be fully |
| 477 | * restarted to come back on. |
| 478 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 479 | 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] | 480 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 481 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 482 | .id = REPLY_CARD_STATE_CMD, |
| 483 | .len = sizeof(u32), |
| 484 | .data = &flags, |
| 485 | .meta.flags = meta_flag, |
| 486 | }; |
| 487 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 488 | return iwl_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 491 | static void iwl_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 492 | { |
| 493 | struct list_head *element; |
| 494 | |
| 495 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 496 | priv->frames_count); |
| 497 | |
| 498 | while (!list_empty(&priv->free_frames)) { |
| 499 | element = priv->free_frames.next; |
| 500 | list_del(element); |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 501 | kfree(list_entry(element, struct iwl_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 502 | priv->frames_count--; |
| 503 | } |
| 504 | |
| 505 | if (priv->frames_count) { |
| 506 | IWL_WARNING("%d frames still in use. Did we lose one?\n", |
| 507 | priv->frames_count); |
| 508 | priv->frames_count = 0; |
| 509 | } |
| 510 | } |
| 511 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 512 | static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 513 | { |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 514 | struct iwl_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 515 | struct list_head *element; |
| 516 | if (list_empty(&priv->free_frames)) { |
| 517 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 518 | if (!frame) { |
| 519 | IWL_ERROR("Could not allocate frame!\n"); |
| 520 | return NULL; |
| 521 | } |
| 522 | |
| 523 | priv->frames_count++; |
| 524 | return frame; |
| 525 | } |
| 526 | |
| 527 | element = priv->free_frames.next; |
| 528 | list_del(element); |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 529 | return list_entry(element, struct iwl_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 532 | 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] | 533 | { |
| 534 | memset(frame, 0, sizeof(*frame)); |
| 535 | list_add(&frame->list, &priv->free_frames); |
| 536 | } |
| 537 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 538 | unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 539 | struct ieee80211_hdr *hdr, |
| 540 | const u8 *dest, int left) |
| 541 | { |
| 542 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 543 | if (!iwl_is_associated(priv) || !priv->ibss_beacon || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 544 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
| 545 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) |
| 546 | return 0; |
| 547 | |
| 548 | if (priv->ibss_beacon->len > left) |
| 549 | return 0; |
| 550 | |
| 551 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 552 | |
| 553 | return priv->ibss_beacon->len; |
| 554 | } |
| 555 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 556 | static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 557 | { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 558 | int i; |
| 559 | int rate_mask; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 560 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 561 | /* Set rate mask*/ |
| 562 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 563 | rate_mask = priv->active_rate_basic & 0xF; |
| 564 | else |
| 565 | rate_mask = priv->active_rate_basic & 0xFF0; |
| 566 | |
| 567 | /* Find lowest valid rate */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 568 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 569 | i = iwl_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 570 | if (rate_mask & (1 << i)) |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 571 | return iwl_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 574 | /* No valid rate was found. Assign the lowest one */ |
| 575 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 576 | return IWL_RATE_1M_PLCP; |
| 577 | else |
| 578 | return IWL_RATE_6M_PLCP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 581 | static int iwl4965_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 582 | { |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 583 | struct iwl_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 584 | unsigned int frame_size; |
| 585 | int rc; |
| 586 | u8 rate; |
| 587 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 588 | frame = iwl_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 589 | |
| 590 | if (!frame) { |
| 591 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 592 | "command.\n"); |
| 593 | return -ENOMEM; |
| 594 | } |
| 595 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 596 | rate = iwl4965_rate_get_lowest_plcp(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 597 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 598 | frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 599 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 600 | rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 601 | &frame->u.cmd[0]); |
| 602 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 603 | iwl_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 604 | |
| 605 | return rc; |
| 606 | } |
| 607 | |
| 608 | /****************************************************************************** |
| 609 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 610 | * Misc. internal state and helper functions |
| 611 | * |
| 612 | ******************************************************************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 613 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 614 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 615 | * 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] | 616 | * |
| 617 | * return : set the bit for each supported rate insert in ie |
| 618 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 619 | static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 620 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 621 | { |
| 622 | u16 ret_rates = 0, bit; |
| 623 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 624 | u8 *cnt = ie; |
| 625 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 626 | |
| 627 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 628 | if (bit & supported_rate) { |
| 629 | ret_rates |= bit; |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 630 | rates[*cnt] = iwl_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 631 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 632 | (*cnt)++; |
| 633 | (*left)--; |
| 634 | if ((*left <= 0) || |
| 635 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 636 | break; |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | return ret_rates; |
| 641 | } |
| 642 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 643 | #ifdef CONFIG_IWL4965_HT |
| 644 | static void iwl4965_ht_conf(struct iwl_priv *priv, |
| 645 | struct ieee80211_bss_conf *bss_conf) |
| 646 | { |
| 647 | struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf; |
| 648 | struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf; |
| 649 | struct iwl_ht_info *iwl_conf = &priv->current_ht_config; |
| 650 | |
| 651 | IWL_DEBUG_MAC80211("enter: \n"); |
| 652 | |
| 653 | iwl_conf->is_ht = bss_conf->assoc_ht; |
| 654 | |
| 655 | if (!iwl_conf->is_ht) |
| 656 | return; |
| 657 | |
| 658 | priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 659 | |
| 660 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) |
Emmanuel Grumbach | a984101 | 2008-05-15 13:54:08 +0800 | [diff] [blame] | 661 | iwl_conf->sgf |= HT_SHORT_GI_20MHZ; |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 662 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) |
Emmanuel Grumbach | a984101 | 2008-05-15 13:54:08 +0800 | [diff] [blame] | 663 | iwl_conf->sgf |= HT_SHORT_GI_40MHZ; |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 664 | |
| 665 | iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); |
| 666 | iwl_conf->max_amsdu_size = |
| 667 | !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); |
| 668 | |
| 669 | iwl_conf->supported_chan_width = |
| 670 | !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); |
| 671 | iwl_conf->extension_chan_offset = |
| 672 | ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; |
| 673 | /* If no above or below channel supplied disable FAT channel */ |
| 674 | if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE && |
| 675 | iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW) |
| 676 | iwl_conf->supported_chan_width = 0; |
| 677 | |
| 678 | iwl_conf->tx_mimo_ps_mode = |
| 679 | (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 680 | memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); |
| 681 | |
| 682 | iwl_conf->control_channel = ht_bss_conf->primary_channel; |
| 683 | iwl_conf->tx_chan_width = |
| 684 | !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); |
| 685 | iwl_conf->ht_protection = |
| 686 | ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; |
| 687 | iwl_conf->non_GF_STA_present = |
| 688 | !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT); |
| 689 | |
| 690 | IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel); |
| 691 | IWL_DEBUG_MAC80211("leave\n"); |
| 692 | } |
| 693 | |
| 694 | static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband, |
| 695 | u8 *pos, int *left) |
| 696 | { |
| 697 | struct ieee80211_ht_cap *ht_cap; |
| 698 | |
| 699 | if (!sband || !sband->ht_info.ht_supported) |
| 700 | return; |
| 701 | |
| 702 | if (*left < sizeof(struct ieee80211_ht_cap)) |
| 703 | return; |
| 704 | |
| 705 | *pos++ = sizeof(struct ieee80211_ht_cap); |
| 706 | ht_cap = (struct ieee80211_ht_cap *) pos; |
| 707 | |
| 708 | ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap); |
| 709 | memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16); |
| 710 | ht_cap->ampdu_params_info = |
| 711 | (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) | |
| 712 | ((sband->ht_info.ampdu_density << 2) & |
| 713 | IEEE80211_HT_CAP_AMPDU_DENSITY); |
| 714 | *left -= sizeof(struct ieee80211_ht_cap); |
| 715 | } |
| 716 | #else |
| 717 | static inline void iwl4965_ht_conf(struct iwl_priv *priv, |
| 718 | struct ieee80211_bss_conf *bss_conf) |
| 719 | { |
| 720 | } |
| 721 | static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband, |
| 722 | u8 *pos, int *left) |
| 723 | { |
| 724 | } |
| 725 | #endif |
| 726 | |
| 727 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 728 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 729 | * 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] | 730 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 731 | static u16 iwl4965_fill_probe_req(struct iwl_priv *priv, |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 732 | enum ieee80211_band band, |
| 733 | struct ieee80211_mgmt *frame, |
| 734 | int left, int is_direct) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 735 | { |
| 736 | int len = 0; |
| 737 | u8 *pos = NULL; |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 738 | u16 active_rates, ret_rates, cck_rates, active_rate_basic; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 739 | const struct ieee80211_supported_band *sband = |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 740 | iwl_get_hw_mode(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 741 | |
| 742 | /* Make sure there is enough space for the probe request, |
| 743 | * two mandatory IEs and the data */ |
| 744 | left -= 24; |
| 745 | if (left < 0) |
| 746 | return 0; |
| 747 | len += 24; |
| 748 | |
| 749 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Tomas Winkler | 57bd1be | 2008-05-15 13:54:03 +0800 | [diff] [blame] | 750 | memcpy(frame->da, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 751 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Tomas Winkler | 57bd1be | 2008-05-15 13:54:03 +0800 | [diff] [blame] | 752 | memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 753 | frame->seq_ctrl = 0; |
| 754 | |
| 755 | /* fill in our indirect SSID IE */ |
| 756 | /* ...next IE... */ |
| 757 | |
| 758 | left -= 2; |
| 759 | if (left < 0) |
| 760 | return 0; |
| 761 | len += 2; |
| 762 | pos = &(frame->u.probe_req.variable[0]); |
| 763 | *pos++ = WLAN_EID_SSID; |
| 764 | *pos++ = 0; |
| 765 | |
| 766 | /* fill in our direct SSID IE... */ |
| 767 | if (is_direct) { |
| 768 | /* ...next IE... */ |
| 769 | left -= 2 + priv->essid_len; |
| 770 | if (left < 0) |
| 771 | return 0; |
| 772 | /* ... fill it in... */ |
| 773 | *pos++ = WLAN_EID_SSID; |
| 774 | *pos++ = priv->essid_len; |
| 775 | memcpy(pos, priv->essid, priv->essid_len); |
| 776 | pos += priv->essid_len; |
| 777 | len += 2 + priv->essid_len; |
| 778 | } |
| 779 | |
| 780 | /* fill in supported rate */ |
| 781 | /* ...next IE... */ |
| 782 | left -= 2; |
| 783 | if (left < 0) |
| 784 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 785 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 786 | /* ... fill it in... */ |
| 787 | *pos++ = WLAN_EID_SUPP_RATES; |
| 788 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 789 | |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 790 | /* exclude 60M rate */ |
| 791 | active_rates = priv->rates_mask; |
| 792 | active_rates &= ~IWL_RATE_60M_MASK; |
| 793 | |
| 794 | active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 795 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 796 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 797 | ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 798 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 799 | active_rates &= ~ret_rates; |
| 800 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 801 | ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 802 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 803 | active_rates &= ~ret_rates; |
| 804 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 805 | len += 2 + *pos; |
| 806 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 807 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 808 | goto fill_end; |
| 809 | |
| 810 | /* fill in supported extended rate */ |
| 811 | /* ...next IE... */ |
| 812 | left -= 2; |
| 813 | if (left < 0) |
| 814 | return 0; |
| 815 | /* ... fill it in... */ |
| 816 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 817 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 818 | iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 819 | active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 820 | if (*pos > 0) |
| 821 | len += 2 + *pos; |
| 822 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 823 | fill_end: |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 824 | /* fill in HT IE */ |
| 825 | left -= 2; |
| 826 | if (left < 0) |
| 827 | return 0; |
| 828 | |
| 829 | *pos++ = WLAN_EID_HT_CAPABILITY; |
| 830 | *pos = 0; |
| 831 | |
| 832 | iwl_ht_cap_to_ie(sband, pos, &left); |
| 833 | |
| 834 | if (*pos > 0) |
| 835 | len += 2 + *pos; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 836 | return (u16)len; |
| 837 | } |
| 838 | |
| 839 | /* |
| 840 | * QoS support |
| 841 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 842 | static int iwl4965_send_qos_params_command(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 843 | struct iwl4965_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 844 | { |
| 845 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 846 | return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 847 | sizeof(struct iwl4965_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 848 | } |
| 849 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 850 | static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 851 | { |
| 852 | unsigned long flags; |
| 853 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 854 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 855 | return; |
| 856 | |
| 857 | if (!priv->qos_data.qos_enable) |
| 858 | return; |
| 859 | |
| 860 | spin_lock_irqsave(&priv->lock, flags); |
| 861 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 862 | |
| 863 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 864 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 865 | priv->qos_data.def_qos_parm.qos_flags |= |
| 866 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 867 | if (priv->qos_data.qos_active) |
| 868 | priv->qos_data.def_qos_parm.qos_flags |= |
| 869 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 870 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 871 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 872 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 873 | 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] | 874 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 875 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 876 | spin_unlock_irqrestore(&priv->lock, flags); |
| 877 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 878 | if (force || iwl_is_associated(priv)) { |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 879 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 880 | priv->qos_data.qos_active, |
| 881 | priv->qos_data.def_qos_parm.qos_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 882 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 883 | iwl4965_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 884 | &(priv->qos_data.def_qos_parm)); |
| 885 | } |
| 886 | } |
| 887 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 888 | 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] | 889 | { |
| 890 | /* Filter incoming packets to determine if they are targeted toward |
| 891 | * this network, discarding packets coming from ourselves */ |
| 892 | switch (priv->iw_mode) { |
| 893 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 894 | /* packets from our adapter are dropped (echo) */ |
| 895 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 896 | return 0; |
| 897 | /* {broad,multi}cast packets to our IBSS go through */ |
| 898 | if (is_multicast_ether_addr(header->addr1)) |
| 899 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 900 | /* packets to our adapter go through */ |
| 901 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 902 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 903 | /* packets from our adapter are dropped (echo) */ |
| 904 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 905 | return 0; |
| 906 | /* {broad,multi}cast packets to our BSS go through */ |
| 907 | if (is_multicast_ether_addr(header->addr1)) |
| 908 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 909 | /* packets to our adapter go through */ |
| 910 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 911 | default: |
| 912 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | return 1; |
| 916 | } |
| 917 | |
| 918 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 919 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 920 | static const char *iwl4965_get_tx_fail_reason(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 921 | { |
| 922 | switch (status & TX_STATUS_MSK) { |
| 923 | case TX_STATUS_SUCCESS: |
| 924 | return "SUCCESS"; |
| 925 | TX_STATUS_ENTRY(SHORT_LIMIT); |
| 926 | TX_STATUS_ENTRY(LONG_LIMIT); |
| 927 | TX_STATUS_ENTRY(FIFO_UNDERRUN); |
| 928 | TX_STATUS_ENTRY(MGMNT_ABORT); |
| 929 | TX_STATUS_ENTRY(NEXT_FRAG); |
| 930 | TX_STATUS_ENTRY(LIFE_EXPIRE); |
| 931 | TX_STATUS_ENTRY(DEST_PS); |
| 932 | TX_STATUS_ENTRY(ABORTED); |
| 933 | TX_STATUS_ENTRY(BT_RETRY); |
| 934 | TX_STATUS_ENTRY(STA_INVALID); |
| 935 | TX_STATUS_ENTRY(FRAG_DROPPED); |
| 936 | TX_STATUS_ENTRY(TID_DISABLE); |
| 937 | TX_STATUS_ENTRY(FRAME_FLUSHED); |
| 938 | TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL); |
| 939 | TX_STATUS_ENTRY(TX_LOCKED); |
| 940 | TX_STATUS_ENTRY(NO_BEACON_ON_RADAR); |
| 941 | } |
| 942 | |
| 943 | return "UNKNOWN"; |
| 944 | } |
| 945 | |
| 946 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 947 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 948 | * |
| 949 | * NOTE: priv->mutex is not required before calling this function |
| 950 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 951 | static int iwl4965_scan_cancel(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 952 | { |
| 953 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 954 | clear_bit(STATUS_SCANNING, &priv->status); |
| 955 | return 0; |
| 956 | } |
| 957 | |
| 958 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 959 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 960 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 961 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 962 | queue_work(priv->workqueue, &priv->abort_scan); |
| 963 | |
| 964 | } else |
| 965 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 966 | |
| 967 | return test_bit(STATUS_SCANNING, &priv->status); |
| 968 | } |
| 969 | |
| 970 | return 0; |
| 971 | } |
| 972 | |
| 973 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 974 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 975 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 976 | * |
| 977 | * NOTE: priv->mutex must be held before calling this function |
| 978 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 979 | 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] | 980 | { |
| 981 | unsigned long now = jiffies; |
| 982 | int ret; |
| 983 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 984 | ret = iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 985 | if (ret && ms) { |
| 986 | mutex_unlock(&priv->mutex); |
| 987 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 988 | test_bit(STATUS_SCANNING, &priv->status)) |
| 989 | msleep(1); |
| 990 | mutex_lock(&priv->mutex); |
| 991 | |
| 992 | return test_bit(STATUS_SCANNING, &priv->status); |
| 993 | } |
| 994 | |
| 995 | return ret; |
| 996 | } |
| 997 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 998 | static void iwl4965_sequence_reset(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 999 | { |
| 1000 | /* Reset ieee stats */ |
| 1001 | |
| 1002 | /* We don't reset the net_device_stats (ieee->stats) on |
| 1003 | * re-association */ |
| 1004 | |
| 1005 | priv->last_seq_num = -1; |
| 1006 | priv->last_frag_num = -1; |
| 1007 | priv->last_packet_time = 0; |
| 1008 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1009 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 1013 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 1014 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1015 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1016 | { |
| 1017 | u16 new_val = 0; |
| 1018 | u16 beacon_factor = 0; |
| 1019 | |
| 1020 | beacon_factor = |
| 1021 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 1022 | / MAX_UCODE_BEACON_INTERVAL; |
| 1023 | new_val = beacon_val / beacon_factor; |
| 1024 | |
| 1025 | return cpu_to_le16(new_val); |
| 1026 | } |
| 1027 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1028 | static void iwl4965_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1029 | { |
| 1030 | u64 interval_tm_unit; |
| 1031 | u64 tsf, result; |
| 1032 | unsigned long flags; |
| 1033 | struct ieee80211_conf *conf = NULL; |
| 1034 | u16 beacon_int = 0; |
| 1035 | |
| 1036 | conf = ieee80211_get_hw_conf(priv->hw); |
| 1037 | |
| 1038 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1039 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32); |
| 1040 | priv->rxon_timing.timestamp.dw[0] = |
| 1041 | cpu_to_le32(priv->timestamp & 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1042 | |
| 1043 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 1044 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1045 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1046 | |
| 1047 | beacon_int = priv->beacon_int; |
| 1048 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1049 | |
| 1050 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 1051 | if (beacon_int == 0) { |
| 1052 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 1053 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 1054 | } else { |
| 1055 | priv->rxon_timing.beacon_interval = |
| 1056 | cpu_to_le16(beacon_int); |
| 1057 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1058 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1059 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1060 | } |
| 1061 | |
| 1062 | priv->rxon_timing.atim_window = 0; |
| 1063 | } else { |
| 1064 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1065 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1066 | /* TODO: we need to get atim_window from upper stack |
| 1067 | * for now we set to 0 */ |
| 1068 | priv->rxon_timing.atim_window = 0; |
| 1069 | } |
| 1070 | |
| 1071 | interval_tm_unit = |
| 1072 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 1073 | result = do_div(tsf, interval_tm_unit); |
| 1074 | priv->rxon_timing.beacon_init_val = |
| 1075 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 1076 | |
| 1077 | IWL_DEBUG_ASSOC |
| 1078 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 1079 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 1080 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 1081 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 1082 | } |
| 1083 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1084 | static int iwl4965_scan_initiate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1085 | { |
| 1086 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 1087 | IWL_ERROR("APs don't scan.\n"); |
| 1088 | return 0; |
| 1089 | } |
| 1090 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1091 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1092 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 1093 | return -EIO; |
| 1094 | } |
| 1095 | |
| 1096 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1097 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 1098 | return -EAGAIN; |
| 1099 | } |
| 1100 | |
| 1101 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1102 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 1103 | "Queuing.\n"); |
| 1104 | return -EAGAIN; |
| 1105 | } |
| 1106 | |
| 1107 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 1108 | priv->scan_bands = 2; |
| 1109 | set_bit(STATUS_SCANNING, &priv->status); |
| 1110 | priv->scan_start = jiffies; |
| 1111 | priv->scan_pass_start = priv->scan_start; |
| 1112 | |
| 1113 | queue_work(priv->workqueue, &priv->request_scan); |
| 1114 | |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1118 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1119 | static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1120 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1121 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1122 | if (band == IEEE80211_BAND_5GHZ) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1123 | priv->staging_rxon.flags &= |
| 1124 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 1125 | | RXON_FLG_CCK_MSK); |
| 1126 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1127 | } else { |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 1128 | /* Copied from iwl4965_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1129 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 1130 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1131 | else |
| 1132 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1133 | |
| 1134 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 1135 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1136 | |
| 1137 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 1138 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 1139 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1144 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1145 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1146 | static void iwl4965_connection_init_rx_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1147 | { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1148 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1149 | |
| 1150 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 1151 | |
| 1152 | switch (priv->iw_mode) { |
| 1153 | case IEEE80211_IF_TYPE_AP: |
| 1154 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 1155 | break; |
| 1156 | |
| 1157 | case IEEE80211_IF_TYPE_STA: |
| 1158 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 1159 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 1160 | break; |
| 1161 | |
| 1162 | case IEEE80211_IF_TYPE_IBSS: |
| 1163 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 1164 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1165 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 1166 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1167 | break; |
| 1168 | |
| 1169 | case IEEE80211_IF_TYPE_MNTR: |
| 1170 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 1171 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 1172 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1173 | break; |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1174 | default: |
| 1175 | IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode); |
| 1176 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | #if 0 |
| 1180 | /* TODO: Figure out when short_preamble would be set and cache from |
| 1181 | * that */ |
| 1182 | if (!hw_to_local(priv->hw)->short_preamble) |
| 1183 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1184 | else |
| 1185 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1186 | #endif |
| 1187 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1188 | ch_info = iwl_get_channel_info(priv, priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1189 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1190 | |
| 1191 | if (!ch_info) |
| 1192 | ch_info = &priv->channel_info[0]; |
| 1193 | |
| 1194 | /* |
| 1195 | * in some case A channels are all non IBSS |
| 1196 | * in this case force B/G channel |
| 1197 | */ |
| 1198 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 1199 | !(is_channel_ibss(ch_info))) |
| 1200 | ch_info = &priv->channel_info[0]; |
| 1201 | |
| 1202 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1203 | priv->band = ch_info->band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1204 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1205 | iwl4965_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1206 | |
| 1207 | priv->staging_rxon.ofdm_basic_rates = |
| 1208 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1209 | priv->staging_rxon.cck_basic_rates = |
| 1210 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1211 | |
| 1212 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 1213 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 1214 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1215 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 1216 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 1217 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 1218 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1221 | static int iwl4965_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1222 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1223 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1224 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1225 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1226 | ch_info = iwl_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1227 | priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1228 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1229 | |
| 1230 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 1231 | IWL_ERROR("channel %d not IBSS channel\n", |
| 1232 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1233 | return -EINVAL; |
| 1234 | } |
| 1235 | } |
| 1236 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1237 | priv->iw_mode = mode; |
| 1238 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1239 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1240 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1241 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1242 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1243 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1244 | /* dont commit rxon if rf-kill is on*/ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1245 | if (!iwl_is_ready_rf(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1246 | return -EAGAIN; |
| 1247 | |
| 1248 | cancel_delayed_work(&priv->scan_check); |
| 1249 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
| 1250 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 1251 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 1252 | return -EAGAIN; |
| 1253 | } |
| 1254 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1255 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1256 | |
| 1257 | return 0; |
| 1258 | } |
| 1259 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1260 | static void iwl4965_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1261 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1262 | const struct ieee80211_supported_band *hw = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1263 | struct ieee80211_rate *rate; |
| 1264 | int i; |
| 1265 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 1266 | hw = iwl_get_hw_mode(priv, priv->band); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 1267 | if (!hw) { |
| 1268 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 1269 | return; |
| 1270 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1271 | |
| 1272 | priv->active_rate = 0; |
| 1273 | priv->active_rate_basic = 0; |
| 1274 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1275 | for (i = 0; i < hw->n_bitrates; i++) { |
| 1276 | rate = &(hw->bitrates[i]); |
| 1277 | if (rate->hw_value < IWL_RATE_COUNT) |
| 1278 | priv->active_rate |= (1 << rate->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 1282 | priv->active_rate, priv->active_rate_basic); |
| 1283 | |
| 1284 | /* |
| 1285 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 1286 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 1287 | * OFDM |
| 1288 | */ |
| 1289 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 1290 | priv->staging_rxon.cck_basic_rates = |
| 1291 | ((priv->active_rate_basic & |
| 1292 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1293 | else |
| 1294 | priv->staging_rxon.cck_basic_rates = |
| 1295 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1296 | |
| 1297 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 1298 | priv->staging_rxon.ofdm_basic_rates = |
| 1299 | ((priv->active_rate_basic & |
| 1300 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 1301 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1302 | else |
| 1303 | priv->staging_rxon.ofdm_basic_rates = |
| 1304 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1305 | } |
| 1306 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1307 | void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1308 | { |
| 1309 | unsigned long flags; |
| 1310 | |
| 1311 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 1312 | return; |
| 1313 | |
| 1314 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 1315 | disable_radio ? "OFF" : "ON"); |
| 1316 | |
| 1317 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1318 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1319 | /* FIXME: This is a workaround for AP */ |
| 1320 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 1321 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1322 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1323 | CSR_UCODE_SW_BIT_RFKILL); |
| 1324 | spin_unlock_irqrestore(&priv->lock, flags); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1325 | /* call the host command only if no hw rf-kill set */ |
Mohamed Abbas | 5900383 | 2008-04-15 16:01:46 -0700 | [diff] [blame] | 1326 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status) && |
| 1327 | iwl_is_ready(priv)) |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1328 | iwl4965_send_card_state(priv, |
| 1329 | CARD_STATE_CMD_DISABLE, |
| 1330 | 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1331 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1332 | |
| 1333 | /* make sure mac80211 stop sending Tx frame */ |
| 1334 | if (priv->mac80211_registered) |
| 1335 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1336 | } |
| 1337 | return; |
| 1338 | } |
| 1339 | |
| 1340 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1341 | 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] | 1342 | |
| 1343 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 1344 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1345 | |
| 1346 | /* wake up ucode */ |
| 1347 | msleep(10); |
| 1348 | |
| 1349 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1350 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 1351 | if (!iwl_grab_nic_access(priv)) |
| 1352 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1353 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1354 | |
| 1355 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 1356 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 1357 | "disabled by HW switch\n"); |
| 1358 | return; |
| 1359 | } |
| 1360 | |
| 1361 | queue_work(priv->workqueue, &priv->restart); |
| 1362 | return; |
| 1363 | } |
| 1364 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1365 | #define IWL_PACKET_RETRY_TIME HZ |
| 1366 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1367 | 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] | 1368 | { |
| 1369 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 1370 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 1371 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 1372 | u16 *last_seq, *last_frag; |
| 1373 | unsigned long *last_time; |
| 1374 | |
| 1375 | switch (priv->iw_mode) { |
| 1376 | case IEEE80211_IF_TYPE_IBSS:{ |
| 1377 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1378 | struct iwl4965_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1379 | u8 *mac = header->addr2; |
| 1380 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 1381 | |
| 1382 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1383 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1384 | if (!compare_ether_addr(entry->mac, mac)) |
| 1385 | break; |
| 1386 | } |
| 1387 | if (p == &priv->ibss_mac_hash[index]) { |
| 1388 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 1389 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1390 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1391 | return 0; |
| 1392 | } |
| 1393 | memcpy(entry->mac, mac, ETH_ALEN); |
| 1394 | entry->seq_num = seq; |
| 1395 | entry->frag_num = frag; |
| 1396 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1397 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1398 | return 0; |
| 1399 | } |
| 1400 | last_seq = &entry->seq_num; |
| 1401 | last_frag = &entry->frag_num; |
| 1402 | last_time = &entry->packet_time; |
| 1403 | break; |
| 1404 | } |
| 1405 | case IEEE80211_IF_TYPE_STA: |
| 1406 | last_seq = &priv->last_seq_num; |
| 1407 | last_frag = &priv->last_frag_num; |
| 1408 | last_time = &priv->last_packet_time; |
| 1409 | break; |
| 1410 | default: |
| 1411 | return 0; |
| 1412 | } |
| 1413 | if ((*last_seq == seq) && |
| 1414 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 1415 | if (*last_frag == frag) |
| 1416 | goto drop; |
| 1417 | if (*last_frag + 1 != frag) |
| 1418 | /* out-of-order fragment */ |
| 1419 | goto drop; |
| 1420 | } else |
| 1421 | *last_seq = seq; |
| 1422 | |
| 1423 | *last_frag = frag; |
| 1424 | *last_time = jiffies; |
| 1425 | return 0; |
| 1426 | |
| 1427 | drop: |
| 1428 | return 1; |
| 1429 | } |
| 1430 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1431 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1432 | |
| 1433 | #include "iwl-spectrum.h" |
| 1434 | |
| 1435 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 1436 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 1437 | #define TIME_UNIT 1024 |
| 1438 | |
| 1439 | /* |
| 1440 | * extended beacon time format |
| 1441 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 1442 | * the high 1 byte is the beacon counts |
| 1443 | * the lower 3 bytes is the time in usec within one beacon interval |
| 1444 | */ |
| 1445 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1446 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1447 | { |
| 1448 | u32 quot; |
| 1449 | u32 rem; |
| 1450 | u32 interval = beacon_interval * 1024; |
| 1451 | |
| 1452 | if (!interval || !usec) |
| 1453 | return 0; |
| 1454 | |
| 1455 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 1456 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 1457 | |
| 1458 | return (quot << 24) + rem; |
| 1459 | } |
| 1460 | |
| 1461 | /* base is usually what we get from ucode with each received frame, |
| 1462 | * the same as HW timer counter counting down |
| 1463 | */ |
| 1464 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1465 | 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] | 1466 | { |
| 1467 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 1468 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 1469 | u32 interval = beacon_interval * TIME_UNIT; |
| 1470 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 1471 | (addon & BEACON_TIME_MASK_HIGH); |
| 1472 | |
| 1473 | if (base_low > addon_low) |
| 1474 | res += base_low - addon_low; |
| 1475 | else if (base_low < addon_low) { |
| 1476 | res += interval + base_low - addon_low; |
| 1477 | res += (1 << 24); |
| 1478 | } else |
| 1479 | res += (1 << 24); |
| 1480 | |
| 1481 | return cpu_to_le32(res); |
| 1482 | } |
| 1483 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1484 | static int iwl4965_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1485 | struct ieee80211_measurement_params *params, |
| 1486 | u8 type) |
| 1487 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1488 | struct iwl4965_spectrum_cmd spectrum; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1489 | struct iwl_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1490 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1491 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 1492 | .data = (void *)&spectrum, |
| 1493 | .meta.flags = CMD_WANT_SKB, |
| 1494 | }; |
| 1495 | u32 add_time = le64_to_cpu(params->start_time); |
| 1496 | int rc; |
| 1497 | int spectrum_resp_status; |
| 1498 | int duration = le16_to_cpu(params->duration); |
| 1499 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1500 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1501 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1502 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1503 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 1504 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1505 | |
| 1506 | memset(&spectrum, 0, sizeof(spectrum)); |
| 1507 | |
| 1508 | spectrum.channel_count = cpu_to_le16(1); |
| 1509 | spectrum.flags = |
| 1510 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 1511 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 1512 | cmd.len = sizeof(spectrum); |
| 1513 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 1514 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1515 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1516 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1517 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1518 | add_time, |
| 1519 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1520 | else |
| 1521 | spectrum.start_time = 0; |
| 1522 | |
| 1523 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 1524 | spectrum.channels[0].channel = params->channel; |
| 1525 | spectrum.channels[0].type = type; |
| 1526 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 1527 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 1528 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 1529 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1530 | rc = iwl_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1531 | if (rc) |
| 1532 | return rc; |
| 1533 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1534 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1535 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1536 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 1537 | rc = -EIO; |
| 1538 | } |
| 1539 | |
| 1540 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 1541 | switch (spectrum_resp_status) { |
| 1542 | case 0: /* Command will be handled */ |
| 1543 | if (res->u.spectrum.id != 0xff) { |
| 1544 | IWL_DEBUG_INFO |
| 1545 | ("Replaced existing measurement: %d\n", |
| 1546 | res->u.spectrum.id); |
| 1547 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 1548 | } |
| 1549 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 1550 | rc = 0; |
| 1551 | break; |
| 1552 | |
| 1553 | case 1: /* Command will not be handled */ |
| 1554 | rc = -EAGAIN; |
| 1555 | break; |
| 1556 | } |
| 1557 | |
| 1558 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1559 | |
| 1560 | return rc; |
| 1561 | } |
| 1562 | #endif |
| 1563 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1564 | static void iwl4965_txstatus_to_ieee(struct iwl_priv *priv, |
Tomas Winkler | 8567c63 | 2008-05-15 13:53:58 +0800 | [diff] [blame] | 1565 | struct iwl_tx_info *tx_sta) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1566 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1567 | ieee80211_tx_status_irqsafe(priv->hw, tx_sta->skb[0]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1568 | tx_sta->skb[0] = NULL; |
| 1569 | } |
| 1570 | |
| 1571 | /** |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1572 | * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1573 | * |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1574 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 1575 | * need to be reclaimed. As result, some free space forms. If there is |
| 1576 | * enough free space (> low mark), wake the stack that feeds us. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1577 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1578 | 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] | 1579 | { |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 1580 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 1581 | struct iwl_queue *q = &txq->q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1582 | int nfreed = 0; |
| 1583 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 1584 | if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1585 | IWL_ERROR("Read index for DMA queue txq id (%d), index %d, " |
| 1586 | "is out of range [0-%d] %d %d.\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1587 | index, q->n_bd, q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1588 | return 0; |
| 1589 | } |
| 1590 | |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 1591 | for (index = iwl_queue_inc_wrap(index, q->n_bd); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1592 | q->read_ptr != index; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 1593 | 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] | 1594 | if (txq_id != IWL_CMD_QUEUE_NUM) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1595 | iwl4965_txstatus_to_ieee(priv, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1596 | &(txq->txb[txq->q.read_ptr])); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 1597 | iwl_hw_txq_free_tfd(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1598 | } else if (nfreed > 1) { |
| 1599 | IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1600 | q->write_ptr, q->read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1601 | queue_work(priv->workqueue, &priv->restart); |
| 1602 | } |
| 1603 | nfreed++; |
| 1604 | } |
| 1605 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1606 | return nfreed; |
| 1607 | } |
| 1608 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1609 | static int iwl4965_is_tx_success(u32 status) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1610 | { |
| 1611 | status &= TX_STATUS_MSK; |
| 1612 | return (status == TX_STATUS_SUCCESS) |
| 1613 | || (status == TX_STATUS_DIRECT_DONE); |
| 1614 | } |
| 1615 | |
| 1616 | /****************************************************************************** |
| 1617 | * |
| 1618 | * Generic RX handler implementations |
| 1619 | * |
| 1620 | ******************************************************************************/ |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1621 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1622 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1623 | static inline int iwl4965_get_ra_sta_id(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1624 | struct ieee80211_hdr *hdr) |
| 1625 | { |
| 1626 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) |
| 1627 | return IWL_AP_ID; |
| 1628 | else { |
| 1629 | u8 *da = ieee80211_get_DA(hdr); |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 1630 | return iwl_find_station(priv, da); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1631 | } |
| 1632 | } |
| 1633 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1634 | static struct ieee80211_hdr *iwl4965_tx_queue_get_hdr( |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1635 | struct iwl_priv *priv, int txq_id, int idx) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1636 | { |
| 1637 | if (priv->txq[txq_id].txb[idx].skb[0]) |
| 1638 | return (struct ieee80211_hdr *)priv->txq[txq_id]. |
| 1639 | txb[idx].skb[0]->data; |
| 1640 | return NULL; |
| 1641 | } |
| 1642 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1643 | 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] | 1644 | { |
| 1645 | __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + |
| 1646 | tx_resp->frame_count); |
| 1647 | return le32_to_cpu(*scd_ssn) & MAX_SN; |
| 1648 | |
| 1649 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1650 | |
| 1651 | /** |
| 1652 | * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue |
| 1653 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1654 | static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv, |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 1655 | struct iwl_ht_agg *agg, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1656 | struct iwl4965_tx_resp_agg *tx_resp, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1657 | u16 start_idx) |
| 1658 | { |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1659 | u16 status; |
| 1660 | struct agg_tx_status *frame_status = &tx_resp->status; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1661 | struct ieee80211_tx_info *info = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1662 | struct ieee80211_hdr *hdr = NULL; |
| 1663 | int i, sh; |
| 1664 | int txq_id, idx; |
| 1665 | u16 seq; |
| 1666 | |
| 1667 | if (agg->wait_for_ba) |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1668 | IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1669 | |
| 1670 | agg->frame_count = tx_resp->frame_count; |
| 1671 | agg->start_idx = start_idx; |
| 1672 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1673 | agg->bitmap = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1674 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1675 | /* # frames attempted by Tx command */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1676 | if (agg->frame_count == 1) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1677 | /* Only one frame was attempted; no block-ack will arrive */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1678 | status = le16_to_cpu(frame_status[0].status); |
| 1679 | seq = le16_to_cpu(frame_status[0].sequence); |
| 1680 | idx = SEQ_TO_INDEX(seq); |
| 1681 | txq_id = SEQ_TO_QUEUE(seq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1682 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1683 | /* FIXME: code repetition */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1684 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n", |
| 1685 | agg->frame_count, agg->start_idx, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1686 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1687 | info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]); |
| 1688 | info->status.retry_count = tx_resp->failure_frame; |
| 1689 | info->flags &= ~IEEE80211_TX_CTL_AMPDU; |
| 1690 | info->flags |= iwl4965_is_tx_success(status)? |
| 1691 | IEEE80211_TX_STAT_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 1692 | iwl4965_hwrate_to_tx_control(priv, |
| 1693 | le32_to_cpu(tx_resp->rate_n_flags), |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1694 | info); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1695 | /* FIXME: code repetition end */ |
| 1696 | |
| 1697 | IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", |
| 1698 | status & 0xff, tx_resp->failure_frame); |
| 1699 | IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1700 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1701 | |
| 1702 | agg->wait_for_ba = 0; |
| 1703 | } else { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1704 | /* Two or more frames were attempted; expect block-ack */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1705 | u64 bitmap = 0; |
| 1706 | int start = agg->start_idx; |
| 1707 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1708 | /* Construct bit-map of pending frames within Tx window */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1709 | for (i = 0; i < agg->frame_count; i++) { |
| 1710 | u16 sc; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1711 | status = le16_to_cpu(frame_status[i].status); |
| 1712 | seq = le16_to_cpu(frame_status[i].sequence); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1713 | idx = SEQ_TO_INDEX(seq); |
| 1714 | txq_id = SEQ_TO_QUEUE(seq); |
| 1715 | |
| 1716 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 1717 | AGG_TX_STATE_ABORT_MSK)) |
| 1718 | continue; |
| 1719 | |
| 1720 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
| 1721 | agg->frame_count, txq_id, idx); |
| 1722 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1723 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1724 | |
| 1725 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 1726 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
| 1727 | IWL_ERROR("BUG_ON idx doesn't match seq control" |
| 1728 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 1729 | idx, SEQ_TO_SN(sc), |
| 1730 | hdr->seq_ctrl); |
| 1731 | return -1; |
| 1732 | } |
| 1733 | |
| 1734 | IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
| 1735 | i, idx, SEQ_TO_SN(sc)); |
| 1736 | |
| 1737 | sh = idx - start; |
| 1738 | if (sh > 64) { |
| 1739 | sh = (start - idx) + 0xff; |
| 1740 | bitmap = bitmap << sh; |
| 1741 | sh = 0; |
| 1742 | start = idx; |
| 1743 | } else if (sh < -64) |
| 1744 | sh = 0xff - (start - idx); |
| 1745 | else if (sh < 0) { |
| 1746 | sh = start - idx; |
| 1747 | start = idx; |
| 1748 | bitmap = bitmap << sh; |
| 1749 | sh = 0; |
| 1750 | } |
| 1751 | bitmap |= (1 << sh); |
| 1752 | IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n", |
| 1753 | start, (u32)(bitmap & 0xFFFFFFFF)); |
| 1754 | } |
| 1755 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1756 | agg->bitmap = bitmap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1757 | agg->start_idx = start; |
| 1758 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1759 | 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] | 1760 | agg->frame_count, agg->start_idx, |
John W. Linville | 06501d2 | 2008-04-01 17:38:47 -0400 | [diff] [blame] | 1761 | (unsigned long long)agg->bitmap); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1762 | |
| 1763 | if (bitmap) |
| 1764 | agg->wait_for_ba = 1; |
| 1765 | } |
| 1766 | return 0; |
| 1767 | } |
| 1768 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1769 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1770 | /** |
| 1771 | * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response |
| 1772 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1773 | static void iwl4965_rx_reply_tx(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1774 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1775 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1776 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1777 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 1778 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 1779 | int index = SEQ_TO_INDEX(sequence); |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 1780 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1781 | struct ieee80211_tx_info *info; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1782 | struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1783 | u32 status = le32_to_cpu(tx_resp->status); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1784 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1785 | int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 1786 | u16 fc; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1787 | struct ieee80211_hdr *hdr; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 1788 | u8 *qc = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1789 | #endif |
| 1790 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 1791 | 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] | 1792 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 1793 | "is out of range [0-%d] %d %d\n", txq_id, |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1794 | index, txq->q.n_bd, txq->q.write_ptr, |
| 1795 | txq->q.read_ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1796 | return; |
| 1797 | } |
| 1798 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1799 | info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]); |
| 1800 | memset(&info->status, 0, sizeof(info->status)); |
| 1801 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1802 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1803 | hdr = iwl4965_tx_queue_get_hdr(priv, txq_id, index); |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 1804 | fc = le16_to_cpu(hdr->frame_control); |
| 1805 | if (ieee80211_is_qos_data(fc)) { |
| 1806 | qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc)); |
| 1807 | tid = qc[0] & 0xf; |
| 1808 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1809 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1810 | sta_id = iwl4965_get_ra_sta_id(priv, hdr); |
| 1811 | if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) { |
| 1812 | IWL_ERROR("Station not known\n"); |
| 1813 | return; |
| 1814 | } |
| 1815 | |
| 1816 | if (txq->sched_retry) { |
| 1817 | const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp); |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 1818 | struct iwl_ht_agg *agg = NULL; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1819 | |
| 1820 | if (!qc) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1821 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1822 | |
| 1823 | agg = &priv->stations[sta_id].tid[tid].agg; |
| 1824 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1825 | iwl4965_tx_status_reply_tx(priv, agg, |
| 1826 | (struct iwl4965_tx_resp_agg *)tx_resp, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1827 | |
| 1828 | if ((tx_resp->frame_count == 1) && |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1829 | !iwl4965_is_tx_success(status)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1830 | /* TODO: send BAR */ |
| 1831 | } |
| 1832 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1833 | if (txq->q.read_ptr != (scd_ssn & 0xff)) { |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 1834 | int freed, ampdu_q; |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 1835 | index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1836 | IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " |
| 1837 | "%d index %d\n", scd_ssn , index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1838 | freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
| 1839 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 1840 | |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 1841 | if (iwl_queue_space(&txq->q) > txq->q.low_mark && |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1842 | txq_id >= 0 && priv->mac80211_registered && |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 1843 | agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) { |
| 1844 | /* calculate mac80211 ampdu sw queue to wake */ |
| 1845 | ampdu_q = txq_id - IWL_BACK_QUEUE_FIRST_ID + |
| 1846 | priv->hw->queues; |
| 1847 | if (agg->state == IWL_AGG_OFF) |
| 1848 | ieee80211_wake_queue(priv->hw, txq_id); |
| 1849 | else |
| 1850 | ieee80211_wake_queue(priv->hw, ampdu_q); |
| 1851 | } |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1852 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1853 | } |
| 1854 | } else { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1855 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1856 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1857 | info->status.retry_count = tx_resp->failure_frame; |
| 1858 | info->flags |= |
| 1859 | iwl4965_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 1860 | 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] | 1861 | info); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1862 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1863 | 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] | 1864 | "retries %d\n", txq_id, iwl4965_get_tx_fail_reason(status), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1865 | status, le32_to_cpu(tx_resp->rate_n_flags), |
| 1866 | tx_resp->failure_frame); |
| 1867 | |
| 1868 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 1869 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1870 | if (index != -1) { |
| 1871 | int freed = iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1872 | if (tid != MAX_TID_COUNT) |
| 1873 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 1874 | if (iwl_queue_space(&txq->q) > txq->q.low_mark && |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 1875 | (txq_id >= 0) && priv->mac80211_registered) |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1876 | ieee80211_wake_queue(priv->hw, txq_id); |
| 1877 | if (tid != MAX_TID_COUNT) |
| 1878 | iwl4965_check_empty_hw_queue(priv, sta_id, tid, txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1879 | } |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 1880 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1881 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1882 | |
| 1883 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 1884 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 1885 | } |
| 1886 | |
| 1887 | |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1888 | static void iwl_rx_reply_alive(struct iwl_priv *priv, |
| 1889 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1890 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1891 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1892 | struct iwl_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1893 | struct delayed_work *pwork; |
| 1894 | |
| 1895 | palive = &pkt->u.alive_frame; |
| 1896 | |
| 1897 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 1898 | "0x%01X 0x%01X\n", |
| 1899 | palive->is_valid, palive->ver_type, |
| 1900 | palive->ver_subtype); |
| 1901 | |
| 1902 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 1903 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 1904 | memcpy(&priv->card_alive_init, |
| 1905 | &pkt->u.alive_frame, |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1906 | sizeof(struct iwl_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1907 | pwork = &priv->init_alive_start; |
| 1908 | } else { |
| 1909 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 1910 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1911 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1912 | pwork = &priv->alive_start; |
| 1913 | } |
| 1914 | |
| 1915 | /* We delay the ALIVE response by 5ms to |
| 1916 | * give the HW RF Kill time to activate... */ |
| 1917 | if (palive->is_valid == UCODE_VALID_OK) |
| 1918 | queue_delayed_work(priv->workqueue, pwork, |
| 1919 | msecs_to_jiffies(5)); |
| 1920 | else |
| 1921 | IWL_WARNING("uCode did not respond OK.\n"); |
| 1922 | } |
| 1923 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1924 | static void iwl4965_rx_reply_error(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1925 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1926 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1927 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1928 | |
| 1929 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 1930 | "seq 0x%04X ser 0x%08X\n", |
| 1931 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 1932 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 1933 | pkt->u.err_resp.cmd_id, |
| 1934 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 1935 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 1936 | } |
| 1937 | |
| 1938 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 1939 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1940 | 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] | 1941 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1942 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 1943 | struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1944 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1945 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 1946 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 1947 | rxon->channel = csa->channel; |
| 1948 | priv->staging_rxon.channel = csa->channel; |
| 1949 | } |
| 1950 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1951 | static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1952 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1953 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1954 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1955 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1956 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1957 | |
| 1958 | if (!report->state) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1959 | IWL_DEBUG(IWL_DL_11H, |
| 1960 | "Spectrum Measure Notification: Start\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1961 | return; |
| 1962 | } |
| 1963 | |
| 1964 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 1965 | priv->measurement_status |= MEASUREMENT_READY; |
| 1966 | #endif |
| 1967 | } |
| 1968 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1969 | static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1970 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1971 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1972 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1973 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1974 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1975 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 1976 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 1977 | #endif |
| 1978 | } |
| 1979 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1980 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1981 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1982 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1983 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1984 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 1985 | "notification for %s:\n", |
| 1986 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1987 | 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] | 1988 | } |
| 1989 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1990 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1991 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1992 | struct iwl_priv *priv = |
| 1993 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1994 | struct sk_buff *beacon; |
| 1995 | |
| 1996 | /* 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] | 1997 | beacon = ieee80211_beacon_get(priv->hw, priv->vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1998 | |
| 1999 | if (!beacon) { |
| 2000 | IWL_ERROR("update beacon failed\n"); |
| 2001 | return; |
| 2002 | } |
| 2003 | |
| 2004 | mutex_lock(&priv->mutex); |
| 2005 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 2006 | if (priv->ibss_beacon) |
| 2007 | dev_kfree_skb(priv->ibss_beacon); |
| 2008 | |
| 2009 | priv->ibss_beacon = beacon; |
| 2010 | mutex_unlock(&priv->mutex); |
| 2011 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2012 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2015 | static void iwl4965_rx_beacon_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2016 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2017 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2018 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2019 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2020 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 2021 | 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] | 2022 | |
| 2023 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 2024 | "tsf %d %d rate %d\n", |
| 2025 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 2026 | beacon->beacon_notify_hdr.failure_frame, |
| 2027 | le32_to_cpu(beacon->ibss_mgr_status), |
| 2028 | le32_to_cpu(beacon->high_tsf), |
| 2029 | le32_to_cpu(beacon->low_tsf), rate); |
| 2030 | #endif |
| 2031 | |
| 2032 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 2033 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 2034 | queue_work(priv->workqueue, &priv->beacon_update); |
| 2035 | } |
| 2036 | |
| 2037 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2038 | static void iwl4965_rx_reply_scan(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2039 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2040 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2041 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2042 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2043 | struct iwl4965_scanreq_notification *notif = |
| 2044 | (struct iwl4965_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2045 | |
| 2046 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 2047 | #endif |
| 2048 | } |
| 2049 | |
| 2050 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2051 | static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2052 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2053 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2054 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2055 | struct iwl4965_scanstart_notification *notif = |
| 2056 | (struct iwl4965_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2057 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 2058 | IWL_DEBUG_SCAN("Scan start: " |
| 2059 | "%d [802.11%s] " |
| 2060 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 2061 | notif->channel, |
| 2062 | notif->band ? "bg" : "a", |
| 2063 | notif->tsf_high, |
| 2064 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 2065 | } |
| 2066 | |
| 2067 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2068 | static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2069 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2070 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2071 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2072 | struct iwl4965_scanresults_notification *notif = |
| 2073 | (struct iwl4965_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2074 | |
| 2075 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 2076 | "%d [802.11%s] " |
| 2077 | "(TSF: 0x%08X:%08X) - %d " |
| 2078 | "elapsed=%lu usec (%dms since last)\n", |
| 2079 | notif->channel, |
| 2080 | notif->band ? "bg" : "a", |
| 2081 | le32_to_cpu(notif->tsf_high), |
| 2082 | le32_to_cpu(notif->tsf_low), |
| 2083 | le32_to_cpu(notif->statistics[0]), |
| 2084 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 2085 | jiffies_to_msecs(elapsed_jiffies |
| 2086 | (priv->last_scan_jiffies, jiffies))); |
| 2087 | |
| 2088 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2089 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2093 | static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2094 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2095 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2096 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2097 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2098 | |
| 2099 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 2100 | scan_notif->scanned_channels, |
| 2101 | scan_notif->tsf_low, |
| 2102 | scan_notif->tsf_high, scan_notif->status); |
| 2103 | |
| 2104 | /* The HW is no longer scanning */ |
| 2105 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 2106 | |
| 2107 | /* The scan completion notification came in, so kill that timer... */ |
| 2108 | cancel_delayed_work(&priv->scan_check); |
| 2109 | |
| 2110 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 2111 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 2112 | jiffies_to_msecs(elapsed_jiffies |
| 2113 | (priv->scan_pass_start, jiffies))); |
| 2114 | |
| 2115 | /* Remove this scanned band from the list |
| 2116 | * of pending bands to scan */ |
| 2117 | priv->scan_bands--; |
| 2118 | |
| 2119 | /* If a request to abort was given, or the scan did not succeed |
| 2120 | * then we reset the scan state machine and terminate, |
| 2121 | * re-queuing another scan if one has been requested */ |
| 2122 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 2123 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 2124 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 2125 | } else { |
| 2126 | /* If there are more bands on this scan pass reschedule */ |
| 2127 | if (priv->scan_bands > 0) |
| 2128 | goto reschedule; |
| 2129 | } |
| 2130 | |
| 2131 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2132 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2133 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 2134 | |
| 2135 | clear_bit(STATUS_SCANNING, &priv->status); |
| 2136 | |
| 2137 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 2138 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 2139 | |
| 2140 | queue_work(priv->workqueue, &priv->scan_completed); |
| 2141 | |
| 2142 | return; |
| 2143 | |
| 2144 | reschedule: |
| 2145 | priv->scan_pass_start = jiffies; |
| 2146 | queue_work(priv->workqueue, &priv->request_scan); |
| 2147 | } |
| 2148 | |
| 2149 | /* Handle notification from uCode that card's power state is changing |
| 2150 | * due to software, hardware, or critical temperature RFKILL */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2151 | static void iwl4965_rx_card_state_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2152 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2153 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2154 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2155 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 2156 | unsigned long status = priv->status; |
| 2157 | |
| 2158 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 2159 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 2160 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 2161 | |
| 2162 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 2163 | RF_CARD_DISABLED)) { |
| 2164 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2165 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2166 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 2167 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2168 | if (!iwl_grab_nic_access(priv)) { |
| 2169 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2170 | priv, HBUS_TARG_MBX_C, |
| 2171 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 2172 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2173 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | if (!(flags & RXON_CARD_DISABLED)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2177 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2178 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2179 | if (!iwl_grab_nic_access(priv)) { |
| 2180 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2181 | priv, HBUS_TARG_MBX_C, |
| 2182 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 2183 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2184 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2185 | } |
| 2186 | } |
| 2187 | |
| 2188 | if (flags & RF_CARD_DISABLED) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2189 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2190 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2191 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 2192 | if (!iwl_grab_nic_access(priv)) |
| 2193 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2194 | } |
| 2195 | } |
| 2196 | |
| 2197 | if (flags & HW_CARD_DISABLED) |
| 2198 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2199 | else |
| 2200 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2201 | |
| 2202 | |
| 2203 | if (flags & SW_CARD_DISABLED) |
| 2204 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2205 | else |
| 2206 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 2207 | |
| 2208 | if (!(flags & RXON_CARD_DISABLED)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2209 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2210 | |
| 2211 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 2212 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 2213 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 2214 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 2215 | queue_work(priv->workqueue, &priv->rf_kill); |
| 2216 | else |
| 2217 | wake_up_interruptible(&priv->wait_command_queue); |
| 2218 | } |
| 2219 | |
| 2220 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2221 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2222 | * |
| 2223 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 2224 | * to the host. |
| 2225 | * |
| 2226 | * This function chains into the hardware specific files for them to setup |
| 2227 | * any hardware specific handlers as well. |
| 2228 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2229 | static void iwl4965_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2230 | { |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 2231 | priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2232 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 2233 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2234 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2235 | iwl4965_rx_spectrum_measure_notif; |
| 2236 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2237 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2238 | iwl4965_rx_pm_debug_statistics_notif; |
| 2239 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2240 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2241 | /* |
| 2242 | * The same handler is used for both the REPLY to a discrete |
| 2243 | * statistics request from the host as well as for the periodic |
| 2244 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2245 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2246 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
| 2247 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2248 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2249 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
| 2250 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2251 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2252 | iwl4965_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2253 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2254 | iwl4965_rx_scan_complete_notif; |
| 2255 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
| 2256 | priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2257 | |
Tomas Winkler | c135475 | 2008-05-29 16:35:04 +0800 | [diff] [blame] | 2258 | priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] = |
| 2259 | iwl_rx_missed_beacon_notif; |
| 2260 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2261 | /* Set up hardware specific Rx handlers */ |
Emmanuel Grumbach | d4789ef | 2008-04-24 11:55:20 -0700 | [diff] [blame] | 2262 | priv->cfg->ops->lib->rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2266 | * 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] | 2267 | * @rxb: Rx buffer to reclaim |
| 2268 | * |
| 2269 | * If an Rx buffer has an async callback associated with it the callback |
| 2270 | * will be executed. The attached skb (if present) will only be freed |
| 2271 | * if the callback returns 1 |
| 2272 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2273 | static void iwl4965_tx_cmd_complete(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2274 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2275 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2276 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2277 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 2278 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 2279 | int index = SEQ_TO_INDEX(sequence); |
| 2280 | int huge = sequence & SEQ_HUGE_FRAME; |
| 2281 | int cmd_index; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2282 | struct iwl_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2283 | |
| 2284 | /* If a Tx command is being handled and it isn't in the actual |
| 2285 | * command queue then there a command routing bug has been introduced |
| 2286 | * in the queue management code. */ |
| 2287 | if (txq_id != IWL_CMD_QUEUE_NUM) |
| 2288 | IWL_ERROR("Error wrong command queue %d command id 0x%X\n", |
| 2289 | txq_id, pkt->hdr.cmd); |
| 2290 | BUG_ON(txq_id != IWL_CMD_QUEUE_NUM); |
| 2291 | |
| 2292 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 2293 | cmd = &priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
| 2294 | |
| 2295 | /* Input error checking is done when commands are added to queue. */ |
| 2296 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 2297 | cmd->meta.source->u.skb = rxb->skb; |
| 2298 | rxb->skb = NULL; |
| 2299 | } else if (cmd->meta.u.callback && |
| 2300 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 2301 | rxb->skb = NULL; |
| 2302 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2303 | iwl4965_tx_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2304 | |
| 2305 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 2306 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 2307 | wake_up_interruptible(&priv->wait_command_queue); |
| 2308 | } |
| 2309 | } |
| 2310 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2311 | /* |
| 2312 | * this should be called while priv->lock is locked |
| 2313 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2314 | static void __iwl_rx_replenish(struct iwl_priv *priv) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2315 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2316 | iwl_rx_allocate(priv); |
| 2317 | iwl_rx_queue_restock(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2321 | /** |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2322 | * iwl_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2323 | * |
| 2324 | * Uses the priv->rx_handlers callback function array to invoke |
| 2325 | * the appropriate handlers, including command responses, |
| 2326 | * frame-received notifications, and other notifications. |
| 2327 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2328 | void iwl_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2329 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2330 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2331 | struct iwl_rx_packet *pkt; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2332 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2333 | u32 r, i; |
| 2334 | int reclaim; |
| 2335 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2336 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 2337 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2338 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 2339 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 2340 | * buffer that the driver may process (last buffer filled by ucode). */ |
Ron Rindjunsky | d67f548 | 2008-05-05 10:22:49 +0800 | [diff] [blame] | 2341 | r = priv->cfg->ops->lib->shared_mem_rx_idx(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2342 | i = rxq->read; |
| 2343 | |
| 2344 | /* Rx interrupt, but nothing sent from uCode */ |
| 2345 | if (i == r) |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2346 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2347 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2348 | if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2349 | fill_rx = 1; |
| 2350 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2351 | while (i != r) { |
| 2352 | rxb = rxq->queue[i]; |
| 2353 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2354 | /* 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] | 2355 | * then a bug has been introduced in the queue refilling |
| 2356 | * routines -- catch it here */ |
| 2357 | BUG_ON(rxb == NULL); |
| 2358 | |
| 2359 | rxq->queue[i] = NULL; |
| 2360 | |
| 2361 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 2362 | priv->hw_params.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2363 | PCI_DMA_FROMDEVICE); |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2364 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2365 | |
| 2366 | /* Reclaim a command buffer only if this packet is a response |
| 2367 | * to a (driver-originated) command. |
| 2368 | * If the packet (e.g. Rx frame) originated from uCode, |
| 2369 | * there is no command buffer to reclaim. |
| 2370 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 2371 | * but apparently a few don't get set; catch them here. */ |
| 2372 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 2373 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2374 | (pkt->hdr.cmd != REPLY_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 2375 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2376 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 2377 | (pkt->hdr.cmd != REPLY_TX); |
| 2378 | |
| 2379 | /* Based on type of command response or notification, |
| 2380 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2381 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2382 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2383 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r, |
| 2384 | i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2385 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 2386 | } else { |
| 2387 | /* No handling needed */ |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2388 | IWL_DEBUG(IWL_DL_RX, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2389 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 2390 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 2391 | pkt->hdr.cmd); |
| 2392 | } |
| 2393 | |
| 2394 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2395 | /* Invoke any callbacks, transfer the skb to caller, and |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2396 | * fire off the (possibly) blocking iwl_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2397 | * as we reclaim the driver command queue */ |
| 2398 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2399 | iwl4965_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2400 | else |
| 2401 | IWL_WARNING("Claim null rxb?\n"); |
| 2402 | } |
| 2403 | |
| 2404 | /* For now we just don't re-use anything. We can tweak this |
| 2405 | * later to try and re-use notification packets and SKBs that |
| 2406 | * fail to Rx correctly */ |
| 2407 | if (rxb->skb != NULL) { |
| 2408 | priv->alloc_rxb_skb--; |
| 2409 | dev_kfree_skb_any(rxb->skb); |
| 2410 | rxb->skb = NULL; |
| 2411 | } |
| 2412 | |
| 2413 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 2414 | priv->hw_params.rx_buf_size, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 2415 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2416 | spin_lock_irqsave(&rxq->lock, flags); |
| 2417 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 2418 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 2419 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2420 | /* If there are a lot of unused frames, |
| 2421 | * restock the Rx queue so ucode wont assert. */ |
| 2422 | if (fill_rx) { |
| 2423 | count++; |
| 2424 | if (count >= 8) { |
| 2425 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2426 | __iwl_rx_replenish(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2427 | count = 0; |
| 2428 | } |
| 2429 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | /* Backtrack one entry */ |
| 2433 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2434 | iwl_rx_queue_restock(priv); |
| 2435 | } |
| 2436 | /* Convert linear signal-to-noise ratio into dB */ |
| 2437 | static u8 ratio2dB[100] = { |
| 2438 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 2439 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 2440 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 2441 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 2442 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 2443 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 2444 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 2445 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 2446 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 2447 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 2448 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 2449 | }; |
| 2450 | |
| 2451 | /* Calculates a relative dB value from a ratio of linear |
| 2452 | * (i.e. not dB) signal levels. |
| 2453 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
| 2454 | int iwl4965_calc_db_from_ratio(int sig_ratio) |
| 2455 | { |
| 2456 | /* 1000:1 or higher just report as 60 dB */ |
| 2457 | if (sig_ratio >= 1000) |
| 2458 | return 60; |
| 2459 | |
| 2460 | /* 100:1 or higher, divide by 10 and use table, |
| 2461 | * add 20 dB to make up for divide by 10 */ |
| 2462 | if (sig_ratio >= 100) |
| 2463 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 2464 | |
| 2465 | /* We shouldn't see this */ |
| 2466 | if (sig_ratio < 1) |
| 2467 | return 0; |
| 2468 | |
| 2469 | /* Use table for ratios 1:1 - 99:1 */ |
| 2470 | return (int)ratio2dB[sig_ratio]; |
| 2471 | } |
| 2472 | |
| 2473 | #define PERFECT_RSSI (-20) /* dBm */ |
| 2474 | #define WORST_RSSI (-95) /* dBm */ |
| 2475 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 2476 | |
| 2477 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 2478 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 2479 | * about formulas used below. */ |
| 2480 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) |
| 2481 | { |
| 2482 | int sig_qual; |
| 2483 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 2484 | |
| 2485 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 2486 | * as indicator; formula is (signal dbm - noise dbm). |
| 2487 | * SNR at or above 40 is a great signal (100%). |
| 2488 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 2489 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 2490 | if (noise_dbm) { |
| 2491 | if (rssi_dbm - noise_dbm >= 40) |
| 2492 | return 100; |
| 2493 | else if (rssi_dbm < noise_dbm) |
| 2494 | return 0; |
| 2495 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 2496 | |
| 2497 | /* Else use just the signal level. |
| 2498 | * This formula is a least squares fit of data points collected and |
| 2499 | * compared with a reference system that had a percentage (%) display |
| 2500 | * for signal quality. */ |
| 2501 | } else |
| 2502 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 2503 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 2504 | (RSSI_RANGE * RSSI_RANGE); |
| 2505 | |
| 2506 | if (sig_qual > 100) |
| 2507 | sig_qual = 100; |
| 2508 | else if (sig_qual < 1) |
| 2509 | sig_qual = 0; |
| 2510 | |
| 2511 | return sig_qual; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2512 | } |
| 2513 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2514 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2515 | static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2516 | { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 2517 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2518 | DECLARE_MAC_BUF(mac); |
| 2519 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2520 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2521 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2522 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 2523 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 2524 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 2525 | le32_to_cpu(rxon->filter_flags)); |
| 2526 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 2527 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 2528 | rxon->ofdm_basic_rates); |
| 2529 | 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] | 2530 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 2531 | print_mac(mac, rxon->node_addr)); |
| 2532 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 2533 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2534 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 2535 | } |
| 2536 | #endif |
| 2537 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2538 | static void iwl4965_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2539 | { |
| 2540 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 2541 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2542 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2543 | } |
| 2544 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2545 | /* call this function to flush any scheduled tasklet */ |
| 2546 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
| 2547 | { |
| 2548 | /* wait to make sure we flush pedding tasklet*/ |
| 2549 | synchronize_irq(priv->pci_dev->irq); |
| 2550 | tasklet_kill(&priv->irq_tasklet); |
| 2551 | } |
| 2552 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2553 | static inline void iwl4965_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2554 | { |
| 2555 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 2556 | |
| 2557 | /* disable interrupts from uCode/NIC to host */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2558 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2559 | |
| 2560 | /* acknowledge/clear/reset any interrupts still pending |
| 2561 | * from uCode or flow handler (Rx/Tx DMA) */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2562 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 2563 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2564 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 2565 | } |
| 2566 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2567 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2568 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2569 | * 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] | 2570 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2571 | static void iwl4965_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2572 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2573 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2574 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 2575 | |
| 2576 | /* Cancel currently queued command. */ |
| 2577 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 2578 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2579 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2580 | if (priv->debug_level & IWL_DL_FW_ERRORS) { |
Ester Kummer | ede0cba | 2008-05-29 16:34:46 +0800 | [diff] [blame] | 2581 | iwl_dump_nic_error_log(priv); |
Ester Kummer | 189a2b5 | 2008-05-15 13:54:18 +0800 | [diff] [blame] | 2582 | iwl_dump_nic_event_log(priv); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2583 | iwl4965_print_rx_config_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2584 | } |
| 2585 | #endif |
| 2586 | |
| 2587 | wake_up_interruptible(&priv->wait_command_queue); |
| 2588 | |
| 2589 | /* Keep the restart process from trying to send host |
| 2590 | * commands by clearing the INIT status bit */ |
| 2591 | clear_bit(STATUS_READY, &priv->status); |
| 2592 | |
| 2593 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2594 | IWL_DEBUG(IWL_DL_FW_ERRORS, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2595 | "Restarting adapter due to uCode error.\n"); |
| 2596 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2597 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2598 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 2599 | sizeof(priv->recovery_rxon)); |
| 2600 | priv->error_recovering = 1; |
| 2601 | } |
Ester Kummer | 3a1081e | 2008-05-06 11:05:14 +0800 | [diff] [blame] | 2602 | if (priv->cfg->mod_params->restart_fw) |
| 2603 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2604 | } |
| 2605 | } |
| 2606 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2607 | static void iwl4965_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2608 | { |
| 2609 | unsigned long flags; |
| 2610 | |
| 2611 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 2612 | sizeof(priv->staging_rxon)); |
| 2613 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2614 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2615 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 2616 | iwl_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2617 | |
| 2618 | spin_lock_irqsave(&priv->lock, flags); |
| 2619 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 2620 | priv->error_recovering = 0; |
| 2621 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2622 | } |
| 2623 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2624 | static void iwl4965_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2625 | { |
| 2626 | u32 inta, handled = 0; |
| 2627 | u32 inta_fh; |
| 2628 | unsigned long flags; |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2629 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2630 | u32 inta_mask; |
| 2631 | #endif |
| 2632 | |
| 2633 | spin_lock_irqsave(&priv->lock, flags); |
| 2634 | |
| 2635 | /* Ack/clear/reset pending uCode interrupts. |
| 2636 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 2637 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2638 | inta = iwl_read32(priv, CSR_INT); |
| 2639 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2640 | |
| 2641 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 2642 | * Any new interrupts that happen after this, either while we're |
| 2643 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2644 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 2645 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2646 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2647 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2648 | if (priv->debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2649 | /* just for debug */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2650 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2651 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 2652 | inta, inta_mask, inta_fh); |
| 2653 | } |
| 2654 | #endif |
| 2655 | |
| 2656 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 2657 | * atomic, make sure that inta covers all the interrupts that |
| 2658 | * we've discovered, even if FH interrupt came in just after |
| 2659 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 2660 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2661 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 2662 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2663 | inta |= CSR_INT_BIT_FH_TX; |
| 2664 | |
| 2665 | /* Now service all interrupt bits discovered above. */ |
| 2666 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 2667 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 2668 | |
| 2669 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2670 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2671 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2672 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2673 | |
| 2674 | handled |= CSR_INT_BIT_HW_ERR; |
| 2675 | |
| 2676 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2677 | |
| 2678 | return; |
| 2679 | } |
| 2680 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2681 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2682 | if (priv->debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2683 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2684 | if (inta & CSR_INT_BIT_SCD) |
| 2685 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 2686 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2687 | |
| 2688 | /* Alive notification via Rx interrupt will do the real work */ |
| 2689 | if (inta & CSR_INT_BIT_ALIVE) |
| 2690 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 2691 | } |
| 2692 | #endif |
| 2693 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2694 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2695 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2696 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2697 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 2698 | int hw_rf_kill = 0; |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2699 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2700 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 2701 | hw_rf_kill = 1; |
| 2702 | |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2703 | 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] | 2704 | hw_rf_kill ? "disable radio":"enable radio"); |
| 2705 | |
| 2706 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 2707 | * when we loaded driver, and is now set to "enable". |
| 2708 | * After we're Alive, RF_KILL gets handled by |
Reinette Chatre | 3230455 | 2008-02-15 14:34:37 -0800 | [diff] [blame] | 2709 | * iwl4965_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 2710 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 2711 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2712 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 2713 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2714 | |
| 2715 | handled |= CSR_INT_BIT_RF_KILL; |
| 2716 | } |
| 2717 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2718 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2719 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 2720 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 2721 | handled |= CSR_INT_BIT_CT_KILL; |
| 2722 | } |
| 2723 | |
| 2724 | /* Error detected by uCode */ |
| 2725 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 2726 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 2727 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2728 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2729 | handled |= CSR_INT_BIT_SW_ERR; |
| 2730 | } |
| 2731 | |
| 2732 | /* uCode wakes up after power-down sleep */ |
| 2733 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 2734 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2735 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 2736 | iwl_txq_update_write_ptr(priv, &priv->txq[0]); |
| 2737 | iwl_txq_update_write_ptr(priv, &priv->txq[1]); |
| 2738 | iwl_txq_update_write_ptr(priv, &priv->txq[2]); |
| 2739 | iwl_txq_update_write_ptr(priv, &priv->txq[3]); |
| 2740 | iwl_txq_update_write_ptr(priv, &priv->txq[4]); |
| 2741 | iwl_txq_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2742 | |
| 2743 | handled |= CSR_INT_BIT_WAKEUP; |
| 2744 | } |
| 2745 | |
| 2746 | /* All uCode command responses, including Tx command responses, |
| 2747 | * Rx "responses" (frame-received notification), and other |
| 2748 | * notifications from uCode come through here*/ |
| 2749 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2750 | iwl_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2751 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 2752 | } |
| 2753 | |
| 2754 | if (inta & CSR_INT_BIT_FH_TX) { |
| 2755 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 2756 | handled |= CSR_INT_BIT_FH_TX; |
Ron Rindjunsky | dbb983b | 2008-05-15 13:54:12 +0800 | [diff] [blame] | 2757 | /* FH finished to write, send event */ |
| 2758 | priv->ucode_write_complete = 1; |
| 2759 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | if (inta & ~handled) |
| 2763 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 2764 | |
| 2765 | if (inta & ~CSR_INI_SET_MASK) { |
| 2766 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 2767 | inta & ~CSR_INI_SET_MASK); |
| 2768 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 2769 | } |
| 2770 | |
| 2771 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2772 | /* only Re-enable if diabled by irq */ |
| 2773 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 2774 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2775 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2776 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2777 | if (priv->debug_level & (IWL_DL_ISR)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2778 | inta = iwl_read32(priv, CSR_INT); |
| 2779 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 2780 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2781 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 2782 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 2783 | } |
| 2784 | #endif |
| 2785 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2786 | } |
| 2787 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2788 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2789 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2790 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2791 | u32 inta, inta_mask; |
| 2792 | u32 inta_fh; |
| 2793 | if (!priv) |
| 2794 | return IRQ_NONE; |
| 2795 | |
| 2796 | spin_lock(&priv->lock); |
| 2797 | |
| 2798 | /* Disable (but don't clear!) interrupts here to avoid |
| 2799 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 2800 | * If we have something to service, the tasklet will re-enable ints. |
| 2801 | * 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] | 2802 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 2803 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2804 | |
| 2805 | /* Discover which interrupts are active/pending */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2806 | inta = iwl_read32(priv, CSR_INT); |
| 2807 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2808 | |
| 2809 | /* Ignore interrupt if there's nothing in NIC to service. |
| 2810 | * This may be due to IRQ shared with another device, |
| 2811 | * or due to sporadic interrupts thrown from our NIC. */ |
| 2812 | if (!inta && !inta_fh) { |
| 2813 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 2814 | goto none; |
| 2815 | } |
| 2816 | |
| 2817 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 2818 | /* Hardware disappeared. It might have already raised |
| 2819 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2820 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 2821 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2822 | } |
| 2823 | |
| 2824 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 2825 | inta, inta_mask, inta_fh); |
| 2826 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2827 | inta &= ~CSR_INT_BIT_SCD; |
| 2828 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2829 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2830 | if (likely(inta || inta_fh)) |
| 2831 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2832 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 2833 | unplugged: |
| 2834 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2835 | return IRQ_HANDLED; |
| 2836 | |
| 2837 | none: |
| 2838 | /* re-enable interrupts here since we don't have anything to service. */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2839 | /* only Re-enable if diabled by irq */ |
| 2840 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 2841 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2842 | spin_unlock(&priv->lock); |
| 2843 | return IRQ_NONE; |
| 2844 | } |
| 2845 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2846 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 2847 | * sending probe req. This should be set long enough to hear probe responses |
| 2848 | * from more than one AP. */ |
| 2849 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 2850 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 2851 | |
| 2852 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 2853 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 2854 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 2855 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 2856 | * no other traffic). |
| 2857 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 2858 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 2859 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 2860 | |
| 2861 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 2862 | * Must be set longer than active dwell time. |
| 2863 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 2864 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 2865 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 2866 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 2867 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 2868 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2869 | static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2870 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2871 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2872 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2873 | return IWL_ACTIVE_DWELL_TIME_52; |
| 2874 | else |
| 2875 | return IWL_ACTIVE_DWELL_TIME_24; |
| 2876 | } |
| 2877 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2878 | static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2879 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2880 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2881 | u16 active = iwl4965_get_active_dwell_time(priv, band); |
| 2882 | u16 passive = (band != IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2883 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 2884 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 2885 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2886 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2887 | /* If we're associated, we clamp the maximum passive |
| 2888 | * dwell time to be 98% of the beacon interval (minus |
| 2889 | * 2 * channel tune time) */ |
| 2890 | passive = priv->beacon_int; |
| 2891 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 2892 | passive = IWL_PASSIVE_DWELL_BASE; |
| 2893 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 2894 | } |
| 2895 | |
| 2896 | if (passive <= active) |
| 2897 | passive = active + 1; |
| 2898 | |
| 2899 | return passive; |
| 2900 | } |
| 2901 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2902 | static int iwl4965_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2903 | enum ieee80211_band band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2904 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2905 | struct iwl4965_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2906 | { |
| 2907 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2908 | const struct ieee80211_supported_band *sband; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 2909 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2910 | u16 passive_dwell = 0; |
| 2911 | u16 active_dwell = 0; |
| 2912 | int added, i; |
| 2913 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 2914 | sband = iwl_get_hw_mode(priv, band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2915 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2916 | return 0; |
| 2917 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2918 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2919 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2920 | active_dwell = iwl4965_get_active_dwell_time(priv, band); |
| 2921 | passive_dwell = iwl4965_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2922 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2923 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 2924 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 2925 | continue; |
| 2926 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2927 | scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2928 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 2929 | ch_info = iwl_get_channel_info(priv, band, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2930 | scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2931 | if (!is_channel_valid(ch_info)) { |
| 2932 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 2933 | scan_ch->channel); |
| 2934 | continue; |
| 2935 | } |
| 2936 | |
| 2937 | if (!is_active || is_channel_passive(ch_info) || |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2938 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2939 | scan_ch->type = 0; /* passive */ |
| 2940 | else |
| 2941 | scan_ch->type = 1; /* active */ |
| 2942 | |
| 2943 | if (scan_ch->type & 1) |
| 2944 | scan_ch->type |= (direct_mask << 1); |
| 2945 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2946 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 2947 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 2948 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2949 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2950 | scan_ch->tpc.dsp_atten = 110; |
| 2951 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 2952 | |
| 2953 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2954 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2955 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 2956 | else { |
| 2957 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 2958 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2959 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 2960 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2961 | */ |
| 2962 | } |
| 2963 | |
| 2964 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 2965 | scan_ch->channel, |
| 2966 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 2967 | (scan_ch->type & 1) ? |
| 2968 | active_dwell : passive_dwell); |
| 2969 | |
| 2970 | scan_ch++; |
| 2971 | added++; |
| 2972 | } |
| 2973 | |
| 2974 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 2975 | return added; |
| 2976 | } |
| 2977 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2978 | /****************************************************************************** |
| 2979 | * |
| 2980 | * uCode download functions |
| 2981 | * |
| 2982 | ******************************************************************************/ |
| 2983 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2984 | static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2985 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2986 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 2987 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 2988 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 2989 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 2990 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 2991 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2992 | } |
| 2993 | |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 2994 | static void iwl4965_nic_start(struct iwl_priv *priv) |
| 2995 | { |
| 2996 | /* Remove all resets to allow NIC to operate */ |
| 2997 | iwl_write32(priv, CSR_RESET, 0); |
| 2998 | } |
| 2999 | |
| 3000 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3001 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3002 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3003 | * |
| 3004 | * Copy into buffers for card to fetch via bus-mastering |
| 3005 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3006 | static int iwl4965_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3007 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3008 | struct iwl4965_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3009 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3010 | const struct firmware *ucode_raw; |
Tomas Winkler | 4bf775c | 2008-03-04 18:09:31 -0800 | [diff] [blame] | 3011 | const char *name = priv->cfg->fw_name; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3012 | u8 *src; |
| 3013 | size_t len; |
| 3014 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 3015 | |
| 3016 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 3017 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3018 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 3019 | if (ret < 0) { |
| 3020 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 3021 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3022 | goto error; |
| 3023 | } |
| 3024 | |
| 3025 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 3026 | name, ucode_raw->size); |
| 3027 | |
| 3028 | /* Make sure that we got at least our header! */ |
| 3029 | if (ucode_raw->size < sizeof(*ucode)) { |
| 3030 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3031 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3032 | goto err_release; |
| 3033 | } |
| 3034 | |
| 3035 | /* Data from ucode file: header followed by uCode images */ |
| 3036 | ucode = (void *)ucode_raw->data; |
| 3037 | |
| 3038 | ver = le32_to_cpu(ucode->ver); |
| 3039 | inst_size = le32_to_cpu(ucode->inst_size); |
| 3040 | data_size = le32_to_cpu(ucode->data_size); |
| 3041 | init_size = le32_to_cpu(ucode->init_size); |
| 3042 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 3043 | boot_size = le32_to_cpu(ucode->boot_size); |
| 3044 | |
| 3045 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 3046 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 3047 | inst_size); |
| 3048 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 3049 | data_size); |
| 3050 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 3051 | init_size); |
| 3052 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 3053 | init_data_size); |
| 3054 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 3055 | boot_size); |
| 3056 | |
| 3057 | /* Verify size of file vs. image size info in file's header */ |
| 3058 | if (ucode_raw->size < sizeof(*ucode) + |
| 3059 | inst_size + data_size + init_size + |
| 3060 | init_data_size + boot_size) { |
| 3061 | |
| 3062 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 3063 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3064 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3065 | goto err_release; |
| 3066 | } |
| 3067 | |
| 3068 | /* Verify that uCode images will fit in card's SRAM */ |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 3069 | if (inst_size > priv->hw_params.max_inst_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3070 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 3071 | inst_size); |
| 3072 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3073 | goto err_release; |
| 3074 | } |
| 3075 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 3076 | if (data_size > priv->hw_params.max_data_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3077 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 3078 | data_size); |
| 3079 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3080 | goto err_release; |
| 3081 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 3082 | if (init_size > priv->hw_params.max_inst_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3083 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3084 | ("uCode init instr len %d too large to fit in\n", |
| 3085 | init_size); |
| 3086 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3087 | goto err_release; |
| 3088 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 3089 | if (init_data_size > priv->hw_params.max_data_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3090 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3091 | ("uCode init data len %d too large to fit in\n", |
| 3092 | init_data_size); |
| 3093 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3094 | goto err_release; |
| 3095 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 3096 | if (boot_size > priv->hw_params.max_bsm_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3097 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3098 | ("uCode boot instr len %d too large to fit in\n", |
| 3099 | boot_size); |
| 3100 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3101 | goto err_release; |
| 3102 | } |
| 3103 | |
| 3104 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 3105 | |
| 3106 | /* Runtime instructions and 2 copies of data: |
| 3107 | * 1) unmodified from disk |
| 3108 | * 2) backup cache for save/restore during power-downs */ |
| 3109 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3110 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3111 | |
| 3112 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3113 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3114 | |
| 3115 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3116 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3117 | |
| 3118 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3119 | if (init_size && init_data_size) { |
| 3120 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3121 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3122 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3123 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3124 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3125 | |
| 3126 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 3127 | goto err_pci_alloc; |
| 3128 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3129 | |
| 3130 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3131 | if (boot_size) { |
| 3132 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 3133 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3134 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3135 | if (!priv->ucode_boot.v_addr) |
| 3136 | goto err_pci_alloc; |
| 3137 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3138 | |
| 3139 | /* Copy images into buffers for card's bus-master reads ... */ |
| 3140 | |
| 3141 | /* Runtime instructions (first block of data in file) */ |
| 3142 | src = &ucode->data[0]; |
| 3143 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3144 | 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] | 3145 | memcpy(priv->ucode_code.v_addr, src, len); |
| 3146 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 3147 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 3148 | |
| 3149 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3150 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3151 | src = &ucode->data[inst_size]; |
| 3152 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3153 | 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] | 3154 | memcpy(priv->ucode_data.v_addr, src, len); |
| 3155 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 3156 | |
| 3157 | /* Initialization instructions (3rd block) */ |
| 3158 | if (init_size) { |
| 3159 | src = &ucode->data[inst_size + data_size]; |
| 3160 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3161 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 3162 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3163 | memcpy(priv->ucode_init.v_addr, src, len); |
| 3164 | } |
| 3165 | |
| 3166 | /* Initialization data (4th block) */ |
| 3167 | if (init_data_size) { |
| 3168 | src = &ucode->data[inst_size + data_size + init_size]; |
| 3169 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3170 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 3171 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3172 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 3173 | } |
| 3174 | |
| 3175 | /* Bootstrap instructions (5th block) */ |
| 3176 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 3177 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3178 | 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] | 3179 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 3180 | |
| 3181 | /* We have our copies now, allow OS release its copies */ |
| 3182 | release_firmware(ucode_raw); |
| 3183 | return 0; |
| 3184 | |
| 3185 | err_pci_alloc: |
| 3186 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3187 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3188 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3189 | |
| 3190 | err_release: |
| 3191 | release_firmware(ucode_raw); |
| 3192 | |
| 3193 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 3194 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3195 | } |
| 3196 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3197 | /** |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3198 | * iwl_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3199 | * from protocol/runtime uCode (initialization uCode's |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3200 | * Alive gets handled by iwl_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3201 | */ |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3202 | static void iwl_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3203 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3204 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3205 | |
| 3206 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 3207 | |
| 3208 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 3209 | /* We had an error bringing up the hardware, so take it |
| 3210 | * all the way back down so we can try again */ |
| 3211 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 3212 | goto restart; |
| 3213 | } |
| 3214 | |
| 3215 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 3216 | * This is a paranoid check, because we would not have gotten the |
| 3217 | * "runtime" alive if code weren't properly loaded. */ |
Emmanuel Grumbach | b0692f2 | 2008-04-24 11:55:18 -0700 | [diff] [blame] | 3218 | if (iwl_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3219 | /* Runtime instruction load was bad; |
| 3220 | * take it all the way back down so we can try again */ |
| 3221 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 3222 | goto restart; |
| 3223 | } |
| 3224 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3225 | iwlcore_clear_stations_table(priv); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3226 | ret = priv->cfg->ops->lib->alive_notify(priv); |
| 3227 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3228 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3229 | ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3230 | goto restart; |
| 3231 | } |
| 3232 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3233 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3234 | set_bit(STATUS_ALIVE, &priv->status); |
| 3235 | |
| 3236 | /* Clear out the uCode error bit if it is set */ |
| 3237 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 3238 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3239 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3240 | return; |
| 3241 | |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 3242 | ieee80211_wake_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3243 | |
| 3244 | priv->active_rate = priv->rates_mask; |
| 3245 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 3246 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3247 | if (iwl_is_associated(priv)) { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 3248 | struct iwl_rxon_cmd *active_rxon = |
| 3249 | (struct iwl_rxon_cmd *)&priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3250 | |
| 3251 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 3252 | sizeof(priv->staging_rxon)); |
| 3253 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 3254 | } else { |
| 3255 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3256 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3257 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 3258 | } |
| 3259 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3260 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3261 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3262 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3263 | iwl_reset_run_time_calib(priv); |
| 3264 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3265 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3266 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3267 | |
| 3268 | /* At this point, the NIC is initialized and operational */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3269 | iwl4965_rf_kill_ct_config(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3270 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 3271 | iwl_leds_register(priv); |
| 3272 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3273 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 3274 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3275 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3276 | |
| 3277 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3278 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3279 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 3280 | iwlcore_low_level_notify(priv, IWLCORE_START_EVT); |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 3281 | ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3282 | return; |
| 3283 | |
| 3284 | restart: |
| 3285 | queue_work(priv->workqueue, &priv->restart); |
| 3286 | } |
| 3287 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3288 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3289 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3290 | static void __iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3291 | { |
| 3292 | unsigned long flags; |
| 3293 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3294 | |
| 3295 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 3296 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3297 | if (!exit_pending) |
| 3298 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 3299 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 3300 | iwl_leds_unregister(priv); |
| 3301 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 3302 | iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT); |
| 3303 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3304 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3305 | |
| 3306 | /* Unblock any waiting calls */ |
| 3307 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 3308 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3309 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 3310 | * exiting the module */ |
| 3311 | if (!exit_pending) |
| 3312 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 3313 | |
| 3314 | /* stop and reset the on-board processor */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3315 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3316 | |
| 3317 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3318 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3319 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3320 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3321 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3322 | |
| 3323 | if (priv->mac80211_registered) |
| 3324 | ieee80211_stop_queues(priv->hw); |
| 3325 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3326 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3327 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3328 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3329 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 3330 | STATUS_RF_KILL_HW | |
| 3331 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 3332 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 3333 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 3334 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3335 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 3336 | STATUS_IN_SUSPEND; |
| 3337 | goto exit; |
| 3338 | } |
| 3339 | |
| 3340 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 3341 | * SUSPEND bits and continue taking the NIC down. */ |
| 3342 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 3343 | STATUS_RF_KILL_HW | |
| 3344 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 3345 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 3346 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 3347 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3348 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 3349 | STATUS_IN_SUSPEND | |
| 3350 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 3351 | STATUS_FW_ERROR; |
| 3352 | |
| 3353 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3354 | iwl_clear_bit(priv, CSR_GP_CNTRL, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 3355 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3356 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3357 | |
Tomas Winkler | da1bc45 | 2008-05-29 16:35:00 +0800 | [diff] [blame] | 3358 | iwl_txq_ctx_stop(priv); |
Tomas Winkler | b3bbacb | 2008-05-29 16:35:01 +0800 | [diff] [blame] | 3359 | iwl_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3360 | |
| 3361 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3362 | if (!iwl_grab_nic_access(priv)) { |
| 3363 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3364 | APMG_CLK_VAL_DMA_CLK_RQT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3365 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3366 | } |
| 3367 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3368 | |
| 3369 | udelay(5); |
| 3370 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 3371 | /* FIXME: apm_ops.suspend(priv) */ |
| 3372 | priv->cfg->ops->lib->apm_ops.reset(priv); |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 3373 | priv->cfg->ops->lib->free_shared_mem(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3374 | |
| 3375 | exit: |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 3376 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3377 | |
| 3378 | if (priv->ibss_beacon) |
| 3379 | dev_kfree_skb(priv->ibss_beacon); |
| 3380 | priv->ibss_beacon = NULL; |
| 3381 | |
| 3382 | /* clear out any free frames */ |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 3383 | iwl_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3384 | } |
| 3385 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3386 | static void iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3387 | { |
| 3388 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3389 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3390 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 3391 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3392 | iwl4965_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3393 | } |
| 3394 | |
| 3395 | #define MAX_HW_RESTARTS 5 |
| 3396 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3397 | static int __iwl4965_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3398 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3399 | int i; |
| 3400 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3401 | |
| 3402 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 3403 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 3404 | return -EIO; |
| 3405 | } |
| 3406 | |
| 3407 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 3408 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 3409 | "parameter)\n"); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3410 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3411 | return -ENODEV; |
| 3412 | } |
| 3413 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 3414 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 3415 | IWL_ERROR("ucode not available for device bringup\n"); |
| 3416 | return -EIO; |
| 3417 | } |
| 3418 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3419 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3420 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3421 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 3422 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3423 | else { |
| 3424 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3425 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3426 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3427 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 3428 | return -ENODEV; |
| 3429 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3430 | } |
| 3431 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3432 | iwl_rfkill_set_hw_state(priv); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3433 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3434 | |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 3435 | ret = priv->cfg->ops->lib->alloc_shared_mem(priv); |
| 3436 | if (ret) { |
| 3437 | IWL_ERROR("Unable to allocate shared memory\n"); |
| 3438 | return ret; |
| 3439 | } |
| 3440 | |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 3441 | ret = iwl_hw_nic_init(priv); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3442 | if (ret) { |
| 3443 | IWL_ERROR("Unable to init nic\n"); |
| 3444 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3445 | } |
| 3446 | |
| 3447 | /* make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3448 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 3449 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3450 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 3451 | |
| 3452 | /* clear (again), then enable host interrupts */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3453 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3454 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3455 | |
| 3456 | /* really make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3457 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 3458 | 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] | 3459 | |
| 3460 | /* Copy original ucode data image from disk into backup cache. |
| 3461 | * This will be used to initialize the on-board processor's |
| 3462 | * data SRAM for a clean start when the runtime program first loads. */ |
| 3463 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3464 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3465 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3466 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 3467 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3468 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3469 | |
| 3470 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 3471 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3472 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3473 | |
| 3474 | /* load bootstrap state machine, |
| 3475 | * load bootstrap program into processor's memory, |
| 3476 | * prepare to load the "initialize" uCode */ |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3477 | ret = priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3478 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3479 | if (ret) { |
| 3480 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3481 | continue; |
| 3482 | } |
| 3483 | |
| 3484 | /* start card; "initialize" will load runtime ucode */ |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 3485 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3486 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3487 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 3488 | |
| 3489 | return 0; |
| 3490 | } |
| 3491 | |
| 3492 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3493 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3494 | |
| 3495 | /* tried to restart and config the device for as long as our |
| 3496 | * patience could withstand */ |
| 3497 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 3498 | return -EIO; |
| 3499 | } |
| 3500 | |
| 3501 | |
| 3502 | /***************************************************************************** |
| 3503 | * |
| 3504 | * Workqueue callbacks |
| 3505 | * |
| 3506 | *****************************************************************************/ |
| 3507 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3508 | static void iwl_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3509 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3510 | struct iwl_priv *priv = |
| 3511 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3512 | |
| 3513 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3514 | return; |
| 3515 | |
| 3516 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | f3ccc08 | 2008-05-05 10:22:45 +0800 | [diff] [blame] | 3517 | priv->cfg->ops->lib->init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3518 | mutex_unlock(&priv->mutex); |
| 3519 | } |
| 3520 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3521 | static void iwl_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3522 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3523 | struct iwl_priv *priv = |
| 3524 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3525 | |
| 3526 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3527 | return; |
| 3528 | |
| 3529 | mutex_lock(&priv->mutex); |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3530 | iwl_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3531 | mutex_unlock(&priv->mutex); |
| 3532 | } |
| 3533 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3534 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3535 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3536 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3537 | |
| 3538 | wake_up_interruptible(&priv->wait_command_queue); |
| 3539 | |
| 3540 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3541 | return; |
| 3542 | |
| 3543 | mutex_lock(&priv->mutex); |
| 3544 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3545 | if (!iwl_is_rfkill(priv)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3546 | IWL_DEBUG(IWL_DL_RF_KILL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3547 | "HW and/or SW RF Kill no longer active, restarting " |
| 3548 | "device\n"); |
| 3549 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3550 | queue_work(priv->workqueue, &priv->restart); |
| 3551 | } else { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3552 | /* make sure mac80211 stop sending Tx frame */ |
| 3553 | if (priv->mac80211_registered) |
| 3554 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3555 | |
| 3556 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 3557 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 3558 | "disabled by SW switch\n"); |
| 3559 | else |
| 3560 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 3561 | "Kill switch must be turned off for " |
| 3562 | "wireless networking to work.\n"); |
| 3563 | } |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3564 | iwl_rfkill_set_hw_state(priv); |
| 3565 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3566 | mutex_unlock(&priv->mutex); |
| 3567 | } |
| 3568 | |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 3569 | static void iwl4965_bg_set_monitor(struct work_struct *work) |
| 3570 | { |
| 3571 | struct iwl_priv *priv = container_of(work, |
| 3572 | struct iwl_priv, set_monitor); |
| 3573 | |
| 3574 | IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n"); |
| 3575 | |
| 3576 | mutex_lock(&priv->mutex); |
| 3577 | |
| 3578 | if (!iwl_is_ready(priv)) |
| 3579 | IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n"); |
| 3580 | else |
| 3581 | if (iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR) != 0) |
| 3582 | IWL_ERROR("iwl4965_set_mode() failed\n"); |
| 3583 | |
| 3584 | mutex_unlock(&priv->mutex); |
| 3585 | } |
| 3586 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3587 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 3588 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3589 | static void iwl4965_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3590 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3591 | struct iwl_priv *priv = |
| 3592 | container_of(data, struct iwl_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3593 | |
| 3594 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3595 | return; |
| 3596 | |
| 3597 | mutex_lock(&priv->mutex); |
| 3598 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 3599 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3600 | IWL_DEBUG(IWL_DL_SCAN, "Scan completion watchdog resetting " |
| 3601 | "adapter (%dms)\n", |
| 3602 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3603 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3604 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3605 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3606 | } |
| 3607 | mutex_unlock(&priv->mutex); |
| 3608 | } |
| 3609 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3610 | static void iwl4965_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3611 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3612 | struct iwl_priv *priv = |
| 3613 | container_of(data, struct iwl_priv, request_scan); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3614 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3615 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3616 | .len = sizeof(struct iwl4965_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3617 | .meta.flags = CMD_SIZE_HUGE, |
| 3618 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3619 | struct iwl4965_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3620 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3621 | u16 cmd_len; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3622 | enum ieee80211_band band; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3623 | u8 direct_mask; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3624 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3625 | |
| 3626 | conf = ieee80211_get_hw_conf(priv->hw); |
| 3627 | |
| 3628 | mutex_lock(&priv->mutex); |
| 3629 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3630 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3631 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 3632 | goto done; |
| 3633 | } |
| 3634 | |
| 3635 | /* Make sure the scan wasn't cancelled before this queued work |
| 3636 | * was given the chance to run... */ |
| 3637 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 3638 | goto done; |
| 3639 | |
| 3640 | /* This should never be called or scheduled if there is currently |
| 3641 | * a scan active in the hardware. */ |
| 3642 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 3643 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 3644 | "Ignoring second request.\n"); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3645 | ret = -EIO; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3646 | goto done; |
| 3647 | } |
| 3648 | |
| 3649 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 3650 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 3651 | goto done; |
| 3652 | } |
| 3653 | |
| 3654 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 3655 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 3656 | goto done; |
| 3657 | } |
| 3658 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3659 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3660 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 3661 | goto done; |
| 3662 | } |
| 3663 | |
| 3664 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 3665 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 3666 | goto done; |
| 3667 | } |
| 3668 | |
| 3669 | if (!priv->scan_bands) { |
| 3670 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 3671 | goto done; |
| 3672 | } |
| 3673 | |
| 3674 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3675 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3676 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 3677 | if (!priv->scan) { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3678 | ret = -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3679 | goto done; |
| 3680 | } |
| 3681 | } |
| 3682 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3683 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3684 | |
| 3685 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 3686 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 3687 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3688 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3689 | u16 interval = 0; |
| 3690 | u32 extra; |
| 3691 | u32 suspend_time = 100; |
| 3692 | u32 scan_suspend_time = 100; |
| 3693 | unsigned long flags; |
| 3694 | |
| 3695 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 3696 | |
| 3697 | spin_lock_irqsave(&priv->lock, flags); |
| 3698 | interval = priv->beacon_int; |
| 3699 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3700 | |
| 3701 | scan->suspend_time = 0; |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3702 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3703 | if (!interval) |
| 3704 | interval = suspend_time; |
| 3705 | |
| 3706 | extra = (suspend_time / interval) << 22; |
| 3707 | scan_suspend_time = (extra | |
| 3708 | ((suspend_time % interval) * 1024)); |
| 3709 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 3710 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 3711 | scan_suspend_time, interval); |
| 3712 | } |
| 3713 | |
| 3714 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 3715 | if (priv->one_direct_scan) { |
| 3716 | IWL_DEBUG_SCAN |
| 3717 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3718 | iwl4965_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3719 | priv->direct_ssid_len)); |
| 3720 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 3721 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 3722 | memcpy(scan->direct_scan[0].ssid, |
| 3723 | priv->direct_ssid, priv->direct_ssid_len); |
| 3724 | direct_mask = 1; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3725 | } else if (!iwl_is_associated(priv) && priv->essid_len) { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3726 | IWL_DEBUG_SCAN |
| 3727 | ("Kicking off one direct scan for '%s' when not associated\n", |
| 3728 | iwl4965_escape_essid(priv->essid, priv->essid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3729 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 3730 | scan->direct_scan[0].len = priv->essid_len; |
| 3731 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 3732 | direct_mask = 1; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3733 | } else { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3734 | IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3735 | direct_mask = 0; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3736 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3737 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3738 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3739 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3740 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 3741 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3742 | |
| 3743 | switch (priv->scan_bands) { |
| 3744 | case 2: |
| 3745 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 3746 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3747 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3748 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 3749 | |
| 3750 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3751 | band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3752 | break; |
| 3753 | |
| 3754 | case 1: |
| 3755 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3756 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3757 | RATE_MCS_ANT_B_MSK); |
| 3758 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3759 | band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3760 | break; |
| 3761 | |
| 3762 | default: |
| 3763 | IWL_WARNING("Invalid scan band count\n"); |
| 3764 | goto done; |
| 3765 | } |
| 3766 | |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3767 | /* We don't build a direct scan probe request; the uCode will do |
| 3768 | * that based on the direct_mask added to each channel entry */ |
| 3769 | cmd_len = iwl4965_fill_probe_req(priv, band, |
| 3770 | (struct ieee80211_mgmt *)scan->data, |
| 3771 | IWL_MAX_SCAN_SIZE - sizeof(*scan), 0); |
| 3772 | |
| 3773 | scan->tx_cmd.len = cpu_to_le16(cmd_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3774 | /* select Rx chains */ |
| 3775 | |
| 3776 | /* Force use of chains B and C (0x6) for scan Rx. |
| 3777 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 3778 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 3779 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 3780 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 3781 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 3782 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 3783 | |
| 3784 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 3785 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 3786 | |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3787 | if (direct_mask) |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 3788 | scan->channel_count = |
| 3789 | iwl4965_get_channels_for_scan( |
| 3790 | priv, band, 1, /* active */ |
| 3791 | direct_mask, |
| 3792 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3793 | else |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 3794 | scan->channel_count = |
| 3795 | iwl4965_get_channels_for_scan( |
| 3796 | priv, band, 0, /* passive */ |
| 3797 | direct_mask, |
| 3798 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3799 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 3800 | scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | |
| 3801 | RXON_FILTER_BCON_AWARE_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3802 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3803 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3804 | cmd.data = scan; |
| 3805 | scan->len = cpu_to_le16(cmd.len); |
| 3806 | |
| 3807 | set_bit(STATUS_SCAN_HW, &priv->status); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3808 | ret = iwl_send_cmd_sync(priv, &cmd); |
| 3809 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3810 | goto done; |
| 3811 | |
| 3812 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 3813 | IWL_SCAN_CHECK_WATCHDOG); |
| 3814 | |
| 3815 | mutex_unlock(&priv->mutex); |
| 3816 | return; |
| 3817 | |
| 3818 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3819 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3820 | queue_work(priv->workqueue, &priv->scan_completed); |
| 3821 | mutex_unlock(&priv->mutex); |
| 3822 | } |
| 3823 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3824 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3825 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3826 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3827 | |
| 3828 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3829 | return; |
| 3830 | |
| 3831 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3832 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3833 | mutex_unlock(&priv->mutex); |
| 3834 | } |
| 3835 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3836 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3837 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3838 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3839 | |
| 3840 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3841 | return; |
| 3842 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3843 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3844 | queue_work(priv->workqueue, &priv->up); |
| 3845 | } |
| 3846 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3847 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3848 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3849 | struct iwl_priv *priv = |
| 3850 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3851 | |
| 3852 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3853 | return; |
| 3854 | |
| 3855 | mutex_lock(&priv->mutex); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3856 | iwl_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3857 | mutex_unlock(&priv->mutex); |
| 3858 | } |
| 3859 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3860 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 3861 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3862 | static void iwl4965_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3863 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3864 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3865 | int ret = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3866 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3867 | |
| 3868 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 3869 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 3870 | return; |
| 3871 | } |
| 3872 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3873 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 3874 | priv->assoc_id, |
| 3875 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3876 | |
| 3877 | |
| 3878 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3879 | return; |
| 3880 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3881 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3882 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 3883 | return; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3884 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3885 | iwl4965_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3886 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3887 | conf = ieee80211_get_hw_conf(priv->hw); |
| 3888 | |
| 3889 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3890 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3891 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3892 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 3893 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3894 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3895 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3896 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3897 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 3898 | "Attempting to continue.\n"); |
| 3899 | |
| 3900 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 3901 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3902 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 3903 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 3904 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3905 | #endif /* CONFIG_IWL4965_HT*/ |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 3906 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3907 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 3908 | |
| 3909 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 3910 | priv->assoc_id, priv->beacon_int); |
| 3911 | |
| 3912 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 3913 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3914 | else |
| 3915 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3916 | |
| 3917 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 3918 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 3919 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 3920 | else |
| 3921 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 3922 | |
| 3923 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 3924 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 3925 | |
| 3926 | } |
| 3927 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3928 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3929 | |
| 3930 | switch (priv->iw_mode) { |
| 3931 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3932 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3933 | break; |
| 3934 | |
| 3935 | case IEEE80211_IF_TYPE_IBSS: |
| 3936 | |
| 3937 | /* clear out the station table */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3938 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3939 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 3940 | iwl_rxon_add_station(priv, iwl_bcast_addr, 0); |
| 3941 | iwl_rxon_add_station(priv, priv->bssid, 0); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3942 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
| 3943 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3944 | |
| 3945 | break; |
| 3946 | |
| 3947 | default: |
| 3948 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 3949 | __FUNCTION__, priv->iw_mode); |
| 3950 | break; |
| 3951 | } |
| 3952 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3953 | iwl4965_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3954 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3955 | /* Enable Rx differential gain and sensitivity calibrations */ |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 3956 | iwl_chain_noise_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3957 | priv->start_calib = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3958 | |
| 3959 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 3960 | priv->assoc_station_added = 1; |
| 3961 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3962 | iwl4965_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 3963 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 3964 | iwl_power_update_mode(priv, 0); |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3965 | /* we have just associated, don't start scan too early */ |
| 3966 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3967 | } |
| 3968 | |
| 3969 | |
| 3970 | static void iwl4965_bg_post_associate(struct work_struct *data) |
| 3971 | { |
| 3972 | struct iwl_priv *priv = container_of(data, struct iwl_priv, |
| 3973 | post_associate.work); |
| 3974 | |
| 3975 | mutex_lock(&priv->mutex); |
| 3976 | iwl4965_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3977 | mutex_unlock(&priv->mutex); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3978 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3979 | } |
| 3980 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3981 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3982 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3983 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3984 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3985 | if (!iwl_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3986 | return; |
| 3987 | |
| 3988 | mutex_lock(&priv->mutex); |
| 3989 | |
| 3990 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3991 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3992 | |
| 3993 | mutex_unlock(&priv->mutex); |
| 3994 | } |
| 3995 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3996 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 3997 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3998 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3999 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4000 | struct iwl_priv *priv = |
| 4001 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4002 | |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 4003 | IWL_DEBUG(IWL_DL_SCAN, "SCAN complete scan\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4004 | |
| 4005 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 4006 | return; |
| 4007 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 4008 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
| 4009 | iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4010 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4011 | ieee80211_scan_completed(priv->hw); |
| 4012 | |
| 4013 | /* Since setting the TXPOWER may have been deferred while |
| 4014 | * performing the scan, fire one off */ |
| 4015 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4016 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4017 | mutex_unlock(&priv->mutex); |
| 4018 | } |
| 4019 | |
| 4020 | /***************************************************************************** |
| 4021 | * |
| 4022 | * mac80211 entry point functions |
| 4023 | * |
| 4024 | *****************************************************************************/ |
| 4025 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4026 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 4027 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4028 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4029 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4030 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4031 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4032 | |
| 4033 | IWL_DEBUG_MAC80211("enter\n"); |
| 4034 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4035 | if (pci_enable_device(priv->pci_dev)) { |
| 4036 | IWL_ERROR("Fail to pci_enable_device\n"); |
| 4037 | return -ENODEV; |
| 4038 | } |
| 4039 | pci_restore_state(priv->pci_dev); |
| 4040 | pci_enable_msi(priv->pci_dev); |
| 4041 | |
| 4042 | ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, |
| 4043 | DRV_NAME, priv); |
| 4044 | if (ret) { |
| 4045 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 4046 | goto out_disable_msi; |
| 4047 | } |
| 4048 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4049 | /* we should be verifying the device is ready to be opened */ |
| 4050 | mutex_lock(&priv->mutex); |
| 4051 | |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 4052 | memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd)); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4053 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 4054 | * ucode filename and max sizes are card-specific. */ |
| 4055 | |
| 4056 | if (!priv->ucode_code.len) { |
| 4057 | ret = iwl4965_read_ucode(priv); |
| 4058 | if (ret) { |
| 4059 | IWL_ERROR("Could not read microcode: %d\n", ret); |
| 4060 | mutex_unlock(&priv->mutex); |
| 4061 | goto out_release_irq; |
| 4062 | } |
| 4063 | } |
| 4064 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4065 | ret = __iwl4965_up(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4066 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4067 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4068 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4069 | if (ret) |
| 4070 | goto out_release_irq; |
| 4071 | |
| 4072 | IWL_DEBUG_INFO("Start UP work done.\n"); |
| 4073 | |
| 4074 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 4075 | return 0; |
| 4076 | |
Ron Rindjunsky | fe9b6b7 | 2008-05-29 16:35:06 +0800 | [diff] [blame^] | 4077 | /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4078 | * mac80211 will not be run successfully. */ |
Ron Rindjunsky | fe9b6b7 | 2008-05-29 16:35:06 +0800 | [diff] [blame^] | 4079 | if (priv->ucode_type == UCODE_RT) { |
| 4080 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 4081 | test_bit(STATUS_READY, &priv->status), |
| 4082 | UCODE_READY_TIMEOUT); |
| 4083 | if (!ret) { |
| 4084 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 4085 | IWL_ERROR("START_ALIVE timeout after %dms.\n", |
| 4086 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 4087 | ret = -ETIMEDOUT; |
| 4088 | goto out_release_irq; |
| 4089 | } |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4090 | } |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4091 | |
Ron Rindjunsky | fe9b6b7 | 2008-05-29 16:35:06 +0800 | [diff] [blame^] | 4092 | priv->is_open = 1; |
| 4093 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4094 | IWL_DEBUG_MAC80211("leave\n"); |
| 4095 | return 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4096 | |
| 4097 | out_release_irq: |
| 4098 | free_irq(priv->pci_dev->irq, priv); |
| 4099 | out_disable_msi: |
| 4100 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4101 | pci_disable_device(priv->pci_dev); |
| 4102 | priv->is_open = 0; |
| 4103 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4104 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4105 | } |
| 4106 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4107 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4108 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4109 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4110 | |
| 4111 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4112 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4113 | if (!priv->is_open) { |
| 4114 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 4115 | return; |
| 4116 | } |
| 4117 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4118 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4119 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4120 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4121 | /* stop mac, cancel any scan request and clear |
| 4122 | * RXON_FILTER_ASSOC_MSK BIT |
| 4123 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4124 | mutex_lock(&priv->mutex); |
| 4125 | iwl4965_scan_cancel_timeout(priv, 100); |
| 4126 | cancel_delayed_work(&priv->post_associate); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4127 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4128 | } |
| 4129 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4130 | iwl4965_down(priv); |
| 4131 | |
| 4132 | flush_workqueue(priv->workqueue); |
| 4133 | free_irq(priv->pci_dev->irq, priv); |
| 4134 | pci_disable_msi(priv->pci_dev); |
| 4135 | pci_save_state(priv->pci_dev); |
| 4136 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4137 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4138 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4139 | } |
| 4140 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 4141 | 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] | 4142 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4143 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4144 | |
| 4145 | IWL_DEBUG_MAC80211("enter\n"); |
| 4146 | |
| 4147 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 4148 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 4149 | return -1; |
| 4150 | } |
| 4151 | |
| 4152 | 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] | 4153 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4154 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 4155 | if (iwl_tx_skb(priv, skb)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4156 | dev_kfree_skb_any(skb); |
| 4157 | |
| 4158 | IWL_DEBUG_MAC80211("leave\n"); |
| 4159 | return 0; |
| 4160 | } |
| 4161 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4162 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4163 | struct ieee80211_if_init_conf *conf) |
| 4164 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4165 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4166 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4167 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4168 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 4169 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4170 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 4171 | if (priv->vif) { |
| 4172 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Reinette Chatre | 75849d2 | 2008-01-23 10:15:17 -0800 | [diff] [blame] | 4173 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 4177 | priv->vif = conf->vif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4178 | |
| 4179 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4180 | |
| 4181 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 4182 | |
| 4183 | if (conf->mac_addr) { |
| 4184 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 4185 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 4186 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4187 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4188 | if (iwl_is_ready(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4189 | iwl4965_set_mode(priv, conf->type); |
| 4190 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4191 | mutex_unlock(&priv->mutex); |
| 4192 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4193 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4194 | return 0; |
| 4195 | } |
| 4196 | |
| 4197 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4198 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4199 | * |
| 4200 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 4201 | * be set inappropriately and the driver currently sets the hardware up to |
| 4202 | * use it whenever needed. |
| 4203 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4204 | 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] | 4205 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4206 | struct iwl_priv *priv = hw->priv; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4207 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4208 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4209 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4210 | |
| 4211 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4212 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4213 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 4214 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
| 4215 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4216 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4217 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4218 | ret = -EIO; |
| 4219 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4220 | } |
| 4221 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 4222 | if (unlikely(!priv->cfg->mod_params->disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4223 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 4224 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 4225 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4226 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 4227 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4228 | } |
| 4229 | |
| 4230 | spin_lock_irqsave(&priv->lock, flags); |
| 4231 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 4232 | ch_info = iwl_get_channel_info(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4233 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4234 | if (!is_channel_valid(ch_info)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4235 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 4236 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4237 | ret = -EINVAL; |
| 4238 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4239 | } |
| 4240 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4241 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 4242 | /* if we are switching from ht to 2.4 clear flags |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4243 | * from any ht related info since 2.4 does not |
| 4244 | * support ht */ |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 4245 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4246 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 4247 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 4248 | #endif |
| 4249 | ) |
| 4250 | priv->staging_rxon.flags = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4251 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4252 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4253 | iwl_set_rxon_channel(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4254 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4255 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4256 | iwl4965_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4257 | |
| 4258 | /* The list of supported rates and rate mask can be different |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4259 | * for each band; since the band may have changed, reset |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4260 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4261 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4262 | |
| 4263 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4264 | |
| 4265 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 4266 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4267 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4268 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4269 | } |
| 4270 | #endif |
| 4271 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4272 | if (priv->cfg->ops->lib->radio_kill_sw) |
| 4273 | priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4274 | |
| 4275 | if (!conf->radio_enabled) { |
| 4276 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4277 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4278 | } |
| 4279 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4280 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4281 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4282 | ret = -EIO; |
| 4283 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4284 | } |
| 4285 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4286 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4287 | |
| 4288 | if (memcmp(&priv->active_rxon, |
| 4289 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4290 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4291 | else |
| 4292 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 4293 | |
| 4294 | IWL_DEBUG_MAC80211("leave\n"); |
| 4295 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 4296 | out: |
| 4297 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4298 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 4299 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4300 | } |
| 4301 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4302 | static void iwl4965_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4303 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4304 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4305 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 4306 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4307 | return; |
| 4308 | |
| 4309 | /* The following should be done only at AP bring up */ |
| 4310 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 4311 | |
| 4312 | /* RXON - unassoc (to set timing command) */ |
| 4313 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4314 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4315 | |
| 4316 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4317 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 4318 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4319 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4320 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4321 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4322 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 4323 | "Attempting to continue.\n"); |
| 4324 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4325 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4326 | |
| 4327 | /* FIXME: what should be the assoc_id for AP? */ |
| 4328 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 4329 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 4330 | priv->staging_rxon.flags |= |
| 4331 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4332 | else |
| 4333 | priv->staging_rxon.flags &= |
| 4334 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4335 | |
| 4336 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 4337 | if (priv->assoc_capability & |
| 4338 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 4339 | priv->staging_rxon.flags |= |
| 4340 | RXON_FLG_SHORT_SLOT_MSK; |
| 4341 | else |
| 4342 | priv->staging_rxon.flags &= |
| 4343 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 4344 | |
| 4345 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 4346 | priv->staging_rxon.flags &= |
| 4347 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 4348 | } |
| 4349 | /* restore RXON assoc */ |
| 4350 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4351 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4352 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 4353 | iwl_rxon_add_station(priv, iwl_bcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 4354 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4355 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4356 | |
| 4357 | /* FIXME - we need to add code here to detect a totally new |
| 4358 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 4359 | * clear sta table, add BCAST sta... */ |
| 4360 | } |
| 4361 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 4362 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, |
| 4363 | struct ieee80211_vif *vif, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4364 | struct ieee80211_if_conf *conf) |
| 4365 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4366 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4367 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4368 | unsigned long flags; |
| 4369 | int rc; |
| 4370 | |
| 4371 | if (conf == NULL) |
| 4372 | return -EIO; |
| 4373 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 4374 | if (priv->vif != vif) { |
| 4375 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 4376 | return 0; |
| 4377 | } |
| 4378 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4379 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 4380 | (!conf->beacon || !conf->ssid_len)) { |
| 4381 | IWL_DEBUG_MAC80211 |
| 4382 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 4383 | return 0; |
| 4384 | } |
| 4385 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4386 | if (!iwl_is_alive(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4387 | return -EAGAIN; |
| 4388 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4389 | mutex_lock(&priv->mutex); |
| 4390 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4391 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4392 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 4393 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4394 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4395 | /* |
| 4396 | * very dubious code was here; the probe filtering flag is never set: |
| 4397 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4398 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 4399 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4400 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4401 | |
| 4402 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 4403 | if (!conf->bssid) { |
| 4404 | conf->bssid = priv->mac_addr; |
| 4405 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4406 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 4407 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4408 | } |
| 4409 | if (priv->ibss_beacon) |
| 4410 | dev_kfree_skb(priv->ibss_beacon); |
| 4411 | |
| 4412 | priv->ibss_beacon = conf->beacon; |
| 4413 | } |
| 4414 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4415 | if (iwl_is_rfkill(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4416 | goto done; |
| 4417 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4418 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 4419 | !is_multicast_ether_addr(conf->bssid)) { |
| 4420 | /* If there is currently a HW scan going on in the background |
| 4421 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4422 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4423 | IWL_WARNING("Aborted scan still in progress " |
| 4424 | "after 100ms\n"); |
| 4425 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 4426 | mutex_unlock(&priv->mutex); |
| 4427 | return -EAGAIN; |
| 4428 | } |
| 4429 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 4430 | |
| 4431 | /* TODO: Audit driver for usage of these members and see |
| 4432 | * if mac80211 deprecates them (priv->bssid looks like it |
| 4433 | * shouldn't be there, but I haven't scanned the IBSS code |
| 4434 | * to verify) - jpk */ |
| 4435 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 4436 | |
| 4437 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4438 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4439 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4440 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4441 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 4442 | iwl_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4443 | priv, priv->active_rxon.bssid_addr, 1); |
| 4444 | } |
| 4445 | |
| 4446 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4447 | iwl4965_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4448 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4449 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4450 | } |
| 4451 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4452 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4453 | spin_lock_irqsave(&priv->lock, flags); |
| 4454 | if (!conf->ssid_len) |
| 4455 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 4456 | else |
| 4457 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 4458 | |
| 4459 | priv->essid_len = conf->ssid_len; |
| 4460 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4461 | |
| 4462 | IWL_DEBUG_MAC80211("leave\n"); |
| 4463 | mutex_unlock(&priv->mutex); |
| 4464 | |
| 4465 | return 0; |
| 4466 | } |
| 4467 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4468 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4469 | unsigned int changed_flags, |
| 4470 | unsigned int *total_flags, |
| 4471 | int mc_count, struct dev_addr_list *mc_list) |
| 4472 | { |
| 4473 | /* |
| 4474 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4475 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4476 | */ |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 4477 | struct iwl_priv *priv = hw->priv; |
| 4478 | int new_flags = 0; |
| 4479 | if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { |
| 4480 | if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { |
| 4481 | IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n", |
| 4482 | IEEE80211_IF_TYPE_MNTR, |
| 4483 | changed_flags, *total_flags); |
| 4484 | /* queue work 'cuz mac80211 is holding a lock which |
| 4485 | * prevents us from issuing (synchronous) f/w cmds */ |
| 4486 | queue_work(priv->workqueue, &priv->set_monitor); |
| 4487 | new_flags &= FIF_PROMISC_IN_BSS | |
| 4488 | FIF_OTHER_BSS | |
| 4489 | FIF_ALLMULTI; |
| 4490 | } |
| 4491 | } |
| 4492 | *total_flags = new_flags; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4493 | } |
| 4494 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4495 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4496 | struct ieee80211_if_init_conf *conf) |
| 4497 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4498 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4499 | |
| 4500 | IWL_DEBUG_MAC80211("enter\n"); |
| 4501 | |
| 4502 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4503 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4504 | if (iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4505 | iwl4965_scan_cancel_timeout(priv, 100); |
| 4506 | cancel_delayed_work(&priv->post_associate); |
| 4507 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 4508 | iwl4965_commit_rxon(priv); |
| 4509 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 4510 | if (priv->vif == conf->vif) { |
| 4511 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4512 | memset(priv->bssid, 0, ETH_ALEN); |
| 4513 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 4514 | priv->essid_len = 0; |
| 4515 | } |
| 4516 | mutex_unlock(&priv->mutex); |
| 4517 | |
| 4518 | IWL_DEBUG_MAC80211("leave\n"); |
| 4519 | |
| 4520 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4521 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4522 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4523 | static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, |
| 4524 | struct ieee80211_vif *vif, |
| 4525 | struct ieee80211_bss_conf *bss_conf, |
| 4526 | u32 changes) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4527 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4528 | struct iwl_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4529 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4530 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
| 4531 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4532 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4533 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
| 4534 | bss_conf->use_short_preamble); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4535 | if (bss_conf->use_short_preamble) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4536 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4537 | else |
| 4538 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4539 | } |
| 4540 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4541 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4542 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4543 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4544 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 4545 | else |
| 4546 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 4547 | } |
| 4548 | |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 4549 | if (changes & BSS_CHANGED_HT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4550 | IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 4551 | iwl4965_ht_conf(priv, bss_conf); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4552 | iwl_set_rxon_chain(priv); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 4553 | } |
| 4554 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4555 | if (changes & BSS_CHANGED_ASSOC) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4556 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4557 | /* This should never happen as this function should |
| 4558 | * never be called from interrupt context. */ |
| 4559 | if (WARN_ON_ONCE(in_interrupt())) |
| 4560 | return; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4561 | if (bss_conf->assoc) { |
| 4562 | priv->assoc_id = bss_conf->aid; |
| 4563 | priv->beacon_int = bss_conf->beacon_int; |
| 4564 | priv->timestamp = bss_conf->timestamp; |
| 4565 | priv->assoc_capability = bss_conf->assoc_capability; |
| 4566 | priv->next_scan_jiffies = jiffies + |
| 4567 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4568 | mutex_lock(&priv->mutex); |
| 4569 | iwl4965_post_associate(priv); |
| 4570 | mutex_unlock(&priv->mutex); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4571 | } else { |
| 4572 | priv->assoc_id = 0; |
| 4573 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); |
| 4574 | } |
| 4575 | } else if (changes && iwl_is_associated(priv) && priv->assoc_id) { |
| 4576 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 4577 | iwl_send_rxon_assoc(priv); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4578 | } |
| 4579 | |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4580 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4581 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4582 | 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] | 4583 | { |
| 4584 | int rc = 0; |
| 4585 | unsigned long flags; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4586 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4587 | |
| 4588 | IWL_DEBUG_MAC80211("enter\n"); |
| 4589 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4590 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4591 | spin_lock_irqsave(&priv->lock, flags); |
| 4592 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4593 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4594 | rc = -EIO; |
| 4595 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 4596 | goto out_unlock; |
| 4597 | } |
| 4598 | |
| 4599 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 4600 | rc = -EIO; |
| 4601 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 4602 | goto out_unlock; |
| 4603 | } |
| 4604 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4605 | /* we don't schedule scan within next_scan_jiffies period */ |
| 4606 | if (priv->next_scan_jiffies && |
| 4607 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 4608 | rc = -EAGAIN; |
| 4609 | goto out_unlock; |
| 4610 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4611 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4612 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 4613 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4614 | rc = -EAGAIN; |
| 4615 | goto out_unlock; |
| 4616 | } |
| 4617 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4618 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4619 | iwl4965_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4620 | |
| 4621 | priv->one_direct_scan = 1; |
| 4622 | priv->direct_ssid_len = (u8) |
| 4623 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 4624 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4625 | } else |
| 4626 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4627 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4628 | rc = iwl4965_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4629 | |
| 4630 | IWL_DEBUG_MAC80211("leave\n"); |
| 4631 | |
| 4632 | out_unlock: |
| 4633 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4634 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4635 | |
| 4636 | return rc; |
| 4637 | } |
| 4638 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4639 | static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 4640 | struct ieee80211_key_conf *keyconf, const u8 *addr, |
| 4641 | u32 iv32, u16 *phase1key) |
| 4642 | { |
| 4643 | struct iwl_priv *priv = hw->priv; |
| 4644 | u8 sta_id = IWL_INVALID_STATION; |
| 4645 | unsigned long flags; |
| 4646 | __le16 key_flags = 0; |
| 4647 | int i; |
| 4648 | DECLARE_MAC_BUF(mac); |
| 4649 | |
| 4650 | IWL_DEBUG_MAC80211("enter\n"); |
| 4651 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 4652 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4653 | if (sta_id == IWL_INVALID_STATION) { |
| 4654 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 4655 | print_mac(mac, addr)); |
| 4656 | return; |
| 4657 | } |
| 4658 | |
| 4659 | iwl4965_scan_cancel_timeout(priv, 100); |
| 4660 | |
| 4661 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); |
| 4662 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 4663 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 4664 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 4665 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4666 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 4667 | |
| 4668 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 4669 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4670 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 4671 | priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; |
| 4672 | |
| 4673 | for (i = 0; i < 5; i++) |
| 4674 | priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = |
| 4675 | cpu_to_le16(phase1key[i]); |
| 4676 | |
| 4677 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 4678 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 4679 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 4680 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4681 | |
| 4682 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 4683 | |
| 4684 | IWL_DEBUG_MAC80211("leave\n"); |
| 4685 | } |
| 4686 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4687 | 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] | 4688 | const u8 *local_addr, const u8 *addr, |
| 4689 | struct ieee80211_key_conf *key) |
| 4690 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4691 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4692 | DECLARE_MAC_BUF(mac); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4693 | int ret = 0; |
| 4694 | u8 sta_id = IWL_INVALID_STATION; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4695 | u8 is_default_wep_key = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4696 | |
| 4697 | IWL_DEBUG_MAC80211("enter\n"); |
| 4698 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4699 | if (priv->hw_params.sw_crypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4700 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 4701 | return -EOPNOTSUPP; |
| 4702 | } |
| 4703 | |
| 4704 | if (is_zero_ether_addr(addr)) |
| 4705 | /* only support pairwise keys */ |
| 4706 | return -EOPNOTSUPP; |
| 4707 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 4708 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4709 | if (sta_id == IWL_INVALID_STATION) { |
| 4710 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 4711 | print_mac(mac, addr)); |
| 4712 | return -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4713 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4714 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4715 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4716 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4717 | iwl4965_scan_cancel_timeout(priv, 100); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4718 | mutex_unlock(&priv->mutex); |
| 4719 | |
| 4720 | /* If we are getting WEP group key and we didn't receive any key mapping |
| 4721 | * so far, we are in legacy wep mode (group key only), otherwise we are |
| 4722 | * in 1X mode. |
| 4723 | * In legacy wep mode, we use another host command to the uCode */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 4724 | 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] | 4725 | priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 4726 | if (cmd == SET_KEY) |
| 4727 | is_default_wep_key = !priv->key_mapping_key; |
| 4728 | else |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 4729 | is_default_wep_key = |
| 4730 | (key->hw_key_idx == HW_KEY_DEFAULT); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4731 | } |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4732 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4733 | switch (cmd) { |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4734 | case SET_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4735 | if (is_default_wep_key) |
| 4736 | ret = iwl_set_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4737 | else |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 4738 | ret = iwl_set_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4739 | |
| 4740 | IWL_DEBUG_MAC80211("enable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4741 | break; |
| 4742 | case DISABLE_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4743 | if (is_default_wep_key) |
| 4744 | ret = iwl_remove_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4745 | else |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 4746 | ret = iwl_remove_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4747 | |
| 4748 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4749 | break; |
| 4750 | default: |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4751 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4752 | } |
| 4753 | |
| 4754 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4755 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4756 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4757 | } |
| 4758 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 4759 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4760 | const struct ieee80211_tx_queue_params *params) |
| 4761 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4762 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4763 | unsigned long flags; |
| 4764 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4765 | |
| 4766 | IWL_DEBUG_MAC80211("enter\n"); |
| 4767 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4768 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4769 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 4770 | return -EIO; |
| 4771 | } |
| 4772 | |
| 4773 | if (queue >= AC_NUM) { |
| 4774 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 4775 | return 0; |
| 4776 | } |
| 4777 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4778 | if (!priv->qos_data.qos_enable) { |
| 4779 | priv->qos_data.qos_active = 0; |
| 4780 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 4781 | return 0; |
| 4782 | } |
| 4783 | q = AC_NUM - 1 - queue; |
| 4784 | |
| 4785 | spin_lock_irqsave(&priv->lock, flags); |
| 4786 | |
| 4787 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 4788 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 4789 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 4790 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 4791 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4792 | |
| 4793 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 4794 | priv->qos_data.qos_active = 1; |
| 4795 | |
| 4796 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4797 | |
| 4798 | mutex_lock(&priv->mutex); |
| 4799 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4800 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4801 | else if (priv->assoc_id && iwl_is_associated(priv)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4802 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4803 | |
| 4804 | mutex_unlock(&priv->mutex); |
| 4805 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4806 | IWL_DEBUG_MAC80211("leave\n"); |
| 4807 | return 0; |
| 4808 | } |
| 4809 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4810 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4811 | struct ieee80211_tx_queue_stats *stats) |
| 4812 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4813 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4814 | int i, avail; |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 4815 | struct iwl_tx_queue *txq; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 4816 | struct iwl_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4817 | unsigned long flags; |
| 4818 | |
| 4819 | IWL_DEBUG_MAC80211("enter\n"); |
| 4820 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4821 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4822 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 4823 | return -EIO; |
| 4824 | } |
| 4825 | |
| 4826 | spin_lock_irqsave(&priv->lock, flags); |
| 4827 | |
| 4828 | for (i = 0; i < AC_NUM; i++) { |
| 4829 | txq = &priv->txq[i]; |
| 4830 | q = &txq->q; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 4831 | avail = iwl_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4832 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 4833 | stats[i].len = q->n_window - avail; |
| 4834 | stats[i].limit = q->n_window - q->high_mark; |
| 4835 | stats[i].count = q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4836 | |
| 4837 | } |
| 4838 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4839 | |
| 4840 | IWL_DEBUG_MAC80211("leave\n"); |
| 4841 | |
| 4842 | return 0; |
| 4843 | } |
| 4844 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4845 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4846 | struct ieee80211_low_level_stats *stats) |
| 4847 | { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 4848 | struct iwl_priv *priv = hw->priv; |
| 4849 | |
| 4850 | priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4851 | IWL_DEBUG_MAC80211("enter\n"); |
| 4852 | IWL_DEBUG_MAC80211("leave\n"); |
| 4853 | |
| 4854 | return 0; |
| 4855 | } |
| 4856 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4857 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4858 | { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 4859 | struct iwl_priv *priv; |
| 4860 | |
| 4861 | priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4862 | IWL_DEBUG_MAC80211("enter\n"); |
| 4863 | IWL_DEBUG_MAC80211("leave\n"); |
| 4864 | |
| 4865 | return 0; |
| 4866 | } |
| 4867 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4868 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4869 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4870 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4871 | unsigned long flags; |
| 4872 | |
| 4873 | mutex_lock(&priv->mutex); |
| 4874 | IWL_DEBUG_MAC80211("enter\n"); |
| 4875 | |
| 4876 | priv->lq_mngr.lq_ready = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4877 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4878 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 4879 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4880 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4881 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4882 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4883 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4884 | |
| 4885 | cancel_delayed_work(&priv->post_associate); |
| 4886 | |
| 4887 | spin_lock_irqsave(&priv->lock, flags); |
| 4888 | priv->assoc_id = 0; |
| 4889 | priv->assoc_capability = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4890 | priv->assoc_station_added = 0; |
| 4891 | |
| 4892 | /* new association get rid of ibss beacon skb */ |
| 4893 | if (priv->ibss_beacon) |
| 4894 | dev_kfree_skb(priv->ibss_beacon); |
| 4895 | |
| 4896 | priv->ibss_beacon = NULL; |
| 4897 | |
| 4898 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4899 | priv->timestamp = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4900 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 4901 | priv->beacon_int = 0; |
| 4902 | |
| 4903 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4904 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4905 | if (!iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4906 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 4907 | mutex_unlock(&priv->mutex); |
| 4908 | return; |
| 4909 | } |
| 4910 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4911 | /* we are restarting association process |
| 4912 | * clear RXON_FILTER_ASSOC_MSK bit |
| 4913 | */ |
| 4914 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4915 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4916 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4917 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4918 | } |
| 4919 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4920 | iwl_power_update_mode(priv, 0); |
| 4921 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4922 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 4923 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4924 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4925 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 4926 | mutex_unlock(&priv->mutex); |
| 4927 | return; |
| 4928 | } |
| 4929 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4930 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4931 | |
| 4932 | mutex_unlock(&priv->mutex); |
| 4933 | |
| 4934 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4935 | } |
| 4936 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 4937 | 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] | 4938 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4939 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4940 | unsigned long flags; |
| 4941 | |
| 4942 | mutex_lock(&priv->mutex); |
| 4943 | IWL_DEBUG_MAC80211("enter\n"); |
| 4944 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4945 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4946 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 4947 | mutex_unlock(&priv->mutex); |
| 4948 | return -EIO; |
| 4949 | } |
| 4950 | |
| 4951 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 4952 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 4953 | mutex_unlock(&priv->mutex); |
| 4954 | return -EIO; |
| 4955 | } |
| 4956 | |
| 4957 | spin_lock_irqsave(&priv->lock, flags); |
| 4958 | |
| 4959 | if (priv->ibss_beacon) |
| 4960 | dev_kfree_skb(priv->ibss_beacon); |
| 4961 | |
| 4962 | priv->ibss_beacon = skb; |
| 4963 | |
| 4964 | priv->assoc_id = 0; |
| 4965 | |
| 4966 | IWL_DEBUG_MAC80211("leave\n"); |
| 4967 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4968 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4969 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4970 | |
| 4971 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 4972 | |
| 4973 | mutex_unlock(&priv->mutex); |
| 4974 | |
| 4975 | return 0; |
| 4976 | } |
| 4977 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4978 | /***************************************************************************** |
| 4979 | * |
| 4980 | * sysfs attributes |
| 4981 | * |
| 4982 | *****************************************************************************/ |
| 4983 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4984 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4985 | |
| 4986 | /* |
| 4987 | * The following adds a new attribute to the sysfs representation |
| 4988 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 4989 | * used for controlling the debug level. |
| 4990 | * |
| 4991 | * See the level definitions in iwl for details. |
| 4992 | */ |
| 4993 | |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4994 | static ssize_t show_debug_level(struct device *d, |
| 4995 | struct device_attribute *attr, char *buf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4996 | { |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4997 | struct iwl_priv *priv = d->driver_data; |
| 4998 | |
| 4999 | return sprintf(buf, "0x%08X\n", priv->debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5000 | } |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5001 | static ssize_t store_debug_level(struct device *d, |
| 5002 | struct device_attribute *attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5003 | const char *buf, size_t count) |
| 5004 | { |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5005 | struct iwl_priv *priv = d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5006 | char *p = (char *)buf; |
| 5007 | u32 val; |
| 5008 | |
| 5009 | val = simple_strtoul(p, &p, 0); |
| 5010 | if (p == buf) |
| 5011 | printk(KERN_INFO DRV_NAME |
| 5012 | ": %s is not in hex or decimal form.\n", buf); |
| 5013 | else |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5014 | priv->debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5015 | |
| 5016 | return strnlen(buf, count); |
| 5017 | } |
| 5018 | |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5019 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 5020 | show_debug_level, store_debug_level); |
| 5021 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5022 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 5023 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5024 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5025 | |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 5026 | static ssize_t show_version(struct device *d, |
| 5027 | struct device_attribute *attr, char *buf) |
| 5028 | { |
| 5029 | struct iwl_priv *priv = d->driver_data; |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 5030 | struct iwl_alive_resp *palive = &priv->card_alive; |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 5031 | |
| 5032 | if (palive->is_valid) |
| 5033 | return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n" |
| 5034 | "fw type: 0x%01X 0x%01X\n", |
| 5035 | palive->ucode_major, palive->ucode_minor, |
| 5036 | palive->sw_rev[0], palive->sw_rev[1], |
| 5037 | palive->ver_type, palive->ver_subtype); |
| 5038 | |
| 5039 | else |
| 5040 | return sprintf(buf, "fw not loaded\n"); |
| 5041 | } |
| 5042 | |
| 5043 | static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL); |
| 5044 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5045 | static ssize_t show_temperature(struct device *d, |
| 5046 | struct device_attribute *attr, char *buf) |
| 5047 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5048 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5049 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5050 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5051 | return -EAGAIN; |
| 5052 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5053 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5054 | } |
| 5055 | |
| 5056 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 5057 | |
| 5058 | static ssize_t show_rs_window(struct device *d, |
| 5059 | struct device_attribute *attr, |
| 5060 | char *buf) |
| 5061 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5062 | struct iwl_priv *priv = d->driver_data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5063 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5064 | } |
| 5065 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 5066 | |
| 5067 | static ssize_t show_tx_power(struct device *d, |
| 5068 | struct device_attribute *attr, char *buf) |
| 5069 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5070 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5071 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 5072 | } |
| 5073 | |
| 5074 | static ssize_t store_tx_power(struct device *d, |
| 5075 | struct device_attribute *attr, |
| 5076 | const char *buf, size_t count) |
| 5077 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5078 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5079 | char *p = (char *)buf; |
| 5080 | u32 val; |
| 5081 | |
| 5082 | val = simple_strtoul(p, &p, 10); |
| 5083 | if (p == buf) |
| 5084 | printk(KERN_INFO DRV_NAME |
| 5085 | ": %s is not in decimal form.\n", buf); |
| 5086 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5087 | iwl4965_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5088 | |
| 5089 | return count; |
| 5090 | } |
| 5091 | |
| 5092 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 5093 | |
| 5094 | static ssize_t show_flags(struct device *d, |
| 5095 | struct device_attribute *attr, char *buf) |
| 5096 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5097 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5098 | |
| 5099 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 5100 | } |
| 5101 | |
| 5102 | static ssize_t store_flags(struct device *d, |
| 5103 | struct device_attribute *attr, |
| 5104 | const char *buf, size_t count) |
| 5105 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5106 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5107 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 5108 | |
| 5109 | mutex_lock(&priv->mutex); |
| 5110 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 5111 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5112 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5113 | IWL_WARNING("Could not cancel scan.\n"); |
| 5114 | else { |
| 5115 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 5116 | flags); |
| 5117 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5118 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5119 | } |
| 5120 | } |
| 5121 | mutex_unlock(&priv->mutex); |
| 5122 | |
| 5123 | return count; |
| 5124 | } |
| 5125 | |
| 5126 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 5127 | |
| 5128 | static ssize_t show_filter_flags(struct device *d, |
| 5129 | struct device_attribute *attr, char *buf) |
| 5130 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5131 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5132 | |
| 5133 | return sprintf(buf, "0x%04X\n", |
| 5134 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 5135 | } |
| 5136 | |
| 5137 | static ssize_t store_filter_flags(struct device *d, |
| 5138 | struct device_attribute *attr, |
| 5139 | const char *buf, size_t count) |
| 5140 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5141 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5142 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 5143 | |
| 5144 | mutex_lock(&priv->mutex); |
| 5145 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 5146 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5147 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5148 | IWL_WARNING("Could not cancel scan.\n"); |
| 5149 | else { |
| 5150 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 5151 | "0x%04X\n", filter_flags); |
| 5152 | priv->staging_rxon.filter_flags = |
| 5153 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5154 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5155 | } |
| 5156 | } |
| 5157 | mutex_unlock(&priv->mutex); |
| 5158 | |
| 5159 | return count; |
| 5160 | } |
| 5161 | |
| 5162 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 5163 | store_filter_flags); |
| 5164 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5165 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5166 | |
| 5167 | static ssize_t show_measurement(struct device *d, |
| 5168 | struct device_attribute *attr, char *buf) |
| 5169 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5170 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5171 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5172 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 5173 | u8 *data = (u8 *) & measure_report; |
| 5174 | unsigned long flags; |
| 5175 | |
| 5176 | spin_lock_irqsave(&priv->lock, flags); |
| 5177 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 5178 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5179 | return 0; |
| 5180 | } |
| 5181 | memcpy(&measure_report, &priv->measure_report, size); |
| 5182 | priv->measurement_status = 0; |
| 5183 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5184 | |
| 5185 | while (size && (PAGE_SIZE - len)) { |
| 5186 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 5187 | PAGE_SIZE - len, 1); |
| 5188 | len = strlen(buf); |
| 5189 | if (PAGE_SIZE - len) |
| 5190 | buf[len++] = '\n'; |
| 5191 | |
| 5192 | ofs += 16; |
| 5193 | size -= min(size, 16U); |
| 5194 | } |
| 5195 | |
| 5196 | return len; |
| 5197 | } |
| 5198 | |
| 5199 | static ssize_t store_measurement(struct device *d, |
| 5200 | struct device_attribute *attr, |
| 5201 | const char *buf, size_t count) |
| 5202 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5203 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5204 | struct ieee80211_measurement_params params = { |
| 5205 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 5206 | .start_time = cpu_to_le64(priv->last_tsf), |
| 5207 | .duration = cpu_to_le16(1), |
| 5208 | }; |
| 5209 | u8 type = IWL_MEASURE_BASIC; |
| 5210 | u8 buffer[32]; |
| 5211 | u8 channel; |
| 5212 | |
| 5213 | if (count) { |
| 5214 | char *p = buffer; |
| 5215 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 5216 | channel = simple_strtoul(p, NULL, 0); |
| 5217 | if (channel) |
| 5218 | params.channel = channel; |
| 5219 | |
| 5220 | p = buffer; |
| 5221 | while (*p && *p != ' ') |
| 5222 | p++; |
| 5223 | if (*p) |
| 5224 | type = simple_strtoul(p + 1, NULL, 0); |
| 5225 | } |
| 5226 | |
| 5227 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 5228 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5229 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5230 | |
| 5231 | return count; |
| 5232 | } |
| 5233 | |
| 5234 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 5235 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5236 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5237 | |
| 5238 | static ssize_t store_retry_rate(struct device *d, |
| 5239 | struct device_attribute *attr, |
| 5240 | const char *buf, size_t count) |
| 5241 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5242 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5243 | |
| 5244 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 5245 | if (priv->retry_rate <= 0) |
| 5246 | priv->retry_rate = 1; |
| 5247 | |
| 5248 | return count; |
| 5249 | } |
| 5250 | |
| 5251 | static ssize_t show_retry_rate(struct device *d, |
| 5252 | struct device_attribute *attr, char *buf) |
| 5253 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5254 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5255 | return sprintf(buf, "%d", priv->retry_rate); |
| 5256 | } |
| 5257 | |
| 5258 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 5259 | store_retry_rate); |
| 5260 | |
| 5261 | static ssize_t store_power_level(struct device *d, |
| 5262 | struct device_attribute *attr, |
| 5263 | const char *buf, size_t count) |
| 5264 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5265 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5266 | int rc; |
| 5267 | int mode; |
| 5268 | |
| 5269 | mode = simple_strtoul(buf, NULL, 0); |
| 5270 | mutex_lock(&priv->mutex); |
| 5271 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5272 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5273 | rc = -EAGAIN; |
| 5274 | goto out; |
| 5275 | } |
| 5276 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 5277 | rc = iwl_power_set_user_mode(priv, mode); |
| 5278 | if (rc) { |
| 5279 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 5280 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5281 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5282 | rc = count; |
| 5283 | |
| 5284 | out: |
| 5285 | mutex_unlock(&priv->mutex); |
| 5286 | return rc; |
| 5287 | } |
| 5288 | |
| 5289 | #define MAX_WX_STRING 80 |
| 5290 | |
| 5291 | /* Values are in microsecond */ |
| 5292 | static const s32 timeout_duration[] = { |
| 5293 | 350000, |
| 5294 | 250000, |
| 5295 | 75000, |
| 5296 | 37000, |
| 5297 | 25000, |
| 5298 | }; |
| 5299 | static const s32 period_duration[] = { |
| 5300 | 400000, |
| 5301 | 700000, |
| 5302 | 1000000, |
| 5303 | 1000000, |
| 5304 | 1000000 |
| 5305 | }; |
| 5306 | |
| 5307 | static ssize_t show_power_level(struct device *d, |
| 5308 | struct device_attribute *attr, char *buf) |
| 5309 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5310 | struct iwl_priv *priv = dev_get_drvdata(d); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 5311 | int level = priv->power_data.power_mode; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5312 | char *p = buf; |
| 5313 | |
| 5314 | p += sprintf(p, "%d ", level); |
| 5315 | switch (level) { |
| 5316 | case IWL_POWER_MODE_CAM: |
| 5317 | case IWL_POWER_AC: |
| 5318 | p += sprintf(p, "(AC)"); |
| 5319 | break; |
| 5320 | case IWL_POWER_BATTERY: |
| 5321 | p += sprintf(p, "(BATTERY)"); |
| 5322 | break; |
| 5323 | default: |
| 5324 | p += sprintf(p, |
| 5325 | "(Timeout %dms, Period %dms)", |
| 5326 | timeout_duration[level - 1] / 1000, |
| 5327 | period_duration[level - 1] / 1000); |
| 5328 | } |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 5329 | /* |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5330 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 5331 | p += sprintf(p, " OFF\n"); |
| 5332 | else |
| 5333 | p += sprintf(p, " \n"); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 5334 | */ |
| 5335 | p += sprintf(p, " \n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5336 | return (p - buf + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5337 | } |
| 5338 | |
| 5339 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 5340 | store_power_level); |
| 5341 | |
| 5342 | static ssize_t show_channels(struct device *d, |
| 5343 | struct device_attribute *attr, char *buf) |
| 5344 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 5345 | /* all this shit doesn't belong into sysfs anyway */ |
| 5346 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5347 | } |
| 5348 | |
| 5349 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 5350 | |
| 5351 | static ssize_t show_statistics(struct device *d, |
| 5352 | struct device_attribute *attr, char *buf) |
| 5353 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5354 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5355 | u32 size = sizeof(struct iwl4965_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5356 | u32 len = 0, ofs = 0; |
| 5357 | u8 *data = (u8 *) & priv->statistics; |
| 5358 | int rc = 0; |
| 5359 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5360 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5361 | return -EAGAIN; |
| 5362 | |
| 5363 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 5364 | rc = iwl_send_statistics_request(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5365 | mutex_unlock(&priv->mutex); |
| 5366 | |
| 5367 | if (rc) { |
| 5368 | len = sprintf(buf, |
| 5369 | "Error sending statistics request: 0x%08X\n", rc); |
| 5370 | return len; |
| 5371 | } |
| 5372 | |
| 5373 | while (size && (PAGE_SIZE - len)) { |
| 5374 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 5375 | PAGE_SIZE - len, 1); |
| 5376 | len = strlen(buf); |
| 5377 | if (PAGE_SIZE - len) |
| 5378 | buf[len++] = '\n'; |
| 5379 | |
| 5380 | ofs += 16; |
| 5381 | size -= min(size, 16U); |
| 5382 | } |
| 5383 | |
| 5384 | return len; |
| 5385 | } |
| 5386 | |
| 5387 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 5388 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5389 | static ssize_t show_status(struct device *d, |
| 5390 | struct device_attribute *attr, char *buf) |
| 5391 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5392 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5393 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5394 | return -EAGAIN; |
| 5395 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 5396 | } |
| 5397 | |
| 5398 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 5399 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5400 | /***************************************************************************** |
| 5401 | * |
| 5402 | * driver setup and teardown |
| 5403 | * |
| 5404 | *****************************************************************************/ |
| 5405 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5406 | static void iwl4965_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5407 | { |
| 5408 | priv->workqueue = create_workqueue(DRV_NAME); |
| 5409 | |
| 5410 | init_waitqueue_head(&priv->wait_command_queue); |
| 5411 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5412 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 5413 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 5414 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
| 5415 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); |
| 5416 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); |
| 5417 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); |
| 5418 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 5419 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 5420 | INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5421 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 5422 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start); |
| 5423 | INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5424 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5425 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5426 | iwl4965_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5427 | |
| 5428 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5429 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5430 | } |
| 5431 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5432 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5433 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5434 | iwl4965_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5435 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 5436 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5437 | cancel_delayed_work(&priv->scan_check); |
| 5438 | cancel_delayed_work(&priv->alive_start); |
| 5439 | cancel_delayed_work(&priv->post_associate); |
| 5440 | cancel_work_sync(&priv->beacon_update); |
| 5441 | } |
| 5442 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5443 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5444 | &dev_attr_channels.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5445 | &dev_attr_flags.attr, |
| 5446 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5447 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5448 | &dev_attr_measurement.attr, |
| 5449 | #endif |
| 5450 | &dev_attr_power_level.attr, |
| 5451 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5452 | &dev_attr_rs_window.attr, |
| 5453 | &dev_attr_statistics.attr, |
| 5454 | &dev_attr_status.attr, |
| 5455 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5456 | &dev_attr_tx_power.attr, |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5457 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 5458 | &dev_attr_debug_level.attr, |
| 5459 | #endif |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 5460 | &dev_attr_version.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5461 | |
| 5462 | NULL |
| 5463 | }; |
| 5464 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5465 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5466 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5467 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5468 | }; |
| 5469 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5470 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 5471 | .tx = iwl4965_mac_tx, |
| 5472 | .start = iwl4965_mac_start, |
| 5473 | .stop = iwl4965_mac_stop, |
| 5474 | .add_interface = iwl4965_mac_add_interface, |
| 5475 | .remove_interface = iwl4965_mac_remove_interface, |
| 5476 | .config = iwl4965_mac_config, |
| 5477 | .config_interface = iwl4965_mac_config_interface, |
| 5478 | .configure_filter = iwl4965_configure_filter, |
| 5479 | .set_key = iwl4965_mac_set_key, |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5480 | .update_tkip_key = iwl4965_mac_update_tkip_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5481 | .get_stats = iwl4965_mac_get_stats, |
| 5482 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 5483 | .conf_tx = iwl4965_mac_conf_tx, |
| 5484 | .get_tsf = iwl4965_mac_get_tsf, |
| 5485 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 5486 | .beacon_update = iwl4965_mac_beacon_update, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5487 | .bss_info_changed = iwl4965_bss_info_changed, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5488 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | 9ab4617 | 2007-12-25 17:00:38 +0200 | [diff] [blame] | 5489 | .ampdu_action = iwl4965_mac_ampdu_action, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5490 | #endif /* CONFIG_IWL4965_HT */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5491 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5492 | }; |
| 5493 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5494 | 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] | 5495 | { |
| 5496 | int err = 0; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5497 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5498 | struct ieee80211_hw *hw; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 5499 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5500 | unsigned long flags; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5501 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5502 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5503 | /************************ |
| 5504 | * 1. Allocating HW data |
| 5505 | ************************/ |
| 5506 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5507 | /* Disabling hardware scan means that mac80211 will perform scans |
| 5508 | * "the hard way", rather than using device's scan. */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 5509 | if (cfg->mod_params->disable_hw_scan) { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 5510 | if (cfg->mod_params->debug & IWL_DL_INFO) |
| 5511 | dev_printk(KERN_DEBUG, &(pdev->dev), |
| 5512 | "Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5513 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5514 | } |
| 5515 | |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 5516 | hw = iwl_alloc_all(cfg, &iwl4965_hw_ops); |
| 5517 | if (!hw) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5518 | err = -ENOMEM; |
| 5519 | goto out; |
| 5520 | } |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 5521 | priv = hw->priv; |
| 5522 | /* At this point both hw and priv are allocated. */ |
| 5523 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5524 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 5525 | |
| 5526 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 5527 | priv->cfg = cfg; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5528 | priv->pci_dev = pdev; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5529 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 5530 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 5531 | priv->debug_level = priv->cfg->mod_params->debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5532 | atomic_set(&priv->restrict_refcnt, 0); |
| 5533 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5534 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5535 | /************************** |
| 5536 | * 2. Initializing PCI bus |
| 5537 | **************************/ |
| 5538 | if (pci_enable_device(pdev)) { |
| 5539 | err = -ENODEV; |
| 5540 | goto out_ieee80211_free_hw; |
| 5541 | } |
| 5542 | |
| 5543 | pci_set_master(pdev); |
| 5544 | |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5545 | err = pci_set_dma_mask(pdev, DMA_64BIT_MASK); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5546 | if (!err) |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5547 | err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); |
| 5548 | if (err) { |
| 5549 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 5550 | if (!err) |
| 5551 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 5552 | /* both attempts failed: */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5553 | if (err) { |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5554 | printk(KERN_WARNING "%s: No suitable DMA available.\n", |
| 5555 | DRV_NAME); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5556 | goto out_pci_disable_device; |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5557 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5558 | } |
| 5559 | |
| 5560 | err = pci_request_regions(pdev, DRV_NAME); |
| 5561 | if (err) |
| 5562 | goto out_pci_disable_device; |
| 5563 | |
| 5564 | pci_set_drvdata(pdev, priv); |
| 5565 | |
| 5566 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 5567 | * PCI Tx retries from interfering with C3 CPU state */ |
| 5568 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 5569 | |
| 5570 | /*********************** |
| 5571 | * 3. Read REV register |
| 5572 | ***********************/ |
| 5573 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 5574 | if (!priv->hw_base) { |
| 5575 | err = -ENODEV; |
| 5576 | goto out_pci_release_regions; |
| 5577 | } |
| 5578 | |
| 5579 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 5580 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 5581 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 5582 | |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 5583 | iwl_hw_detect(priv); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5584 | printk(KERN_INFO DRV_NAME |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 5585 | ": Detected Intel Wireless WiFi Link %s REV=0x%X\n", |
| 5586 | priv->cfg->name, priv->hw_rev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5587 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 5588 | /* amp init */ |
| 5589 | err = priv->cfg->ops->lib->apm_ops.init(priv); |
| 5590 | if (err < 0) { |
| 5591 | IWL_DEBUG_INFO("Failed to init APMG\n"); |
| 5592 | goto out_iounmap; |
| 5593 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5594 | /***************** |
| 5595 | * 4. Read EEPROM |
| 5596 | *****************/ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5597 | /* Read the EEPROM */ |
| 5598 | err = iwl_eeprom_init(priv); |
| 5599 | if (err) { |
| 5600 | IWL_ERROR("Unable to init EEPROM\n"); |
| 5601 | goto out_iounmap; |
| 5602 | } |
Tomas Winkler | 8614f36 | 2008-04-23 17:14:55 -0700 | [diff] [blame] | 5603 | err = iwl_eeprom_check_version(priv); |
| 5604 | if (err) |
| 5605 | goto out_iounmap; |
| 5606 | |
Ron Rindjunsky | 0288301 | 2008-05-15 13:53:53 +0800 | [diff] [blame] | 5607 | /* extract MAC Address */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5608 | iwl_eeprom_get_mac(priv, priv->mac_addr); |
| 5609 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); |
| 5610 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 5611 | |
| 5612 | /************************ |
| 5613 | * 5. Setup HW constants |
| 5614 | ************************/ |
| 5615 | /* Device-specific setup */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 5616 | if (priv->cfg->ops->lib->set_hw_params(priv)) { |
| 5617 | IWL_ERROR("failed to set hw parameters\n"); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 5618 | goto out_free_eeprom; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5619 | } |
| 5620 | |
| 5621 | /******************* |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5622 | * 6. Setup priv |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5623 | *******************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5624 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5625 | err = iwl_init_drv(priv); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5626 | if (err) |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 5627 | goto out_free_eeprom; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5628 | /* At this point both hw and priv are initialized. */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5629 | |
| 5630 | /********************************** |
| 5631 | * 7. Initialize module parameters |
| 5632 | **********************************/ |
| 5633 | |
| 5634 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 5635 | if (priv->cfg->mod_params->disable) { |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5636 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 5637 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 5638 | } |
| 5639 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5640 | /******************** |
| 5641 | * 8. Setup services |
| 5642 | ********************/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5643 | spin_lock_irqsave(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5644 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5645 | spin_unlock_irqrestore(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5646 | |
| 5647 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
| 5648 | if (err) { |
| 5649 | IWL_ERROR("failed to create sysfs device attributes\n"); |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5650 | goto out_uninit_drv; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5651 | } |
| 5652 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5653 | |
| 5654 | iwl4965_setup_deferred_work(priv); |
| 5655 | iwl4965_setup_rx_handlers(priv); |
| 5656 | |
| 5657 | /******************** |
| 5658 | * 9. Conclude |
| 5659 | ********************/ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5660 | pci_save_state(pdev); |
| 5661 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5662 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5663 | /********************************** |
| 5664 | * 10. Setup and register mac80211 |
| 5665 | **********************************/ |
| 5666 | |
| 5667 | err = iwl_setup_mac(priv); |
| 5668 | if (err) |
| 5669 | goto out_remove_sysfs; |
| 5670 | |
| 5671 | err = iwl_dbgfs_register(priv, DRV_NAME); |
| 5672 | if (err) |
| 5673 | IWL_ERROR("failed to create debugfs files\n"); |
| 5674 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 5675 | /* notify iwlcore to init */ |
| 5676 | iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5677 | return 0; |
| 5678 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5679 | out_remove_sysfs: |
| 5680 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5681 | out_uninit_drv: |
| 5682 | iwl_uninit_drv(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 5683 | out_free_eeprom: |
| 5684 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5685 | out_iounmap: |
| 5686 | pci_iounmap(pdev, priv->hw_base); |
| 5687 | out_pci_release_regions: |
| 5688 | pci_release_regions(pdev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5689 | pci_set_drvdata(pdev, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5690 | out_pci_disable_device: |
| 5691 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5692 | out_ieee80211_free_hw: |
| 5693 | ieee80211_free_hw(priv->hw); |
| 5694 | out: |
| 5695 | return err; |
| 5696 | } |
| 5697 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 5698 | static void __devexit iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5699 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5700 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5701 | struct list_head *p, *q; |
| 5702 | int i; |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5703 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5704 | |
| 5705 | if (!priv) |
| 5706 | return; |
| 5707 | |
| 5708 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 5709 | |
Ron Rindjunsky | c4f5523 | 2008-03-28 16:21:10 -0700 | [diff] [blame] | 5710 | if (priv->mac80211_registered) { |
| 5711 | ieee80211_unregister_hw(priv->hw); |
| 5712 | priv->mac80211_registered = 0; |
| 5713 | } |
| 5714 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5715 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 5716 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5717 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5718 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5719 | /* make sure we flush any pending irq or |
| 5720 | * tasklet for the driver |
| 5721 | */ |
| 5722 | spin_lock_irqsave(&priv->lock, flags); |
| 5723 | iwl4965_disable_interrupts(priv); |
| 5724 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5725 | |
| 5726 | iwl_synchronize_irq(priv); |
| 5727 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5728 | /* Free MAC hash list for ADHOC */ |
| 5729 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 5730 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 5731 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5732 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5733 | } |
| 5734 | } |
| 5735 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 5736 | iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 5737 | iwl_dbgfs_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5738 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5739 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5740 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5741 | |
| 5742 | if (priv->rxq.bd) |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 5743 | iwl_rx_queue_free(priv, &priv->rxq); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 5744 | iwl_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5745 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5746 | iwlcore_clear_stations_table(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 5747 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5748 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5749 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5750 | /*netif_stop_queue(dev); */ |
| 5751 | flush_workqueue(priv->workqueue); |
| 5752 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5753 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5754 | * priv->workqueue... so we can't take down the workqueue |
| 5755 | * until now... */ |
| 5756 | destroy_workqueue(priv->workqueue); |
| 5757 | priv->workqueue = NULL; |
| 5758 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5759 | pci_iounmap(pdev, priv->hw_base); |
| 5760 | pci_release_regions(pdev); |
| 5761 | pci_disable_device(pdev); |
| 5762 | pci_set_drvdata(pdev, NULL); |
| 5763 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5764 | iwl_uninit_drv(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5765 | |
| 5766 | if (priv->ibss_beacon) |
| 5767 | dev_kfree_skb(priv->ibss_beacon); |
| 5768 | |
| 5769 | ieee80211_free_hw(priv->hw); |
| 5770 | } |
| 5771 | |
| 5772 | #ifdef CONFIG_PM |
| 5773 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5774 | 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] | 5775 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5776 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5777 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5778 | if (priv->is_open) { |
| 5779 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 5780 | iwl4965_mac_stop(priv->hw); |
| 5781 | priv->is_open = 1; |
| 5782 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5783 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5784 | pci_set_power_state(pdev, PCI_D3hot); |
| 5785 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5786 | return 0; |
| 5787 | } |
| 5788 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5789 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5790 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5791 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5792 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5793 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5794 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5795 | if (priv->is_open) |
| 5796 | iwl4965_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5797 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5798 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5799 | return 0; |
| 5800 | } |
| 5801 | |
| 5802 | #endif /* CONFIG_PM */ |
| 5803 | |
| 5804 | /***************************************************************************** |
| 5805 | * |
| 5806 | * driver and module entry point |
| 5807 | * |
| 5808 | *****************************************************************************/ |
| 5809 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5810 | /* Hardware specific file defines the PCI IDs table for that hardware module */ |
| 5811 | static struct pci_device_id iwl_hw_card_ids[] = { |
| 5812 | {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)}, |
| 5813 | {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)}, |
Tomas Winkler | 5a6a256 | 2008-04-24 11:55:23 -0700 | [diff] [blame] | 5814 | #ifdef CONFIG_IWL5000 |
| 5815 | {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)}, |
| 5816 | {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)}, |
| 5817 | {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)}, |
| 5818 | #endif /* CONFIG_IWL5000 */ |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5819 | {0} |
| 5820 | }; |
| 5821 | MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); |
| 5822 | |
| 5823 | static struct pci_driver iwl_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5824 | .name = DRV_NAME, |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5825 | .id_table = iwl_hw_card_ids, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5826 | .probe = iwl4965_pci_probe, |
| 5827 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5828 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5829 | .suspend = iwl4965_pci_suspend, |
| 5830 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5831 | #endif |
| 5832 | }; |
| 5833 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5834 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5835 | { |
| 5836 | |
| 5837 | int ret; |
| 5838 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 5839 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5840 | |
| 5841 | ret = iwl4965_rate_control_register(); |
| 5842 | if (ret) { |
| 5843 | IWL_ERROR("Unable to register rate control algorithm: %d\n", ret); |
| 5844 | return ret; |
| 5845 | } |
| 5846 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5847 | ret = pci_register_driver(&iwl_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5848 | if (ret) { |
| 5849 | IWL_ERROR("Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5850 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5851 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5852 | |
| 5853 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5854 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5855 | error_register: |
| 5856 | iwl4965_rate_control_unregister(); |
| 5857 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5858 | } |
| 5859 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5860 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5861 | { |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5862 | pci_unregister_driver(&iwl_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5863 | iwl4965_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5864 | } |
| 5865 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5866 | module_exit(iwl4965_exit); |
| 5867 | module_init(iwl4965_init); |