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 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 918 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 919 | |
| 920 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 921 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 922 | * |
| 923 | * NOTE: priv->mutex is not required before calling this function |
| 924 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 925 | static int iwl4965_scan_cancel(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 926 | { |
| 927 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 928 | clear_bit(STATUS_SCANNING, &priv->status); |
| 929 | return 0; |
| 930 | } |
| 931 | |
| 932 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 933 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 934 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 935 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 936 | queue_work(priv->workqueue, &priv->abort_scan); |
| 937 | |
| 938 | } else |
| 939 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 940 | |
| 941 | return test_bit(STATUS_SCANNING, &priv->status); |
| 942 | } |
| 943 | |
| 944 | return 0; |
| 945 | } |
| 946 | |
| 947 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 948 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 949 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 950 | * |
| 951 | * NOTE: priv->mutex must be held before calling this function |
| 952 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 953 | 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] | 954 | { |
| 955 | unsigned long now = jiffies; |
| 956 | int ret; |
| 957 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 958 | ret = iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 959 | if (ret && ms) { |
| 960 | mutex_unlock(&priv->mutex); |
| 961 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 962 | test_bit(STATUS_SCANNING, &priv->status)) |
| 963 | msleep(1); |
| 964 | mutex_lock(&priv->mutex); |
| 965 | |
| 966 | return test_bit(STATUS_SCANNING, &priv->status); |
| 967 | } |
| 968 | |
| 969 | return ret; |
| 970 | } |
| 971 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 972 | static void iwl4965_sequence_reset(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 973 | { |
| 974 | /* Reset ieee stats */ |
| 975 | |
| 976 | /* We don't reset the net_device_stats (ieee->stats) on |
| 977 | * re-association */ |
| 978 | |
| 979 | priv->last_seq_num = -1; |
| 980 | priv->last_frag_num = -1; |
| 981 | priv->last_packet_time = 0; |
| 982 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 983 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 987 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 988 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 989 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 990 | { |
| 991 | u16 new_val = 0; |
| 992 | u16 beacon_factor = 0; |
| 993 | |
| 994 | beacon_factor = |
| 995 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 996 | / MAX_UCODE_BEACON_INTERVAL; |
| 997 | new_val = beacon_val / beacon_factor; |
| 998 | |
| 999 | return cpu_to_le16(new_val); |
| 1000 | } |
| 1001 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1002 | static void iwl4965_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1003 | { |
| 1004 | u64 interval_tm_unit; |
| 1005 | u64 tsf, result; |
| 1006 | unsigned long flags; |
| 1007 | struct ieee80211_conf *conf = NULL; |
| 1008 | u16 beacon_int = 0; |
| 1009 | |
| 1010 | conf = ieee80211_get_hw_conf(priv->hw); |
| 1011 | |
| 1012 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1013 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32); |
| 1014 | priv->rxon_timing.timestamp.dw[0] = |
| 1015 | cpu_to_le32(priv->timestamp & 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1016 | |
| 1017 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 1018 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1019 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1020 | |
| 1021 | beacon_int = priv->beacon_int; |
| 1022 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1023 | |
| 1024 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 1025 | if (beacon_int == 0) { |
| 1026 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 1027 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 1028 | } else { |
| 1029 | priv->rxon_timing.beacon_interval = |
| 1030 | cpu_to_le16(beacon_int); |
| 1031 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1032 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1033 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1034 | } |
| 1035 | |
| 1036 | priv->rxon_timing.atim_window = 0; |
| 1037 | } else { |
| 1038 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1039 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1040 | /* TODO: we need to get atim_window from upper stack |
| 1041 | * for now we set to 0 */ |
| 1042 | priv->rxon_timing.atim_window = 0; |
| 1043 | } |
| 1044 | |
| 1045 | interval_tm_unit = |
| 1046 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 1047 | result = do_div(tsf, interval_tm_unit); |
| 1048 | priv->rxon_timing.beacon_init_val = |
| 1049 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 1050 | |
| 1051 | IWL_DEBUG_ASSOC |
| 1052 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 1053 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 1054 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 1055 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 1056 | } |
| 1057 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1058 | static int iwl4965_scan_initiate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1059 | { |
| 1060 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 1061 | IWL_ERROR("APs don't scan.\n"); |
| 1062 | return 0; |
| 1063 | } |
| 1064 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1065 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1066 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 1067 | return -EIO; |
| 1068 | } |
| 1069 | |
| 1070 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1071 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 1072 | return -EAGAIN; |
| 1073 | } |
| 1074 | |
| 1075 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1076 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 1077 | "Queuing.\n"); |
| 1078 | return -EAGAIN; |
| 1079 | } |
| 1080 | |
| 1081 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 1082 | priv->scan_bands = 2; |
| 1083 | set_bit(STATUS_SCANNING, &priv->status); |
| 1084 | priv->scan_start = jiffies; |
| 1085 | priv->scan_pass_start = priv->scan_start; |
| 1086 | |
| 1087 | queue_work(priv->workqueue, &priv->request_scan); |
| 1088 | |
| 1089 | return 0; |
| 1090 | } |
| 1091 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1092 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1093 | static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1094 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1095 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1096 | if (band == IEEE80211_BAND_5GHZ) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1097 | priv->staging_rxon.flags &= |
| 1098 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 1099 | | RXON_FLG_CCK_MSK); |
| 1100 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1101 | } else { |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 1102 | /* Copied from iwl4965_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1103 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 1104 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1105 | else |
| 1106 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1107 | |
| 1108 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 1109 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1110 | |
| 1111 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 1112 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 1113 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1118 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1119 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1120 | static void iwl4965_connection_init_rx_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1121 | { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1122 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1123 | |
| 1124 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 1125 | |
| 1126 | switch (priv->iw_mode) { |
| 1127 | case IEEE80211_IF_TYPE_AP: |
| 1128 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 1129 | break; |
| 1130 | |
| 1131 | case IEEE80211_IF_TYPE_STA: |
| 1132 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 1133 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 1134 | break; |
| 1135 | |
| 1136 | case IEEE80211_IF_TYPE_IBSS: |
| 1137 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 1138 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1139 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 1140 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1141 | break; |
| 1142 | |
| 1143 | case IEEE80211_IF_TYPE_MNTR: |
| 1144 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 1145 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 1146 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1147 | break; |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1148 | default: |
| 1149 | IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode); |
| 1150 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | #if 0 |
| 1154 | /* TODO: Figure out when short_preamble would be set and cache from |
| 1155 | * that */ |
| 1156 | if (!hw_to_local(priv->hw)->short_preamble) |
| 1157 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1158 | else |
| 1159 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1160 | #endif |
| 1161 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1162 | ch_info = iwl_get_channel_info(priv, priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1163 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1164 | |
| 1165 | if (!ch_info) |
| 1166 | ch_info = &priv->channel_info[0]; |
| 1167 | |
| 1168 | /* |
| 1169 | * in some case A channels are all non IBSS |
| 1170 | * in this case force B/G channel |
| 1171 | */ |
| 1172 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 1173 | !(is_channel_ibss(ch_info))) |
| 1174 | ch_info = &priv->channel_info[0]; |
| 1175 | |
| 1176 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1177 | priv->band = ch_info->band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1178 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1179 | iwl4965_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1180 | |
| 1181 | priv->staging_rxon.ofdm_basic_rates = |
| 1182 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1183 | priv->staging_rxon.cck_basic_rates = |
| 1184 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1185 | |
| 1186 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 1187 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 1188 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1189 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 1190 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 1191 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 1192 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1193 | } |
| 1194 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1195 | static int iwl4965_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1196 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1197 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1198 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1199 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1200 | ch_info = iwl_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1201 | priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1202 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1203 | |
| 1204 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 1205 | IWL_ERROR("channel %d not IBSS channel\n", |
| 1206 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1207 | return -EINVAL; |
| 1208 | } |
| 1209 | } |
| 1210 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1211 | priv->iw_mode = mode; |
| 1212 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1213 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1214 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1215 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1216 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1217 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1218 | /* dont commit rxon if rf-kill is on*/ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1219 | if (!iwl_is_ready_rf(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1220 | return -EAGAIN; |
| 1221 | |
| 1222 | cancel_delayed_work(&priv->scan_check); |
| 1223 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
| 1224 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 1225 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 1226 | return -EAGAIN; |
| 1227 | } |
| 1228 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1229 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1230 | |
| 1231 | return 0; |
| 1232 | } |
| 1233 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1234 | static void iwl4965_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1235 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1236 | const struct ieee80211_supported_band *hw = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1237 | struct ieee80211_rate *rate; |
| 1238 | int i; |
| 1239 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 1240 | hw = iwl_get_hw_mode(priv, priv->band); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 1241 | if (!hw) { |
| 1242 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 1243 | return; |
| 1244 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1245 | |
| 1246 | priv->active_rate = 0; |
| 1247 | priv->active_rate_basic = 0; |
| 1248 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1249 | for (i = 0; i < hw->n_bitrates; i++) { |
| 1250 | rate = &(hw->bitrates[i]); |
| 1251 | if (rate->hw_value < IWL_RATE_COUNT) |
| 1252 | priv->active_rate |= (1 << rate->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 1256 | priv->active_rate, priv->active_rate_basic); |
| 1257 | |
| 1258 | /* |
| 1259 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 1260 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 1261 | * OFDM |
| 1262 | */ |
| 1263 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 1264 | priv->staging_rxon.cck_basic_rates = |
| 1265 | ((priv->active_rate_basic & |
| 1266 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1267 | else |
| 1268 | priv->staging_rxon.cck_basic_rates = |
| 1269 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1270 | |
| 1271 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 1272 | priv->staging_rxon.ofdm_basic_rates = |
| 1273 | ((priv->active_rate_basic & |
| 1274 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 1275 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1276 | else |
| 1277 | priv->staging_rxon.ofdm_basic_rates = |
| 1278 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1279 | } |
| 1280 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1281 | void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1282 | { |
| 1283 | unsigned long flags; |
| 1284 | |
| 1285 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 1286 | return; |
| 1287 | |
| 1288 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 1289 | disable_radio ? "OFF" : "ON"); |
| 1290 | |
| 1291 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1292 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1293 | /* FIXME: This is a workaround for AP */ |
| 1294 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 1295 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1296 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1297 | CSR_UCODE_SW_BIT_RFKILL); |
| 1298 | spin_unlock_irqrestore(&priv->lock, flags); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1299 | /* call the host command only if no hw rf-kill set */ |
Mohamed Abbas | 5900383 | 2008-04-15 16:01:46 -0700 | [diff] [blame] | 1300 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status) && |
| 1301 | iwl_is_ready(priv)) |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1302 | iwl4965_send_card_state(priv, |
| 1303 | CARD_STATE_CMD_DISABLE, |
| 1304 | 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1305 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1306 | |
| 1307 | /* make sure mac80211 stop sending Tx frame */ |
| 1308 | if (priv->mac80211_registered) |
| 1309 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1310 | } |
| 1311 | return; |
| 1312 | } |
| 1313 | |
| 1314 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1315 | 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] | 1316 | |
| 1317 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 1318 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1319 | |
| 1320 | /* wake up ucode */ |
| 1321 | msleep(10); |
| 1322 | |
| 1323 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1324 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 1325 | if (!iwl_grab_nic_access(priv)) |
| 1326 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1327 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1328 | |
| 1329 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 1330 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 1331 | "disabled by HW switch\n"); |
| 1332 | return; |
| 1333 | } |
| 1334 | |
| 1335 | queue_work(priv->workqueue, &priv->restart); |
| 1336 | return; |
| 1337 | } |
| 1338 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1339 | #define IWL_PACKET_RETRY_TIME HZ |
| 1340 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1341 | 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] | 1342 | { |
| 1343 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 1344 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 1345 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 1346 | u16 *last_seq, *last_frag; |
| 1347 | unsigned long *last_time; |
| 1348 | |
| 1349 | switch (priv->iw_mode) { |
| 1350 | case IEEE80211_IF_TYPE_IBSS:{ |
| 1351 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1352 | struct iwl4965_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1353 | u8 *mac = header->addr2; |
| 1354 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 1355 | |
| 1356 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1357 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1358 | if (!compare_ether_addr(entry->mac, mac)) |
| 1359 | break; |
| 1360 | } |
| 1361 | if (p == &priv->ibss_mac_hash[index]) { |
| 1362 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 1363 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1364 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1365 | return 0; |
| 1366 | } |
| 1367 | memcpy(entry->mac, mac, ETH_ALEN); |
| 1368 | entry->seq_num = seq; |
| 1369 | entry->frag_num = frag; |
| 1370 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1371 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1372 | return 0; |
| 1373 | } |
| 1374 | last_seq = &entry->seq_num; |
| 1375 | last_frag = &entry->frag_num; |
| 1376 | last_time = &entry->packet_time; |
| 1377 | break; |
| 1378 | } |
| 1379 | case IEEE80211_IF_TYPE_STA: |
| 1380 | last_seq = &priv->last_seq_num; |
| 1381 | last_frag = &priv->last_frag_num; |
| 1382 | last_time = &priv->last_packet_time; |
| 1383 | break; |
| 1384 | default: |
| 1385 | return 0; |
| 1386 | } |
| 1387 | if ((*last_seq == seq) && |
| 1388 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 1389 | if (*last_frag == frag) |
| 1390 | goto drop; |
| 1391 | if (*last_frag + 1 != frag) |
| 1392 | /* out-of-order fragment */ |
| 1393 | goto drop; |
| 1394 | } else |
| 1395 | *last_seq = seq; |
| 1396 | |
| 1397 | *last_frag = frag; |
| 1398 | *last_time = jiffies; |
| 1399 | return 0; |
| 1400 | |
| 1401 | drop: |
| 1402 | return 1; |
| 1403 | } |
| 1404 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1405 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1406 | |
| 1407 | #include "iwl-spectrum.h" |
| 1408 | |
| 1409 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 1410 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 1411 | #define TIME_UNIT 1024 |
| 1412 | |
| 1413 | /* |
| 1414 | * extended beacon time format |
| 1415 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 1416 | * the high 1 byte is the beacon counts |
| 1417 | * the lower 3 bytes is the time in usec within one beacon interval |
| 1418 | */ |
| 1419 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1420 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1421 | { |
| 1422 | u32 quot; |
| 1423 | u32 rem; |
| 1424 | u32 interval = beacon_interval * 1024; |
| 1425 | |
| 1426 | if (!interval || !usec) |
| 1427 | return 0; |
| 1428 | |
| 1429 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 1430 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 1431 | |
| 1432 | return (quot << 24) + rem; |
| 1433 | } |
| 1434 | |
| 1435 | /* base is usually what we get from ucode with each received frame, |
| 1436 | * the same as HW timer counter counting down |
| 1437 | */ |
| 1438 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1439 | 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] | 1440 | { |
| 1441 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 1442 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 1443 | u32 interval = beacon_interval * TIME_UNIT; |
| 1444 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 1445 | (addon & BEACON_TIME_MASK_HIGH); |
| 1446 | |
| 1447 | if (base_low > addon_low) |
| 1448 | res += base_low - addon_low; |
| 1449 | else if (base_low < addon_low) { |
| 1450 | res += interval + base_low - addon_low; |
| 1451 | res += (1 << 24); |
| 1452 | } else |
| 1453 | res += (1 << 24); |
| 1454 | |
| 1455 | return cpu_to_le32(res); |
| 1456 | } |
| 1457 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1458 | static int iwl4965_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1459 | struct ieee80211_measurement_params *params, |
| 1460 | u8 type) |
| 1461 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1462 | struct iwl4965_spectrum_cmd spectrum; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1463 | struct iwl_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1464 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1465 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 1466 | .data = (void *)&spectrum, |
| 1467 | .meta.flags = CMD_WANT_SKB, |
| 1468 | }; |
| 1469 | u32 add_time = le64_to_cpu(params->start_time); |
| 1470 | int rc; |
| 1471 | int spectrum_resp_status; |
| 1472 | int duration = le16_to_cpu(params->duration); |
| 1473 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1474 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1475 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1476 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1477 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 1478 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1479 | |
| 1480 | memset(&spectrum, 0, sizeof(spectrum)); |
| 1481 | |
| 1482 | spectrum.channel_count = cpu_to_le16(1); |
| 1483 | spectrum.flags = |
| 1484 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 1485 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 1486 | cmd.len = sizeof(spectrum); |
| 1487 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 1488 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1489 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1490 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1491 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1492 | add_time, |
| 1493 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1494 | else |
| 1495 | spectrum.start_time = 0; |
| 1496 | |
| 1497 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 1498 | spectrum.channels[0].channel = params->channel; |
| 1499 | spectrum.channels[0].type = type; |
| 1500 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 1501 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 1502 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 1503 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1504 | rc = iwl_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1505 | if (rc) |
| 1506 | return rc; |
| 1507 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1508 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1509 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1510 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 1511 | rc = -EIO; |
| 1512 | } |
| 1513 | |
| 1514 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 1515 | switch (spectrum_resp_status) { |
| 1516 | case 0: /* Command will be handled */ |
| 1517 | if (res->u.spectrum.id != 0xff) { |
| 1518 | IWL_DEBUG_INFO |
| 1519 | ("Replaced existing measurement: %d\n", |
| 1520 | res->u.spectrum.id); |
| 1521 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 1522 | } |
| 1523 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 1524 | rc = 0; |
| 1525 | break; |
| 1526 | |
| 1527 | case 1: /* Command will not be handled */ |
| 1528 | rc = -EAGAIN; |
| 1529 | break; |
| 1530 | } |
| 1531 | |
| 1532 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1533 | |
| 1534 | return rc; |
| 1535 | } |
| 1536 | #endif |
| 1537 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1538 | /****************************************************************************** |
| 1539 | * |
| 1540 | * Generic RX handler implementations |
| 1541 | * |
| 1542 | ******************************************************************************/ |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1543 | static void iwl_rx_reply_alive(struct iwl_priv *priv, |
| 1544 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1545 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1546 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1547 | struct iwl_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1548 | struct delayed_work *pwork; |
| 1549 | |
| 1550 | palive = &pkt->u.alive_frame; |
| 1551 | |
| 1552 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 1553 | "0x%01X 0x%01X\n", |
| 1554 | palive->is_valid, palive->ver_type, |
| 1555 | palive->ver_subtype); |
| 1556 | |
| 1557 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 1558 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 1559 | memcpy(&priv->card_alive_init, |
| 1560 | &pkt->u.alive_frame, |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1561 | sizeof(struct iwl_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1562 | pwork = &priv->init_alive_start; |
| 1563 | } else { |
| 1564 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 1565 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1566 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1567 | pwork = &priv->alive_start; |
| 1568 | } |
| 1569 | |
| 1570 | /* We delay the ALIVE response by 5ms to |
| 1571 | * give the HW RF Kill time to activate... */ |
| 1572 | if (palive->is_valid == UCODE_VALID_OK) |
| 1573 | queue_delayed_work(priv->workqueue, pwork, |
| 1574 | msecs_to_jiffies(5)); |
| 1575 | else |
| 1576 | IWL_WARNING("uCode did not respond OK.\n"); |
| 1577 | } |
| 1578 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1579 | static void iwl4965_rx_reply_error(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1580 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1581 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1582 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1583 | |
| 1584 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 1585 | "seq 0x%04X ser 0x%08X\n", |
| 1586 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 1587 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 1588 | pkt->u.err_resp.cmd_id, |
| 1589 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 1590 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 1591 | } |
| 1592 | |
| 1593 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 1594 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1595 | 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] | 1596 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1597 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 1598 | struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1599 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1600 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 1601 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 1602 | rxon->channel = csa->channel; |
| 1603 | priv->staging_rxon.channel = csa->channel; |
| 1604 | } |
| 1605 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1606 | static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1607 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1608 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1609 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1610 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1611 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1612 | |
| 1613 | if (!report->state) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1614 | IWL_DEBUG(IWL_DL_11H, |
| 1615 | "Spectrum Measure Notification: Start\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1616 | return; |
| 1617 | } |
| 1618 | |
| 1619 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 1620 | priv->measurement_status |= MEASUREMENT_READY; |
| 1621 | #endif |
| 1622 | } |
| 1623 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1624 | static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1625 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1626 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1627 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1628 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1629 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1630 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 1631 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 1632 | #endif |
| 1633 | } |
| 1634 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1635 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1636 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1637 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1638 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1639 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 1640 | "notification for %s:\n", |
| 1641 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1642 | 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] | 1643 | } |
| 1644 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1645 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1646 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1647 | struct iwl_priv *priv = |
| 1648 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1649 | struct sk_buff *beacon; |
| 1650 | |
| 1651 | /* 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] | 1652 | beacon = ieee80211_beacon_get(priv->hw, priv->vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1653 | |
| 1654 | if (!beacon) { |
| 1655 | IWL_ERROR("update beacon failed\n"); |
| 1656 | return; |
| 1657 | } |
| 1658 | |
| 1659 | mutex_lock(&priv->mutex); |
| 1660 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 1661 | if (priv->ibss_beacon) |
| 1662 | dev_kfree_skb(priv->ibss_beacon); |
| 1663 | |
| 1664 | priv->ibss_beacon = beacon; |
| 1665 | mutex_unlock(&priv->mutex); |
| 1666 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1667 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1670 | static void iwl4965_rx_beacon_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1671 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1672 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1673 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1674 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1675 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 1676 | 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] | 1677 | |
| 1678 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 1679 | "tsf %d %d rate %d\n", |
| 1680 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 1681 | beacon->beacon_notify_hdr.failure_frame, |
| 1682 | le32_to_cpu(beacon->ibss_mgr_status), |
| 1683 | le32_to_cpu(beacon->high_tsf), |
| 1684 | le32_to_cpu(beacon->low_tsf), rate); |
| 1685 | #endif |
| 1686 | |
| 1687 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 1688 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 1689 | queue_work(priv->workqueue, &priv->beacon_update); |
| 1690 | } |
| 1691 | |
| 1692 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1693 | static void iwl4965_rx_reply_scan(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1694 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1695 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1696 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1697 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1698 | struct iwl4965_scanreq_notification *notif = |
| 1699 | (struct iwl4965_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1700 | |
| 1701 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 1702 | #endif |
| 1703 | } |
| 1704 | |
| 1705 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1706 | static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1707 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1708 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1709 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1710 | struct iwl4965_scanstart_notification *notif = |
| 1711 | (struct iwl4965_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1712 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 1713 | IWL_DEBUG_SCAN("Scan start: " |
| 1714 | "%d [802.11%s] " |
| 1715 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 1716 | notif->channel, |
| 1717 | notif->band ? "bg" : "a", |
| 1718 | notif->tsf_high, |
| 1719 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 1720 | } |
| 1721 | |
| 1722 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1723 | static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1724 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1725 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1726 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1727 | struct iwl4965_scanresults_notification *notif = |
| 1728 | (struct iwl4965_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1729 | |
| 1730 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 1731 | "%d [802.11%s] " |
| 1732 | "(TSF: 0x%08X:%08X) - %d " |
| 1733 | "elapsed=%lu usec (%dms since last)\n", |
| 1734 | notif->channel, |
| 1735 | notif->band ? "bg" : "a", |
| 1736 | le32_to_cpu(notif->tsf_high), |
| 1737 | le32_to_cpu(notif->tsf_low), |
| 1738 | le32_to_cpu(notif->statistics[0]), |
| 1739 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 1740 | jiffies_to_msecs(elapsed_jiffies |
| 1741 | (priv->last_scan_jiffies, jiffies))); |
| 1742 | |
| 1743 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 1744 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1748 | static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1749 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1750 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1751 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1752 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1753 | |
| 1754 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 1755 | scan_notif->scanned_channels, |
| 1756 | scan_notif->tsf_low, |
| 1757 | scan_notif->tsf_high, scan_notif->status); |
| 1758 | |
| 1759 | /* The HW is no longer scanning */ |
| 1760 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 1761 | |
| 1762 | /* The scan completion notification came in, so kill that timer... */ |
| 1763 | cancel_delayed_work(&priv->scan_check); |
| 1764 | |
| 1765 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 1766 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 1767 | jiffies_to_msecs(elapsed_jiffies |
| 1768 | (priv->scan_pass_start, jiffies))); |
| 1769 | |
| 1770 | /* Remove this scanned band from the list |
| 1771 | * of pending bands to scan */ |
| 1772 | priv->scan_bands--; |
| 1773 | |
| 1774 | /* If a request to abort was given, or the scan did not succeed |
| 1775 | * then we reset the scan state machine and terminate, |
| 1776 | * re-queuing another scan if one has been requested */ |
| 1777 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1778 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 1779 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1780 | } else { |
| 1781 | /* If there are more bands on this scan pass reschedule */ |
| 1782 | if (priv->scan_bands > 0) |
| 1783 | goto reschedule; |
| 1784 | } |
| 1785 | |
| 1786 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 1787 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1788 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 1789 | |
| 1790 | clear_bit(STATUS_SCANNING, &priv->status); |
| 1791 | |
| 1792 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 1793 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 1794 | |
| 1795 | queue_work(priv->workqueue, &priv->scan_completed); |
| 1796 | |
| 1797 | return; |
| 1798 | |
| 1799 | reschedule: |
| 1800 | priv->scan_pass_start = jiffies; |
| 1801 | queue_work(priv->workqueue, &priv->request_scan); |
| 1802 | } |
| 1803 | |
| 1804 | /* Handle notification from uCode that card's power state is changing |
| 1805 | * due to software, hardware, or critical temperature RFKILL */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1806 | static void iwl4965_rx_card_state_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1807 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1808 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1809 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1810 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 1811 | unsigned long status = priv->status; |
| 1812 | |
| 1813 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 1814 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 1815 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 1816 | |
| 1817 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 1818 | RF_CARD_DISABLED)) { |
| 1819 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1820 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1821 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 1822 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1823 | if (!iwl_grab_nic_access(priv)) { |
| 1824 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1825 | priv, HBUS_TARG_MBX_C, |
| 1826 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 1827 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1828 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | if (!(flags & RXON_CARD_DISABLED)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1832 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1833 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1834 | if (!iwl_grab_nic_access(priv)) { |
| 1835 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1836 | priv, HBUS_TARG_MBX_C, |
| 1837 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 1838 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1839 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1840 | } |
| 1841 | } |
| 1842 | |
| 1843 | if (flags & RF_CARD_DISABLED) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1844 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1845 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1846 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 1847 | if (!iwl_grab_nic_access(priv)) |
| 1848 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1849 | } |
| 1850 | } |
| 1851 | |
| 1852 | if (flags & HW_CARD_DISABLED) |
| 1853 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 1854 | else |
| 1855 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 1856 | |
| 1857 | |
| 1858 | if (flags & SW_CARD_DISABLED) |
| 1859 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 1860 | else |
| 1861 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 1862 | |
| 1863 | if (!(flags & RXON_CARD_DISABLED)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1864 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1865 | |
| 1866 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 1867 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 1868 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 1869 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 1870 | queue_work(priv->workqueue, &priv->rf_kill); |
| 1871 | else |
| 1872 | wake_up_interruptible(&priv->wait_command_queue); |
| 1873 | } |
| 1874 | |
| 1875 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1876 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1877 | * |
| 1878 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 1879 | * to the host. |
| 1880 | * |
| 1881 | * This function chains into the hardware specific files for them to setup |
| 1882 | * any hardware specific handlers as well. |
| 1883 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1884 | static void iwl4965_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1885 | { |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1886 | priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1887 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 1888 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1889 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1890 | iwl4965_rx_spectrum_measure_notif; |
| 1891 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1892 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1893 | iwl4965_rx_pm_debug_statistics_notif; |
| 1894 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1895 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1896 | /* |
| 1897 | * The same handler is used for both the REPLY to a discrete |
| 1898 | * statistics request from the host as well as for the periodic |
| 1899 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1900 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1901 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
| 1902 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1903 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1904 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
| 1905 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1906 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1907 | iwl4965_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1908 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1909 | iwl4965_rx_scan_complete_notif; |
| 1910 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1911 | |
Tomas Winkler | c135475 | 2008-05-29 16:35:04 +0800 | [diff] [blame] | 1912 | priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] = |
| 1913 | iwl_rx_missed_beacon_notif; |
| 1914 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1915 | /* Set up hardware specific Rx handlers */ |
Emmanuel Grumbach | d4789ef | 2008-04-24 11:55:20 -0700 | [diff] [blame] | 1916 | priv->cfg->ops->lib->rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1917 | } |
| 1918 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1919 | /* |
| 1920 | * this should be called while priv->lock is locked |
| 1921 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1922 | static void __iwl_rx_replenish(struct iwl_priv *priv) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1923 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1924 | iwl_rx_allocate(priv); |
| 1925 | iwl_rx_queue_restock(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1929 | /** |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1930 | * iwl_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1931 | * |
| 1932 | * Uses the priv->rx_handlers callback function array to invoke |
| 1933 | * the appropriate handlers, including command responses, |
| 1934 | * frame-received notifications, and other notifications. |
| 1935 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1936 | void iwl_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1937 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1938 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1939 | struct iwl_rx_packet *pkt; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1940 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1941 | u32 r, i; |
| 1942 | int reclaim; |
| 1943 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1944 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 1945 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1946 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1947 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 1948 | * buffer that the driver may process (last buffer filled by ucode). */ |
Ron Rindjunsky | d67f548 | 2008-05-05 10:22:49 +0800 | [diff] [blame] | 1949 | r = priv->cfg->ops->lib->shared_mem_rx_idx(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1950 | i = rxq->read; |
| 1951 | |
| 1952 | /* Rx interrupt, but nothing sent from uCode */ |
| 1953 | if (i == r) |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1954 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1955 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1956 | if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1957 | fill_rx = 1; |
| 1958 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1959 | while (i != r) { |
| 1960 | rxb = rxq->queue[i]; |
| 1961 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1962 | /* 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] | 1963 | * then a bug has been introduced in the queue refilling |
| 1964 | * routines -- catch it here */ |
| 1965 | BUG_ON(rxb == NULL); |
| 1966 | |
| 1967 | rxq->queue[i] = NULL; |
| 1968 | |
| 1969 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1970 | priv->hw_params.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1971 | PCI_DMA_FROMDEVICE); |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1972 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1973 | |
| 1974 | /* Reclaim a command buffer only if this packet is a response |
| 1975 | * to a (driver-originated) command. |
| 1976 | * If the packet (e.g. Rx frame) originated from uCode, |
| 1977 | * there is no command buffer to reclaim. |
| 1978 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 1979 | * but apparently a few don't get set; catch them here. */ |
| 1980 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 1981 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1982 | (pkt->hdr.cmd != REPLY_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 1983 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1984 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 1985 | (pkt->hdr.cmd != REPLY_TX); |
| 1986 | |
| 1987 | /* Based on type of command response or notification, |
| 1988 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1989 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1990 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1991 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r, |
| 1992 | i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1993 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 1994 | } else { |
| 1995 | /* No handling needed */ |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1996 | IWL_DEBUG(IWL_DL_RX, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1997 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 1998 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 1999 | pkt->hdr.cmd); |
| 2000 | } |
| 2001 | |
| 2002 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2003 | /* Invoke any callbacks, transfer the skb to caller, and |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2004 | * fire off the (possibly) blocking iwl_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2005 | * as we reclaim the driver command queue */ |
| 2006 | if (rxb && rxb->skb) |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame^] | 2007 | iwl_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2008 | else |
| 2009 | IWL_WARNING("Claim null rxb?\n"); |
| 2010 | } |
| 2011 | |
| 2012 | /* For now we just don't re-use anything. We can tweak this |
| 2013 | * later to try and re-use notification packets and SKBs that |
| 2014 | * fail to Rx correctly */ |
| 2015 | if (rxb->skb != NULL) { |
| 2016 | priv->alloc_rxb_skb--; |
| 2017 | dev_kfree_skb_any(rxb->skb); |
| 2018 | rxb->skb = NULL; |
| 2019 | } |
| 2020 | |
| 2021 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 2022 | priv->hw_params.rx_buf_size, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 2023 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2024 | spin_lock_irqsave(&rxq->lock, flags); |
| 2025 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 2026 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 2027 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2028 | /* If there are a lot of unused frames, |
| 2029 | * restock the Rx queue so ucode wont assert. */ |
| 2030 | if (fill_rx) { |
| 2031 | count++; |
| 2032 | if (count >= 8) { |
| 2033 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2034 | __iwl_rx_replenish(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2035 | count = 0; |
| 2036 | } |
| 2037 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2038 | } |
| 2039 | |
| 2040 | /* Backtrack one entry */ |
| 2041 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2042 | iwl_rx_queue_restock(priv); |
| 2043 | } |
| 2044 | /* Convert linear signal-to-noise ratio into dB */ |
| 2045 | static u8 ratio2dB[100] = { |
| 2046 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 2047 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 2048 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 2049 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 2050 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 2051 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 2052 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 2053 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 2054 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 2055 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 2056 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 2057 | }; |
| 2058 | |
| 2059 | /* Calculates a relative dB value from a ratio of linear |
| 2060 | * (i.e. not dB) signal levels. |
| 2061 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
| 2062 | int iwl4965_calc_db_from_ratio(int sig_ratio) |
| 2063 | { |
| 2064 | /* 1000:1 or higher just report as 60 dB */ |
| 2065 | if (sig_ratio >= 1000) |
| 2066 | return 60; |
| 2067 | |
| 2068 | /* 100:1 or higher, divide by 10 and use table, |
| 2069 | * add 20 dB to make up for divide by 10 */ |
| 2070 | if (sig_ratio >= 100) |
| 2071 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 2072 | |
| 2073 | /* We shouldn't see this */ |
| 2074 | if (sig_ratio < 1) |
| 2075 | return 0; |
| 2076 | |
| 2077 | /* Use table for ratios 1:1 - 99:1 */ |
| 2078 | return (int)ratio2dB[sig_ratio]; |
| 2079 | } |
| 2080 | |
| 2081 | #define PERFECT_RSSI (-20) /* dBm */ |
| 2082 | #define WORST_RSSI (-95) /* dBm */ |
| 2083 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 2084 | |
| 2085 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 2086 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 2087 | * about formulas used below. */ |
| 2088 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) |
| 2089 | { |
| 2090 | int sig_qual; |
| 2091 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 2092 | |
| 2093 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 2094 | * as indicator; formula is (signal dbm - noise dbm). |
| 2095 | * SNR at or above 40 is a great signal (100%). |
| 2096 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 2097 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 2098 | if (noise_dbm) { |
| 2099 | if (rssi_dbm - noise_dbm >= 40) |
| 2100 | return 100; |
| 2101 | else if (rssi_dbm < noise_dbm) |
| 2102 | return 0; |
| 2103 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 2104 | |
| 2105 | /* Else use just the signal level. |
| 2106 | * This formula is a least squares fit of data points collected and |
| 2107 | * compared with a reference system that had a percentage (%) display |
| 2108 | * for signal quality. */ |
| 2109 | } else |
| 2110 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 2111 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 2112 | (RSSI_RANGE * RSSI_RANGE); |
| 2113 | |
| 2114 | if (sig_qual > 100) |
| 2115 | sig_qual = 100; |
| 2116 | else if (sig_qual < 1) |
| 2117 | sig_qual = 0; |
| 2118 | |
| 2119 | return sig_qual; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2122 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2123 | static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2124 | { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 2125 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2126 | DECLARE_MAC_BUF(mac); |
| 2127 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2128 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2129 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2130 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 2131 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 2132 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 2133 | le32_to_cpu(rxon->filter_flags)); |
| 2134 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 2135 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 2136 | rxon->ofdm_basic_rates); |
| 2137 | 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] | 2138 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 2139 | print_mac(mac, rxon->node_addr)); |
| 2140 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 2141 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2142 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 2143 | } |
| 2144 | #endif |
| 2145 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2146 | static void iwl4965_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2147 | { |
| 2148 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 2149 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2150 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2153 | /* call this function to flush any scheduled tasklet */ |
| 2154 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
| 2155 | { |
| 2156 | /* wait to make sure we flush pedding tasklet*/ |
| 2157 | synchronize_irq(priv->pci_dev->irq); |
| 2158 | tasklet_kill(&priv->irq_tasklet); |
| 2159 | } |
| 2160 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2161 | static inline void iwl4965_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2162 | { |
| 2163 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 2164 | |
| 2165 | /* disable interrupts from uCode/NIC to host */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2166 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2167 | |
| 2168 | /* acknowledge/clear/reset any interrupts still pending |
| 2169 | * from uCode or flow handler (Rx/Tx DMA) */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2170 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 2171 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2172 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 2173 | } |
| 2174 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2175 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2176 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2177 | * 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] | 2178 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2179 | static void iwl4965_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2180 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2181 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2182 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 2183 | |
| 2184 | /* Cancel currently queued command. */ |
| 2185 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 2186 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2187 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2188 | if (priv->debug_level & IWL_DL_FW_ERRORS) { |
Ester Kummer | ede0cba | 2008-05-29 16:34:46 +0800 | [diff] [blame] | 2189 | iwl_dump_nic_error_log(priv); |
Ester Kummer | 189a2b5 | 2008-05-15 13:54:18 +0800 | [diff] [blame] | 2190 | iwl_dump_nic_event_log(priv); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2191 | iwl4965_print_rx_config_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2192 | } |
| 2193 | #endif |
| 2194 | |
| 2195 | wake_up_interruptible(&priv->wait_command_queue); |
| 2196 | |
| 2197 | /* Keep the restart process from trying to send host |
| 2198 | * commands by clearing the INIT status bit */ |
| 2199 | clear_bit(STATUS_READY, &priv->status); |
| 2200 | |
| 2201 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2202 | IWL_DEBUG(IWL_DL_FW_ERRORS, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2203 | "Restarting adapter due to uCode error.\n"); |
| 2204 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2205 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2206 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 2207 | sizeof(priv->recovery_rxon)); |
| 2208 | priv->error_recovering = 1; |
| 2209 | } |
Ester Kummer | 3a1081e | 2008-05-06 11:05:14 +0800 | [diff] [blame] | 2210 | if (priv->cfg->mod_params->restart_fw) |
| 2211 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2212 | } |
| 2213 | } |
| 2214 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2215 | static void iwl4965_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2216 | { |
| 2217 | unsigned long flags; |
| 2218 | |
| 2219 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 2220 | sizeof(priv->staging_rxon)); |
| 2221 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2222 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2223 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 2224 | iwl_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2225 | |
| 2226 | spin_lock_irqsave(&priv->lock, flags); |
| 2227 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 2228 | priv->error_recovering = 0; |
| 2229 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2230 | } |
| 2231 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2232 | static void iwl4965_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2233 | { |
| 2234 | u32 inta, handled = 0; |
| 2235 | u32 inta_fh; |
| 2236 | unsigned long flags; |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2237 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2238 | u32 inta_mask; |
| 2239 | #endif |
| 2240 | |
| 2241 | spin_lock_irqsave(&priv->lock, flags); |
| 2242 | |
| 2243 | /* Ack/clear/reset pending uCode interrupts. |
| 2244 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 2245 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2246 | inta = iwl_read32(priv, CSR_INT); |
| 2247 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2248 | |
| 2249 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 2250 | * Any new interrupts that happen after this, either while we're |
| 2251 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2252 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 2253 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2254 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2255 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2256 | if (priv->debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2257 | /* just for debug */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2258 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2259 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 2260 | inta, inta_mask, inta_fh); |
| 2261 | } |
| 2262 | #endif |
| 2263 | |
| 2264 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 2265 | * atomic, make sure that inta covers all the interrupts that |
| 2266 | * we've discovered, even if FH interrupt came in just after |
| 2267 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 2268 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2269 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 2270 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2271 | inta |= CSR_INT_BIT_FH_TX; |
| 2272 | |
| 2273 | /* Now service all interrupt bits discovered above. */ |
| 2274 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 2275 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 2276 | |
| 2277 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2278 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2279 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2280 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2281 | |
| 2282 | handled |= CSR_INT_BIT_HW_ERR; |
| 2283 | |
| 2284 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2285 | |
| 2286 | return; |
| 2287 | } |
| 2288 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2289 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2290 | if (priv->debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2291 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2292 | if (inta & CSR_INT_BIT_SCD) |
| 2293 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 2294 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2295 | |
| 2296 | /* Alive notification via Rx interrupt will do the real work */ |
| 2297 | if (inta & CSR_INT_BIT_ALIVE) |
| 2298 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 2299 | } |
| 2300 | #endif |
| 2301 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2302 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2303 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2304 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2305 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 2306 | int hw_rf_kill = 0; |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2307 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2308 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 2309 | hw_rf_kill = 1; |
| 2310 | |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2311 | 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] | 2312 | hw_rf_kill ? "disable radio":"enable radio"); |
| 2313 | |
| 2314 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 2315 | * when we loaded driver, and is now set to "enable". |
| 2316 | * After we're Alive, RF_KILL gets handled by |
Reinette Chatre | 3230455 | 2008-02-15 14:34:37 -0800 | [diff] [blame] | 2317 | * iwl4965_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 2318 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 2319 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2320 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 2321 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2322 | |
| 2323 | handled |= CSR_INT_BIT_RF_KILL; |
| 2324 | } |
| 2325 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2326 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2327 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 2328 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 2329 | handled |= CSR_INT_BIT_CT_KILL; |
| 2330 | } |
| 2331 | |
| 2332 | /* Error detected by uCode */ |
| 2333 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 2334 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 2335 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2336 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2337 | handled |= CSR_INT_BIT_SW_ERR; |
| 2338 | } |
| 2339 | |
| 2340 | /* uCode wakes up after power-down sleep */ |
| 2341 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 2342 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2343 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 2344 | iwl_txq_update_write_ptr(priv, &priv->txq[0]); |
| 2345 | iwl_txq_update_write_ptr(priv, &priv->txq[1]); |
| 2346 | iwl_txq_update_write_ptr(priv, &priv->txq[2]); |
| 2347 | iwl_txq_update_write_ptr(priv, &priv->txq[3]); |
| 2348 | iwl_txq_update_write_ptr(priv, &priv->txq[4]); |
| 2349 | iwl_txq_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2350 | |
| 2351 | handled |= CSR_INT_BIT_WAKEUP; |
| 2352 | } |
| 2353 | |
| 2354 | /* All uCode command responses, including Tx command responses, |
| 2355 | * Rx "responses" (frame-received notification), and other |
| 2356 | * notifications from uCode come through here*/ |
| 2357 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2358 | iwl_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2359 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 2360 | } |
| 2361 | |
| 2362 | if (inta & CSR_INT_BIT_FH_TX) { |
| 2363 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 2364 | handled |= CSR_INT_BIT_FH_TX; |
Ron Rindjunsky | dbb983b | 2008-05-15 13:54:12 +0800 | [diff] [blame] | 2365 | /* FH finished to write, send event */ |
| 2366 | priv->ucode_write_complete = 1; |
| 2367 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | if (inta & ~handled) |
| 2371 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 2372 | |
| 2373 | if (inta & ~CSR_INI_SET_MASK) { |
| 2374 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 2375 | inta & ~CSR_INI_SET_MASK); |
| 2376 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 2377 | } |
| 2378 | |
| 2379 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2380 | /* only Re-enable if diabled by irq */ |
| 2381 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 2382 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2383 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2384 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2385 | if (priv->debug_level & (IWL_DL_ISR)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2386 | inta = iwl_read32(priv, CSR_INT); |
| 2387 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 2388 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2389 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 2390 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 2391 | } |
| 2392 | #endif |
| 2393 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2394 | } |
| 2395 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2396 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2397 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2398 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2399 | u32 inta, inta_mask; |
| 2400 | u32 inta_fh; |
| 2401 | if (!priv) |
| 2402 | return IRQ_NONE; |
| 2403 | |
| 2404 | spin_lock(&priv->lock); |
| 2405 | |
| 2406 | /* Disable (but don't clear!) interrupts here to avoid |
| 2407 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 2408 | * If we have something to service, the tasklet will re-enable ints. |
| 2409 | * 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] | 2410 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 2411 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2412 | |
| 2413 | /* Discover which interrupts are active/pending */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2414 | inta = iwl_read32(priv, CSR_INT); |
| 2415 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2416 | |
| 2417 | /* Ignore interrupt if there's nothing in NIC to service. |
| 2418 | * This may be due to IRQ shared with another device, |
| 2419 | * or due to sporadic interrupts thrown from our NIC. */ |
| 2420 | if (!inta && !inta_fh) { |
| 2421 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 2422 | goto none; |
| 2423 | } |
| 2424 | |
| 2425 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 2426 | /* Hardware disappeared. It might have already raised |
| 2427 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2428 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 2429 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 2433 | inta, inta_mask, inta_fh); |
| 2434 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2435 | inta &= ~CSR_INT_BIT_SCD; |
| 2436 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2437 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2438 | if (likely(inta || inta_fh)) |
| 2439 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2440 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 2441 | unplugged: |
| 2442 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2443 | return IRQ_HANDLED; |
| 2444 | |
| 2445 | none: |
| 2446 | /* re-enable interrupts here since we don't have anything to service. */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2447 | /* only Re-enable if diabled by irq */ |
| 2448 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 2449 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2450 | spin_unlock(&priv->lock); |
| 2451 | return IRQ_NONE; |
| 2452 | } |
| 2453 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2454 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 2455 | * sending probe req. This should be set long enough to hear probe responses |
| 2456 | * from more than one AP. */ |
| 2457 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 2458 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 2459 | |
| 2460 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 2461 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 2462 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 2463 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 2464 | * no other traffic). |
| 2465 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 2466 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 2467 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 2468 | |
| 2469 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 2470 | * Must be set longer than active dwell time. |
| 2471 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 2472 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 2473 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 2474 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 2475 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 2476 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2477 | static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2478 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2479 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2480 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2481 | return IWL_ACTIVE_DWELL_TIME_52; |
| 2482 | else |
| 2483 | return IWL_ACTIVE_DWELL_TIME_24; |
| 2484 | } |
| 2485 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2486 | static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2487 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2488 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2489 | u16 active = iwl4965_get_active_dwell_time(priv, band); |
| 2490 | u16 passive = (band != IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2491 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 2492 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 2493 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2494 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2495 | /* If we're associated, we clamp the maximum passive |
| 2496 | * dwell time to be 98% of the beacon interval (minus |
| 2497 | * 2 * channel tune time) */ |
| 2498 | passive = priv->beacon_int; |
| 2499 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 2500 | passive = IWL_PASSIVE_DWELL_BASE; |
| 2501 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 2502 | } |
| 2503 | |
| 2504 | if (passive <= active) |
| 2505 | passive = active + 1; |
| 2506 | |
| 2507 | return passive; |
| 2508 | } |
| 2509 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2510 | static int iwl4965_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2511 | enum ieee80211_band band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2512 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2513 | struct iwl4965_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2514 | { |
| 2515 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2516 | const struct ieee80211_supported_band *sband; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 2517 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2518 | u16 passive_dwell = 0; |
| 2519 | u16 active_dwell = 0; |
| 2520 | int added, i; |
| 2521 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 2522 | sband = iwl_get_hw_mode(priv, band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2523 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2524 | return 0; |
| 2525 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2526 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2527 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2528 | active_dwell = iwl4965_get_active_dwell_time(priv, band); |
| 2529 | passive_dwell = iwl4965_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2530 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2531 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 2532 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 2533 | continue; |
| 2534 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2535 | scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2536 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 2537 | ch_info = iwl_get_channel_info(priv, band, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2538 | scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2539 | if (!is_channel_valid(ch_info)) { |
| 2540 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 2541 | scan_ch->channel); |
| 2542 | continue; |
| 2543 | } |
| 2544 | |
| 2545 | if (!is_active || is_channel_passive(ch_info) || |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2546 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2547 | scan_ch->type = 0; /* passive */ |
| 2548 | else |
| 2549 | scan_ch->type = 1; /* active */ |
| 2550 | |
| 2551 | if (scan_ch->type & 1) |
| 2552 | scan_ch->type |= (direct_mask << 1); |
| 2553 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2554 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 2555 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 2556 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2557 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2558 | scan_ch->tpc.dsp_atten = 110; |
| 2559 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 2560 | |
| 2561 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2562 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2563 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 2564 | else { |
| 2565 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 2566 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2567 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 2568 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2569 | */ |
| 2570 | } |
| 2571 | |
| 2572 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 2573 | scan_ch->channel, |
| 2574 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 2575 | (scan_ch->type & 1) ? |
| 2576 | active_dwell : passive_dwell); |
| 2577 | |
| 2578 | scan_ch++; |
| 2579 | added++; |
| 2580 | } |
| 2581 | |
| 2582 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 2583 | return added; |
| 2584 | } |
| 2585 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2586 | /****************************************************************************** |
| 2587 | * |
| 2588 | * uCode download functions |
| 2589 | * |
| 2590 | ******************************************************************************/ |
| 2591 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2592 | static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2593 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2594 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 2595 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 2596 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 2597 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 2598 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 2599 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2600 | } |
| 2601 | |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 2602 | static void iwl4965_nic_start(struct iwl_priv *priv) |
| 2603 | { |
| 2604 | /* Remove all resets to allow NIC to operate */ |
| 2605 | iwl_write32(priv, CSR_RESET, 0); |
| 2606 | } |
| 2607 | |
| 2608 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2609 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2610 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2611 | * |
| 2612 | * Copy into buffers for card to fetch via bus-mastering |
| 2613 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2614 | static int iwl4965_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2615 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2616 | struct iwl4965_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2617 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2618 | const struct firmware *ucode_raw; |
Tomas Winkler | 4bf775c | 2008-03-04 18:09:31 -0800 | [diff] [blame] | 2619 | const char *name = priv->cfg->fw_name; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2620 | u8 *src; |
| 2621 | size_t len; |
| 2622 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 2623 | |
| 2624 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 2625 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2626 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 2627 | if (ret < 0) { |
| 2628 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 2629 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2630 | goto error; |
| 2631 | } |
| 2632 | |
| 2633 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 2634 | name, ucode_raw->size); |
| 2635 | |
| 2636 | /* Make sure that we got at least our header! */ |
| 2637 | if (ucode_raw->size < sizeof(*ucode)) { |
| 2638 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2639 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2640 | goto err_release; |
| 2641 | } |
| 2642 | |
| 2643 | /* Data from ucode file: header followed by uCode images */ |
| 2644 | ucode = (void *)ucode_raw->data; |
| 2645 | |
| 2646 | ver = le32_to_cpu(ucode->ver); |
| 2647 | inst_size = le32_to_cpu(ucode->inst_size); |
| 2648 | data_size = le32_to_cpu(ucode->data_size); |
| 2649 | init_size = le32_to_cpu(ucode->init_size); |
| 2650 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 2651 | boot_size = le32_to_cpu(ucode->boot_size); |
| 2652 | |
| 2653 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 2654 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 2655 | inst_size); |
| 2656 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 2657 | data_size); |
| 2658 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 2659 | init_size); |
| 2660 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 2661 | init_data_size); |
| 2662 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 2663 | boot_size); |
| 2664 | |
| 2665 | /* Verify size of file vs. image size info in file's header */ |
| 2666 | if (ucode_raw->size < sizeof(*ucode) + |
| 2667 | inst_size + data_size + init_size + |
| 2668 | init_data_size + boot_size) { |
| 2669 | |
| 2670 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 2671 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2672 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2673 | goto err_release; |
| 2674 | } |
| 2675 | |
| 2676 | /* Verify that uCode images will fit in card's SRAM */ |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 2677 | if (inst_size > priv->hw_params.max_inst_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2678 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 2679 | inst_size); |
| 2680 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2681 | goto err_release; |
| 2682 | } |
| 2683 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 2684 | if (data_size > priv->hw_params.max_data_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2685 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 2686 | data_size); |
| 2687 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2688 | goto err_release; |
| 2689 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 2690 | if (init_size > priv->hw_params.max_inst_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2691 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2692 | ("uCode init instr len %d too large to fit in\n", |
| 2693 | init_size); |
| 2694 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2695 | goto err_release; |
| 2696 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 2697 | if (init_data_size > priv->hw_params.max_data_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2698 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2699 | ("uCode init data len %d too large to fit in\n", |
| 2700 | init_data_size); |
| 2701 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2702 | goto err_release; |
| 2703 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 2704 | if (boot_size > priv->hw_params.max_bsm_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2705 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2706 | ("uCode boot instr len %d too large to fit in\n", |
| 2707 | boot_size); |
| 2708 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2709 | goto err_release; |
| 2710 | } |
| 2711 | |
| 2712 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 2713 | |
| 2714 | /* Runtime instructions and 2 copies of data: |
| 2715 | * 1) unmodified from disk |
| 2716 | * 2) backup cache for save/restore during power-downs */ |
| 2717 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2718 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2719 | |
| 2720 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2721 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2722 | |
| 2723 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2724 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2725 | |
| 2726 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2727 | if (init_size && init_data_size) { |
| 2728 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2729 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2730 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2731 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2732 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2733 | |
| 2734 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 2735 | goto err_pci_alloc; |
| 2736 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2737 | |
| 2738 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2739 | if (boot_size) { |
| 2740 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2741 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2742 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2743 | if (!priv->ucode_boot.v_addr) |
| 2744 | goto err_pci_alloc; |
| 2745 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2746 | |
| 2747 | /* Copy images into buffers for card's bus-master reads ... */ |
| 2748 | |
| 2749 | /* Runtime instructions (first block of data in file) */ |
| 2750 | src = &ucode->data[0]; |
| 2751 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2752 | 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] | 2753 | memcpy(priv->ucode_code.v_addr, src, len); |
| 2754 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 2755 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 2756 | |
| 2757 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2758 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2759 | src = &ucode->data[inst_size]; |
| 2760 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2761 | 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] | 2762 | memcpy(priv->ucode_data.v_addr, src, len); |
| 2763 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 2764 | |
| 2765 | /* Initialization instructions (3rd block) */ |
| 2766 | if (init_size) { |
| 2767 | src = &ucode->data[inst_size + data_size]; |
| 2768 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2769 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 2770 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2771 | memcpy(priv->ucode_init.v_addr, src, len); |
| 2772 | } |
| 2773 | |
| 2774 | /* Initialization data (4th block) */ |
| 2775 | if (init_data_size) { |
| 2776 | src = &ucode->data[inst_size + data_size + init_size]; |
| 2777 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2778 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 2779 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2780 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 2781 | } |
| 2782 | |
| 2783 | /* Bootstrap instructions (5th block) */ |
| 2784 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 2785 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2786 | 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] | 2787 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 2788 | |
| 2789 | /* We have our copies now, allow OS release its copies */ |
| 2790 | release_firmware(ucode_raw); |
| 2791 | return 0; |
| 2792 | |
| 2793 | err_pci_alloc: |
| 2794 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2795 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2796 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2797 | |
| 2798 | err_release: |
| 2799 | release_firmware(ucode_raw); |
| 2800 | |
| 2801 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2802 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2803 | } |
| 2804 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2805 | /** |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2806 | * iwl_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2807 | * from protocol/runtime uCode (initialization uCode's |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2808 | * Alive gets handled by iwl_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2809 | */ |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2810 | static void iwl_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2811 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 2812 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2813 | |
| 2814 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 2815 | |
| 2816 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 2817 | /* We had an error bringing up the hardware, so take it |
| 2818 | * all the way back down so we can try again */ |
| 2819 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 2820 | goto restart; |
| 2821 | } |
| 2822 | |
| 2823 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 2824 | * This is a paranoid check, because we would not have gotten the |
| 2825 | * "runtime" alive if code weren't properly loaded. */ |
Emmanuel Grumbach | b0692f2 | 2008-04-24 11:55:18 -0700 | [diff] [blame] | 2826 | if (iwl_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2827 | /* Runtime instruction load was bad; |
| 2828 | * take it all the way back down so we can try again */ |
| 2829 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 2830 | goto restart; |
| 2831 | } |
| 2832 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 2833 | iwlcore_clear_stations_table(priv); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 2834 | ret = priv->cfg->ops->lib->alive_notify(priv); |
| 2835 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2836 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 2837 | ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2838 | goto restart; |
| 2839 | } |
| 2840 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2841 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2842 | set_bit(STATUS_ALIVE, &priv->status); |
| 2843 | |
| 2844 | /* Clear out the uCode error bit if it is set */ |
| 2845 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 2846 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 2847 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2848 | return; |
| 2849 | |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 2850 | ieee80211_wake_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2851 | |
| 2852 | priv->active_rate = priv->rates_mask; |
| 2853 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 2854 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2855 | if (iwl_is_associated(priv)) { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 2856 | struct iwl_rxon_cmd *active_rxon = |
| 2857 | (struct iwl_rxon_cmd *)&priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2858 | |
| 2859 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 2860 | sizeof(priv->staging_rxon)); |
| 2861 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 2862 | } else { |
| 2863 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2864 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2865 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2866 | } |
| 2867 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2868 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2869 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2870 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2871 | iwl_reset_run_time_calib(priv); |
| 2872 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2873 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2874 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2875 | |
| 2876 | /* At this point, the NIC is initialized and operational */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2877 | iwl4965_rf_kill_ct_config(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2878 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 2879 | iwl_leds_register(priv); |
| 2880 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2881 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 2882 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2883 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2884 | |
| 2885 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2886 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2887 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 2888 | iwlcore_low_level_notify(priv, IWLCORE_START_EVT); |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 2889 | ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2890 | return; |
| 2891 | |
| 2892 | restart: |
| 2893 | queue_work(priv->workqueue, &priv->restart); |
| 2894 | } |
| 2895 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2896 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2897 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2898 | static void __iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2899 | { |
| 2900 | unsigned long flags; |
| 2901 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2902 | |
| 2903 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 2904 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2905 | if (!exit_pending) |
| 2906 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 2907 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2908 | iwl_leds_unregister(priv); |
| 2909 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 2910 | iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT); |
| 2911 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 2912 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2913 | |
| 2914 | /* Unblock any waiting calls */ |
| 2915 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 2916 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2917 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 2918 | * exiting the module */ |
| 2919 | if (!exit_pending) |
| 2920 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 2921 | |
| 2922 | /* stop and reset the on-board processor */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2923 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2924 | |
| 2925 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2926 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2927 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2928 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2929 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2930 | |
| 2931 | if (priv->mac80211_registered) |
| 2932 | ieee80211_stop_queues(priv->hw); |
| 2933 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2934 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2935 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 2936 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2937 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 2938 | STATUS_RF_KILL_HW | |
| 2939 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 2940 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 2941 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 2942 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2943 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 2944 | STATUS_IN_SUSPEND; |
| 2945 | goto exit; |
| 2946 | } |
| 2947 | |
| 2948 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 2949 | * SUSPEND bits and continue taking the NIC down. */ |
| 2950 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 2951 | STATUS_RF_KILL_HW | |
| 2952 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 2953 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 2954 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 2955 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2956 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 2957 | STATUS_IN_SUSPEND | |
| 2958 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 2959 | STATUS_FW_ERROR; |
| 2960 | |
| 2961 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2962 | iwl_clear_bit(priv, CSR_GP_CNTRL, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2963 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2964 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2965 | |
Tomas Winkler | da1bc45 | 2008-05-29 16:35:00 +0800 | [diff] [blame] | 2966 | iwl_txq_ctx_stop(priv); |
Tomas Winkler | b3bbacb | 2008-05-29 16:35:01 +0800 | [diff] [blame] | 2967 | iwl_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2968 | |
| 2969 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2970 | if (!iwl_grab_nic_access(priv)) { |
| 2971 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2972 | APMG_CLK_VAL_DMA_CLK_RQT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2973 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2974 | } |
| 2975 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2976 | |
| 2977 | udelay(5); |
| 2978 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 2979 | /* FIXME: apm_ops.suspend(priv) */ |
| 2980 | priv->cfg->ops->lib->apm_ops.reset(priv); |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 2981 | priv->cfg->ops->lib->free_shared_mem(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2982 | |
| 2983 | exit: |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 2984 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2985 | |
| 2986 | if (priv->ibss_beacon) |
| 2987 | dev_kfree_skb(priv->ibss_beacon); |
| 2988 | priv->ibss_beacon = NULL; |
| 2989 | |
| 2990 | /* clear out any free frames */ |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 2991 | iwl_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2992 | } |
| 2993 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2994 | static void iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2995 | { |
| 2996 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2997 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2998 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 2999 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3000 | iwl4965_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3001 | } |
| 3002 | |
| 3003 | #define MAX_HW_RESTARTS 5 |
| 3004 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3005 | static int __iwl4965_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3006 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3007 | int i; |
| 3008 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3009 | |
| 3010 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 3011 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 3012 | return -EIO; |
| 3013 | } |
| 3014 | |
| 3015 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 3016 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 3017 | "parameter)\n"); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3018 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3019 | return -ENODEV; |
| 3020 | } |
| 3021 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 3022 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 3023 | IWL_ERROR("ucode not available for device bringup\n"); |
| 3024 | return -EIO; |
| 3025 | } |
| 3026 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3027 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3028 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3029 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 3030 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3031 | else { |
| 3032 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3033 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3034 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3035 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 3036 | return -ENODEV; |
| 3037 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3038 | } |
| 3039 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3040 | iwl_rfkill_set_hw_state(priv); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3041 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3042 | |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 3043 | ret = priv->cfg->ops->lib->alloc_shared_mem(priv); |
| 3044 | if (ret) { |
| 3045 | IWL_ERROR("Unable to allocate shared memory\n"); |
| 3046 | return ret; |
| 3047 | } |
| 3048 | |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 3049 | ret = iwl_hw_nic_init(priv); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3050 | if (ret) { |
| 3051 | IWL_ERROR("Unable to init nic\n"); |
| 3052 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3053 | } |
| 3054 | |
| 3055 | /* make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3056 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 3057 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3058 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 3059 | |
| 3060 | /* clear (again), then enable host interrupts */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3061 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3062 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3063 | |
| 3064 | /* really make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3065 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 3066 | 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] | 3067 | |
| 3068 | /* Copy original ucode data image from disk into backup cache. |
| 3069 | * This will be used to initialize the on-board processor's |
| 3070 | * data SRAM for a clean start when the runtime program first loads. */ |
| 3071 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3072 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3073 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3074 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 3075 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3076 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3077 | |
| 3078 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 3079 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3080 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3081 | |
| 3082 | /* load bootstrap state machine, |
| 3083 | * load bootstrap program into processor's memory, |
| 3084 | * prepare to load the "initialize" uCode */ |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3085 | ret = priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3086 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3087 | if (ret) { |
| 3088 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3089 | continue; |
| 3090 | } |
| 3091 | |
| 3092 | /* start card; "initialize" will load runtime ucode */ |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 3093 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3094 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3095 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 3096 | |
| 3097 | return 0; |
| 3098 | } |
| 3099 | |
| 3100 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3101 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3102 | |
| 3103 | /* tried to restart and config the device for as long as our |
| 3104 | * patience could withstand */ |
| 3105 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 3106 | return -EIO; |
| 3107 | } |
| 3108 | |
| 3109 | |
| 3110 | /***************************************************************************** |
| 3111 | * |
| 3112 | * Workqueue callbacks |
| 3113 | * |
| 3114 | *****************************************************************************/ |
| 3115 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3116 | static void iwl_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3117 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3118 | struct iwl_priv *priv = |
| 3119 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3120 | |
| 3121 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3122 | return; |
| 3123 | |
| 3124 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | f3ccc08 | 2008-05-05 10:22:45 +0800 | [diff] [blame] | 3125 | priv->cfg->ops->lib->init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3126 | mutex_unlock(&priv->mutex); |
| 3127 | } |
| 3128 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3129 | static void iwl_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3130 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3131 | struct iwl_priv *priv = |
| 3132 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3133 | |
| 3134 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3135 | return; |
| 3136 | |
| 3137 | mutex_lock(&priv->mutex); |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3138 | iwl_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3139 | mutex_unlock(&priv->mutex); |
| 3140 | } |
| 3141 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3142 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3143 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3144 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3145 | |
| 3146 | wake_up_interruptible(&priv->wait_command_queue); |
| 3147 | |
| 3148 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3149 | return; |
| 3150 | |
| 3151 | mutex_lock(&priv->mutex); |
| 3152 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3153 | if (!iwl_is_rfkill(priv)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3154 | IWL_DEBUG(IWL_DL_RF_KILL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3155 | "HW and/or SW RF Kill no longer active, restarting " |
| 3156 | "device\n"); |
| 3157 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3158 | queue_work(priv->workqueue, &priv->restart); |
| 3159 | } else { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3160 | /* make sure mac80211 stop sending Tx frame */ |
| 3161 | if (priv->mac80211_registered) |
| 3162 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3163 | |
| 3164 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 3165 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 3166 | "disabled by SW switch\n"); |
| 3167 | else |
| 3168 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 3169 | "Kill switch must be turned off for " |
| 3170 | "wireless networking to work.\n"); |
| 3171 | } |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3172 | iwl_rfkill_set_hw_state(priv); |
| 3173 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3174 | mutex_unlock(&priv->mutex); |
| 3175 | } |
| 3176 | |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 3177 | static void iwl4965_bg_set_monitor(struct work_struct *work) |
| 3178 | { |
| 3179 | struct iwl_priv *priv = container_of(work, |
| 3180 | struct iwl_priv, set_monitor); |
| 3181 | |
| 3182 | IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n"); |
| 3183 | |
| 3184 | mutex_lock(&priv->mutex); |
| 3185 | |
| 3186 | if (!iwl_is_ready(priv)) |
| 3187 | IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n"); |
| 3188 | else |
| 3189 | if (iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR) != 0) |
| 3190 | IWL_ERROR("iwl4965_set_mode() failed\n"); |
| 3191 | |
| 3192 | mutex_unlock(&priv->mutex); |
| 3193 | } |
| 3194 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3195 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 3196 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3197 | static void iwl4965_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3198 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3199 | struct iwl_priv *priv = |
| 3200 | container_of(data, struct iwl_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3201 | |
| 3202 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3203 | return; |
| 3204 | |
| 3205 | mutex_lock(&priv->mutex); |
| 3206 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 3207 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3208 | IWL_DEBUG(IWL_DL_SCAN, "Scan completion watchdog resetting " |
| 3209 | "adapter (%dms)\n", |
| 3210 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3211 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3212 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3213 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3214 | } |
| 3215 | mutex_unlock(&priv->mutex); |
| 3216 | } |
| 3217 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3218 | static void iwl4965_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3219 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3220 | struct iwl_priv *priv = |
| 3221 | container_of(data, struct iwl_priv, request_scan); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3222 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3223 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3224 | .len = sizeof(struct iwl4965_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3225 | .meta.flags = CMD_SIZE_HUGE, |
| 3226 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3227 | struct iwl4965_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3228 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3229 | u16 cmd_len; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3230 | enum ieee80211_band band; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3231 | u8 direct_mask; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3232 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3233 | |
| 3234 | conf = ieee80211_get_hw_conf(priv->hw); |
| 3235 | |
| 3236 | mutex_lock(&priv->mutex); |
| 3237 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3238 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3239 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 3240 | goto done; |
| 3241 | } |
| 3242 | |
| 3243 | /* Make sure the scan wasn't cancelled before this queued work |
| 3244 | * was given the chance to run... */ |
| 3245 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 3246 | goto done; |
| 3247 | |
| 3248 | /* This should never be called or scheduled if there is currently |
| 3249 | * a scan active in the hardware. */ |
| 3250 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 3251 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 3252 | "Ignoring second request.\n"); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3253 | ret = -EIO; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3254 | goto done; |
| 3255 | } |
| 3256 | |
| 3257 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 3258 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 3259 | goto done; |
| 3260 | } |
| 3261 | |
| 3262 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 3263 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 3264 | goto done; |
| 3265 | } |
| 3266 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3267 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3268 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 3269 | goto done; |
| 3270 | } |
| 3271 | |
| 3272 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 3273 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 3274 | goto done; |
| 3275 | } |
| 3276 | |
| 3277 | if (!priv->scan_bands) { |
| 3278 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 3279 | goto done; |
| 3280 | } |
| 3281 | |
| 3282 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3283 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3284 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 3285 | if (!priv->scan) { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3286 | ret = -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3287 | goto done; |
| 3288 | } |
| 3289 | } |
| 3290 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3291 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3292 | |
| 3293 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 3294 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 3295 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3296 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3297 | u16 interval = 0; |
| 3298 | u32 extra; |
| 3299 | u32 suspend_time = 100; |
| 3300 | u32 scan_suspend_time = 100; |
| 3301 | unsigned long flags; |
| 3302 | |
| 3303 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 3304 | |
| 3305 | spin_lock_irqsave(&priv->lock, flags); |
| 3306 | interval = priv->beacon_int; |
| 3307 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3308 | |
| 3309 | scan->suspend_time = 0; |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3310 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3311 | if (!interval) |
| 3312 | interval = suspend_time; |
| 3313 | |
| 3314 | extra = (suspend_time / interval) << 22; |
| 3315 | scan_suspend_time = (extra | |
| 3316 | ((suspend_time % interval) * 1024)); |
| 3317 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 3318 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 3319 | scan_suspend_time, interval); |
| 3320 | } |
| 3321 | |
| 3322 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 3323 | if (priv->one_direct_scan) { |
| 3324 | IWL_DEBUG_SCAN |
| 3325 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3326 | iwl4965_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3327 | priv->direct_ssid_len)); |
| 3328 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 3329 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 3330 | memcpy(scan->direct_scan[0].ssid, |
| 3331 | priv->direct_ssid, priv->direct_ssid_len); |
| 3332 | direct_mask = 1; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3333 | } else if (!iwl_is_associated(priv) && priv->essid_len) { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3334 | IWL_DEBUG_SCAN |
| 3335 | ("Kicking off one direct scan for '%s' when not associated\n", |
| 3336 | iwl4965_escape_essid(priv->essid, priv->essid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3337 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 3338 | scan->direct_scan[0].len = priv->essid_len; |
| 3339 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 3340 | direct_mask = 1; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3341 | } else { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3342 | IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3343 | direct_mask = 0; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3344 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3345 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3346 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3347 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3348 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 3349 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3350 | |
| 3351 | switch (priv->scan_bands) { |
| 3352 | case 2: |
| 3353 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 3354 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3355 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3356 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 3357 | |
| 3358 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3359 | band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3360 | break; |
| 3361 | |
| 3362 | case 1: |
| 3363 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3364 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3365 | RATE_MCS_ANT_B_MSK); |
| 3366 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3367 | band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3368 | break; |
| 3369 | |
| 3370 | default: |
| 3371 | IWL_WARNING("Invalid scan band count\n"); |
| 3372 | goto done; |
| 3373 | } |
| 3374 | |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3375 | /* We don't build a direct scan probe request; the uCode will do |
| 3376 | * that based on the direct_mask added to each channel entry */ |
| 3377 | cmd_len = iwl4965_fill_probe_req(priv, band, |
| 3378 | (struct ieee80211_mgmt *)scan->data, |
| 3379 | IWL_MAX_SCAN_SIZE - sizeof(*scan), 0); |
| 3380 | |
| 3381 | scan->tx_cmd.len = cpu_to_le16(cmd_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3382 | /* select Rx chains */ |
| 3383 | |
| 3384 | /* Force use of chains B and C (0x6) for scan Rx. |
| 3385 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 3386 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 3387 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 3388 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 3389 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 3390 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 3391 | |
| 3392 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 3393 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 3394 | |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3395 | if (direct_mask) |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 3396 | scan->channel_count = |
| 3397 | iwl4965_get_channels_for_scan( |
| 3398 | priv, band, 1, /* active */ |
| 3399 | direct_mask, |
| 3400 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3401 | else |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 3402 | scan->channel_count = |
| 3403 | iwl4965_get_channels_for_scan( |
| 3404 | priv, band, 0, /* passive */ |
| 3405 | direct_mask, |
| 3406 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3407 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 3408 | scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | |
| 3409 | RXON_FILTER_BCON_AWARE_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3410 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3411 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3412 | cmd.data = scan; |
| 3413 | scan->len = cpu_to_le16(cmd.len); |
| 3414 | |
| 3415 | set_bit(STATUS_SCAN_HW, &priv->status); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3416 | ret = iwl_send_cmd_sync(priv, &cmd); |
| 3417 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3418 | goto done; |
| 3419 | |
| 3420 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 3421 | IWL_SCAN_CHECK_WATCHDOG); |
| 3422 | |
| 3423 | mutex_unlock(&priv->mutex); |
| 3424 | return; |
| 3425 | |
| 3426 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3427 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3428 | queue_work(priv->workqueue, &priv->scan_completed); |
| 3429 | mutex_unlock(&priv->mutex); |
| 3430 | } |
| 3431 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3432 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3433 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3434 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3435 | |
| 3436 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3437 | return; |
| 3438 | |
| 3439 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3440 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3441 | mutex_unlock(&priv->mutex); |
| 3442 | } |
| 3443 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3444 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3445 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3446 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3447 | |
| 3448 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3449 | return; |
| 3450 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3451 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3452 | queue_work(priv->workqueue, &priv->up); |
| 3453 | } |
| 3454 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3455 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3456 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3457 | struct iwl_priv *priv = |
| 3458 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3459 | |
| 3460 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3461 | return; |
| 3462 | |
| 3463 | mutex_lock(&priv->mutex); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3464 | iwl_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3465 | mutex_unlock(&priv->mutex); |
| 3466 | } |
| 3467 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3468 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 3469 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3470 | static void iwl4965_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3471 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3472 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3473 | int ret = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3474 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3475 | |
| 3476 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 3477 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 3478 | return; |
| 3479 | } |
| 3480 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3481 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 3482 | priv->assoc_id, |
| 3483 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3484 | |
| 3485 | |
| 3486 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3487 | return; |
| 3488 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3489 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3490 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 3491 | return; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3492 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3493 | iwl4965_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3494 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3495 | conf = ieee80211_get_hw_conf(priv->hw); |
| 3496 | |
| 3497 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3498 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3499 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3500 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 3501 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3502 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3503 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3504 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3505 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 3506 | "Attempting to continue.\n"); |
| 3507 | |
| 3508 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 3509 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3510 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 3511 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 3512 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3513 | #endif /* CONFIG_IWL4965_HT*/ |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 3514 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3515 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 3516 | |
| 3517 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 3518 | priv->assoc_id, priv->beacon_int); |
| 3519 | |
| 3520 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 3521 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3522 | else |
| 3523 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3524 | |
| 3525 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 3526 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 3527 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 3528 | else |
| 3529 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 3530 | |
| 3531 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 3532 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 3533 | |
| 3534 | } |
| 3535 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3536 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3537 | |
| 3538 | switch (priv->iw_mode) { |
| 3539 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3540 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3541 | break; |
| 3542 | |
| 3543 | case IEEE80211_IF_TYPE_IBSS: |
| 3544 | |
| 3545 | /* clear out the station table */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3546 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3547 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 3548 | iwl_rxon_add_station(priv, iwl_bcast_addr, 0); |
| 3549 | iwl_rxon_add_station(priv, priv->bssid, 0); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3550 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
| 3551 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3552 | |
| 3553 | break; |
| 3554 | |
| 3555 | default: |
| 3556 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 3557 | __FUNCTION__, priv->iw_mode); |
| 3558 | break; |
| 3559 | } |
| 3560 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3561 | iwl4965_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3562 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3563 | /* Enable Rx differential gain and sensitivity calibrations */ |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 3564 | iwl_chain_noise_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3565 | priv->start_calib = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3566 | |
| 3567 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 3568 | priv->assoc_station_added = 1; |
| 3569 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3570 | iwl4965_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 3571 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 3572 | iwl_power_update_mode(priv, 0); |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3573 | /* we have just associated, don't start scan too early */ |
| 3574 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | |
| 3578 | static void iwl4965_bg_post_associate(struct work_struct *data) |
| 3579 | { |
| 3580 | struct iwl_priv *priv = container_of(data, struct iwl_priv, |
| 3581 | post_associate.work); |
| 3582 | |
| 3583 | mutex_lock(&priv->mutex); |
| 3584 | iwl4965_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3585 | mutex_unlock(&priv->mutex); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3586 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3587 | } |
| 3588 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3589 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
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 = container_of(work, struct iwl_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3592 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3593 | if (!iwl_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3594 | return; |
| 3595 | |
| 3596 | mutex_lock(&priv->mutex); |
| 3597 | |
| 3598 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3599 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3600 | |
| 3601 | mutex_unlock(&priv->mutex); |
| 3602 | } |
| 3603 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3604 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 3605 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3606 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3607 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3608 | struct iwl_priv *priv = |
| 3609 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3610 | |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3611 | IWL_DEBUG(IWL_DL_SCAN, "SCAN complete scan\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3612 | |
| 3613 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3614 | return; |
| 3615 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 3616 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
| 3617 | iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3618 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3619 | ieee80211_scan_completed(priv->hw); |
| 3620 | |
| 3621 | /* Since setting the TXPOWER may have been deferred while |
| 3622 | * performing the scan, fire one off */ |
| 3623 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3624 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3625 | mutex_unlock(&priv->mutex); |
| 3626 | } |
| 3627 | |
| 3628 | /***************************************************************************** |
| 3629 | * |
| 3630 | * mac80211 entry point functions |
| 3631 | * |
| 3632 | *****************************************************************************/ |
| 3633 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3634 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 3635 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3636 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3637 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3638 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3639 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3640 | |
| 3641 | IWL_DEBUG_MAC80211("enter\n"); |
| 3642 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3643 | if (pci_enable_device(priv->pci_dev)) { |
| 3644 | IWL_ERROR("Fail to pci_enable_device\n"); |
| 3645 | return -ENODEV; |
| 3646 | } |
| 3647 | pci_restore_state(priv->pci_dev); |
| 3648 | pci_enable_msi(priv->pci_dev); |
| 3649 | |
| 3650 | ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, |
| 3651 | DRV_NAME, priv); |
| 3652 | if (ret) { |
| 3653 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 3654 | goto out_disable_msi; |
| 3655 | } |
| 3656 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3657 | /* we should be verifying the device is ready to be opened */ |
| 3658 | mutex_lock(&priv->mutex); |
| 3659 | |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 3660 | memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd)); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3661 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 3662 | * ucode filename and max sizes are card-specific. */ |
| 3663 | |
| 3664 | if (!priv->ucode_code.len) { |
| 3665 | ret = iwl4965_read_ucode(priv); |
| 3666 | if (ret) { |
| 3667 | IWL_ERROR("Could not read microcode: %d\n", ret); |
| 3668 | mutex_unlock(&priv->mutex); |
| 3669 | goto out_release_irq; |
| 3670 | } |
| 3671 | } |
| 3672 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3673 | ret = __iwl4965_up(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3674 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3675 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3676 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3677 | if (ret) |
| 3678 | goto out_release_irq; |
| 3679 | |
| 3680 | IWL_DEBUG_INFO("Start UP work done.\n"); |
| 3681 | |
| 3682 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 3683 | return 0; |
| 3684 | |
Ron Rindjunsky | fe9b6b7 | 2008-05-29 16:35:06 +0800 | [diff] [blame] | 3685 | /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3686 | * mac80211 will not be run successfully. */ |
Ron Rindjunsky | fe9b6b7 | 2008-05-29 16:35:06 +0800 | [diff] [blame] | 3687 | if (priv->ucode_type == UCODE_RT) { |
| 3688 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 3689 | test_bit(STATUS_READY, &priv->status), |
| 3690 | UCODE_READY_TIMEOUT); |
| 3691 | if (!ret) { |
| 3692 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 3693 | IWL_ERROR("START_ALIVE timeout after %dms.\n", |
| 3694 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 3695 | ret = -ETIMEDOUT; |
| 3696 | goto out_release_irq; |
| 3697 | } |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3698 | } |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3699 | |
Ron Rindjunsky | fe9b6b7 | 2008-05-29 16:35:06 +0800 | [diff] [blame] | 3700 | priv->is_open = 1; |
| 3701 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3702 | IWL_DEBUG_MAC80211("leave\n"); |
| 3703 | return 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3704 | |
| 3705 | out_release_irq: |
| 3706 | free_irq(priv->pci_dev->irq, priv); |
| 3707 | out_disable_msi: |
| 3708 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3709 | pci_disable_device(priv->pci_dev); |
| 3710 | priv->is_open = 0; |
| 3711 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3712 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3713 | } |
| 3714 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3715 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3716 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3717 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3718 | |
| 3719 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 3720 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3721 | if (!priv->is_open) { |
| 3722 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 3723 | return; |
| 3724 | } |
| 3725 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3726 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3727 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3728 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3729 | /* stop mac, cancel any scan request and clear |
| 3730 | * RXON_FILTER_ASSOC_MSK BIT |
| 3731 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3732 | mutex_lock(&priv->mutex); |
| 3733 | iwl4965_scan_cancel_timeout(priv, 100); |
| 3734 | cancel_delayed_work(&priv->post_associate); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 3735 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 3736 | } |
| 3737 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3738 | iwl4965_down(priv); |
| 3739 | |
| 3740 | flush_workqueue(priv->workqueue); |
| 3741 | free_irq(priv->pci_dev->irq, priv); |
| 3742 | pci_disable_msi(priv->pci_dev); |
| 3743 | pci_save_state(priv->pci_dev); |
| 3744 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 3745 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3746 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3747 | } |
| 3748 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 3749 | 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] | 3750 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3751 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3752 | |
| 3753 | IWL_DEBUG_MAC80211("enter\n"); |
| 3754 | |
| 3755 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 3756 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 3757 | return -1; |
| 3758 | } |
| 3759 | |
| 3760 | 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] | 3761 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3762 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 3763 | if (iwl_tx_skb(priv, skb)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3764 | dev_kfree_skb_any(skb); |
| 3765 | |
| 3766 | IWL_DEBUG_MAC80211("leave\n"); |
| 3767 | return 0; |
| 3768 | } |
| 3769 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3770 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3771 | struct ieee80211_if_init_conf *conf) |
| 3772 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3773 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3774 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3775 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3776 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3777 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3778 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3779 | if (priv->vif) { |
| 3780 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Reinette Chatre | 75849d2 | 2008-01-23 10:15:17 -0800 | [diff] [blame] | 3781 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3785 | priv->vif = conf->vif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3786 | |
| 3787 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3788 | |
| 3789 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 3790 | |
| 3791 | if (conf->mac_addr) { |
| 3792 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 3793 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 3794 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3795 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3796 | if (iwl_is_ready(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3797 | iwl4965_set_mode(priv, conf->type); |
| 3798 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3799 | mutex_unlock(&priv->mutex); |
| 3800 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3801 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3802 | return 0; |
| 3803 | } |
| 3804 | |
| 3805 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3806 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3807 | * |
| 3808 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 3809 | * be set inappropriately and the driver currently sets the hardware up to |
| 3810 | * use it whenever needed. |
| 3811 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3812 | 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] | 3813 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3814 | struct iwl_priv *priv = hw->priv; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3815 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3816 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3817 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3818 | |
| 3819 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3820 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3821 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 3822 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
| 3823 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3824 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3825 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3826 | ret = -EIO; |
| 3827 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3828 | } |
| 3829 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 3830 | if (unlikely(!priv->cfg->mod_params->disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3831 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 3832 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 3833 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3834 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 3835 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3836 | } |
| 3837 | |
| 3838 | spin_lock_irqsave(&priv->lock, flags); |
| 3839 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 3840 | ch_info = iwl_get_channel_info(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3841 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3842 | if (!is_channel_valid(ch_info)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3843 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 3844 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3845 | ret = -EINVAL; |
| 3846 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3847 | } |
| 3848 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3849 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3850 | /* if we are switching from ht to 2.4 clear flags |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3851 | * from any ht related info since 2.4 does not |
| 3852 | * support ht */ |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3853 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3854 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 3855 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 3856 | #endif |
| 3857 | ) |
| 3858 | priv->staging_rxon.flags = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3859 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3860 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 3861 | iwl_set_rxon_channel(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3862 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3863 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3864 | iwl4965_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3865 | |
| 3866 | /* The list of supported rates and rate mask can be different |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3867 | * for each band; since the band may have changed, reset |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3868 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3869 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3870 | |
| 3871 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3872 | |
| 3873 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 3874 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3875 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3876 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3877 | } |
| 3878 | #endif |
| 3879 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3880 | if (priv->cfg->ops->lib->radio_kill_sw) |
| 3881 | priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3882 | |
| 3883 | if (!conf->radio_enabled) { |
| 3884 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3885 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3886 | } |
| 3887 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3888 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3889 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3890 | ret = -EIO; |
| 3891 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3892 | } |
| 3893 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3894 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3895 | |
| 3896 | if (memcmp(&priv->active_rxon, |
| 3897 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3898 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3899 | else |
| 3900 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 3901 | |
| 3902 | IWL_DEBUG_MAC80211("leave\n"); |
| 3903 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 3904 | out: |
| 3905 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3906 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3907 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3910 | static void iwl4965_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3911 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3912 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3913 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 3914 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3915 | return; |
| 3916 | |
| 3917 | /* The following should be done only at AP bring up */ |
| 3918 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 3919 | |
| 3920 | /* RXON - unassoc (to set timing command) */ |
| 3921 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3922 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3923 | |
| 3924 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3925 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 3926 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3927 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3928 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3929 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3930 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 3931 | "Attempting to continue.\n"); |
| 3932 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 3933 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3934 | |
| 3935 | /* FIXME: what should be the assoc_id for AP? */ |
| 3936 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 3937 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 3938 | priv->staging_rxon.flags |= |
| 3939 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3940 | else |
| 3941 | priv->staging_rxon.flags &= |
| 3942 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3943 | |
| 3944 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 3945 | if (priv->assoc_capability & |
| 3946 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 3947 | priv->staging_rxon.flags |= |
| 3948 | RXON_FLG_SHORT_SLOT_MSK; |
| 3949 | else |
| 3950 | priv->staging_rxon.flags &= |
| 3951 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 3952 | |
| 3953 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 3954 | priv->staging_rxon.flags &= |
| 3955 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 3956 | } |
| 3957 | /* restore RXON assoc */ |
| 3958 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3959 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3960 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 3961 | iwl_rxon_add_station(priv, iwl_bcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 3962 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3963 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3964 | |
| 3965 | /* FIXME - we need to add code here to detect a totally new |
| 3966 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 3967 | * clear sta table, add BCAST sta... */ |
| 3968 | } |
| 3969 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3970 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, |
| 3971 | struct ieee80211_vif *vif, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3972 | struct ieee80211_if_conf *conf) |
| 3973 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3974 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3975 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3976 | unsigned long flags; |
| 3977 | int rc; |
| 3978 | |
| 3979 | if (conf == NULL) |
| 3980 | return -EIO; |
| 3981 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 3982 | if (priv->vif != vif) { |
| 3983 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 3984 | return 0; |
| 3985 | } |
| 3986 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3987 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 3988 | (!conf->beacon || !conf->ssid_len)) { |
| 3989 | IWL_DEBUG_MAC80211 |
| 3990 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 3991 | return 0; |
| 3992 | } |
| 3993 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3994 | if (!iwl_is_alive(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3995 | return -EAGAIN; |
| 3996 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3997 | mutex_lock(&priv->mutex); |
| 3998 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3999 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4000 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 4001 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4002 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4003 | /* |
| 4004 | * very dubious code was here; the probe filtering flag is never set: |
| 4005 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4006 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 4007 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4008 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4009 | |
| 4010 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 4011 | if (!conf->bssid) { |
| 4012 | conf->bssid = priv->mac_addr; |
| 4013 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4014 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 4015 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4016 | } |
| 4017 | if (priv->ibss_beacon) |
| 4018 | dev_kfree_skb(priv->ibss_beacon); |
| 4019 | |
| 4020 | priv->ibss_beacon = conf->beacon; |
| 4021 | } |
| 4022 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4023 | if (iwl_is_rfkill(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4024 | goto done; |
| 4025 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4026 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 4027 | !is_multicast_ether_addr(conf->bssid)) { |
| 4028 | /* If there is currently a HW scan going on in the background |
| 4029 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4030 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4031 | IWL_WARNING("Aborted scan still in progress " |
| 4032 | "after 100ms\n"); |
| 4033 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 4034 | mutex_unlock(&priv->mutex); |
| 4035 | return -EAGAIN; |
| 4036 | } |
| 4037 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 4038 | |
| 4039 | /* TODO: Audit driver for usage of these members and see |
| 4040 | * if mac80211 deprecates them (priv->bssid looks like it |
| 4041 | * shouldn't be there, but I haven't scanned the IBSS code |
| 4042 | * to verify) - jpk */ |
| 4043 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 4044 | |
| 4045 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4046 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4047 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4048 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4049 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 4050 | iwl_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4051 | priv, priv->active_rxon.bssid_addr, 1); |
| 4052 | } |
| 4053 | |
| 4054 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4055 | iwl4965_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4056 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4057 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4058 | } |
| 4059 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4060 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4061 | spin_lock_irqsave(&priv->lock, flags); |
| 4062 | if (!conf->ssid_len) |
| 4063 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 4064 | else |
| 4065 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 4066 | |
| 4067 | priv->essid_len = conf->ssid_len; |
| 4068 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4069 | |
| 4070 | IWL_DEBUG_MAC80211("leave\n"); |
| 4071 | mutex_unlock(&priv->mutex); |
| 4072 | |
| 4073 | return 0; |
| 4074 | } |
| 4075 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4076 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4077 | unsigned int changed_flags, |
| 4078 | unsigned int *total_flags, |
| 4079 | int mc_count, struct dev_addr_list *mc_list) |
| 4080 | { |
| 4081 | /* |
| 4082 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4083 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4084 | */ |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 4085 | struct iwl_priv *priv = hw->priv; |
| 4086 | int new_flags = 0; |
| 4087 | if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { |
| 4088 | if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { |
| 4089 | IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n", |
| 4090 | IEEE80211_IF_TYPE_MNTR, |
| 4091 | changed_flags, *total_flags); |
| 4092 | /* queue work 'cuz mac80211 is holding a lock which |
| 4093 | * prevents us from issuing (synchronous) f/w cmds */ |
| 4094 | queue_work(priv->workqueue, &priv->set_monitor); |
| 4095 | new_flags &= FIF_PROMISC_IN_BSS | |
| 4096 | FIF_OTHER_BSS | |
| 4097 | FIF_ALLMULTI; |
| 4098 | } |
| 4099 | } |
| 4100 | *total_flags = new_flags; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4101 | } |
| 4102 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4103 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4104 | struct ieee80211_if_init_conf *conf) |
| 4105 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4106 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4107 | |
| 4108 | IWL_DEBUG_MAC80211("enter\n"); |
| 4109 | |
| 4110 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4111 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4112 | if (iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4113 | iwl4965_scan_cancel_timeout(priv, 100); |
| 4114 | cancel_delayed_work(&priv->post_associate); |
| 4115 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 4116 | iwl4965_commit_rxon(priv); |
| 4117 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 4118 | if (priv->vif == conf->vif) { |
| 4119 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4120 | memset(priv->bssid, 0, ETH_ALEN); |
| 4121 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 4122 | priv->essid_len = 0; |
| 4123 | } |
| 4124 | mutex_unlock(&priv->mutex); |
| 4125 | |
| 4126 | IWL_DEBUG_MAC80211("leave\n"); |
| 4127 | |
| 4128 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4129 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4130 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4131 | static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, |
| 4132 | struct ieee80211_vif *vif, |
| 4133 | struct ieee80211_bss_conf *bss_conf, |
| 4134 | u32 changes) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4135 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4136 | struct iwl_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4137 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4138 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
| 4139 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4140 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4141 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
| 4142 | bss_conf->use_short_preamble); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4143 | if (bss_conf->use_short_preamble) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4144 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4145 | else |
| 4146 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4147 | } |
| 4148 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4149 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4150 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4151 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4152 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 4153 | else |
| 4154 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 4155 | } |
| 4156 | |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 4157 | if (changes & BSS_CHANGED_HT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4158 | IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 4159 | iwl4965_ht_conf(priv, bss_conf); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4160 | iwl_set_rxon_chain(priv); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 4161 | } |
| 4162 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4163 | if (changes & BSS_CHANGED_ASSOC) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4164 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4165 | /* This should never happen as this function should |
| 4166 | * never be called from interrupt context. */ |
| 4167 | if (WARN_ON_ONCE(in_interrupt())) |
| 4168 | return; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4169 | if (bss_conf->assoc) { |
| 4170 | priv->assoc_id = bss_conf->aid; |
| 4171 | priv->beacon_int = bss_conf->beacon_int; |
| 4172 | priv->timestamp = bss_conf->timestamp; |
| 4173 | priv->assoc_capability = bss_conf->assoc_capability; |
| 4174 | priv->next_scan_jiffies = jiffies + |
| 4175 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4176 | mutex_lock(&priv->mutex); |
| 4177 | iwl4965_post_associate(priv); |
| 4178 | mutex_unlock(&priv->mutex); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4179 | } else { |
| 4180 | priv->assoc_id = 0; |
| 4181 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); |
| 4182 | } |
| 4183 | } else if (changes && iwl_is_associated(priv) && priv->assoc_id) { |
| 4184 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 4185 | iwl_send_rxon_assoc(priv); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4186 | } |
| 4187 | |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4188 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4189 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4190 | 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] | 4191 | { |
| 4192 | int rc = 0; |
| 4193 | unsigned long flags; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4194 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4195 | |
| 4196 | IWL_DEBUG_MAC80211("enter\n"); |
| 4197 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4198 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4199 | spin_lock_irqsave(&priv->lock, flags); |
| 4200 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4201 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4202 | rc = -EIO; |
| 4203 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 4204 | goto out_unlock; |
| 4205 | } |
| 4206 | |
| 4207 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 4208 | rc = -EIO; |
| 4209 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 4210 | goto out_unlock; |
| 4211 | } |
| 4212 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4213 | /* we don't schedule scan within next_scan_jiffies period */ |
| 4214 | if (priv->next_scan_jiffies && |
| 4215 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 4216 | rc = -EAGAIN; |
| 4217 | goto out_unlock; |
| 4218 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4219 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4220 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 4221 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4222 | rc = -EAGAIN; |
| 4223 | goto out_unlock; |
| 4224 | } |
| 4225 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4226 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4227 | iwl4965_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4228 | |
| 4229 | priv->one_direct_scan = 1; |
| 4230 | priv->direct_ssid_len = (u8) |
| 4231 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 4232 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4233 | } else |
| 4234 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4235 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4236 | rc = iwl4965_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4237 | |
| 4238 | IWL_DEBUG_MAC80211("leave\n"); |
| 4239 | |
| 4240 | out_unlock: |
| 4241 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4242 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4243 | |
| 4244 | return rc; |
| 4245 | } |
| 4246 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4247 | static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 4248 | struct ieee80211_key_conf *keyconf, const u8 *addr, |
| 4249 | u32 iv32, u16 *phase1key) |
| 4250 | { |
| 4251 | struct iwl_priv *priv = hw->priv; |
| 4252 | u8 sta_id = IWL_INVALID_STATION; |
| 4253 | unsigned long flags; |
| 4254 | __le16 key_flags = 0; |
| 4255 | int i; |
| 4256 | DECLARE_MAC_BUF(mac); |
| 4257 | |
| 4258 | IWL_DEBUG_MAC80211("enter\n"); |
| 4259 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 4260 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4261 | if (sta_id == IWL_INVALID_STATION) { |
| 4262 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 4263 | print_mac(mac, addr)); |
| 4264 | return; |
| 4265 | } |
| 4266 | |
| 4267 | iwl4965_scan_cancel_timeout(priv, 100); |
| 4268 | |
| 4269 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); |
| 4270 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 4271 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 4272 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 4273 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4274 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 4275 | |
| 4276 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 4277 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4278 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 4279 | priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; |
| 4280 | |
| 4281 | for (i = 0; i < 5; i++) |
| 4282 | priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = |
| 4283 | cpu_to_le16(phase1key[i]); |
| 4284 | |
| 4285 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 4286 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 4287 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 4288 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4289 | |
| 4290 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 4291 | |
| 4292 | IWL_DEBUG_MAC80211("leave\n"); |
| 4293 | } |
| 4294 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4295 | 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] | 4296 | const u8 *local_addr, const u8 *addr, |
| 4297 | struct ieee80211_key_conf *key) |
| 4298 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4299 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4300 | DECLARE_MAC_BUF(mac); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4301 | int ret = 0; |
| 4302 | u8 sta_id = IWL_INVALID_STATION; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4303 | u8 is_default_wep_key = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4304 | |
| 4305 | IWL_DEBUG_MAC80211("enter\n"); |
| 4306 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4307 | if (priv->hw_params.sw_crypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4308 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 4309 | return -EOPNOTSUPP; |
| 4310 | } |
| 4311 | |
| 4312 | if (is_zero_ether_addr(addr)) |
| 4313 | /* only support pairwise keys */ |
| 4314 | return -EOPNOTSUPP; |
| 4315 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 4316 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4317 | if (sta_id == IWL_INVALID_STATION) { |
| 4318 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 4319 | print_mac(mac, addr)); |
| 4320 | return -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4321 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4322 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4323 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4324 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4325 | iwl4965_scan_cancel_timeout(priv, 100); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4326 | mutex_unlock(&priv->mutex); |
| 4327 | |
| 4328 | /* If we are getting WEP group key and we didn't receive any key mapping |
| 4329 | * so far, we are in legacy wep mode (group key only), otherwise we are |
| 4330 | * in 1X mode. |
| 4331 | * In legacy wep mode, we use another host command to the uCode */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 4332 | 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] | 4333 | priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 4334 | if (cmd == SET_KEY) |
| 4335 | is_default_wep_key = !priv->key_mapping_key; |
| 4336 | else |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 4337 | is_default_wep_key = |
| 4338 | (key->hw_key_idx == HW_KEY_DEFAULT); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4339 | } |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4340 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4341 | switch (cmd) { |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4342 | case SET_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4343 | if (is_default_wep_key) |
| 4344 | ret = iwl_set_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4345 | else |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 4346 | ret = iwl_set_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4347 | |
| 4348 | IWL_DEBUG_MAC80211("enable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4349 | break; |
| 4350 | case DISABLE_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4351 | if (is_default_wep_key) |
| 4352 | ret = iwl_remove_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4353 | else |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 4354 | ret = iwl_remove_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4355 | |
| 4356 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4357 | break; |
| 4358 | default: |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4359 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4360 | } |
| 4361 | |
| 4362 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4363 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4364 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4365 | } |
| 4366 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 4367 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4368 | const struct ieee80211_tx_queue_params *params) |
| 4369 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4370 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4371 | unsigned long flags; |
| 4372 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4373 | |
| 4374 | IWL_DEBUG_MAC80211("enter\n"); |
| 4375 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4376 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4377 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 4378 | return -EIO; |
| 4379 | } |
| 4380 | |
| 4381 | if (queue >= AC_NUM) { |
| 4382 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 4383 | return 0; |
| 4384 | } |
| 4385 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4386 | if (!priv->qos_data.qos_enable) { |
| 4387 | priv->qos_data.qos_active = 0; |
| 4388 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 4389 | return 0; |
| 4390 | } |
| 4391 | q = AC_NUM - 1 - queue; |
| 4392 | |
| 4393 | spin_lock_irqsave(&priv->lock, flags); |
| 4394 | |
| 4395 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 4396 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 4397 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 4398 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 4399 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4400 | |
| 4401 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 4402 | priv->qos_data.qos_active = 1; |
| 4403 | |
| 4404 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4405 | |
| 4406 | mutex_lock(&priv->mutex); |
| 4407 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4408 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4409 | else if (priv->assoc_id && iwl_is_associated(priv)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4410 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4411 | |
| 4412 | mutex_unlock(&priv->mutex); |
| 4413 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4414 | IWL_DEBUG_MAC80211("leave\n"); |
| 4415 | return 0; |
| 4416 | } |
| 4417 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4418 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4419 | struct ieee80211_tx_queue_stats *stats) |
| 4420 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4421 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4422 | int i, avail; |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 4423 | struct iwl_tx_queue *txq; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 4424 | struct iwl_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4425 | unsigned long flags; |
| 4426 | |
| 4427 | IWL_DEBUG_MAC80211("enter\n"); |
| 4428 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4429 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4430 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 4431 | return -EIO; |
| 4432 | } |
| 4433 | |
| 4434 | spin_lock_irqsave(&priv->lock, flags); |
| 4435 | |
| 4436 | for (i = 0; i < AC_NUM; i++) { |
| 4437 | txq = &priv->txq[i]; |
| 4438 | q = &txq->q; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 4439 | avail = iwl_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4440 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 4441 | stats[i].len = q->n_window - avail; |
| 4442 | stats[i].limit = q->n_window - q->high_mark; |
| 4443 | stats[i].count = q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4444 | |
| 4445 | } |
| 4446 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4447 | |
| 4448 | IWL_DEBUG_MAC80211("leave\n"); |
| 4449 | |
| 4450 | return 0; |
| 4451 | } |
| 4452 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4453 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4454 | struct ieee80211_low_level_stats *stats) |
| 4455 | { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 4456 | struct iwl_priv *priv = hw->priv; |
| 4457 | |
| 4458 | priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4459 | IWL_DEBUG_MAC80211("enter\n"); |
| 4460 | IWL_DEBUG_MAC80211("leave\n"); |
| 4461 | |
| 4462 | return 0; |
| 4463 | } |
| 4464 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4465 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4466 | { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 4467 | struct iwl_priv *priv; |
| 4468 | |
| 4469 | priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4470 | IWL_DEBUG_MAC80211("enter\n"); |
| 4471 | IWL_DEBUG_MAC80211("leave\n"); |
| 4472 | |
| 4473 | return 0; |
| 4474 | } |
| 4475 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4476 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4477 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4478 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4479 | unsigned long flags; |
| 4480 | |
| 4481 | mutex_lock(&priv->mutex); |
| 4482 | IWL_DEBUG_MAC80211("enter\n"); |
| 4483 | |
| 4484 | priv->lq_mngr.lq_ready = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4485 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4486 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 4487 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4488 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4489 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4490 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4491 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4492 | |
| 4493 | cancel_delayed_work(&priv->post_associate); |
| 4494 | |
| 4495 | spin_lock_irqsave(&priv->lock, flags); |
| 4496 | priv->assoc_id = 0; |
| 4497 | priv->assoc_capability = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4498 | priv->assoc_station_added = 0; |
| 4499 | |
| 4500 | /* new association get rid of ibss beacon skb */ |
| 4501 | if (priv->ibss_beacon) |
| 4502 | dev_kfree_skb(priv->ibss_beacon); |
| 4503 | |
| 4504 | priv->ibss_beacon = NULL; |
| 4505 | |
| 4506 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4507 | priv->timestamp = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4508 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 4509 | priv->beacon_int = 0; |
| 4510 | |
| 4511 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4512 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4513 | if (!iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4514 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 4515 | mutex_unlock(&priv->mutex); |
| 4516 | return; |
| 4517 | } |
| 4518 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4519 | /* we are restarting association process |
| 4520 | * clear RXON_FILTER_ASSOC_MSK bit |
| 4521 | */ |
| 4522 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4523 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4524 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4525 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4526 | } |
| 4527 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4528 | iwl_power_update_mode(priv, 0); |
| 4529 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4530 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 4531 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4532 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4533 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 4534 | mutex_unlock(&priv->mutex); |
| 4535 | return; |
| 4536 | } |
| 4537 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4538 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4539 | |
| 4540 | mutex_unlock(&priv->mutex); |
| 4541 | |
| 4542 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4543 | } |
| 4544 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 4545 | 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] | 4546 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4547 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4548 | unsigned long flags; |
| 4549 | |
| 4550 | mutex_lock(&priv->mutex); |
| 4551 | IWL_DEBUG_MAC80211("enter\n"); |
| 4552 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4553 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4554 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 4555 | mutex_unlock(&priv->mutex); |
| 4556 | return -EIO; |
| 4557 | } |
| 4558 | |
| 4559 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 4560 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 4561 | mutex_unlock(&priv->mutex); |
| 4562 | return -EIO; |
| 4563 | } |
| 4564 | |
| 4565 | spin_lock_irqsave(&priv->lock, flags); |
| 4566 | |
| 4567 | if (priv->ibss_beacon) |
| 4568 | dev_kfree_skb(priv->ibss_beacon); |
| 4569 | |
| 4570 | priv->ibss_beacon = skb; |
| 4571 | |
| 4572 | priv->assoc_id = 0; |
| 4573 | |
| 4574 | IWL_DEBUG_MAC80211("leave\n"); |
| 4575 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4576 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4577 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4578 | |
| 4579 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 4580 | |
| 4581 | mutex_unlock(&priv->mutex); |
| 4582 | |
| 4583 | return 0; |
| 4584 | } |
| 4585 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4586 | /***************************************************************************** |
| 4587 | * |
| 4588 | * sysfs attributes |
| 4589 | * |
| 4590 | *****************************************************************************/ |
| 4591 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4592 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4593 | |
| 4594 | /* |
| 4595 | * The following adds a new attribute to the sysfs representation |
| 4596 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 4597 | * used for controlling the debug level. |
| 4598 | * |
| 4599 | * See the level definitions in iwl for details. |
| 4600 | */ |
| 4601 | |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4602 | static ssize_t show_debug_level(struct device *d, |
| 4603 | struct device_attribute *attr, char *buf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4604 | { |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4605 | struct iwl_priv *priv = d->driver_data; |
| 4606 | |
| 4607 | return sprintf(buf, "0x%08X\n", priv->debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4608 | } |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4609 | static ssize_t store_debug_level(struct device *d, |
| 4610 | struct device_attribute *attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4611 | const char *buf, size_t count) |
| 4612 | { |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4613 | struct iwl_priv *priv = d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4614 | char *p = (char *)buf; |
| 4615 | u32 val; |
| 4616 | |
| 4617 | val = simple_strtoul(p, &p, 0); |
| 4618 | if (p == buf) |
| 4619 | printk(KERN_INFO DRV_NAME |
| 4620 | ": %s is not in hex or decimal form.\n", buf); |
| 4621 | else |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4622 | priv->debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4623 | |
| 4624 | return strnlen(buf, count); |
| 4625 | } |
| 4626 | |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4627 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 4628 | show_debug_level, store_debug_level); |
| 4629 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4630 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4631 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4632 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4633 | |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 4634 | static ssize_t show_version(struct device *d, |
| 4635 | struct device_attribute *attr, char *buf) |
| 4636 | { |
| 4637 | struct iwl_priv *priv = d->driver_data; |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 4638 | struct iwl_alive_resp *palive = &priv->card_alive; |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 4639 | |
| 4640 | if (palive->is_valid) |
| 4641 | return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n" |
| 4642 | "fw type: 0x%01X 0x%01X\n", |
| 4643 | palive->ucode_major, palive->ucode_minor, |
| 4644 | palive->sw_rev[0], palive->sw_rev[1], |
| 4645 | palive->ver_type, palive->ver_subtype); |
| 4646 | |
| 4647 | else |
| 4648 | return sprintf(buf, "fw not loaded\n"); |
| 4649 | } |
| 4650 | |
| 4651 | static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL); |
| 4652 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4653 | static ssize_t show_temperature(struct device *d, |
| 4654 | struct device_attribute *attr, char *buf) |
| 4655 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4656 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4657 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4658 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4659 | return -EAGAIN; |
| 4660 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4661 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4662 | } |
| 4663 | |
| 4664 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 4665 | |
| 4666 | static ssize_t show_rs_window(struct device *d, |
| 4667 | struct device_attribute *attr, |
| 4668 | char *buf) |
| 4669 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4670 | struct iwl_priv *priv = d->driver_data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4671 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4672 | } |
| 4673 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 4674 | |
| 4675 | static ssize_t show_tx_power(struct device *d, |
| 4676 | struct device_attribute *attr, char *buf) |
| 4677 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4678 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4679 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 4680 | } |
| 4681 | |
| 4682 | static ssize_t store_tx_power(struct device *d, |
| 4683 | struct device_attribute *attr, |
| 4684 | const char *buf, size_t count) |
| 4685 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4686 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4687 | char *p = (char *)buf; |
| 4688 | u32 val; |
| 4689 | |
| 4690 | val = simple_strtoul(p, &p, 10); |
| 4691 | if (p == buf) |
| 4692 | printk(KERN_INFO DRV_NAME |
| 4693 | ": %s is not in decimal form.\n", buf); |
| 4694 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4695 | iwl4965_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4696 | |
| 4697 | return count; |
| 4698 | } |
| 4699 | |
| 4700 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 4701 | |
| 4702 | static ssize_t show_flags(struct device *d, |
| 4703 | struct device_attribute *attr, char *buf) |
| 4704 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4705 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4706 | |
| 4707 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 4708 | } |
| 4709 | |
| 4710 | static ssize_t store_flags(struct device *d, |
| 4711 | struct device_attribute *attr, |
| 4712 | const char *buf, size_t count) |
| 4713 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4714 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4715 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 4716 | |
| 4717 | mutex_lock(&priv->mutex); |
| 4718 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 4719 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4720 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4721 | IWL_WARNING("Could not cancel scan.\n"); |
| 4722 | else { |
| 4723 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 4724 | flags); |
| 4725 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4726 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4727 | } |
| 4728 | } |
| 4729 | mutex_unlock(&priv->mutex); |
| 4730 | |
| 4731 | return count; |
| 4732 | } |
| 4733 | |
| 4734 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 4735 | |
| 4736 | static ssize_t show_filter_flags(struct device *d, |
| 4737 | struct device_attribute *attr, char *buf) |
| 4738 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4739 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4740 | |
| 4741 | return sprintf(buf, "0x%04X\n", |
| 4742 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 4743 | } |
| 4744 | |
| 4745 | static ssize_t store_filter_flags(struct device *d, |
| 4746 | struct device_attribute *attr, |
| 4747 | const char *buf, size_t count) |
| 4748 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4749 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4750 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 4751 | |
| 4752 | mutex_lock(&priv->mutex); |
| 4753 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 4754 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4755 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4756 | IWL_WARNING("Could not cancel scan.\n"); |
| 4757 | else { |
| 4758 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 4759 | "0x%04X\n", filter_flags); |
| 4760 | priv->staging_rxon.filter_flags = |
| 4761 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4762 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4763 | } |
| 4764 | } |
| 4765 | mutex_unlock(&priv->mutex); |
| 4766 | |
| 4767 | return count; |
| 4768 | } |
| 4769 | |
| 4770 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 4771 | store_filter_flags); |
| 4772 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4773 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4774 | |
| 4775 | static ssize_t show_measurement(struct device *d, |
| 4776 | struct device_attribute *attr, char *buf) |
| 4777 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4778 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4779 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4780 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 4781 | u8 *data = (u8 *) & measure_report; |
| 4782 | unsigned long flags; |
| 4783 | |
| 4784 | spin_lock_irqsave(&priv->lock, flags); |
| 4785 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 4786 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4787 | return 0; |
| 4788 | } |
| 4789 | memcpy(&measure_report, &priv->measure_report, size); |
| 4790 | priv->measurement_status = 0; |
| 4791 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4792 | |
| 4793 | while (size && (PAGE_SIZE - len)) { |
| 4794 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 4795 | PAGE_SIZE - len, 1); |
| 4796 | len = strlen(buf); |
| 4797 | if (PAGE_SIZE - len) |
| 4798 | buf[len++] = '\n'; |
| 4799 | |
| 4800 | ofs += 16; |
| 4801 | size -= min(size, 16U); |
| 4802 | } |
| 4803 | |
| 4804 | return len; |
| 4805 | } |
| 4806 | |
| 4807 | static ssize_t store_measurement(struct device *d, |
| 4808 | struct device_attribute *attr, |
| 4809 | const char *buf, size_t count) |
| 4810 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4811 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4812 | struct ieee80211_measurement_params params = { |
| 4813 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 4814 | .start_time = cpu_to_le64(priv->last_tsf), |
| 4815 | .duration = cpu_to_le16(1), |
| 4816 | }; |
| 4817 | u8 type = IWL_MEASURE_BASIC; |
| 4818 | u8 buffer[32]; |
| 4819 | u8 channel; |
| 4820 | |
| 4821 | if (count) { |
| 4822 | char *p = buffer; |
| 4823 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 4824 | channel = simple_strtoul(p, NULL, 0); |
| 4825 | if (channel) |
| 4826 | params.channel = channel; |
| 4827 | |
| 4828 | p = buffer; |
| 4829 | while (*p && *p != ' ') |
| 4830 | p++; |
| 4831 | if (*p) |
| 4832 | type = simple_strtoul(p + 1, NULL, 0); |
| 4833 | } |
| 4834 | |
| 4835 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 4836 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4837 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4838 | |
| 4839 | return count; |
| 4840 | } |
| 4841 | |
| 4842 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 4843 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4844 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4845 | |
| 4846 | static ssize_t store_retry_rate(struct device *d, |
| 4847 | struct device_attribute *attr, |
| 4848 | const char *buf, size_t count) |
| 4849 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4850 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4851 | |
| 4852 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 4853 | if (priv->retry_rate <= 0) |
| 4854 | priv->retry_rate = 1; |
| 4855 | |
| 4856 | return count; |
| 4857 | } |
| 4858 | |
| 4859 | static ssize_t show_retry_rate(struct device *d, |
| 4860 | struct device_attribute *attr, char *buf) |
| 4861 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4862 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4863 | return sprintf(buf, "%d", priv->retry_rate); |
| 4864 | } |
| 4865 | |
| 4866 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 4867 | store_retry_rate); |
| 4868 | |
| 4869 | static ssize_t store_power_level(struct device *d, |
| 4870 | struct device_attribute *attr, |
| 4871 | const char *buf, size_t count) |
| 4872 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4873 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4874 | int rc; |
| 4875 | int mode; |
| 4876 | |
| 4877 | mode = simple_strtoul(buf, NULL, 0); |
| 4878 | mutex_lock(&priv->mutex); |
| 4879 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4880 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4881 | rc = -EAGAIN; |
| 4882 | goto out; |
| 4883 | } |
| 4884 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4885 | rc = iwl_power_set_user_mode(priv, mode); |
| 4886 | if (rc) { |
| 4887 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 4888 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4889 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4890 | rc = count; |
| 4891 | |
| 4892 | out: |
| 4893 | mutex_unlock(&priv->mutex); |
| 4894 | return rc; |
| 4895 | } |
| 4896 | |
| 4897 | #define MAX_WX_STRING 80 |
| 4898 | |
| 4899 | /* Values are in microsecond */ |
| 4900 | static const s32 timeout_duration[] = { |
| 4901 | 350000, |
| 4902 | 250000, |
| 4903 | 75000, |
| 4904 | 37000, |
| 4905 | 25000, |
| 4906 | }; |
| 4907 | static const s32 period_duration[] = { |
| 4908 | 400000, |
| 4909 | 700000, |
| 4910 | 1000000, |
| 4911 | 1000000, |
| 4912 | 1000000 |
| 4913 | }; |
| 4914 | |
| 4915 | static ssize_t show_power_level(struct device *d, |
| 4916 | struct device_attribute *attr, char *buf) |
| 4917 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4918 | struct iwl_priv *priv = dev_get_drvdata(d); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4919 | int level = priv->power_data.power_mode; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4920 | char *p = buf; |
| 4921 | |
| 4922 | p += sprintf(p, "%d ", level); |
| 4923 | switch (level) { |
| 4924 | case IWL_POWER_MODE_CAM: |
| 4925 | case IWL_POWER_AC: |
| 4926 | p += sprintf(p, "(AC)"); |
| 4927 | break; |
| 4928 | case IWL_POWER_BATTERY: |
| 4929 | p += sprintf(p, "(BATTERY)"); |
| 4930 | break; |
| 4931 | default: |
| 4932 | p += sprintf(p, |
| 4933 | "(Timeout %dms, Period %dms)", |
| 4934 | timeout_duration[level - 1] / 1000, |
| 4935 | period_duration[level - 1] / 1000); |
| 4936 | } |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4937 | /* |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4938 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 4939 | p += sprintf(p, " OFF\n"); |
| 4940 | else |
| 4941 | p += sprintf(p, " \n"); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4942 | */ |
| 4943 | p += sprintf(p, " \n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4944 | return (p - buf + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4945 | } |
| 4946 | |
| 4947 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 4948 | store_power_level); |
| 4949 | |
| 4950 | static ssize_t show_channels(struct device *d, |
| 4951 | struct device_attribute *attr, char *buf) |
| 4952 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4953 | /* all this shit doesn't belong into sysfs anyway */ |
| 4954 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4955 | } |
| 4956 | |
| 4957 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 4958 | |
| 4959 | static ssize_t show_statistics(struct device *d, |
| 4960 | struct device_attribute *attr, char *buf) |
| 4961 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4962 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4963 | u32 size = sizeof(struct iwl4965_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4964 | u32 len = 0, ofs = 0; |
| 4965 | u8 *data = (u8 *) & priv->statistics; |
| 4966 | int rc = 0; |
| 4967 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4968 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4969 | return -EAGAIN; |
| 4970 | |
| 4971 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 4972 | rc = iwl_send_statistics_request(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4973 | mutex_unlock(&priv->mutex); |
| 4974 | |
| 4975 | if (rc) { |
| 4976 | len = sprintf(buf, |
| 4977 | "Error sending statistics request: 0x%08X\n", rc); |
| 4978 | return len; |
| 4979 | } |
| 4980 | |
| 4981 | while (size && (PAGE_SIZE - len)) { |
| 4982 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 4983 | PAGE_SIZE - len, 1); |
| 4984 | len = strlen(buf); |
| 4985 | if (PAGE_SIZE - len) |
| 4986 | buf[len++] = '\n'; |
| 4987 | |
| 4988 | ofs += 16; |
| 4989 | size -= min(size, 16U); |
| 4990 | } |
| 4991 | |
| 4992 | return len; |
| 4993 | } |
| 4994 | |
| 4995 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 4996 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4997 | static ssize_t show_status(struct device *d, |
| 4998 | struct device_attribute *attr, char *buf) |
| 4999 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5000 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5001 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5002 | return -EAGAIN; |
| 5003 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 5004 | } |
| 5005 | |
| 5006 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 5007 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5008 | /***************************************************************************** |
| 5009 | * |
| 5010 | * driver setup and teardown |
| 5011 | * |
| 5012 | *****************************************************************************/ |
| 5013 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5014 | static void iwl4965_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5015 | { |
| 5016 | priv->workqueue = create_workqueue(DRV_NAME); |
| 5017 | |
| 5018 | init_waitqueue_head(&priv->wait_command_queue); |
| 5019 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5020 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 5021 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 5022 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
| 5023 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); |
| 5024 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); |
| 5025 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); |
| 5026 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 5027 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 5028 | INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5029 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 5030 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start); |
| 5031 | INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5032 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5033 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5034 | iwl4965_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5035 | |
| 5036 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5037 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5038 | } |
| 5039 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5040 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5041 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5042 | iwl4965_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5043 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 5044 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5045 | cancel_delayed_work(&priv->scan_check); |
| 5046 | cancel_delayed_work(&priv->alive_start); |
| 5047 | cancel_delayed_work(&priv->post_associate); |
| 5048 | cancel_work_sync(&priv->beacon_update); |
| 5049 | } |
| 5050 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5051 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5052 | &dev_attr_channels.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5053 | &dev_attr_flags.attr, |
| 5054 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5055 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5056 | &dev_attr_measurement.attr, |
| 5057 | #endif |
| 5058 | &dev_attr_power_level.attr, |
| 5059 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5060 | &dev_attr_rs_window.attr, |
| 5061 | &dev_attr_statistics.attr, |
| 5062 | &dev_attr_status.attr, |
| 5063 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5064 | &dev_attr_tx_power.attr, |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5065 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 5066 | &dev_attr_debug_level.attr, |
| 5067 | #endif |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 5068 | &dev_attr_version.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5069 | |
| 5070 | NULL |
| 5071 | }; |
| 5072 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5073 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5074 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5075 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5076 | }; |
| 5077 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5078 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 5079 | .tx = iwl4965_mac_tx, |
| 5080 | .start = iwl4965_mac_start, |
| 5081 | .stop = iwl4965_mac_stop, |
| 5082 | .add_interface = iwl4965_mac_add_interface, |
| 5083 | .remove_interface = iwl4965_mac_remove_interface, |
| 5084 | .config = iwl4965_mac_config, |
| 5085 | .config_interface = iwl4965_mac_config_interface, |
| 5086 | .configure_filter = iwl4965_configure_filter, |
| 5087 | .set_key = iwl4965_mac_set_key, |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5088 | .update_tkip_key = iwl4965_mac_update_tkip_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5089 | .get_stats = iwl4965_mac_get_stats, |
| 5090 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 5091 | .conf_tx = iwl4965_mac_conf_tx, |
| 5092 | .get_tsf = iwl4965_mac_get_tsf, |
| 5093 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 5094 | .beacon_update = iwl4965_mac_beacon_update, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5095 | .bss_info_changed = iwl4965_bss_info_changed, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5096 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | 9ab4617 | 2007-12-25 17:00:38 +0200 | [diff] [blame] | 5097 | .ampdu_action = iwl4965_mac_ampdu_action, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5098 | #endif /* CONFIG_IWL4965_HT */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5099 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5100 | }; |
| 5101 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5102 | 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] | 5103 | { |
| 5104 | int err = 0; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5105 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5106 | struct ieee80211_hw *hw; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 5107 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5108 | unsigned long flags; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5109 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5110 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5111 | /************************ |
| 5112 | * 1. Allocating HW data |
| 5113 | ************************/ |
| 5114 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5115 | /* Disabling hardware scan means that mac80211 will perform scans |
| 5116 | * "the hard way", rather than using device's scan. */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 5117 | if (cfg->mod_params->disable_hw_scan) { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 5118 | if (cfg->mod_params->debug & IWL_DL_INFO) |
| 5119 | dev_printk(KERN_DEBUG, &(pdev->dev), |
| 5120 | "Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5121 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5122 | } |
| 5123 | |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 5124 | hw = iwl_alloc_all(cfg, &iwl4965_hw_ops); |
| 5125 | if (!hw) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5126 | err = -ENOMEM; |
| 5127 | goto out; |
| 5128 | } |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 5129 | priv = hw->priv; |
| 5130 | /* At this point both hw and priv are allocated. */ |
| 5131 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5132 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 5133 | |
| 5134 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 5135 | priv->cfg = cfg; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5136 | priv->pci_dev = pdev; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5137 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 5138 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 5139 | priv->debug_level = priv->cfg->mod_params->debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5140 | atomic_set(&priv->restrict_refcnt, 0); |
| 5141 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5142 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5143 | /************************** |
| 5144 | * 2. Initializing PCI bus |
| 5145 | **************************/ |
| 5146 | if (pci_enable_device(pdev)) { |
| 5147 | err = -ENODEV; |
| 5148 | goto out_ieee80211_free_hw; |
| 5149 | } |
| 5150 | |
| 5151 | pci_set_master(pdev); |
| 5152 | |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5153 | err = pci_set_dma_mask(pdev, DMA_64BIT_MASK); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5154 | if (!err) |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5155 | err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); |
| 5156 | if (err) { |
| 5157 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 5158 | if (!err) |
| 5159 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 5160 | /* both attempts failed: */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5161 | if (err) { |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5162 | printk(KERN_WARNING "%s: No suitable DMA available.\n", |
| 5163 | DRV_NAME); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5164 | goto out_pci_disable_device; |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5165 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5166 | } |
| 5167 | |
| 5168 | err = pci_request_regions(pdev, DRV_NAME); |
| 5169 | if (err) |
| 5170 | goto out_pci_disable_device; |
| 5171 | |
| 5172 | pci_set_drvdata(pdev, priv); |
| 5173 | |
| 5174 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 5175 | * PCI Tx retries from interfering with C3 CPU state */ |
| 5176 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 5177 | |
| 5178 | /*********************** |
| 5179 | * 3. Read REV register |
| 5180 | ***********************/ |
| 5181 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 5182 | if (!priv->hw_base) { |
| 5183 | err = -ENODEV; |
| 5184 | goto out_pci_release_regions; |
| 5185 | } |
| 5186 | |
| 5187 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 5188 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 5189 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 5190 | |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 5191 | iwl_hw_detect(priv); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5192 | printk(KERN_INFO DRV_NAME |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 5193 | ": Detected Intel Wireless WiFi Link %s REV=0x%X\n", |
| 5194 | priv->cfg->name, priv->hw_rev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5195 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 5196 | /* amp init */ |
| 5197 | err = priv->cfg->ops->lib->apm_ops.init(priv); |
| 5198 | if (err < 0) { |
| 5199 | IWL_DEBUG_INFO("Failed to init APMG\n"); |
| 5200 | goto out_iounmap; |
| 5201 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5202 | /***************** |
| 5203 | * 4. Read EEPROM |
| 5204 | *****************/ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5205 | /* Read the EEPROM */ |
| 5206 | err = iwl_eeprom_init(priv); |
| 5207 | if (err) { |
| 5208 | IWL_ERROR("Unable to init EEPROM\n"); |
| 5209 | goto out_iounmap; |
| 5210 | } |
Tomas Winkler | 8614f36 | 2008-04-23 17:14:55 -0700 | [diff] [blame] | 5211 | err = iwl_eeprom_check_version(priv); |
| 5212 | if (err) |
| 5213 | goto out_iounmap; |
| 5214 | |
Ron Rindjunsky | 0288301 | 2008-05-15 13:53:53 +0800 | [diff] [blame] | 5215 | /* extract MAC Address */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5216 | iwl_eeprom_get_mac(priv, priv->mac_addr); |
| 5217 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); |
| 5218 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 5219 | |
| 5220 | /************************ |
| 5221 | * 5. Setup HW constants |
| 5222 | ************************/ |
| 5223 | /* Device-specific setup */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 5224 | if (priv->cfg->ops->lib->set_hw_params(priv)) { |
| 5225 | IWL_ERROR("failed to set hw parameters\n"); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 5226 | goto out_free_eeprom; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5227 | } |
| 5228 | |
| 5229 | /******************* |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5230 | * 6. Setup priv |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5231 | *******************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5232 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5233 | err = iwl_init_drv(priv); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5234 | if (err) |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 5235 | goto out_free_eeprom; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5236 | /* At this point both hw and priv are initialized. */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5237 | |
| 5238 | /********************************** |
| 5239 | * 7. Initialize module parameters |
| 5240 | **********************************/ |
| 5241 | |
| 5242 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 5243 | if (priv->cfg->mod_params->disable) { |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5244 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 5245 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 5246 | } |
| 5247 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5248 | /******************** |
| 5249 | * 8. Setup services |
| 5250 | ********************/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5251 | spin_lock_irqsave(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5252 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5253 | spin_unlock_irqrestore(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5254 | |
| 5255 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
| 5256 | if (err) { |
| 5257 | IWL_ERROR("failed to create sysfs device attributes\n"); |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5258 | goto out_uninit_drv; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5259 | } |
| 5260 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5261 | |
| 5262 | iwl4965_setup_deferred_work(priv); |
| 5263 | iwl4965_setup_rx_handlers(priv); |
| 5264 | |
| 5265 | /******************** |
| 5266 | * 9. Conclude |
| 5267 | ********************/ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5268 | pci_save_state(pdev); |
| 5269 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5270 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5271 | /********************************** |
| 5272 | * 10. Setup and register mac80211 |
| 5273 | **********************************/ |
| 5274 | |
| 5275 | err = iwl_setup_mac(priv); |
| 5276 | if (err) |
| 5277 | goto out_remove_sysfs; |
| 5278 | |
| 5279 | err = iwl_dbgfs_register(priv, DRV_NAME); |
| 5280 | if (err) |
| 5281 | IWL_ERROR("failed to create debugfs files\n"); |
| 5282 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 5283 | /* notify iwlcore to init */ |
| 5284 | iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5285 | return 0; |
| 5286 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5287 | out_remove_sysfs: |
| 5288 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5289 | out_uninit_drv: |
| 5290 | iwl_uninit_drv(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 5291 | out_free_eeprom: |
| 5292 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5293 | out_iounmap: |
| 5294 | pci_iounmap(pdev, priv->hw_base); |
| 5295 | out_pci_release_regions: |
| 5296 | pci_release_regions(pdev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5297 | pci_set_drvdata(pdev, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5298 | out_pci_disable_device: |
| 5299 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5300 | out_ieee80211_free_hw: |
| 5301 | ieee80211_free_hw(priv->hw); |
| 5302 | out: |
| 5303 | return err; |
| 5304 | } |
| 5305 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 5306 | static void __devexit iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5307 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5308 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5309 | struct list_head *p, *q; |
| 5310 | int i; |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5311 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5312 | |
| 5313 | if (!priv) |
| 5314 | return; |
| 5315 | |
| 5316 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 5317 | |
Ron Rindjunsky | c4f5523 | 2008-03-28 16:21:10 -0700 | [diff] [blame] | 5318 | if (priv->mac80211_registered) { |
| 5319 | ieee80211_unregister_hw(priv->hw); |
| 5320 | priv->mac80211_registered = 0; |
| 5321 | } |
| 5322 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5323 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 5324 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5325 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5326 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5327 | /* make sure we flush any pending irq or |
| 5328 | * tasklet for the driver |
| 5329 | */ |
| 5330 | spin_lock_irqsave(&priv->lock, flags); |
| 5331 | iwl4965_disable_interrupts(priv); |
| 5332 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5333 | |
| 5334 | iwl_synchronize_irq(priv); |
| 5335 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5336 | /* Free MAC hash list for ADHOC */ |
| 5337 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 5338 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 5339 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5340 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5341 | } |
| 5342 | } |
| 5343 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 5344 | iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT); |
Tomas Winkler | 712b6cf | 2008-03-12 16:58:52 -0700 | [diff] [blame] | 5345 | iwl_dbgfs_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5346 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5347 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5348 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5349 | |
| 5350 | if (priv->rxq.bd) |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 5351 | iwl_rx_queue_free(priv, &priv->rxq); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 5352 | iwl_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5353 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5354 | iwlcore_clear_stations_table(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 5355 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5356 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5357 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5358 | /*netif_stop_queue(dev); */ |
| 5359 | flush_workqueue(priv->workqueue); |
| 5360 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5361 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5362 | * priv->workqueue... so we can't take down the workqueue |
| 5363 | * until now... */ |
| 5364 | destroy_workqueue(priv->workqueue); |
| 5365 | priv->workqueue = NULL; |
| 5366 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5367 | pci_iounmap(pdev, priv->hw_base); |
| 5368 | pci_release_regions(pdev); |
| 5369 | pci_disable_device(pdev); |
| 5370 | pci_set_drvdata(pdev, NULL); |
| 5371 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5372 | iwl_uninit_drv(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5373 | |
| 5374 | if (priv->ibss_beacon) |
| 5375 | dev_kfree_skb(priv->ibss_beacon); |
| 5376 | |
| 5377 | ieee80211_free_hw(priv->hw); |
| 5378 | } |
| 5379 | |
| 5380 | #ifdef CONFIG_PM |
| 5381 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5382 | 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] | 5383 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5384 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5385 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5386 | if (priv->is_open) { |
| 5387 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 5388 | iwl4965_mac_stop(priv->hw); |
| 5389 | priv->is_open = 1; |
| 5390 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5391 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5392 | pci_set_power_state(pdev, PCI_D3hot); |
| 5393 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5394 | return 0; |
| 5395 | } |
| 5396 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5397 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5398 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5399 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5400 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5401 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5402 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5403 | if (priv->is_open) |
| 5404 | iwl4965_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5405 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5406 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5407 | return 0; |
| 5408 | } |
| 5409 | |
| 5410 | #endif /* CONFIG_PM */ |
| 5411 | |
| 5412 | /***************************************************************************** |
| 5413 | * |
| 5414 | * driver and module entry point |
| 5415 | * |
| 5416 | *****************************************************************************/ |
| 5417 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5418 | /* Hardware specific file defines the PCI IDs table for that hardware module */ |
| 5419 | static struct pci_device_id iwl_hw_card_ids[] = { |
| 5420 | {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)}, |
| 5421 | {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)}, |
Tomas Winkler | 5a6a256 | 2008-04-24 11:55:23 -0700 | [diff] [blame] | 5422 | #ifdef CONFIG_IWL5000 |
| 5423 | {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)}, |
| 5424 | {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)}, |
| 5425 | {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)}, |
| 5426 | #endif /* CONFIG_IWL5000 */ |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5427 | {0} |
| 5428 | }; |
| 5429 | MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); |
| 5430 | |
| 5431 | static struct pci_driver iwl_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5432 | .name = DRV_NAME, |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5433 | .id_table = iwl_hw_card_ids, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5434 | .probe = iwl4965_pci_probe, |
| 5435 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5436 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5437 | .suspend = iwl4965_pci_suspend, |
| 5438 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5439 | #endif |
| 5440 | }; |
| 5441 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5442 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5443 | { |
| 5444 | |
| 5445 | int ret; |
| 5446 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 5447 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5448 | |
| 5449 | ret = iwl4965_rate_control_register(); |
| 5450 | if (ret) { |
| 5451 | IWL_ERROR("Unable to register rate control algorithm: %d\n", ret); |
| 5452 | return ret; |
| 5453 | } |
| 5454 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5455 | ret = pci_register_driver(&iwl_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5456 | if (ret) { |
| 5457 | IWL_ERROR("Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5458 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5459 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5460 | |
| 5461 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5462 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5463 | error_register: |
| 5464 | iwl4965_rate_control_unregister(); |
| 5465 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5466 | } |
| 5467 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5468 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5469 | { |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5470 | pci_unregister_driver(&iwl_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5471 | iwl4965_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5472 | } |
| 5473 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5474 | module_exit(iwl4965_exit); |
| 5475 | module_init(iwl4965_init); |