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 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 90 | static int iwl4965_is_empty_essid(const char *essid, int essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 91 | { |
| 92 | /* Single white space is for Linksys APs */ |
| 93 | if (essid_len == 1 && essid[0] == ' ') |
| 94 | return 1; |
| 95 | |
| 96 | /* Otherwise, if the entire essid is 0, we assume it is hidden */ |
| 97 | while (essid_len) { |
| 98 | essid_len--; |
| 99 | if (essid[essid_len] != '\0') |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | return 1; |
| 104 | } |
| 105 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 106 | static const char *iwl4965_escape_essid(const char *essid, u8 essid_len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 107 | { |
| 108 | static char escaped[IW_ESSID_MAX_SIZE * 2 + 1]; |
| 109 | const char *s = essid; |
| 110 | char *d = escaped; |
| 111 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 112 | if (iwl4965_is_empty_essid(essid, essid_len)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 113 | memcpy(escaped, "<hidden>", sizeof("<hidden>")); |
| 114 | return escaped; |
| 115 | } |
| 116 | |
| 117 | essid_len = min(essid_len, (u8) IW_ESSID_MAX_SIZE); |
| 118 | while (essid_len--) { |
| 119 | if (*s == '\0') { |
| 120 | *d++ = '\\'; |
| 121 | *d++ = '0'; |
| 122 | s++; |
| 123 | } else |
| 124 | *d++ = *s++; |
| 125 | } |
| 126 | *d = '\0'; |
| 127 | return escaped; |
| 128 | } |
| 129 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 130 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 131 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 132 | * the functionality provided here |
| 133 | */ |
| 134 | |
| 135 | /**************************************************************/ |
| 136 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 137 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 138 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 139 | static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) |
| 140 | { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 141 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 142 | |
| 143 | if (hw_decrypt) |
| 144 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 145 | else |
| 146 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 147 | |
| 148 | } |
| 149 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 150 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 151 | * iwl4965_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 152 | * |
| 153 | * NOTE: This is really only useful during development and can eventually |
| 154 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 155 | * making changes |
| 156 | */ |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 157 | static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 158 | { |
| 159 | int error = 0; |
| 160 | int counter = 1; |
| 161 | |
| 162 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 163 | error |= le32_to_cpu(rxon->flags & |
| 164 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 165 | RXON_FLG_RADAR_DETECT_MSK)); |
| 166 | if (error) |
| 167 | IWL_WARNING("check 24G fields %d | %d\n", |
| 168 | counter++, error); |
| 169 | } else { |
| 170 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 171 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 172 | if (error) |
| 173 | IWL_WARNING("check 52 fields %d | %d\n", |
| 174 | counter++, error); |
| 175 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 176 | if (error) |
| 177 | IWL_WARNING("check 52 CCK %d | %d\n", |
| 178 | counter++, error); |
| 179 | } |
| 180 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 181 | if (error) |
| 182 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); |
| 183 | |
| 184 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 185 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 186 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 187 | if (error) |
| 188 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); |
| 189 | |
| 190 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 191 | if (error) |
| 192 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); |
| 193 | |
| 194 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 195 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 196 | if (error) |
| 197 | IWL_WARNING("check CCK and short slot %d | %d\n", |
| 198 | counter++, error); |
| 199 | |
| 200 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 201 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 202 | if (error) |
| 203 | IWL_WARNING("check CCK & auto detect %d | %d\n", |
| 204 | counter++, error); |
| 205 | |
| 206 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 207 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 208 | if (error) |
| 209 | IWL_WARNING("check TGG and auto detect %d | %d\n", |
| 210 | counter++, error); |
| 211 | |
| 212 | if (error) |
| 213 | IWL_WARNING("Tuning to channel %d\n", |
| 214 | le16_to_cpu(rxon->channel)); |
| 215 | |
| 216 | if (error) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 217 | IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 218 | return -1; |
| 219 | } |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 224 | * 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] | 225 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 226 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 227 | * If the RXON structure is changing enough to require a new tune, |
| 228 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 229 | * 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] | 230 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 231 | static int iwl4965_full_rxon_required(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 232 | { |
| 233 | |
| 234 | /* These items are only settable from the full RXON command */ |
| 235 | if (!(priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) || |
| 236 | compare_ether_addr(priv->staging_rxon.bssid_addr, |
| 237 | priv->active_rxon.bssid_addr) || |
| 238 | compare_ether_addr(priv->staging_rxon.node_addr, |
| 239 | priv->active_rxon.node_addr) || |
| 240 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, |
| 241 | priv->active_rxon.wlap_bssid_addr) || |
| 242 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || |
| 243 | (priv->staging_rxon.channel != priv->active_rxon.channel) || |
| 244 | (priv->staging_rxon.air_propagation != |
| 245 | priv->active_rxon.air_propagation) || |
| 246 | (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != |
| 247 | priv->active_rxon.ofdm_ht_single_stream_basic_rates) || |
| 248 | (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != |
| 249 | priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || |
| 250 | (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) || |
| 251 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) |
| 252 | return 1; |
| 253 | |
| 254 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 255 | * be updated with the RXON_ASSOC command -- however only some |
| 256 | * flag transitions are allowed using RXON_ASSOC */ |
| 257 | |
| 258 | /* Check if we are not switching bands */ |
| 259 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 260 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
| 261 | return 1; |
| 262 | |
| 263 | /* Check if we are switching association toggle */ |
| 264 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 265 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
| 266 | return 1; |
| 267 | |
| 268 | return 0; |
| 269 | } |
| 270 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 271 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 272 | * iwl4965_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 273 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 274 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 275 | * the active_rxon structure is updated with the new data. This |
| 276 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 277 | * a HW tune is required based on the RXON structure changes. |
| 278 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 279 | static int iwl4965_commit_rxon(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 280 | { |
| 281 | /* cast away the const for active_rxon in this function */ |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 282 | struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 283 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 284 | int rc = 0; |
| 285 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 286 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 287 | return -1; |
| 288 | |
| 289 | /* always get timestamp with Rx frame */ |
| 290 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
| 291 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 292 | rc = iwl4965_check_rxon_cmd(&priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 293 | if (rc) { |
| 294 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); |
| 295 | return -EINVAL; |
| 296 | } |
| 297 | |
| 298 | /* 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] | 299 | * iwl4965_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 300 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 301 | if (!iwl4965_full_rxon_required(priv)) { |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 302 | rc = iwl_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 303 | if (rc) { |
| 304 | IWL_ERROR("Error setting RXON_ASSOC " |
| 305 | "configuration (%d).\n", rc); |
| 306 | return rc; |
| 307 | } |
| 308 | |
| 309 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | /* station table will be cleared */ |
| 315 | priv->assoc_station_added = 0; |
| 316 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 317 | /* If we are currently associated and the new config requires |
| 318 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 319 | * we must clear the associated from the active configuration |
| 320 | * before we apply the new config */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 321 | if (iwl_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 322 | (priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) { |
| 323 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 324 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 325 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 326 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 327 | sizeof(struct iwl_rxon_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 328 | &priv->active_rxon); |
| 329 | |
| 330 | /* If the mask clearing failed then we set |
| 331 | * active_rxon back to what it was previously */ |
| 332 | if (rc) { |
| 333 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 334 | IWL_ERROR("Error clearing ASSOC_MSK on current " |
| 335 | "configuration (%d).\n", rc); |
| 336 | return rc; |
| 337 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | IWL_DEBUG_INFO("Sending RXON\n" |
| 341 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 342 | "* channel = %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 343 | "* bssid = %s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 344 | ((priv->staging_rxon.filter_flags & |
| 345 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
| 346 | le16_to_cpu(priv->staging_rxon.channel), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 347 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 348 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 349 | iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 350 | /* Apply the new configuration */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 351 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 352 | sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 353 | if (rc) { |
| 354 | IWL_ERROR("Error setting new configuration (%d).\n", rc); |
| 355 | return rc; |
| 356 | } |
| 357 | |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 358 | iwl_remove_station(priv, iwl_bcast_addr, 0); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 359 | iwlcore_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 360 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 361 | if (!priv->error_recovering) |
| 362 | priv->start_calib = 0; |
| 363 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 364 | iwl_init_sensitivity(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 365 | |
| 366 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
| 367 | |
| 368 | /* If we issue a new RXON command which required a tune then we must |
| 369 | * 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] | 370 | rc = iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 371 | if (rc) { |
| 372 | IWL_ERROR("Error setting Tx power (%d).\n", rc); |
| 373 | return rc; |
| 374 | } |
| 375 | |
| 376 | /* Add the broadcast address so we can send broadcast frames */ |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 377 | if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 378 | IWL_INVALID_STATION) { |
| 379 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); |
| 380 | return -EIO; |
| 381 | } |
| 382 | |
| 383 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 384 | * add the IWL_AP_ID to the station rate table */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 385 | if (iwl_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 386 | (priv->iw_mode == IEEE80211_IF_TYPE_STA)) { |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 387 | if (iwl_rxon_add_station(priv, priv->active_rxon.bssid_addr, 1) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 388 | == IWL_INVALID_STATION) { |
| 389 | IWL_ERROR("Error adding AP address for transmit.\n"); |
| 390 | return -EIO; |
| 391 | } |
| 392 | priv->assoc_station_added = 1; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 393 | if (priv->default_wep_key && |
| 394 | iwl_send_static_wepkey_cmd(priv, 0)) |
| 395 | IWL_ERROR("Could not send WEP static key.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | return 0; |
| 399 | } |
| 400 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 401 | void iwl4965_update_chain_flags(struct iwl_priv *priv) |
| 402 | { |
| 403 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 404 | iwl_set_rxon_chain(priv); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 405 | iwl4965_commit_rxon(priv); |
| 406 | } |
| 407 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 408 | static int iwl4965_send_bt_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 409 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 410 | struct iwl4965_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 411 | .flags = 3, |
| 412 | .lead_time = 0xAA, |
| 413 | .max_kill = 1, |
| 414 | .kill_ack_mask = 0, |
| 415 | .kill_cts_mask = 0, |
| 416 | }; |
| 417 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 418 | return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 419 | sizeof(struct iwl4965_bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 422 | static int iwl4965_send_scan_abort(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 423 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 424 | int ret = 0; |
| 425 | struct iwl_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 426 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 427 | .id = REPLY_SCAN_ABORT_CMD, |
| 428 | .meta.flags = CMD_WANT_SKB, |
| 429 | }; |
| 430 | |
| 431 | /* If there isn't a scan actively going on in the hardware |
| 432 | * then we are in between scan bands and not actually |
| 433 | * actively scanning, so don't send the abort command */ |
| 434 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 435 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 436 | return 0; |
| 437 | } |
| 438 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 439 | ret = iwl_send_cmd_sync(priv, &cmd); |
| 440 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 441 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 442 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 445 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 446 | if (res->u.status != CAN_ABORT_STATUS) { |
| 447 | /* The scan abort will return 1 for success or |
| 448 | * 2 for "failure". A failure condition can be |
| 449 | * due to simply not being in an active scan which |
| 450 | * can occur if we send the scan abort before we |
| 451 | * the microcode has notified us that a scan is |
| 452 | * completed. */ |
| 453 | IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res->u.status); |
| 454 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 455 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 456 | } |
| 457 | |
| 458 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 459 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 460 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 463 | /* |
| 464 | * CARD_STATE_CMD |
| 465 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 466 | * 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] | 467 | * |
| 468 | * When in the 'enable' state the card operates as normal. |
| 469 | * When in the 'disable' state, the card enters into a low power mode. |
| 470 | * When in the 'halt' state, the card is shut down and must be fully |
| 471 | * restarted to come back on. |
| 472 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 473 | 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] | 474 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 475 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 476 | .id = REPLY_CARD_STATE_CMD, |
| 477 | .len = sizeof(u32), |
| 478 | .data = &flags, |
| 479 | .meta.flags = meta_flag, |
| 480 | }; |
| 481 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 482 | return iwl_send_cmd(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 485 | static void iwl_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 486 | { |
| 487 | struct list_head *element; |
| 488 | |
| 489 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 490 | priv->frames_count); |
| 491 | |
| 492 | while (!list_empty(&priv->free_frames)) { |
| 493 | element = priv->free_frames.next; |
| 494 | list_del(element); |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 495 | kfree(list_entry(element, struct iwl_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 496 | priv->frames_count--; |
| 497 | } |
| 498 | |
| 499 | if (priv->frames_count) { |
| 500 | IWL_WARNING("%d frames still in use. Did we lose one?\n", |
| 501 | priv->frames_count); |
| 502 | priv->frames_count = 0; |
| 503 | } |
| 504 | } |
| 505 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 506 | static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 507 | { |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 508 | struct iwl_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 509 | struct list_head *element; |
| 510 | if (list_empty(&priv->free_frames)) { |
| 511 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 512 | if (!frame) { |
| 513 | IWL_ERROR("Could not allocate frame!\n"); |
| 514 | return NULL; |
| 515 | } |
| 516 | |
| 517 | priv->frames_count++; |
| 518 | return frame; |
| 519 | } |
| 520 | |
| 521 | element = priv->free_frames.next; |
| 522 | list_del(element); |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 523 | return list_entry(element, struct iwl_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 524 | } |
| 525 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 526 | 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] | 527 | { |
| 528 | memset(frame, 0, sizeof(*frame)); |
| 529 | list_add(&frame->list, &priv->free_frames); |
| 530 | } |
| 531 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 532 | unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 533 | struct ieee80211_hdr *hdr, |
| 534 | const u8 *dest, int left) |
| 535 | { |
| 536 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 537 | if (!iwl_is_associated(priv) || !priv->ibss_beacon || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 538 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
| 539 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) |
| 540 | return 0; |
| 541 | |
| 542 | if (priv->ibss_beacon->len > left) |
| 543 | return 0; |
| 544 | |
| 545 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 546 | |
| 547 | return priv->ibss_beacon->len; |
| 548 | } |
| 549 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 550 | static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 551 | { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 552 | int i; |
| 553 | int rate_mask; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 554 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 555 | /* Set rate mask*/ |
| 556 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 557 | rate_mask = priv->active_rate_basic & 0xF; |
| 558 | else |
| 559 | rate_mask = priv->active_rate_basic & 0xFF0; |
| 560 | |
| 561 | /* Find lowest valid rate */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 562 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 563 | i = iwl_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 564 | if (rate_mask & (1 << i)) |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 565 | return iwl_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 566 | } |
| 567 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 568 | /* No valid rate was found. Assign the lowest one */ |
| 569 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 570 | return IWL_RATE_1M_PLCP; |
| 571 | else |
| 572 | return IWL_RATE_6M_PLCP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 575 | static int iwl4965_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 576 | { |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 577 | struct iwl_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 578 | unsigned int frame_size; |
| 579 | int rc; |
| 580 | u8 rate; |
| 581 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 582 | frame = iwl_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 583 | |
| 584 | if (!frame) { |
| 585 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 586 | "command.\n"); |
| 587 | return -ENOMEM; |
| 588 | } |
| 589 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 590 | rate = iwl4965_rate_get_lowest_plcp(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 591 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 592 | frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 593 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 594 | rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 595 | &frame->u.cmd[0]); |
| 596 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 597 | iwl_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 598 | |
| 599 | return rc; |
| 600 | } |
| 601 | |
| 602 | /****************************************************************************** |
| 603 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 604 | * Misc. internal state and helper functions |
| 605 | * |
| 606 | ******************************************************************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 607 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 608 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 609 | * 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] | 610 | * |
| 611 | * return : set the bit for each supported rate insert in ie |
| 612 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 613 | static u16 iwl4965_supported_rate_to_ie(u8 *ie, u16 supported_rate, |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 614 | u16 basic_rate, int *left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 615 | { |
| 616 | u16 ret_rates = 0, bit; |
| 617 | int i; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 618 | u8 *cnt = ie; |
| 619 | u8 *rates = ie + 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 620 | |
| 621 | for (bit = 1, i = 0; i < IWL_RATE_COUNT; i++, bit <<= 1) { |
| 622 | if (bit & supported_rate) { |
| 623 | ret_rates |= bit; |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 624 | rates[*cnt] = iwl_rates[i].ieee | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 625 | ((bit & basic_rate) ? 0x80 : 0x00); |
| 626 | (*cnt)++; |
| 627 | (*left)--; |
| 628 | if ((*left <= 0) || |
| 629 | (*cnt >= IWL_SUPPORTED_RATES_IE_LEN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 630 | break; |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | return ret_rates; |
| 635 | } |
| 636 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 637 | #ifdef CONFIG_IWL4965_HT |
| 638 | static void iwl4965_ht_conf(struct iwl_priv *priv, |
| 639 | struct ieee80211_bss_conf *bss_conf) |
| 640 | { |
| 641 | struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf; |
| 642 | struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf; |
| 643 | struct iwl_ht_info *iwl_conf = &priv->current_ht_config; |
| 644 | |
| 645 | IWL_DEBUG_MAC80211("enter: \n"); |
| 646 | |
| 647 | iwl_conf->is_ht = bss_conf->assoc_ht; |
| 648 | |
| 649 | if (!iwl_conf->is_ht) |
| 650 | return; |
| 651 | |
| 652 | priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 653 | |
| 654 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) |
Emmanuel Grumbach | a984101 | 2008-05-15 13:54:08 +0800 | [diff] [blame] | 655 | iwl_conf->sgf |= HT_SHORT_GI_20MHZ; |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 656 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) |
Emmanuel Grumbach | a984101 | 2008-05-15 13:54:08 +0800 | [diff] [blame] | 657 | iwl_conf->sgf |= HT_SHORT_GI_40MHZ; |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 658 | |
| 659 | iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); |
| 660 | iwl_conf->max_amsdu_size = |
| 661 | !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); |
| 662 | |
| 663 | iwl_conf->supported_chan_width = |
| 664 | !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); |
| 665 | iwl_conf->extension_chan_offset = |
| 666 | ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; |
| 667 | /* If no above or below channel supplied disable FAT channel */ |
| 668 | if (iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_ABOVE && |
| 669 | iwl_conf->extension_chan_offset != IWL_EXT_CHANNEL_OFFSET_BELOW) |
| 670 | iwl_conf->supported_chan_width = 0; |
| 671 | |
| 672 | iwl_conf->tx_mimo_ps_mode = |
| 673 | (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 674 | memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); |
| 675 | |
| 676 | iwl_conf->control_channel = ht_bss_conf->primary_channel; |
| 677 | iwl_conf->tx_chan_width = |
| 678 | !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); |
| 679 | iwl_conf->ht_protection = |
| 680 | ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; |
| 681 | iwl_conf->non_GF_STA_present = |
| 682 | !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT); |
| 683 | |
| 684 | IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel); |
| 685 | IWL_DEBUG_MAC80211("leave\n"); |
| 686 | } |
| 687 | |
| 688 | static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband, |
| 689 | u8 *pos, int *left) |
| 690 | { |
| 691 | struct ieee80211_ht_cap *ht_cap; |
| 692 | |
| 693 | if (!sband || !sband->ht_info.ht_supported) |
| 694 | return; |
| 695 | |
| 696 | if (*left < sizeof(struct ieee80211_ht_cap)) |
| 697 | return; |
| 698 | |
| 699 | *pos++ = sizeof(struct ieee80211_ht_cap); |
| 700 | ht_cap = (struct ieee80211_ht_cap *) pos; |
| 701 | |
| 702 | ht_cap->cap_info = cpu_to_le16(sband->ht_info.cap); |
| 703 | memcpy(ht_cap->supp_mcs_set, sband->ht_info.supp_mcs_set, 16); |
| 704 | ht_cap->ampdu_params_info = |
| 705 | (sband->ht_info.ampdu_factor & IEEE80211_HT_CAP_AMPDU_FACTOR) | |
| 706 | ((sband->ht_info.ampdu_density << 2) & |
| 707 | IEEE80211_HT_CAP_AMPDU_DENSITY); |
| 708 | *left -= sizeof(struct ieee80211_ht_cap); |
| 709 | } |
| 710 | #else |
| 711 | static inline void iwl4965_ht_conf(struct iwl_priv *priv, |
| 712 | struct ieee80211_bss_conf *bss_conf) |
| 713 | { |
| 714 | } |
| 715 | static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band *sband, |
| 716 | u8 *pos, int *left) |
| 717 | { |
| 718 | } |
| 719 | #endif |
| 720 | |
| 721 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 722 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 723 | * 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] | 724 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 725 | static u16 iwl4965_fill_probe_req(struct iwl_priv *priv, |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 726 | enum ieee80211_band band, |
| 727 | struct ieee80211_mgmt *frame, |
| 728 | int left, int is_direct) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 729 | { |
| 730 | int len = 0; |
| 731 | u8 *pos = NULL; |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 732 | u16 active_rates, ret_rates, cck_rates, active_rate_basic; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 733 | const struct ieee80211_supported_band *sband = |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 734 | iwl_get_hw_mode(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 735 | |
| 736 | /* Make sure there is enough space for the probe request, |
| 737 | * two mandatory IEs and the data */ |
| 738 | left -= 24; |
| 739 | if (left < 0) |
| 740 | return 0; |
| 741 | len += 24; |
| 742 | |
| 743 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
Tomas Winkler | 57bd1be | 2008-05-15 13:54:03 +0800 | [diff] [blame] | 744 | memcpy(frame->da, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 745 | memcpy(frame->sa, priv->mac_addr, ETH_ALEN); |
Tomas Winkler | 57bd1be | 2008-05-15 13:54:03 +0800 | [diff] [blame] | 746 | memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 747 | frame->seq_ctrl = 0; |
| 748 | |
| 749 | /* fill in our indirect SSID IE */ |
| 750 | /* ...next IE... */ |
| 751 | |
| 752 | left -= 2; |
| 753 | if (left < 0) |
| 754 | return 0; |
| 755 | len += 2; |
| 756 | pos = &(frame->u.probe_req.variable[0]); |
| 757 | *pos++ = WLAN_EID_SSID; |
| 758 | *pos++ = 0; |
| 759 | |
| 760 | /* fill in our direct SSID IE... */ |
| 761 | if (is_direct) { |
| 762 | /* ...next IE... */ |
| 763 | left -= 2 + priv->essid_len; |
| 764 | if (left < 0) |
| 765 | return 0; |
| 766 | /* ... fill it in... */ |
| 767 | *pos++ = WLAN_EID_SSID; |
| 768 | *pos++ = priv->essid_len; |
| 769 | memcpy(pos, priv->essid, priv->essid_len); |
| 770 | pos += priv->essid_len; |
| 771 | len += 2 + priv->essid_len; |
| 772 | } |
| 773 | |
| 774 | /* fill in supported rate */ |
| 775 | /* ...next IE... */ |
| 776 | left -= 2; |
| 777 | if (left < 0) |
| 778 | return 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 779 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 780 | /* ... fill it in... */ |
| 781 | *pos++ = WLAN_EID_SUPP_RATES; |
| 782 | *pos = 0; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 783 | |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 784 | /* exclude 60M rate */ |
| 785 | active_rates = priv->rates_mask; |
| 786 | active_rates &= ~IWL_RATE_60M_MASK; |
| 787 | |
| 788 | active_rate_basic = active_rates & IWL_BASIC_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 789 | |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 790 | cck_rates = IWL_CCK_RATES_MASK & active_rates; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 791 | ret_rates = iwl4965_supported_rate_to_ie(pos, cck_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 792 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 793 | active_rates &= ~ret_rates; |
| 794 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 795 | ret_rates = iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 796 | active_rate_basic, &left); |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 797 | active_rates &= ~ret_rates; |
| 798 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 799 | len += 2 + *pos; |
| 800 | pos += (*pos) + 1; |
Tomas Winkler | c7c4667 | 2007-10-18 02:04:15 +0200 | [diff] [blame] | 801 | if (active_rates == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 802 | goto fill_end; |
| 803 | |
| 804 | /* fill in supported extended rate */ |
| 805 | /* ...next IE... */ |
| 806 | left -= 2; |
| 807 | if (left < 0) |
| 808 | return 0; |
| 809 | /* ... fill it in... */ |
| 810 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 811 | *pos = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 812 | iwl4965_supported_rate_to_ie(pos, active_rates, |
mabbas | bee488d | 2007-10-25 17:15:42 +0800 | [diff] [blame] | 813 | active_rate_basic, &left); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 814 | if (*pos > 0) |
| 815 | len += 2 + *pos; |
| 816 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 817 | fill_end: |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 818 | /* fill in HT IE */ |
| 819 | left -= 2; |
| 820 | if (left < 0) |
| 821 | return 0; |
| 822 | |
| 823 | *pos++ = WLAN_EID_HT_CAPABILITY; |
| 824 | *pos = 0; |
| 825 | |
| 826 | iwl_ht_cap_to_ie(sband, pos, &left); |
| 827 | |
| 828 | if (*pos > 0) |
| 829 | len += 2 + *pos; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 830 | return (u16)len; |
| 831 | } |
| 832 | |
| 833 | /* |
| 834 | * QoS support |
| 835 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 836 | static int iwl4965_send_qos_params_command(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 837 | struct iwl4965_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 838 | { |
| 839 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 840 | return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 841 | sizeof(struct iwl4965_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 842 | } |
| 843 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 844 | static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 845 | { |
| 846 | unsigned long flags; |
| 847 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 848 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 849 | return; |
| 850 | |
| 851 | if (!priv->qos_data.qos_enable) |
| 852 | return; |
| 853 | |
| 854 | spin_lock_irqsave(&priv->lock, flags); |
| 855 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 856 | |
| 857 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 858 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 859 | priv->qos_data.def_qos_parm.qos_flags |= |
| 860 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 861 | if (priv->qos_data.qos_active) |
| 862 | priv->qos_data.def_qos_parm.qos_flags |= |
| 863 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 864 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 865 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 866 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 867 | 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] | 868 | #endif /* CONFIG_IWL4965_HT */ |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 869 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 870 | spin_unlock_irqrestore(&priv->lock, flags); |
| 871 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 872 | if (force || iwl_is_associated(priv)) { |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 873 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 874 | priv->qos_data.qos_active, |
| 875 | priv->qos_data.def_qos_parm.qos_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 876 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 877 | iwl4965_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 878 | &(priv->qos_data.def_qos_parm)); |
| 879 | } |
| 880 | } |
| 881 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 882 | 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] | 883 | { |
| 884 | /* Filter incoming packets to determine if they are targeted toward |
| 885 | * this network, discarding packets coming from ourselves */ |
| 886 | switch (priv->iw_mode) { |
| 887 | case IEEE80211_IF_TYPE_IBSS: /* Header: Dest. | Source | BSSID */ |
| 888 | /* packets from our adapter are dropped (echo) */ |
| 889 | if (!compare_ether_addr(header->addr2, priv->mac_addr)) |
| 890 | return 0; |
| 891 | /* {broad,multi}cast packets to our IBSS go through */ |
| 892 | if (is_multicast_ether_addr(header->addr1)) |
| 893 | return !compare_ether_addr(header->addr3, priv->bssid); |
| 894 | /* packets to our adapter go through */ |
| 895 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
| 896 | case IEEE80211_IF_TYPE_STA: /* Header: Dest. | AP{BSSID} | Source */ |
| 897 | /* packets from our adapter are dropped (echo) */ |
| 898 | if (!compare_ether_addr(header->addr3, priv->mac_addr)) |
| 899 | return 0; |
| 900 | /* {broad,multi}cast packets to our BSS go through */ |
| 901 | if (is_multicast_ether_addr(header->addr1)) |
| 902 | return !compare_ether_addr(header->addr2, priv->bssid); |
| 903 | /* packets to our adapter go through */ |
| 904 | return !compare_ether_addr(header->addr1, priv->mac_addr); |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 905 | default: |
| 906 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | return 1; |
| 910 | } |
| 911 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 912 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 913 | |
| 914 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 915 | * iwl4965_scan_cancel - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 916 | * |
| 917 | * NOTE: priv->mutex is not required before calling this function |
| 918 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 919 | static int iwl4965_scan_cancel(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 920 | { |
| 921 | if (!test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 922 | clear_bit(STATUS_SCANNING, &priv->status); |
| 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 927 | if (!test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 928 | IWL_DEBUG_SCAN("Queuing scan abort.\n"); |
| 929 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 930 | queue_work(priv->workqueue, &priv->abort_scan); |
| 931 | |
| 932 | } else |
| 933 | IWL_DEBUG_SCAN("Scan abort already in progress.\n"); |
| 934 | |
| 935 | return test_bit(STATUS_SCANNING, &priv->status); |
| 936 | } |
| 937 | |
| 938 | return 0; |
| 939 | } |
| 940 | |
| 941 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 942 | * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 943 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 944 | * |
| 945 | * NOTE: priv->mutex must be held before calling this function |
| 946 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 947 | 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] | 948 | { |
| 949 | unsigned long now = jiffies; |
| 950 | int ret; |
| 951 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 952 | ret = iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 953 | if (ret && ms) { |
| 954 | mutex_unlock(&priv->mutex); |
| 955 | while (!time_after(jiffies, now + msecs_to_jiffies(ms)) && |
| 956 | test_bit(STATUS_SCANNING, &priv->status)) |
| 957 | msleep(1); |
| 958 | mutex_lock(&priv->mutex); |
| 959 | |
| 960 | return test_bit(STATUS_SCANNING, &priv->status); |
| 961 | } |
| 962 | |
| 963 | return ret; |
| 964 | } |
| 965 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 966 | static void iwl4965_sequence_reset(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 967 | { |
| 968 | /* Reset ieee stats */ |
| 969 | |
| 970 | /* We don't reset the net_device_stats (ieee->stats) on |
| 971 | * re-association */ |
| 972 | |
| 973 | priv->last_seq_num = -1; |
| 974 | priv->last_frag_num = -1; |
| 975 | priv->last_packet_time = 0; |
| 976 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 977 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 981 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 982 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 983 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 984 | { |
| 985 | u16 new_val = 0; |
| 986 | u16 beacon_factor = 0; |
| 987 | |
| 988 | beacon_factor = |
| 989 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 990 | / MAX_UCODE_BEACON_INTERVAL; |
| 991 | new_val = beacon_val / beacon_factor; |
| 992 | |
| 993 | return cpu_to_le16(new_val); |
| 994 | } |
| 995 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 996 | static void iwl4965_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 997 | { |
| 998 | u64 interval_tm_unit; |
| 999 | u64 tsf, result; |
| 1000 | unsigned long flags; |
| 1001 | struct ieee80211_conf *conf = NULL; |
| 1002 | u16 beacon_int = 0; |
| 1003 | |
| 1004 | conf = ieee80211_get_hw_conf(priv->hw); |
| 1005 | |
| 1006 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1007 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32); |
| 1008 | priv->rxon_timing.timestamp.dw[0] = |
| 1009 | cpu_to_le32(priv->timestamp & 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1010 | |
| 1011 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 1012 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1013 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1014 | |
| 1015 | beacon_int = priv->beacon_int; |
| 1016 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1017 | |
| 1018 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 1019 | if (beacon_int == 0) { |
| 1020 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 1021 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 1022 | } else { |
| 1023 | priv->rxon_timing.beacon_interval = |
| 1024 | cpu_to_le16(beacon_int); |
| 1025 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1026 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1027 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1028 | } |
| 1029 | |
| 1030 | priv->rxon_timing.atim_window = 0; |
| 1031 | } else { |
| 1032 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1033 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1034 | /* TODO: we need to get atim_window from upper stack |
| 1035 | * for now we set to 0 */ |
| 1036 | priv->rxon_timing.atim_window = 0; |
| 1037 | } |
| 1038 | |
| 1039 | interval_tm_unit = |
| 1040 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 1041 | result = do_div(tsf, interval_tm_unit); |
| 1042 | priv->rxon_timing.beacon_init_val = |
| 1043 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 1044 | |
| 1045 | IWL_DEBUG_ASSOC |
| 1046 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 1047 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 1048 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 1049 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 1050 | } |
| 1051 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1052 | static int iwl4965_scan_initiate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1053 | { |
| 1054 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 1055 | IWL_ERROR("APs don't scan.\n"); |
| 1056 | return 0; |
| 1057 | } |
| 1058 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1059 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1060 | IWL_DEBUG_SCAN("Aborting scan due to not ready.\n"); |
| 1061 | return -EIO; |
| 1062 | } |
| 1063 | |
| 1064 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1065 | IWL_DEBUG_SCAN("Scan already in progress.\n"); |
| 1066 | return -EAGAIN; |
| 1067 | } |
| 1068 | |
| 1069 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1070 | IWL_DEBUG_SCAN("Scan request while abort pending. " |
| 1071 | "Queuing.\n"); |
| 1072 | return -EAGAIN; |
| 1073 | } |
| 1074 | |
| 1075 | IWL_DEBUG_INFO("Starting scan...\n"); |
| 1076 | priv->scan_bands = 2; |
| 1077 | set_bit(STATUS_SCANNING, &priv->status); |
| 1078 | priv->scan_start = jiffies; |
| 1079 | priv->scan_pass_start = priv->scan_start; |
| 1080 | |
| 1081 | queue_work(priv->workqueue, &priv->request_scan); |
| 1082 | |
| 1083 | return 0; |
| 1084 | } |
| 1085 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1086 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1087 | static void iwl4965_set_flags_for_phymode(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1088 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1089 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1090 | if (band == IEEE80211_BAND_5GHZ) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1091 | priv->staging_rxon.flags &= |
| 1092 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 1093 | | RXON_FLG_CCK_MSK); |
| 1094 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1095 | } else { |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 1096 | /* Copied from iwl4965_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1097 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 1098 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 1099 | else |
| 1100 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1101 | |
| 1102 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 1103 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 1104 | |
| 1105 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 1106 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 1107 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1112 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1113 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1114 | static void iwl4965_connection_init_rx_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1115 | { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1116 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1117 | |
| 1118 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 1119 | |
| 1120 | switch (priv->iw_mode) { |
| 1121 | case IEEE80211_IF_TYPE_AP: |
| 1122 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 1123 | break; |
| 1124 | |
| 1125 | case IEEE80211_IF_TYPE_STA: |
| 1126 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 1127 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 1128 | break; |
| 1129 | |
| 1130 | case IEEE80211_IF_TYPE_IBSS: |
| 1131 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 1132 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1133 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 1134 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1135 | break; |
| 1136 | |
| 1137 | case IEEE80211_IF_TYPE_MNTR: |
| 1138 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 1139 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 1140 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 1141 | break; |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 1142 | default: |
| 1143 | IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode); |
| 1144 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | #if 0 |
| 1148 | /* TODO: Figure out when short_preamble would be set and cache from |
| 1149 | * that */ |
| 1150 | if (!hw_to_local(priv->hw)->short_preamble) |
| 1151 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1152 | else |
| 1153 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 1154 | #endif |
| 1155 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1156 | ch_info = iwl_get_channel_info(priv, priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1157 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1158 | |
| 1159 | if (!ch_info) |
| 1160 | ch_info = &priv->channel_info[0]; |
| 1161 | |
| 1162 | /* |
| 1163 | * in some case A channels are all non IBSS |
| 1164 | * in this case force B/G channel |
| 1165 | */ |
| 1166 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 1167 | !(is_channel_ibss(ch_info))) |
| 1168 | ch_info = &priv->channel_info[0]; |
| 1169 | |
| 1170 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1171 | priv->band = ch_info->band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1172 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1173 | iwl4965_set_flags_for_phymode(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1174 | |
| 1175 | priv->staging_rxon.ofdm_basic_rates = |
| 1176 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1177 | priv->staging_rxon.cck_basic_rates = |
| 1178 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1179 | |
| 1180 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 1181 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 1182 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1183 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 1184 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 1185 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 1186 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1187 | } |
| 1188 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1189 | static int iwl4965_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1190 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1191 | if (mode == IEEE80211_IF_TYPE_IBSS) { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1192 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1193 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1194 | ch_info = iwl_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1195 | priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1196 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1197 | |
| 1198 | if (!ch_info || !is_channel_ibss(ch_info)) { |
| 1199 | IWL_ERROR("channel %d not IBSS channel\n", |
| 1200 | le16_to_cpu(priv->staging_rxon.channel)); |
| 1201 | return -EINVAL; |
| 1202 | } |
| 1203 | } |
| 1204 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1205 | priv->iw_mode = mode; |
| 1206 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1207 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1208 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 1209 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1210 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1211 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1212 | /* dont commit rxon if rf-kill is on*/ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 1213 | if (!iwl_is_ready_rf(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 1214 | return -EAGAIN; |
| 1215 | |
| 1216 | cancel_delayed_work(&priv->scan_check); |
| 1217 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
| 1218 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 1219 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 1220 | return -EAGAIN; |
| 1221 | } |
| 1222 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1223 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1224 | |
| 1225 | return 0; |
| 1226 | } |
| 1227 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1228 | static void iwl4965_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1229 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1230 | const struct ieee80211_supported_band *hw = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1231 | struct ieee80211_rate *rate; |
| 1232 | int i; |
| 1233 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 1234 | hw = iwl_get_hw_mode(priv, priv->band); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 1235 | if (!hw) { |
| 1236 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 1237 | return; |
| 1238 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1239 | |
| 1240 | priv->active_rate = 0; |
| 1241 | priv->active_rate_basic = 0; |
| 1242 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1243 | for (i = 0; i < hw->n_bitrates; i++) { |
| 1244 | rate = &(hw->bitrates[i]); |
| 1245 | if (rate->hw_value < IWL_RATE_COUNT) |
| 1246 | priv->active_rate |= (1 << rate->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 1250 | priv->active_rate, priv->active_rate_basic); |
| 1251 | |
| 1252 | /* |
| 1253 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 1254 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 1255 | * OFDM |
| 1256 | */ |
| 1257 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 1258 | priv->staging_rxon.cck_basic_rates = |
| 1259 | ((priv->active_rate_basic & |
| 1260 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1261 | else |
| 1262 | priv->staging_rxon.cck_basic_rates = |
| 1263 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 1264 | |
| 1265 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 1266 | priv->staging_rxon.ofdm_basic_rates = |
| 1267 | ((priv->active_rate_basic & |
| 1268 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 1269 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1270 | else |
| 1271 | priv->staging_rxon.ofdm_basic_rates = |
| 1272 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 1273 | } |
| 1274 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1275 | void iwl4965_radio_kill_sw(struct iwl_priv *priv, int disable_radio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1276 | { |
| 1277 | unsigned long flags; |
| 1278 | |
| 1279 | if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status)) |
| 1280 | return; |
| 1281 | |
| 1282 | IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n", |
| 1283 | disable_radio ? "OFF" : "ON"); |
| 1284 | |
| 1285 | if (disable_radio) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1286 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1287 | /* FIXME: This is a workaround for AP */ |
| 1288 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 1289 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1290 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1291 | CSR_UCODE_SW_BIT_RFKILL); |
| 1292 | spin_unlock_irqrestore(&priv->lock, flags); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1293 | /* call the host command only if no hw rf-kill set */ |
Mohamed Abbas | 5900383 | 2008-04-15 16:01:46 -0700 | [diff] [blame] | 1294 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status) && |
| 1295 | iwl_is_ready(priv)) |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1296 | iwl4965_send_card_state(priv, |
| 1297 | CARD_STATE_CMD_DISABLE, |
| 1298 | 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1299 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 1300 | |
| 1301 | /* make sure mac80211 stop sending Tx frame */ |
| 1302 | if (priv->mac80211_registered) |
| 1303 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1304 | } |
| 1305 | return; |
| 1306 | } |
| 1307 | |
| 1308 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1309 | 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] | 1310 | |
| 1311 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 1312 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1313 | |
| 1314 | /* wake up ucode */ |
| 1315 | msleep(10); |
| 1316 | |
| 1317 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1318 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 1319 | if (!iwl_grab_nic_access(priv)) |
| 1320 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1321 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1322 | |
| 1323 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) { |
| 1324 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 1325 | "disabled by HW switch\n"); |
| 1326 | return; |
| 1327 | } |
| 1328 | |
| 1329 | queue_work(priv->workqueue, &priv->restart); |
| 1330 | return; |
| 1331 | } |
| 1332 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1333 | #define IWL_PACKET_RETRY_TIME HZ |
| 1334 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1335 | 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] | 1336 | { |
| 1337 | u16 sc = le16_to_cpu(header->seq_ctrl); |
| 1338 | u16 seq = (sc & IEEE80211_SCTL_SEQ) >> 4; |
| 1339 | u16 frag = sc & IEEE80211_SCTL_FRAG; |
| 1340 | u16 *last_seq, *last_frag; |
| 1341 | unsigned long *last_time; |
| 1342 | |
| 1343 | switch (priv->iw_mode) { |
| 1344 | case IEEE80211_IF_TYPE_IBSS:{ |
| 1345 | struct list_head *p; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1346 | struct iwl4965_ibss_seq *entry = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1347 | u8 *mac = header->addr2; |
| 1348 | int index = mac[5] & (IWL_IBSS_MAC_HASH_SIZE - 1); |
| 1349 | |
| 1350 | __list_for_each(p, &priv->ibss_mac_hash[index]) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1351 | entry = list_entry(p, struct iwl4965_ibss_seq, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1352 | if (!compare_ether_addr(entry->mac, mac)) |
| 1353 | break; |
| 1354 | } |
| 1355 | if (p == &priv->ibss_mac_hash[index]) { |
| 1356 | entry = kzalloc(sizeof(*entry), GFP_ATOMIC); |
| 1357 | if (!entry) { |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1358 | IWL_ERROR("Cannot malloc new mac entry\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1359 | return 0; |
| 1360 | } |
| 1361 | memcpy(entry->mac, mac, ETH_ALEN); |
| 1362 | entry->seq_num = seq; |
| 1363 | entry->frag_num = frag; |
| 1364 | entry->packet_time = jiffies; |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1365 | list_add(&entry->list, &priv->ibss_mac_hash[index]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1366 | return 0; |
| 1367 | } |
| 1368 | last_seq = &entry->seq_num; |
| 1369 | last_frag = &entry->frag_num; |
| 1370 | last_time = &entry->packet_time; |
| 1371 | break; |
| 1372 | } |
| 1373 | case IEEE80211_IF_TYPE_STA: |
| 1374 | last_seq = &priv->last_seq_num; |
| 1375 | last_frag = &priv->last_frag_num; |
| 1376 | last_time = &priv->last_packet_time; |
| 1377 | break; |
| 1378 | default: |
| 1379 | return 0; |
| 1380 | } |
| 1381 | if ((*last_seq == seq) && |
| 1382 | time_after(*last_time + IWL_PACKET_RETRY_TIME, jiffies)) { |
| 1383 | if (*last_frag == frag) |
| 1384 | goto drop; |
| 1385 | if (*last_frag + 1 != frag) |
| 1386 | /* out-of-order fragment */ |
| 1387 | goto drop; |
| 1388 | } else |
| 1389 | *last_seq = seq; |
| 1390 | |
| 1391 | *last_frag = frag; |
| 1392 | *last_time = jiffies; |
| 1393 | return 0; |
| 1394 | |
| 1395 | drop: |
| 1396 | return 1; |
| 1397 | } |
| 1398 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1399 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1400 | |
| 1401 | #include "iwl-spectrum.h" |
| 1402 | |
| 1403 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 1404 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 1405 | #define TIME_UNIT 1024 |
| 1406 | |
| 1407 | /* |
| 1408 | * extended beacon time format |
| 1409 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 1410 | * the high 1 byte is the beacon counts |
| 1411 | * the lower 3 bytes is the time in usec within one beacon interval |
| 1412 | */ |
| 1413 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1414 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1415 | { |
| 1416 | u32 quot; |
| 1417 | u32 rem; |
| 1418 | u32 interval = beacon_interval * 1024; |
| 1419 | |
| 1420 | if (!interval || !usec) |
| 1421 | return 0; |
| 1422 | |
| 1423 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 1424 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 1425 | |
| 1426 | return (quot << 24) + rem; |
| 1427 | } |
| 1428 | |
| 1429 | /* base is usually what we get from ucode with each received frame, |
| 1430 | * the same as HW timer counter counting down |
| 1431 | */ |
| 1432 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1433 | 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] | 1434 | { |
| 1435 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 1436 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 1437 | u32 interval = beacon_interval * TIME_UNIT; |
| 1438 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 1439 | (addon & BEACON_TIME_MASK_HIGH); |
| 1440 | |
| 1441 | if (base_low > addon_low) |
| 1442 | res += base_low - addon_low; |
| 1443 | else if (base_low < addon_low) { |
| 1444 | res += interval + base_low - addon_low; |
| 1445 | res += (1 << 24); |
| 1446 | } else |
| 1447 | res += (1 << 24); |
| 1448 | |
| 1449 | return cpu_to_le32(res); |
| 1450 | } |
| 1451 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1452 | static int iwl4965_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1453 | struct ieee80211_measurement_params *params, |
| 1454 | u8 type) |
| 1455 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1456 | struct iwl4965_spectrum_cmd spectrum; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1457 | struct iwl_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1458 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1459 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 1460 | .data = (void *)&spectrum, |
| 1461 | .meta.flags = CMD_WANT_SKB, |
| 1462 | }; |
| 1463 | u32 add_time = le64_to_cpu(params->start_time); |
| 1464 | int rc; |
| 1465 | int spectrum_resp_status; |
| 1466 | int duration = le16_to_cpu(params->duration); |
| 1467 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1468 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1469 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1470 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1471 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 1472 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1473 | |
| 1474 | memset(&spectrum, 0, sizeof(spectrum)); |
| 1475 | |
| 1476 | spectrum.channel_count = cpu_to_le16(1); |
| 1477 | spectrum.flags = |
| 1478 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 1479 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 1480 | cmd.len = sizeof(spectrum); |
| 1481 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 1482 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1483 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1484 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1485 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1486 | add_time, |
| 1487 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1488 | else |
| 1489 | spectrum.start_time = 0; |
| 1490 | |
| 1491 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 1492 | spectrum.channels[0].channel = params->channel; |
| 1493 | spectrum.channels[0].type = type; |
| 1494 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 1495 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 1496 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 1497 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1498 | rc = iwl_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1499 | if (rc) |
| 1500 | return rc; |
| 1501 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1502 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1503 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 1504 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 1505 | rc = -EIO; |
| 1506 | } |
| 1507 | |
| 1508 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 1509 | switch (spectrum_resp_status) { |
| 1510 | case 0: /* Command will be handled */ |
| 1511 | if (res->u.spectrum.id != 0xff) { |
| 1512 | IWL_DEBUG_INFO |
| 1513 | ("Replaced existing measurement: %d\n", |
| 1514 | res->u.spectrum.id); |
| 1515 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 1516 | } |
| 1517 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 1518 | rc = 0; |
| 1519 | break; |
| 1520 | |
| 1521 | case 1: /* Command will not be handled */ |
| 1522 | rc = -EAGAIN; |
| 1523 | break; |
| 1524 | } |
| 1525 | |
| 1526 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1527 | |
| 1528 | return rc; |
| 1529 | } |
| 1530 | #endif |
| 1531 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1532 | /****************************************************************************** |
| 1533 | * |
| 1534 | * Generic RX handler implementations |
| 1535 | * |
| 1536 | ******************************************************************************/ |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1537 | static void iwl_rx_reply_alive(struct iwl_priv *priv, |
| 1538 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1539 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1540 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1541 | struct iwl_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1542 | struct delayed_work *pwork; |
| 1543 | |
| 1544 | palive = &pkt->u.alive_frame; |
| 1545 | |
| 1546 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 1547 | "0x%01X 0x%01X\n", |
| 1548 | palive->is_valid, palive->ver_type, |
| 1549 | palive->ver_subtype); |
| 1550 | |
| 1551 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 1552 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 1553 | memcpy(&priv->card_alive_init, |
| 1554 | &pkt->u.alive_frame, |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1555 | sizeof(struct iwl_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1556 | pwork = &priv->init_alive_start; |
| 1557 | } else { |
| 1558 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 1559 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1560 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1561 | pwork = &priv->alive_start; |
| 1562 | } |
| 1563 | |
| 1564 | /* We delay the ALIVE response by 5ms to |
| 1565 | * give the HW RF Kill time to activate... */ |
| 1566 | if (palive->is_valid == UCODE_VALID_OK) |
| 1567 | queue_delayed_work(priv->workqueue, pwork, |
| 1568 | msecs_to_jiffies(5)); |
| 1569 | else |
| 1570 | IWL_WARNING("uCode did not respond OK.\n"); |
| 1571 | } |
| 1572 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1573 | static void iwl4965_rx_reply_error(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1574 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1575 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1576 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1577 | |
| 1578 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 1579 | "seq 0x%04X ser 0x%08X\n", |
| 1580 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 1581 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 1582 | pkt->u.err_resp.cmd_id, |
| 1583 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 1584 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 1585 | } |
| 1586 | |
| 1587 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 1588 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1589 | 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] | 1590 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1591 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 1592 | struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1593 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1594 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 1595 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 1596 | rxon->channel = csa->channel; |
| 1597 | priv->staging_rxon.channel = csa->channel; |
| 1598 | } |
| 1599 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1600 | static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1601 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1602 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1603 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1604 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1605 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1606 | |
| 1607 | if (!report->state) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1608 | IWL_DEBUG(IWL_DL_11H, |
| 1609 | "Spectrum Measure Notification: Start\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1610 | return; |
| 1611 | } |
| 1612 | |
| 1613 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 1614 | priv->measurement_status |= MEASUREMENT_READY; |
| 1615 | #endif |
| 1616 | } |
| 1617 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1618 | static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1619 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1620 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1621 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1622 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1623 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1624 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 1625 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 1626 | #endif |
| 1627 | } |
| 1628 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1629 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1630 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1631 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1632 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1633 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 1634 | "notification for %s:\n", |
| 1635 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1636 | 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] | 1637 | } |
| 1638 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1639 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1640 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1641 | struct iwl_priv *priv = |
| 1642 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1643 | struct sk_buff *beacon; |
| 1644 | |
| 1645 | /* 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] | 1646 | beacon = ieee80211_beacon_get(priv->hw, priv->vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1647 | |
| 1648 | if (!beacon) { |
| 1649 | IWL_ERROR("update beacon failed\n"); |
| 1650 | return; |
| 1651 | } |
| 1652 | |
| 1653 | mutex_lock(&priv->mutex); |
| 1654 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 1655 | if (priv->ibss_beacon) |
| 1656 | dev_kfree_skb(priv->ibss_beacon); |
| 1657 | |
| 1658 | priv->ibss_beacon = beacon; |
| 1659 | mutex_unlock(&priv->mutex); |
| 1660 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1661 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1662 | } |
| 1663 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1664 | static void iwl4965_rx_beacon_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1665 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1666 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1667 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1668 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1669 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
| 1670 | 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] | 1671 | |
| 1672 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 1673 | "tsf %d %d rate %d\n", |
| 1674 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 1675 | beacon->beacon_notify_hdr.failure_frame, |
| 1676 | le32_to_cpu(beacon->ibss_mgr_status), |
| 1677 | le32_to_cpu(beacon->high_tsf), |
| 1678 | le32_to_cpu(beacon->low_tsf), rate); |
| 1679 | #endif |
| 1680 | |
| 1681 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 1682 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 1683 | queue_work(priv->workqueue, &priv->beacon_update); |
| 1684 | } |
| 1685 | |
| 1686 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1687 | static void iwl4965_rx_reply_scan(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1688 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1689 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1690 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1691 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1692 | struct iwl4965_scanreq_notification *notif = |
| 1693 | (struct iwl4965_scanreq_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1694 | |
| 1695 | IWL_DEBUG_RX("Scan request status = 0x%x\n", notif->status); |
| 1696 | #endif |
| 1697 | } |
| 1698 | |
| 1699 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1700 | static void iwl4965_rx_scan_start_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1701 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1702 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1703 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1704 | struct iwl4965_scanstart_notification *notif = |
| 1705 | (struct iwl4965_scanstart_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1706 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
| 1707 | IWL_DEBUG_SCAN("Scan start: " |
| 1708 | "%d [802.11%s] " |
| 1709 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 1710 | notif->channel, |
| 1711 | notif->band ? "bg" : "a", |
| 1712 | notif->tsf_high, |
| 1713 | notif->tsf_low, notif->status, notif->beacon_timer); |
| 1714 | } |
| 1715 | |
| 1716 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1717 | static void iwl4965_rx_scan_results_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1718 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1719 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1720 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1721 | struct iwl4965_scanresults_notification *notif = |
| 1722 | (struct iwl4965_scanresults_notification *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1723 | |
| 1724 | IWL_DEBUG_SCAN("Scan ch.res: " |
| 1725 | "%d [802.11%s] " |
| 1726 | "(TSF: 0x%08X:%08X) - %d " |
| 1727 | "elapsed=%lu usec (%dms since last)\n", |
| 1728 | notif->channel, |
| 1729 | notif->band ? "bg" : "a", |
| 1730 | le32_to_cpu(notif->tsf_high), |
| 1731 | le32_to_cpu(notif->tsf_low), |
| 1732 | le32_to_cpu(notif->statistics[0]), |
| 1733 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf, |
| 1734 | jiffies_to_msecs(elapsed_jiffies |
| 1735 | (priv->last_scan_jiffies, jiffies))); |
| 1736 | |
| 1737 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 1738 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1742 | static void iwl4965_rx_scan_complete_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1743 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1744 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1745 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1746 | struct iwl4965_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1747 | |
| 1748 | IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
| 1749 | scan_notif->scanned_channels, |
| 1750 | scan_notif->tsf_low, |
| 1751 | scan_notif->tsf_high, scan_notif->status); |
| 1752 | |
| 1753 | /* The HW is no longer scanning */ |
| 1754 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 1755 | |
| 1756 | /* The scan completion notification came in, so kill that timer... */ |
| 1757 | cancel_delayed_work(&priv->scan_check); |
| 1758 | |
| 1759 | IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n", |
| 1760 | (priv->scan_bands == 2) ? "2.4" : "5.2", |
| 1761 | jiffies_to_msecs(elapsed_jiffies |
| 1762 | (priv->scan_pass_start, jiffies))); |
| 1763 | |
| 1764 | /* Remove this scanned band from the list |
| 1765 | * of pending bands to scan */ |
| 1766 | priv->scan_bands--; |
| 1767 | |
| 1768 | /* If a request to abort was given, or the scan did not succeed |
| 1769 | * then we reset the scan state machine and terminate, |
| 1770 | * re-queuing another scan if one has been requested */ |
| 1771 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 1772 | IWL_DEBUG_INFO("Aborted scan completed.\n"); |
| 1773 | clear_bit(STATUS_SCAN_ABORTING, &priv->status); |
| 1774 | } else { |
| 1775 | /* If there are more bands on this scan pass reschedule */ |
| 1776 | if (priv->scan_bands > 0) |
| 1777 | goto reschedule; |
| 1778 | } |
| 1779 | |
| 1780 | priv->last_scan_jiffies = jiffies; |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 1781 | priv->next_scan_jiffies = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1782 | IWL_DEBUG_INFO("Setting scan to off\n"); |
| 1783 | |
| 1784 | clear_bit(STATUS_SCANNING, &priv->status); |
| 1785 | |
| 1786 | IWL_DEBUG_INFO("Scan took %dms\n", |
| 1787 | jiffies_to_msecs(elapsed_jiffies(priv->scan_start, jiffies))); |
| 1788 | |
| 1789 | queue_work(priv->workqueue, &priv->scan_completed); |
| 1790 | |
| 1791 | return; |
| 1792 | |
| 1793 | reschedule: |
| 1794 | priv->scan_pass_start = jiffies; |
| 1795 | queue_work(priv->workqueue, &priv->request_scan); |
| 1796 | } |
| 1797 | |
| 1798 | /* Handle notification from uCode that card's power state is changing |
| 1799 | * due to software, hardware, or critical temperature RFKILL */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1800 | static void iwl4965_rx_card_state_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1801 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1802 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1803 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1804 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 1805 | unsigned long status = priv->status; |
| 1806 | |
| 1807 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 1808 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 1809 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 1810 | |
| 1811 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 1812 | RF_CARD_DISABLED)) { |
| 1813 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1814 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1815 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 1816 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1817 | if (!iwl_grab_nic_access(priv)) { |
| 1818 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1819 | priv, HBUS_TARG_MBX_C, |
| 1820 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 1821 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1822 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | if (!(flags & RXON_CARD_DISABLED)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1826 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1827 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1828 | if (!iwl_grab_nic_access(priv)) { |
| 1829 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1830 | priv, HBUS_TARG_MBX_C, |
| 1831 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 1832 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1833 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1834 | } |
| 1835 | } |
| 1836 | |
| 1837 | if (flags & RF_CARD_DISABLED) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1838 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1839 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1840 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 1841 | if (!iwl_grab_nic_access(priv)) |
| 1842 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1843 | } |
| 1844 | } |
| 1845 | |
| 1846 | if (flags & HW_CARD_DISABLED) |
| 1847 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 1848 | else |
| 1849 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 1850 | |
| 1851 | |
| 1852 | if (flags & SW_CARD_DISABLED) |
| 1853 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 1854 | else |
| 1855 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 1856 | |
| 1857 | if (!(flags & RXON_CARD_DISABLED)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1858 | iwl4965_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1859 | |
| 1860 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 1861 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 1862 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 1863 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 1864 | queue_work(priv->workqueue, &priv->rf_kill); |
| 1865 | else |
| 1866 | wake_up_interruptible(&priv->wait_command_queue); |
| 1867 | } |
| 1868 | |
Ron Rindjunsky | 37a4421 | 2008-05-29 16:35:18 +0800 | [diff] [blame] | 1869 | /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD). |
| 1870 | * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */ |
| 1871 | static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv, |
| 1872 | struct iwl_rx_mem_buffer *rxb) |
| 1873 | { |
| 1874 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
| 1875 | priv->last_phy_res[0] = 1; |
| 1876 | memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]), |
| 1877 | sizeof(struct iwl4965_rx_phy_res)); |
| 1878 | } |
| 1879 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1880 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1881 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1882 | * |
| 1883 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 1884 | * to the host. |
| 1885 | * |
| 1886 | * This function chains into the hardware specific files for them to setup |
| 1887 | * any hardware specific handlers as well. |
| 1888 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1889 | static void iwl4965_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1890 | { |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1891 | priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1892 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 1893 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1894 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1895 | iwl4965_rx_spectrum_measure_notif; |
| 1896 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1897 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1898 | iwl4965_rx_pm_debug_statistics_notif; |
| 1899 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1900 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1901 | /* |
| 1902 | * The same handler is used for both the REPLY to a discrete |
| 1903 | * statistics request from the host as well as for the periodic |
| 1904 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1905 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1906 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_hw_rx_statistics; |
| 1907 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_hw_rx_statistics; |
Ron Rindjunsky | 37a4421 | 2008-05-29 16:35:18 +0800 | [diff] [blame] | 1908 | /* scan handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1909 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl4965_rx_reply_scan; |
| 1910 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl4965_rx_scan_start_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1911 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1912 | iwl4965_rx_scan_results_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1913 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1914 | iwl4965_rx_scan_complete_notif; |
Ron Rindjunsky | 37a4421 | 2008-05-29 16:35:18 +0800 | [diff] [blame] | 1915 | /* status change handler */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1916 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1917 | |
Tomas Winkler | c135475 | 2008-05-29 16:35:04 +0800 | [diff] [blame] | 1918 | priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] = |
| 1919 | iwl_rx_missed_beacon_notif; |
Ron Rindjunsky | 37a4421 | 2008-05-29 16:35:18 +0800 | [diff] [blame] | 1920 | /* Rx handlers */ |
| 1921 | priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy; |
| 1922 | priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1923 | /* Set up hardware specific Rx handlers */ |
Emmanuel Grumbach | d4789ef | 2008-04-24 11:55:20 -0700 | [diff] [blame] | 1924 | priv->cfg->ops->lib->rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1925 | } |
| 1926 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1927 | /* |
| 1928 | * this should be called while priv->lock is locked |
| 1929 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1930 | static void __iwl_rx_replenish(struct iwl_priv *priv) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1931 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1932 | iwl_rx_allocate(priv); |
| 1933 | iwl_rx_queue_restock(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | |
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 | * iwl_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1939 | * |
| 1940 | * Uses the priv->rx_handlers callback function array to invoke |
| 1941 | * the appropriate handlers, including command responses, |
| 1942 | * frame-received notifications, and other notifications. |
| 1943 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1944 | void iwl_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1945 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1946 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1947 | struct iwl_rx_packet *pkt; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1948 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1949 | u32 r, i; |
| 1950 | int reclaim; |
| 1951 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1952 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 1953 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1954 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1955 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 1956 | * buffer that the driver may process (last buffer filled by ucode). */ |
Ron Rindjunsky | d67f548 | 2008-05-05 10:22:49 +0800 | [diff] [blame] | 1957 | r = priv->cfg->ops->lib->shared_mem_rx_idx(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1958 | i = rxq->read; |
| 1959 | |
| 1960 | /* Rx interrupt, but nothing sent from uCode */ |
| 1961 | if (i == r) |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1962 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1963 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1964 | if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1965 | fill_rx = 1; |
| 1966 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1967 | while (i != r) { |
| 1968 | rxb = rxq->queue[i]; |
| 1969 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1970 | /* 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] | 1971 | * then a bug has been introduced in the queue refilling |
| 1972 | * routines -- catch it here */ |
| 1973 | BUG_ON(rxb == NULL); |
| 1974 | |
| 1975 | rxq->queue[i] = NULL; |
| 1976 | |
| 1977 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1978 | priv->hw_params.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1979 | PCI_DMA_FROMDEVICE); |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1980 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1981 | |
| 1982 | /* Reclaim a command buffer only if this packet is a response |
| 1983 | * to a (driver-originated) command. |
| 1984 | * If the packet (e.g. Rx frame) originated from uCode, |
| 1985 | * there is no command buffer to reclaim. |
| 1986 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 1987 | * but apparently a few don't get set; catch them here. */ |
| 1988 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 1989 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1990 | (pkt->hdr.cmd != REPLY_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 1991 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1992 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 1993 | (pkt->hdr.cmd != REPLY_TX); |
| 1994 | |
| 1995 | /* Based on type of command response or notification, |
| 1996 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1997 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1998 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1999 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r, |
| 2000 | i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2001 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 2002 | } else { |
| 2003 | /* No handling needed */ |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2004 | IWL_DEBUG(IWL_DL_RX, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2005 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 2006 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 2007 | pkt->hdr.cmd); |
| 2008 | } |
| 2009 | |
| 2010 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2011 | /* Invoke any callbacks, transfer the skb to caller, and |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2012 | * fire off the (possibly) blocking iwl_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2013 | * as we reclaim the driver command queue */ |
| 2014 | if (rxb && rxb->skb) |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 2015 | iwl_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2016 | else |
| 2017 | IWL_WARNING("Claim null rxb?\n"); |
| 2018 | } |
| 2019 | |
| 2020 | /* For now we just don't re-use anything. We can tweak this |
| 2021 | * later to try and re-use notification packets and SKBs that |
| 2022 | * fail to Rx correctly */ |
| 2023 | if (rxb->skb != NULL) { |
| 2024 | priv->alloc_rxb_skb--; |
| 2025 | dev_kfree_skb_any(rxb->skb); |
| 2026 | rxb->skb = NULL; |
| 2027 | } |
| 2028 | |
| 2029 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 2030 | priv->hw_params.rx_buf_size, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 2031 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2032 | spin_lock_irqsave(&rxq->lock, flags); |
| 2033 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 2034 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 2035 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2036 | /* If there are a lot of unused frames, |
| 2037 | * restock the Rx queue so ucode wont assert. */ |
| 2038 | if (fill_rx) { |
| 2039 | count++; |
| 2040 | if (count >= 8) { |
| 2041 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2042 | __iwl_rx_replenish(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 2043 | count = 0; |
| 2044 | } |
| 2045 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
| 2048 | /* Backtrack one entry */ |
| 2049 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2050 | iwl_rx_queue_restock(priv); |
| 2051 | } |
| 2052 | /* Convert linear signal-to-noise ratio into dB */ |
| 2053 | static u8 ratio2dB[100] = { |
| 2054 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 2055 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 2056 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 2057 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 2058 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 2059 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 2060 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 2061 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 2062 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 2063 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 2064 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 2065 | }; |
| 2066 | |
| 2067 | /* Calculates a relative dB value from a ratio of linear |
| 2068 | * (i.e. not dB) signal levels. |
| 2069 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
| 2070 | int iwl4965_calc_db_from_ratio(int sig_ratio) |
| 2071 | { |
| 2072 | /* 1000:1 or higher just report as 60 dB */ |
| 2073 | if (sig_ratio >= 1000) |
| 2074 | return 60; |
| 2075 | |
| 2076 | /* 100:1 or higher, divide by 10 and use table, |
| 2077 | * add 20 dB to make up for divide by 10 */ |
| 2078 | if (sig_ratio >= 100) |
| 2079 | return (20 + (int)ratio2dB[sig_ratio/10]); |
| 2080 | |
| 2081 | /* We shouldn't see this */ |
| 2082 | if (sig_ratio < 1) |
| 2083 | return 0; |
| 2084 | |
| 2085 | /* Use table for ratios 1:1 - 99:1 */ |
| 2086 | return (int)ratio2dB[sig_ratio]; |
| 2087 | } |
| 2088 | |
| 2089 | #define PERFECT_RSSI (-20) /* dBm */ |
| 2090 | #define WORST_RSSI (-95) /* dBm */ |
| 2091 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 2092 | |
| 2093 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 2094 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 2095 | * about formulas used below. */ |
| 2096 | int iwl4965_calc_sig_qual(int rssi_dbm, int noise_dbm) |
| 2097 | { |
| 2098 | int sig_qual; |
| 2099 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 2100 | |
| 2101 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 2102 | * as indicator; formula is (signal dbm - noise dbm). |
| 2103 | * SNR at or above 40 is a great signal (100%). |
| 2104 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 2105 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 2106 | if (noise_dbm) { |
| 2107 | if (rssi_dbm - noise_dbm >= 40) |
| 2108 | return 100; |
| 2109 | else if (rssi_dbm < noise_dbm) |
| 2110 | return 0; |
| 2111 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 2112 | |
| 2113 | /* Else use just the signal level. |
| 2114 | * This formula is a least squares fit of data points collected and |
| 2115 | * compared with a reference system that had a percentage (%) display |
| 2116 | * for signal quality. */ |
| 2117 | } else |
| 2118 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 2119 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 2120 | (RSSI_RANGE * RSSI_RANGE); |
| 2121 | |
| 2122 | if (sig_qual > 100) |
| 2123 | sig_qual = 100; |
| 2124 | else if (sig_qual < 1) |
| 2125 | sig_qual = 0; |
| 2126 | |
| 2127 | return sig_qual; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2128 | } |
| 2129 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2130 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2131 | static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2132 | { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 2133 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2134 | DECLARE_MAC_BUF(mac); |
| 2135 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2136 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2137 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2138 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 2139 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 2140 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 2141 | le32_to_cpu(rxon->filter_flags)); |
| 2142 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 2143 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 2144 | rxon->ofdm_basic_rates); |
| 2145 | 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] | 2146 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 2147 | print_mac(mac, rxon->node_addr)); |
| 2148 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 2149 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2150 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 2151 | } |
| 2152 | #endif |
| 2153 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2154 | static void iwl4965_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2155 | { |
| 2156 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 2157 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2158 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2161 | /* call this function to flush any scheduled tasklet */ |
| 2162 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
| 2163 | { |
| 2164 | /* wait to make sure we flush pedding tasklet*/ |
| 2165 | synchronize_irq(priv->pci_dev->irq); |
| 2166 | tasklet_kill(&priv->irq_tasklet); |
| 2167 | } |
| 2168 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2169 | static inline void iwl4965_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2170 | { |
| 2171 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 2172 | |
| 2173 | /* disable interrupts from uCode/NIC to host */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2174 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2175 | |
| 2176 | /* acknowledge/clear/reset any interrupts still pending |
| 2177 | * from uCode or flow handler (Rx/Tx DMA) */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2178 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 2179 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2180 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 2181 | } |
| 2182 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2183 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2184 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2185 | * 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] | 2186 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2187 | static void iwl4965_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2188 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2189 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2190 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 2191 | |
| 2192 | /* Cancel currently queued command. */ |
| 2193 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 2194 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2195 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2196 | if (priv->debug_level & IWL_DL_FW_ERRORS) { |
Ester Kummer | ede0cba | 2008-05-29 16:34:46 +0800 | [diff] [blame] | 2197 | iwl_dump_nic_error_log(priv); |
Ester Kummer | 189a2b5 | 2008-05-15 13:54:18 +0800 | [diff] [blame] | 2198 | iwl_dump_nic_event_log(priv); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2199 | iwl4965_print_rx_config_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2200 | } |
| 2201 | #endif |
| 2202 | |
| 2203 | wake_up_interruptible(&priv->wait_command_queue); |
| 2204 | |
| 2205 | /* Keep the restart process from trying to send host |
| 2206 | * commands by clearing the INIT status bit */ |
| 2207 | clear_bit(STATUS_READY, &priv->status); |
| 2208 | |
| 2209 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2210 | IWL_DEBUG(IWL_DL_FW_ERRORS, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2211 | "Restarting adapter due to uCode error.\n"); |
| 2212 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2213 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2214 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 2215 | sizeof(priv->recovery_rxon)); |
| 2216 | priv->error_recovering = 1; |
| 2217 | } |
Ester Kummer | 3a1081e | 2008-05-06 11:05:14 +0800 | [diff] [blame] | 2218 | if (priv->cfg->mod_params->restart_fw) |
| 2219 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2220 | } |
| 2221 | } |
| 2222 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2223 | static void iwl4965_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2224 | { |
| 2225 | unsigned long flags; |
| 2226 | |
| 2227 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 2228 | sizeof(priv->staging_rxon)); |
| 2229 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2230 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2231 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 2232 | iwl_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2233 | |
| 2234 | spin_lock_irqsave(&priv->lock, flags); |
| 2235 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 2236 | priv->error_recovering = 0; |
| 2237 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2238 | } |
| 2239 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2240 | static void iwl4965_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2241 | { |
| 2242 | u32 inta, handled = 0; |
| 2243 | u32 inta_fh; |
| 2244 | unsigned long flags; |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2245 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2246 | u32 inta_mask; |
| 2247 | #endif |
| 2248 | |
| 2249 | spin_lock_irqsave(&priv->lock, flags); |
| 2250 | |
| 2251 | /* Ack/clear/reset pending uCode interrupts. |
| 2252 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 2253 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2254 | inta = iwl_read32(priv, CSR_INT); |
| 2255 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2256 | |
| 2257 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 2258 | * Any new interrupts that happen after this, either while we're |
| 2259 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2260 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 2261 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2262 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2263 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2264 | if (priv->debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2265 | /* just for debug */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2266 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2267 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 2268 | inta, inta_mask, inta_fh); |
| 2269 | } |
| 2270 | #endif |
| 2271 | |
| 2272 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 2273 | * atomic, make sure that inta covers all the interrupts that |
| 2274 | * we've discovered, even if FH interrupt came in just after |
| 2275 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 2276 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2277 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 2278 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2279 | inta |= CSR_INT_BIT_FH_TX; |
| 2280 | |
| 2281 | /* Now service all interrupt bits discovered above. */ |
| 2282 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 2283 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 2284 | |
| 2285 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2286 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2287 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2288 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2289 | |
| 2290 | handled |= CSR_INT_BIT_HW_ERR; |
| 2291 | |
| 2292 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2293 | |
| 2294 | return; |
| 2295 | } |
| 2296 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2297 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2298 | if (priv->debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2299 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2300 | if (inta & CSR_INT_BIT_SCD) |
| 2301 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 2302 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2303 | |
| 2304 | /* Alive notification via Rx interrupt will do the real work */ |
| 2305 | if (inta & CSR_INT_BIT_ALIVE) |
| 2306 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 2307 | } |
| 2308 | #endif |
| 2309 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2310 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2311 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2312 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2313 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 2314 | int hw_rf_kill = 0; |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2315 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2316 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 2317 | hw_rf_kill = 1; |
| 2318 | |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2319 | 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] | 2320 | hw_rf_kill ? "disable radio":"enable radio"); |
| 2321 | |
| 2322 | /* Queue restart only if RF_KILL switch was set to "kill" |
| 2323 | * when we loaded driver, and is now set to "enable". |
| 2324 | * After we're Alive, RF_KILL gets handled by |
Reinette Chatre | 3230455 | 2008-02-15 14:34:37 -0800 | [diff] [blame] | 2325 | * iwl4965_rx_card_state_notif() */ |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 2326 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { |
| 2327 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2328 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 2329 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2330 | |
| 2331 | handled |= CSR_INT_BIT_RF_KILL; |
| 2332 | } |
| 2333 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2334 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2335 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 2336 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 2337 | handled |= CSR_INT_BIT_CT_KILL; |
| 2338 | } |
| 2339 | |
| 2340 | /* Error detected by uCode */ |
| 2341 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 2342 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 2343 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2344 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2345 | handled |= CSR_INT_BIT_SW_ERR; |
| 2346 | } |
| 2347 | |
| 2348 | /* uCode wakes up after power-down sleep */ |
| 2349 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 2350 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2351 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 2352 | iwl_txq_update_write_ptr(priv, &priv->txq[0]); |
| 2353 | iwl_txq_update_write_ptr(priv, &priv->txq[1]); |
| 2354 | iwl_txq_update_write_ptr(priv, &priv->txq[2]); |
| 2355 | iwl_txq_update_write_ptr(priv, &priv->txq[3]); |
| 2356 | iwl_txq_update_write_ptr(priv, &priv->txq[4]); |
| 2357 | iwl_txq_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2358 | |
| 2359 | handled |= CSR_INT_BIT_WAKEUP; |
| 2360 | } |
| 2361 | |
| 2362 | /* All uCode command responses, including Tx command responses, |
| 2363 | * Rx "responses" (frame-received notification), and other |
| 2364 | * notifications from uCode come through here*/ |
| 2365 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2366 | iwl_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2367 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 2368 | } |
| 2369 | |
| 2370 | if (inta & CSR_INT_BIT_FH_TX) { |
| 2371 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 2372 | handled |= CSR_INT_BIT_FH_TX; |
Ron Rindjunsky | dbb983b | 2008-05-15 13:54:12 +0800 | [diff] [blame] | 2373 | /* FH finished to write, send event */ |
| 2374 | priv->ucode_write_complete = 1; |
| 2375 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2376 | } |
| 2377 | |
| 2378 | if (inta & ~handled) |
| 2379 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 2380 | |
| 2381 | if (inta & ~CSR_INI_SET_MASK) { |
| 2382 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 2383 | inta & ~CSR_INI_SET_MASK); |
| 2384 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 2385 | } |
| 2386 | |
| 2387 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2388 | /* only Re-enable if diabled by irq */ |
| 2389 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 2390 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2391 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2392 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2393 | if (priv->debug_level & (IWL_DL_ISR)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2394 | inta = iwl_read32(priv, CSR_INT); |
| 2395 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 2396 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2397 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 2398 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 2399 | } |
| 2400 | #endif |
| 2401 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2402 | } |
| 2403 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2404 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2405 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2406 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2407 | u32 inta, inta_mask; |
| 2408 | u32 inta_fh; |
| 2409 | if (!priv) |
| 2410 | return IRQ_NONE; |
| 2411 | |
| 2412 | spin_lock(&priv->lock); |
| 2413 | |
| 2414 | /* Disable (but don't clear!) interrupts here to avoid |
| 2415 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 2416 | * If we have something to service, the tasklet will re-enable ints. |
| 2417 | * 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] | 2418 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 2419 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2420 | |
| 2421 | /* Discover which interrupts are active/pending */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2422 | inta = iwl_read32(priv, CSR_INT); |
| 2423 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2424 | |
| 2425 | /* Ignore interrupt if there's nothing in NIC to service. |
| 2426 | * This may be due to IRQ shared with another device, |
| 2427 | * or due to sporadic interrupts thrown from our NIC. */ |
| 2428 | if (!inta && !inta_fh) { |
| 2429 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 2430 | goto none; |
| 2431 | } |
| 2432 | |
| 2433 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 2434 | /* Hardware disappeared. It might have already raised |
| 2435 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2436 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 2437 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 2441 | inta, inta_mask, inta_fh); |
| 2442 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2443 | inta &= ~CSR_INT_BIT_SCD; |
| 2444 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2445 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2446 | if (likely(inta || inta_fh)) |
| 2447 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2448 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 2449 | unplugged: |
| 2450 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2451 | return IRQ_HANDLED; |
| 2452 | |
| 2453 | none: |
| 2454 | /* re-enable interrupts here since we don't have anything to service. */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2455 | /* only Re-enable if diabled by irq */ |
| 2456 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 2457 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2458 | spin_unlock(&priv->lock); |
| 2459 | return IRQ_NONE; |
| 2460 | } |
| 2461 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2462 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 2463 | * sending probe req. This should be set long enough to hear probe responses |
| 2464 | * from more than one AP. */ |
| 2465 | #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 2466 | #define IWL_ACTIVE_DWELL_TIME_52 (10) |
| 2467 | |
| 2468 | /* For faster active scanning, scan will move to the next channel if fewer than |
| 2469 | * PLCP_QUIET_THRESH packets are heard on this channel within |
| 2470 | * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell |
| 2471 | * time if it's a quiet channel (nothing responded to our probe, and there's |
| 2472 | * no other traffic). |
| 2473 | * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */ |
| 2474 | #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */ |
| 2475 | #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */ |
| 2476 | |
| 2477 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 2478 | * Must be set longer than active dwell time. |
| 2479 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 2480 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 2481 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 2482 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 2483 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 2484 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2485 | static inline u16 iwl4965_get_active_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2486 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2487 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2488 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2489 | return IWL_ACTIVE_DWELL_TIME_52; |
| 2490 | else |
| 2491 | return IWL_ACTIVE_DWELL_TIME_24; |
| 2492 | } |
| 2493 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2494 | static u16 iwl4965_get_passive_dwell_time(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2495 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2496 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2497 | u16 active = iwl4965_get_active_dwell_time(priv, band); |
| 2498 | u16 passive = (band != IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2499 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 2500 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 2501 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2502 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2503 | /* If we're associated, we clamp the maximum passive |
| 2504 | * dwell time to be 98% of the beacon interval (minus |
| 2505 | * 2 * channel tune time) */ |
| 2506 | passive = priv->beacon_int; |
| 2507 | if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) |
| 2508 | passive = IWL_PASSIVE_DWELL_BASE; |
| 2509 | passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 2510 | } |
| 2511 | |
| 2512 | if (passive <= active) |
| 2513 | passive = active + 1; |
| 2514 | |
| 2515 | return passive; |
| 2516 | } |
| 2517 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2518 | static int iwl4965_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2519 | enum ieee80211_band band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2520 | u8 is_active, u8 direct_mask, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2521 | struct iwl4965_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2522 | { |
| 2523 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2524 | const struct ieee80211_supported_band *sband; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 2525 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2526 | u16 passive_dwell = 0; |
| 2527 | u16 active_dwell = 0; |
| 2528 | int added, i; |
| 2529 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 2530 | sband = iwl_get_hw_mode(priv, band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2531 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2532 | return 0; |
| 2533 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2534 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2535 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2536 | active_dwell = iwl4965_get_active_dwell_time(priv, band); |
| 2537 | passive_dwell = iwl4965_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2538 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2539 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 2540 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 2541 | continue; |
| 2542 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2543 | scan_ch->channel = ieee80211_frequency_to_channel(channels[i].center_freq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2544 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 2545 | ch_info = iwl_get_channel_info(priv, band, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2546 | scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2547 | if (!is_channel_valid(ch_info)) { |
| 2548 | IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n", |
| 2549 | scan_ch->channel); |
| 2550 | continue; |
| 2551 | } |
| 2552 | |
| 2553 | if (!is_active || is_channel_passive(ch_info) || |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2554 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2555 | scan_ch->type = 0; /* passive */ |
| 2556 | else |
| 2557 | scan_ch->type = 1; /* active */ |
| 2558 | |
| 2559 | if (scan_ch->type & 1) |
| 2560 | scan_ch->type |= (direct_mask << 1); |
| 2561 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2562 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 2563 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 2564 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2565 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2566 | scan_ch->tpc.dsp_atten = 110; |
| 2567 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 2568 | |
| 2569 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2570 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2571 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 2572 | else { |
| 2573 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 2574 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2575 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 2576 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2577 | */ |
| 2578 | } |
| 2579 | |
| 2580 | IWL_DEBUG_SCAN("Scanning %d [%s %d]\n", |
| 2581 | scan_ch->channel, |
| 2582 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 2583 | (scan_ch->type & 1) ? |
| 2584 | active_dwell : passive_dwell); |
| 2585 | |
| 2586 | scan_ch++; |
| 2587 | added++; |
| 2588 | } |
| 2589 | |
| 2590 | IWL_DEBUG_SCAN("total channels to scan %d \n", added); |
| 2591 | return added; |
| 2592 | } |
| 2593 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2594 | /****************************************************************************** |
| 2595 | * |
| 2596 | * uCode download functions |
| 2597 | * |
| 2598 | ******************************************************************************/ |
| 2599 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2600 | static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2601 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2602 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 2603 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 2604 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 2605 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 2606 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 2607 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2608 | } |
| 2609 | |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 2610 | static void iwl4965_nic_start(struct iwl_priv *priv) |
| 2611 | { |
| 2612 | /* Remove all resets to allow NIC to operate */ |
| 2613 | iwl_write32(priv, CSR_RESET, 0); |
| 2614 | } |
| 2615 | |
| 2616 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2617 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2618 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2619 | * |
| 2620 | * Copy into buffers for card to fetch via bus-mastering |
| 2621 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2622 | static int iwl4965_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2623 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2624 | struct iwl4965_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2625 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2626 | const struct firmware *ucode_raw; |
Tomas Winkler | 4bf775c | 2008-03-04 18:09:31 -0800 | [diff] [blame] | 2627 | const char *name = priv->cfg->fw_name; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2628 | u8 *src; |
| 2629 | size_t len; |
| 2630 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 2631 | |
| 2632 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 2633 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2634 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 2635 | if (ret < 0) { |
| 2636 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 2637 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2638 | goto error; |
| 2639 | } |
| 2640 | |
| 2641 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 2642 | name, ucode_raw->size); |
| 2643 | |
| 2644 | /* Make sure that we got at least our header! */ |
| 2645 | if (ucode_raw->size < sizeof(*ucode)) { |
| 2646 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2647 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2648 | goto err_release; |
| 2649 | } |
| 2650 | |
| 2651 | /* Data from ucode file: header followed by uCode images */ |
| 2652 | ucode = (void *)ucode_raw->data; |
| 2653 | |
| 2654 | ver = le32_to_cpu(ucode->ver); |
| 2655 | inst_size = le32_to_cpu(ucode->inst_size); |
| 2656 | data_size = le32_to_cpu(ucode->data_size); |
| 2657 | init_size = le32_to_cpu(ucode->init_size); |
| 2658 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 2659 | boot_size = le32_to_cpu(ucode->boot_size); |
| 2660 | |
| 2661 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 2662 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 2663 | inst_size); |
| 2664 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 2665 | data_size); |
| 2666 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 2667 | init_size); |
| 2668 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 2669 | init_data_size); |
| 2670 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 2671 | boot_size); |
| 2672 | |
| 2673 | /* Verify size of file vs. image size info in file's header */ |
| 2674 | if (ucode_raw->size < sizeof(*ucode) + |
| 2675 | inst_size + data_size + init_size + |
| 2676 | init_data_size + boot_size) { |
| 2677 | |
| 2678 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 2679 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2680 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2681 | goto err_release; |
| 2682 | } |
| 2683 | |
| 2684 | /* Verify that uCode images will fit in card's SRAM */ |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 2685 | if (inst_size > priv->hw_params.max_inst_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2686 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 2687 | inst_size); |
| 2688 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2689 | goto err_release; |
| 2690 | } |
| 2691 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 2692 | if (data_size > priv->hw_params.max_data_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2693 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 2694 | data_size); |
| 2695 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2696 | goto err_release; |
| 2697 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 2698 | if (init_size > priv->hw_params.max_inst_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2699 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2700 | ("uCode init instr len %d too large to fit in\n", |
| 2701 | init_size); |
| 2702 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2703 | goto err_release; |
| 2704 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 2705 | if (init_data_size > priv->hw_params.max_data_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2706 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2707 | ("uCode init data len %d too large to fit in\n", |
| 2708 | init_data_size); |
| 2709 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2710 | goto err_release; |
| 2711 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 2712 | if (boot_size > priv->hw_params.max_bsm_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2713 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2714 | ("uCode boot instr len %d too large to fit in\n", |
| 2715 | boot_size); |
| 2716 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2717 | goto err_release; |
| 2718 | } |
| 2719 | |
| 2720 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 2721 | |
| 2722 | /* Runtime instructions and 2 copies of data: |
| 2723 | * 1) unmodified from disk |
| 2724 | * 2) backup cache for save/restore during power-downs */ |
| 2725 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2726 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2727 | |
| 2728 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2729 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2730 | |
| 2731 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2732 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2733 | |
| 2734 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2735 | if (init_size && init_data_size) { |
| 2736 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2737 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2738 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2739 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2740 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2741 | |
| 2742 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 2743 | goto err_pci_alloc; |
| 2744 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2745 | |
| 2746 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2747 | if (boot_size) { |
| 2748 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2749 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2750 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2751 | if (!priv->ucode_boot.v_addr) |
| 2752 | goto err_pci_alloc; |
| 2753 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2754 | |
| 2755 | /* Copy images into buffers for card's bus-master reads ... */ |
| 2756 | |
| 2757 | /* Runtime instructions (first block of data in file) */ |
| 2758 | src = &ucode->data[0]; |
| 2759 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2760 | 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] | 2761 | memcpy(priv->ucode_code.v_addr, src, len); |
| 2762 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 2763 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 2764 | |
| 2765 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2766 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2767 | src = &ucode->data[inst_size]; |
| 2768 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2769 | 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] | 2770 | memcpy(priv->ucode_data.v_addr, src, len); |
| 2771 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 2772 | |
| 2773 | /* Initialization instructions (3rd block) */ |
| 2774 | if (init_size) { |
| 2775 | src = &ucode->data[inst_size + data_size]; |
| 2776 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2777 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 2778 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2779 | memcpy(priv->ucode_init.v_addr, src, len); |
| 2780 | } |
| 2781 | |
| 2782 | /* Initialization data (4th block) */ |
| 2783 | if (init_data_size) { |
| 2784 | src = &ucode->data[inst_size + data_size + init_size]; |
| 2785 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2786 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 2787 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2788 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 2789 | } |
| 2790 | |
| 2791 | /* Bootstrap instructions (5th block) */ |
| 2792 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 2793 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2794 | 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] | 2795 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 2796 | |
| 2797 | /* We have our copies now, allow OS release its copies */ |
| 2798 | release_firmware(ucode_raw); |
| 2799 | return 0; |
| 2800 | |
| 2801 | err_pci_alloc: |
| 2802 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2803 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2804 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2805 | |
| 2806 | err_release: |
| 2807 | release_firmware(ucode_raw); |
| 2808 | |
| 2809 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2810 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2811 | } |
| 2812 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2813 | /** |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2814 | * iwl_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2815 | * from protocol/runtime uCode (initialization uCode's |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2816 | * Alive gets handled by iwl_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2817 | */ |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2818 | static void iwl_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2819 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 2820 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2821 | |
| 2822 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 2823 | |
| 2824 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 2825 | /* We had an error bringing up the hardware, so take it |
| 2826 | * all the way back down so we can try again */ |
| 2827 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 2828 | goto restart; |
| 2829 | } |
| 2830 | |
| 2831 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 2832 | * This is a paranoid check, because we would not have gotten the |
| 2833 | * "runtime" alive if code weren't properly loaded. */ |
Emmanuel Grumbach | b0692f2 | 2008-04-24 11:55:18 -0700 | [diff] [blame] | 2834 | if (iwl_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2835 | /* Runtime instruction load was bad; |
| 2836 | * take it all the way back down so we can try again */ |
| 2837 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 2838 | goto restart; |
| 2839 | } |
| 2840 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 2841 | iwlcore_clear_stations_table(priv); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 2842 | ret = priv->cfg->ops->lib->alive_notify(priv); |
| 2843 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2844 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 2845 | ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2846 | goto restart; |
| 2847 | } |
| 2848 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2849 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2850 | set_bit(STATUS_ALIVE, &priv->status); |
| 2851 | |
| 2852 | /* Clear out the uCode error bit if it is set */ |
| 2853 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 2854 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 2855 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2856 | return; |
| 2857 | |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 2858 | ieee80211_wake_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2859 | |
| 2860 | priv->active_rate = priv->rates_mask; |
| 2861 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 2862 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2863 | if (iwl_is_associated(priv)) { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 2864 | struct iwl_rxon_cmd *active_rxon = |
| 2865 | (struct iwl_rxon_cmd *)&priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2866 | |
| 2867 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 2868 | sizeof(priv->staging_rxon)); |
| 2869 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 2870 | } else { |
| 2871 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2872 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2873 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2874 | } |
| 2875 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2876 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2877 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2878 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2879 | iwl_reset_run_time_calib(priv); |
| 2880 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2881 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2882 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2883 | |
| 2884 | /* At this point, the NIC is initialized and operational */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2885 | iwl4965_rf_kill_ct_config(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2886 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 2887 | iwl_leds_register(priv); |
| 2888 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2889 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 2890 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2891 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2892 | |
| 2893 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2894 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2895 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 2896 | iwlcore_low_level_notify(priv, IWLCORE_START_EVT); |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 2897 | ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2898 | return; |
| 2899 | |
| 2900 | restart: |
| 2901 | queue_work(priv->workqueue, &priv->restart); |
| 2902 | } |
| 2903 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2904 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2905 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2906 | static void __iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2907 | { |
| 2908 | unsigned long flags; |
| 2909 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2910 | |
| 2911 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 2912 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2913 | if (!exit_pending) |
| 2914 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 2915 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2916 | iwl_leds_unregister(priv); |
| 2917 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 2918 | iwlcore_low_level_notify(priv, IWLCORE_STOP_EVT); |
| 2919 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 2920 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2921 | |
| 2922 | /* Unblock any waiting calls */ |
| 2923 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 2924 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2925 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 2926 | * exiting the module */ |
| 2927 | if (!exit_pending) |
| 2928 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 2929 | |
| 2930 | /* stop and reset the on-board processor */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2931 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2932 | |
| 2933 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2934 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2935 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2936 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2937 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2938 | |
| 2939 | if (priv->mac80211_registered) |
| 2940 | ieee80211_stop_queues(priv->hw); |
| 2941 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2942 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2943 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 2944 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2945 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 2946 | STATUS_RF_KILL_HW | |
| 2947 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 2948 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 2949 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 2950 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2951 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 2952 | STATUS_IN_SUSPEND; |
| 2953 | goto exit; |
| 2954 | } |
| 2955 | |
| 2956 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 2957 | * SUSPEND bits and continue taking the NIC down. */ |
| 2958 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 2959 | STATUS_RF_KILL_HW | |
| 2960 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 2961 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 2962 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 2963 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2964 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 2965 | STATUS_IN_SUSPEND | |
| 2966 | test_bit(STATUS_FW_ERROR, &priv->status) << |
| 2967 | STATUS_FW_ERROR; |
| 2968 | |
| 2969 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2970 | iwl_clear_bit(priv, CSR_GP_CNTRL, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2971 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2972 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2973 | |
Tomas Winkler | da1bc45 | 2008-05-29 16:35:00 +0800 | [diff] [blame] | 2974 | iwl_txq_ctx_stop(priv); |
Tomas Winkler | b3bbacb | 2008-05-29 16:35:01 +0800 | [diff] [blame] | 2975 | iwl_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2976 | |
| 2977 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2978 | if (!iwl_grab_nic_access(priv)) { |
| 2979 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2980 | APMG_CLK_VAL_DMA_CLK_RQT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2981 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2982 | } |
| 2983 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2984 | |
| 2985 | udelay(5); |
| 2986 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 2987 | /* FIXME: apm_ops.suspend(priv) */ |
| 2988 | priv->cfg->ops->lib->apm_ops.reset(priv); |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 2989 | priv->cfg->ops->lib->free_shared_mem(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2990 | |
| 2991 | exit: |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 2992 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2993 | |
| 2994 | if (priv->ibss_beacon) |
| 2995 | dev_kfree_skb(priv->ibss_beacon); |
| 2996 | priv->ibss_beacon = NULL; |
| 2997 | |
| 2998 | /* clear out any free frames */ |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 2999 | iwl_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3000 | } |
| 3001 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3002 | static void iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3003 | { |
| 3004 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3005 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3006 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 3007 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3008 | iwl4965_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3009 | } |
| 3010 | |
| 3011 | #define MAX_HW_RESTARTS 5 |
| 3012 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3013 | static int __iwl4965_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3014 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3015 | int i; |
| 3016 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3017 | |
| 3018 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 3019 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 3020 | return -EIO; |
| 3021 | } |
| 3022 | |
| 3023 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
| 3024 | IWL_WARNING("Radio disabled by SW RF kill (module " |
| 3025 | "parameter)\n"); |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3026 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3027 | return -ENODEV; |
| 3028 | } |
| 3029 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 3030 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 3031 | IWL_ERROR("ucode not available for device bringup\n"); |
| 3032 | return -EIO; |
| 3033 | } |
| 3034 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3035 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3036 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3037 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 3038 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3039 | else { |
| 3040 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3041 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3042 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3043 | IWL_WARNING("Radio disabled by HW RF Kill switch\n"); |
| 3044 | return -ENODEV; |
| 3045 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3046 | } |
| 3047 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3048 | iwl_rfkill_set_hw_state(priv); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3049 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3050 | |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 3051 | ret = priv->cfg->ops->lib->alloc_shared_mem(priv); |
| 3052 | if (ret) { |
| 3053 | IWL_ERROR("Unable to allocate shared memory\n"); |
| 3054 | return ret; |
| 3055 | } |
| 3056 | |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 3057 | ret = iwl_hw_nic_init(priv); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3058 | if (ret) { |
| 3059 | IWL_ERROR("Unable to init nic\n"); |
| 3060 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
| 3063 | /* make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3064 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 3065 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3066 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 3067 | |
| 3068 | /* clear (again), then enable host interrupts */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3069 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3070 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3071 | |
| 3072 | /* really make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3073 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 3074 | 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] | 3075 | |
| 3076 | /* Copy original ucode data image from disk into backup cache. |
| 3077 | * This will be used to initialize the on-board processor's |
| 3078 | * data SRAM for a clean start when the runtime program first loads. */ |
| 3079 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3080 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3081 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3082 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 3083 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3084 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3085 | |
| 3086 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 3087 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3088 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3089 | |
| 3090 | /* load bootstrap state machine, |
| 3091 | * load bootstrap program into processor's memory, |
| 3092 | * prepare to load the "initialize" uCode */ |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3093 | ret = priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3094 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3095 | if (ret) { |
| 3096 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3097 | continue; |
| 3098 | } |
| 3099 | |
| 3100 | /* start card; "initialize" will load runtime ucode */ |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 3101 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3102 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3103 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 3104 | |
| 3105 | return 0; |
| 3106 | } |
| 3107 | |
| 3108 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3109 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3110 | |
| 3111 | /* tried to restart and config the device for as long as our |
| 3112 | * patience could withstand */ |
| 3113 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 3114 | return -EIO; |
| 3115 | } |
| 3116 | |
| 3117 | |
| 3118 | /***************************************************************************** |
| 3119 | * |
| 3120 | * Workqueue callbacks |
| 3121 | * |
| 3122 | *****************************************************************************/ |
| 3123 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3124 | static void iwl_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3125 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3126 | struct iwl_priv *priv = |
| 3127 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3128 | |
| 3129 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3130 | return; |
| 3131 | |
| 3132 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | f3ccc08 | 2008-05-05 10:22:45 +0800 | [diff] [blame] | 3133 | priv->cfg->ops->lib->init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3134 | mutex_unlock(&priv->mutex); |
| 3135 | } |
| 3136 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3137 | static void iwl_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3138 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3139 | struct iwl_priv *priv = |
| 3140 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3141 | |
| 3142 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3143 | return; |
| 3144 | |
| 3145 | mutex_lock(&priv->mutex); |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3146 | iwl_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3147 | mutex_unlock(&priv->mutex); |
| 3148 | } |
| 3149 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3150 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3151 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3152 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3153 | |
| 3154 | wake_up_interruptible(&priv->wait_command_queue); |
| 3155 | |
| 3156 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3157 | return; |
| 3158 | |
| 3159 | mutex_lock(&priv->mutex); |
| 3160 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3161 | if (!iwl_is_rfkill(priv)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3162 | IWL_DEBUG(IWL_DL_RF_KILL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3163 | "HW and/or SW RF Kill no longer active, restarting " |
| 3164 | "device\n"); |
| 3165 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3166 | queue_work(priv->workqueue, &priv->restart); |
| 3167 | } else { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3168 | /* make sure mac80211 stop sending Tx frame */ |
| 3169 | if (priv->mac80211_registered) |
| 3170 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3171 | |
| 3172 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 3173 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 3174 | "disabled by SW switch\n"); |
| 3175 | else |
| 3176 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 3177 | "Kill switch must be turned off for " |
| 3178 | "wireless networking to work.\n"); |
| 3179 | } |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3180 | iwl_rfkill_set_hw_state(priv); |
| 3181 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3182 | mutex_unlock(&priv->mutex); |
| 3183 | } |
| 3184 | |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 3185 | static void iwl4965_bg_set_monitor(struct work_struct *work) |
| 3186 | { |
| 3187 | struct iwl_priv *priv = container_of(work, |
| 3188 | struct iwl_priv, set_monitor); |
| 3189 | |
| 3190 | IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n"); |
| 3191 | |
| 3192 | mutex_lock(&priv->mutex); |
| 3193 | |
| 3194 | if (!iwl_is_ready(priv)) |
| 3195 | IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n"); |
| 3196 | else |
| 3197 | if (iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR) != 0) |
| 3198 | IWL_ERROR("iwl4965_set_mode() failed\n"); |
| 3199 | |
| 3200 | mutex_unlock(&priv->mutex); |
| 3201 | } |
| 3202 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3203 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
| 3204 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3205 | static void iwl4965_bg_scan_check(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3206 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3207 | struct iwl_priv *priv = |
| 3208 | container_of(data, struct iwl_priv, scan_check.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3209 | |
| 3210 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3211 | return; |
| 3212 | |
| 3213 | mutex_lock(&priv->mutex); |
| 3214 | if (test_bit(STATUS_SCANNING, &priv->status) || |
| 3215 | test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3216 | IWL_DEBUG(IWL_DL_SCAN, "Scan completion watchdog resetting " |
| 3217 | "adapter (%dms)\n", |
| 3218 | jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG)); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3219 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3220 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3221 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3222 | } |
| 3223 | mutex_unlock(&priv->mutex); |
| 3224 | } |
| 3225 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3226 | static void iwl4965_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3227 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3228 | struct iwl_priv *priv = |
| 3229 | container_of(data, struct iwl_priv, request_scan); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3230 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3231 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3232 | .len = sizeof(struct iwl4965_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3233 | .meta.flags = CMD_SIZE_HUGE, |
| 3234 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3235 | struct iwl4965_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3236 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3237 | u16 cmd_len; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3238 | enum ieee80211_band band; |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3239 | u8 direct_mask; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3240 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3241 | |
| 3242 | conf = ieee80211_get_hw_conf(priv->hw); |
| 3243 | |
| 3244 | mutex_lock(&priv->mutex); |
| 3245 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3246 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3247 | IWL_WARNING("request scan called when driver not ready.\n"); |
| 3248 | goto done; |
| 3249 | } |
| 3250 | |
| 3251 | /* Make sure the scan wasn't cancelled before this queued work |
| 3252 | * was given the chance to run... */ |
| 3253 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 3254 | goto done; |
| 3255 | |
| 3256 | /* This should never be called or scheduled if there is currently |
| 3257 | * a scan active in the hardware. */ |
| 3258 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
| 3259 | IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. " |
| 3260 | "Ignoring second request.\n"); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3261 | ret = -EIO; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3262 | goto done; |
| 3263 | } |
| 3264 | |
| 3265 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 3266 | IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n"); |
| 3267 | goto done; |
| 3268 | } |
| 3269 | |
| 3270 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
| 3271 | IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n"); |
| 3272 | goto done; |
| 3273 | } |
| 3274 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3275 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3276 | IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n"); |
| 3277 | goto done; |
| 3278 | } |
| 3279 | |
| 3280 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 3281 | IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n"); |
| 3282 | goto done; |
| 3283 | } |
| 3284 | |
| 3285 | if (!priv->scan_bands) { |
| 3286 | IWL_DEBUG_HC("Aborting scan due to no requested bands\n"); |
| 3287 | goto done; |
| 3288 | } |
| 3289 | |
| 3290 | if (!priv->scan) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3291 | priv->scan = kmalloc(sizeof(struct iwl4965_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3292 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 3293 | if (!priv->scan) { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3294 | ret = -ENOMEM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3295 | goto done; |
| 3296 | } |
| 3297 | } |
| 3298 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3299 | memset(scan, 0, sizeof(struct iwl4965_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3300 | |
| 3301 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 3302 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 3303 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3304 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3305 | u16 interval = 0; |
| 3306 | u32 extra; |
| 3307 | u32 suspend_time = 100; |
| 3308 | u32 scan_suspend_time = 100; |
| 3309 | unsigned long flags; |
| 3310 | |
| 3311 | IWL_DEBUG_INFO("Scanning while associated...\n"); |
| 3312 | |
| 3313 | spin_lock_irqsave(&priv->lock, flags); |
| 3314 | interval = priv->beacon_int; |
| 3315 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3316 | |
| 3317 | scan->suspend_time = 0; |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3318 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3319 | if (!interval) |
| 3320 | interval = suspend_time; |
| 3321 | |
| 3322 | extra = (suspend_time / interval) << 22; |
| 3323 | scan_suspend_time = (extra | |
| 3324 | ((suspend_time % interval) * 1024)); |
| 3325 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 3326 | IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n", |
| 3327 | scan_suspend_time, interval); |
| 3328 | } |
| 3329 | |
| 3330 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 3331 | if (priv->one_direct_scan) { |
| 3332 | IWL_DEBUG_SCAN |
| 3333 | ("Kicking off one direct scan for '%s'\n", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3334 | iwl4965_escape_essid(priv->direct_ssid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3335 | priv->direct_ssid_len)); |
| 3336 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 3337 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 3338 | memcpy(scan->direct_scan[0].ssid, |
| 3339 | priv->direct_ssid, priv->direct_ssid_len); |
| 3340 | direct_mask = 1; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3341 | } else if (!iwl_is_associated(priv) && priv->essid_len) { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3342 | IWL_DEBUG_SCAN |
| 3343 | ("Kicking off one direct scan for '%s' when not associated\n", |
| 3344 | iwl4965_escape_essid(priv->essid, priv->essid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3345 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 3346 | scan->direct_scan[0].len = priv->essid_len; |
| 3347 | memcpy(scan->direct_scan[0].ssid, priv->essid, priv->essid_len); |
| 3348 | direct_mask = 1; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3349 | } else { |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3350 | IWL_DEBUG_SCAN("Kicking off one indirect scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3351 | direct_mask = 0; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3352 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3353 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3354 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3355 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3356 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 3357 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3358 | |
| 3359 | switch (priv->scan_bands) { |
| 3360 | case 2: |
| 3361 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 3362 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3363 | iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3364 | RATE_MCS_ANT_B_MSK|RATE_MCS_CCK_MSK); |
| 3365 | |
| 3366 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3367 | band = IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3368 | break; |
| 3369 | |
| 3370 | case 1: |
| 3371 | scan->tx_cmd.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3372 | iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3373 | RATE_MCS_ANT_B_MSK); |
| 3374 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3375 | band = IEEE80211_BAND_5GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3376 | break; |
| 3377 | |
| 3378 | default: |
| 3379 | IWL_WARNING("Invalid scan band count\n"); |
| 3380 | goto done; |
| 3381 | } |
| 3382 | |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3383 | /* We don't build a direct scan probe request; the uCode will do |
| 3384 | * that based on the direct_mask added to each channel entry */ |
| 3385 | cmd_len = iwl4965_fill_probe_req(priv, band, |
| 3386 | (struct ieee80211_mgmt *)scan->data, |
| 3387 | IWL_MAX_SCAN_SIZE - sizeof(*scan), 0); |
| 3388 | |
| 3389 | scan->tx_cmd.len = cpu_to_le16(cmd_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3390 | /* select Rx chains */ |
| 3391 | |
| 3392 | /* Force use of chains B and C (0x6) for scan Rx. |
| 3393 | * Avoid A (0x1) because of its off-channel reception on A-band. |
| 3394 | * MIMO is not used here, but value is required to make uCode happy. */ |
| 3395 | scan->rx_chain = RXON_RX_CHAIN_DRIVER_FORCE_MSK | |
| 3396 | cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS) | |
| 3397 | (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) | |
| 3398 | (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS)); |
| 3399 | |
| 3400 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) |
| 3401 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 3402 | |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3403 | if (direct_mask) |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 3404 | scan->channel_count = |
| 3405 | iwl4965_get_channels_for_scan( |
| 3406 | priv, band, 1, /* active */ |
| 3407 | direct_mask, |
| 3408 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Bill Moss | 786b455 | 2008-04-17 16:03:40 -0700 | [diff] [blame] | 3409 | else |
Reinette Chatre | 26c0f03 | 2008-03-11 16:17:15 -0700 | [diff] [blame] | 3410 | scan->channel_count = |
| 3411 | iwl4965_get_channels_for_scan( |
| 3412 | priv, band, 0, /* passive */ |
| 3413 | direct_mask, |
| 3414 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3415 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 3416 | scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | |
| 3417 | RXON_FILTER_BCON_AWARE_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3418 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3419 | scan->channel_count * sizeof(struct iwl4965_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3420 | cmd.data = scan; |
| 3421 | scan->len = cpu_to_le16(cmd.len); |
| 3422 | |
| 3423 | set_bit(STATUS_SCAN_HW, &priv->status); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3424 | ret = iwl_send_cmd_sync(priv, &cmd); |
| 3425 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3426 | goto done; |
| 3427 | |
| 3428 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 3429 | IWL_SCAN_CHECK_WATCHDOG); |
| 3430 | |
| 3431 | mutex_unlock(&priv->mutex); |
| 3432 | return; |
| 3433 | |
| 3434 | done: |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3435 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3436 | queue_work(priv->workqueue, &priv->scan_completed); |
| 3437 | mutex_unlock(&priv->mutex); |
| 3438 | } |
| 3439 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3440 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3441 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3442 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3443 | |
| 3444 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3445 | return; |
| 3446 | |
| 3447 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3448 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3449 | mutex_unlock(&priv->mutex); |
| 3450 | } |
| 3451 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3452 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3453 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3454 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3455 | |
| 3456 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3457 | return; |
| 3458 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3459 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3460 | queue_work(priv->workqueue, &priv->up); |
| 3461 | } |
| 3462 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3463 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3464 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3465 | struct iwl_priv *priv = |
| 3466 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3467 | |
| 3468 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3469 | return; |
| 3470 | |
| 3471 | mutex_lock(&priv->mutex); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 3472 | iwl_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3473 | mutex_unlock(&priv->mutex); |
| 3474 | } |
| 3475 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3476 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 3477 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3478 | static void iwl4965_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3479 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3480 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3481 | int ret = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3482 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3483 | |
| 3484 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 3485 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 3486 | return; |
| 3487 | } |
| 3488 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3489 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 3490 | priv->assoc_id, |
| 3491 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3492 | |
| 3493 | |
| 3494 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3495 | return; |
| 3496 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3497 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3498 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 3499 | return; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3500 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3501 | iwl4965_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3502 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3503 | conf = ieee80211_get_hw_conf(priv->hw); |
| 3504 | |
| 3505 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3506 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3507 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3508 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 3509 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3510 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3511 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3512 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3513 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 3514 | "Attempting to continue.\n"); |
| 3515 | |
| 3516 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 3517 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3518 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 3519 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 3520 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3521 | #endif /* CONFIG_IWL4965_HT*/ |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 3522 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3523 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 3524 | |
| 3525 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 3526 | priv->assoc_id, priv->beacon_int); |
| 3527 | |
| 3528 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 3529 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3530 | else |
| 3531 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3532 | |
| 3533 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 3534 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 3535 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 3536 | else |
| 3537 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 3538 | |
| 3539 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 3540 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 3541 | |
| 3542 | } |
| 3543 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3544 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3545 | |
| 3546 | switch (priv->iw_mode) { |
| 3547 | case IEEE80211_IF_TYPE_STA: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3548 | iwl4965_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3549 | break; |
| 3550 | |
| 3551 | case IEEE80211_IF_TYPE_IBSS: |
| 3552 | |
| 3553 | /* clear out the station table */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3554 | iwlcore_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3555 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 3556 | iwl_rxon_add_station(priv, iwl_bcast_addr, 0); |
| 3557 | iwl_rxon_add_station(priv, priv->bssid, 0); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3558 | iwl4965_rate_scale_init(priv->hw, IWL_STA_ID); |
| 3559 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3560 | |
| 3561 | break; |
| 3562 | |
| 3563 | default: |
| 3564 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 3565 | __FUNCTION__, priv->iw_mode); |
| 3566 | break; |
| 3567 | } |
| 3568 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3569 | iwl4965_sequence_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3570 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3571 | /* Enable Rx differential gain and sensitivity calibrations */ |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 3572 | iwl_chain_noise_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3573 | priv->start_calib = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3574 | |
| 3575 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 3576 | priv->assoc_station_added = 1; |
| 3577 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3578 | iwl4965_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 3579 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 3580 | iwl_power_update_mode(priv, 0); |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3581 | /* we have just associated, don't start scan too early */ |
| 3582 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3583 | } |
| 3584 | |
| 3585 | |
| 3586 | static void iwl4965_bg_post_associate(struct work_struct *data) |
| 3587 | { |
| 3588 | struct iwl_priv *priv = container_of(data, struct iwl_priv, |
| 3589 | post_associate.work); |
| 3590 | |
| 3591 | mutex_lock(&priv->mutex); |
| 3592 | iwl4965_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3593 | mutex_unlock(&priv->mutex); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3594 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3595 | } |
| 3596 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3597 | static void iwl4965_bg_abort_scan(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3598 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3599 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3600 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3601 | if (!iwl_is_ready(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3602 | return; |
| 3603 | |
| 3604 | mutex_lock(&priv->mutex); |
| 3605 | |
| 3606 | set_bit(STATUS_SCAN_ABORTING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3607 | iwl4965_send_scan_abort(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3608 | |
| 3609 | mutex_unlock(&priv->mutex); |
| 3610 | } |
| 3611 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3612 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 3613 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3614 | static void iwl4965_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3615 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3616 | struct iwl_priv *priv = |
| 3617 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3618 | |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 3619 | IWL_DEBUG(IWL_DL_SCAN, "SCAN complete scan\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3620 | |
| 3621 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3622 | return; |
| 3623 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 3624 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
| 3625 | iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3626 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3627 | ieee80211_scan_completed(priv->hw); |
| 3628 | |
| 3629 | /* Since setting the TXPOWER may have been deferred while |
| 3630 | * performing the scan, fire one off */ |
| 3631 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3632 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3633 | mutex_unlock(&priv->mutex); |
| 3634 | } |
| 3635 | |
| 3636 | /***************************************************************************** |
| 3637 | * |
| 3638 | * mac80211 entry point functions |
| 3639 | * |
| 3640 | *****************************************************************************/ |
| 3641 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3642 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 3643 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3644 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3645 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3646 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3647 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3648 | |
| 3649 | IWL_DEBUG_MAC80211("enter\n"); |
| 3650 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3651 | if (pci_enable_device(priv->pci_dev)) { |
| 3652 | IWL_ERROR("Fail to pci_enable_device\n"); |
| 3653 | return -ENODEV; |
| 3654 | } |
| 3655 | pci_restore_state(priv->pci_dev); |
| 3656 | pci_enable_msi(priv->pci_dev); |
| 3657 | |
| 3658 | ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, |
| 3659 | DRV_NAME, priv); |
| 3660 | if (ret) { |
| 3661 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 3662 | goto out_disable_msi; |
| 3663 | } |
| 3664 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3665 | /* we should be verifying the device is ready to be opened */ |
| 3666 | mutex_lock(&priv->mutex); |
| 3667 | |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 3668 | memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd)); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3669 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 3670 | * ucode filename and max sizes are card-specific. */ |
| 3671 | |
| 3672 | if (!priv->ucode_code.len) { |
| 3673 | ret = iwl4965_read_ucode(priv); |
| 3674 | if (ret) { |
| 3675 | IWL_ERROR("Could not read microcode: %d\n", ret); |
| 3676 | mutex_unlock(&priv->mutex); |
| 3677 | goto out_release_irq; |
| 3678 | } |
| 3679 | } |
| 3680 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3681 | ret = __iwl4965_up(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3682 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3683 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3684 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3685 | if (ret) |
| 3686 | goto out_release_irq; |
| 3687 | |
| 3688 | IWL_DEBUG_INFO("Start UP work done.\n"); |
| 3689 | |
| 3690 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 3691 | return 0; |
| 3692 | |
Ron Rindjunsky | fe9b6b7 | 2008-05-29 16:35:06 +0800 | [diff] [blame] | 3693 | /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3694 | * mac80211 will not be run successfully. */ |
Ron Rindjunsky | fe9b6b7 | 2008-05-29 16:35:06 +0800 | [diff] [blame] | 3695 | if (priv->ucode_type == UCODE_RT) { |
| 3696 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 3697 | test_bit(STATUS_READY, &priv->status), |
| 3698 | UCODE_READY_TIMEOUT); |
| 3699 | if (!ret) { |
| 3700 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 3701 | IWL_ERROR("START_ALIVE timeout after %dms.\n", |
| 3702 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 3703 | ret = -ETIMEDOUT; |
| 3704 | goto out_release_irq; |
| 3705 | } |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3706 | } |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3707 | |
Ron Rindjunsky | fe9b6b7 | 2008-05-29 16:35:06 +0800 | [diff] [blame] | 3708 | priv->is_open = 1; |
| 3709 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3710 | IWL_DEBUG_MAC80211("leave\n"); |
| 3711 | return 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3712 | |
| 3713 | out_release_irq: |
| 3714 | free_irq(priv->pci_dev->irq, priv); |
| 3715 | out_disable_msi: |
| 3716 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3717 | pci_disable_device(priv->pci_dev); |
| 3718 | priv->is_open = 0; |
| 3719 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3720 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3721 | } |
| 3722 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3723 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3724 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3725 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3726 | |
| 3727 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 3728 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3729 | if (!priv->is_open) { |
| 3730 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 3731 | return; |
| 3732 | } |
| 3733 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3734 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3735 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3736 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3737 | /* stop mac, cancel any scan request and clear |
| 3738 | * RXON_FILTER_ASSOC_MSK BIT |
| 3739 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3740 | mutex_lock(&priv->mutex); |
| 3741 | iwl4965_scan_cancel_timeout(priv, 100); |
| 3742 | cancel_delayed_work(&priv->post_associate); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 3743 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 3744 | } |
| 3745 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3746 | iwl4965_down(priv); |
| 3747 | |
| 3748 | flush_workqueue(priv->workqueue); |
| 3749 | free_irq(priv->pci_dev->irq, priv); |
| 3750 | pci_disable_msi(priv->pci_dev); |
| 3751 | pci_save_state(priv->pci_dev); |
| 3752 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 3753 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3754 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 3757 | 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] | 3758 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3759 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3760 | |
| 3761 | IWL_DEBUG_MAC80211("enter\n"); |
| 3762 | |
| 3763 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 3764 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 3765 | return -1; |
| 3766 | } |
| 3767 | |
| 3768 | 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] | 3769 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3770 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 3771 | if (iwl_tx_skb(priv, skb)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3772 | dev_kfree_skb_any(skb); |
| 3773 | |
| 3774 | IWL_DEBUG_MAC80211("leave\n"); |
| 3775 | return 0; |
| 3776 | } |
| 3777 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3778 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3779 | struct ieee80211_if_init_conf *conf) |
| 3780 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3781 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3782 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3783 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3784 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3785 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3786 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3787 | if (priv->vif) { |
| 3788 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Reinette Chatre | 75849d2 | 2008-01-23 10:15:17 -0800 | [diff] [blame] | 3789 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3790 | } |
| 3791 | |
| 3792 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3793 | priv->vif = conf->vif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3794 | |
| 3795 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3796 | |
| 3797 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 3798 | |
| 3799 | if (conf->mac_addr) { |
| 3800 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 3801 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 3802 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3803 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3804 | if (iwl_is_ready(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3805 | iwl4965_set_mode(priv, conf->type); |
| 3806 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3807 | mutex_unlock(&priv->mutex); |
| 3808 | |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3809 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3810 | return 0; |
| 3811 | } |
| 3812 | |
| 3813 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3814 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3815 | * |
| 3816 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 3817 | * be set inappropriately and the driver currently sets the hardware up to |
| 3818 | * use it whenever needed. |
| 3819 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3820 | 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] | 3821 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3822 | struct iwl_priv *priv = hw->priv; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3823 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3824 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3825 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3826 | |
| 3827 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3828 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3829 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 3830 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
| 3831 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3832 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3833 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3834 | ret = -EIO; |
| 3835 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3836 | } |
| 3837 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 3838 | if (unlikely(!priv->cfg->mod_params->disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3839 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 3840 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 3841 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3842 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 3843 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3844 | } |
| 3845 | |
| 3846 | spin_lock_irqsave(&priv->lock, flags); |
| 3847 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 3848 | ch_info = iwl_get_channel_info(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3849 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3850 | if (!is_channel_valid(ch_info)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3851 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
| 3852 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3853 | ret = -EINVAL; |
| 3854 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3855 | } |
| 3856 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3857 | #ifdef CONFIG_IWL4965_HT |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3858 | /* if we are switching from ht to 2.4 clear flags |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3859 | * from any ht related info since 2.4 does not |
| 3860 | * support ht */ |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3861 | if ((le16_to_cpu(priv->staging_rxon.channel) != conf->channel->hw_value) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3862 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 3863 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 3864 | #endif |
| 3865 | ) |
| 3866 | priv->staging_rxon.flags = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3867 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3868 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 3869 | iwl_set_rxon_channel(priv, conf->channel->band, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3870 | ieee80211_frequency_to_channel(conf->channel->center_freq)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3871 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3872 | iwl4965_set_flags_for_phymode(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3873 | |
| 3874 | /* The list of supported rates and rate mask can be different |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3875 | * for each band; since the band may have changed, reset |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3876 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3877 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3878 | |
| 3879 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3880 | |
| 3881 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 3882 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3883 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3884 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3885 | } |
| 3886 | #endif |
| 3887 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3888 | if (priv->cfg->ops->lib->radio_kill_sw) |
| 3889 | priv->cfg->ops->lib->radio_kill_sw(priv, !conf->radio_enabled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3890 | |
| 3891 | if (!conf->radio_enabled) { |
| 3892 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3893 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3894 | } |
| 3895 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3896 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3897 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3898 | ret = -EIO; |
| 3899 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3900 | } |
| 3901 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3902 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3903 | |
| 3904 | if (memcmp(&priv->active_rxon, |
| 3905 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3906 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3907 | else |
| 3908 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 3909 | |
| 3910 | IWL_DEBUG_MAC80211("leave\n"); |
| 3911 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 3912 | out: |
| 3913 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3914 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3915 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3916 | } |
| 3917 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3918 | static void iwl4965_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3919 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3920 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3921 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 3922 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3923 | return; |
| 3924 | |
| 3925 | /* The following should be done only at AP bring up */ |
| 3926 | if ((priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) == 0) { |
| 3927 | |
| 3928 | /* RXON - unassoc (to set timing command) */ |
| 3929 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3930 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3931 | |
| 3932 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3933 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 3934 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3935 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3936 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3937 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3938 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 3939 | "Attempting to continue.\n"); |
| 3940 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 3941 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3942 | |
| 3943 | /* FIXME: what should be the assoc_id for AP? */ |
| 3944 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 3945 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 3946 | priv->staging_rxon.flags |= |
| 3947 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3948 | else |
| 3949 | priv->staging_rxon.flags &= |
| 3950 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3951 | |
| 3952 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 3953 | if (priv->assoc_capability & |
| 3954 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 3955 | priv->staging_rxon.flags |= |
| 3956 | RXON_FLG_SHORT_SLOT_MSK; |
| 3957 | else |
| 3958 | priv->staging_rxon.flags &= |
| 3959 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 3960 | |
| 3961 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 3962 | priv->staging_rxon.flags &= |
| 3963 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 3964 | } |
| 3965 | /* restore RXON assoc */ |
| 3966 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3967 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3968 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 3969 | iwl_rxon_add_station(priv, iwl_bcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 3970 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3971 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3972 | |
| 3973 | /* FIXME - we need to add code here to detect a totally new |
| 3974 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 3975 | * clear sta table, add BCAST sta... */ |
| 3976 | } |
| 3977 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3978 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, |
| 3979 | struct ieee80211_vif *vif, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3980 | struct ieee80211_if_conf *conf) |
| 3981 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3982 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3983 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3984 | unsigned long flags; |
| 3985 | int rc; |
| 3986 | |
| 3987 | if (conf == NULL) |
| 3988 | return -EIO; |
| 3989 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 3990 | if (priv->vif != vif) { |
| 3991 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 3992 | return 0; |
| 3993 | } |
| 3994 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3995 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 3996 | (!conf->beacon || !conf->ssid_len)) { |
| 3997 | IWL_DEBUG_MAC80211 |
| 3998 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 3999 | return 0; |
| 4000 | } |
| 4001 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4002 | if (!iwl_is_alive(priv)) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4003 | return -EAGAIN; |
| 4004 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4005 | mutex_lock(&priv->mutex); |
| 4006 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4007 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4008 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 4009 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4010 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4011 | /* |
| 4012 | * very dubious code was here; the probe filtering flag is never set: |
| 4013 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4014 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 4015 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4016 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4017 | |
| 4018 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 4019 | if (!conf->bssid) { |
| 4020 | conf->bssid = priv->mac_addr; |
| 4021 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4022 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 4023 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4024 | } |
| 4025 | if (priv->ibss_beacon) |
| 4026 | dev_kfree_skb(priv->ibss_beacon); |
| 4027 | |
| 4028 | priv->ibss_beacon = conf->beacon; |
| 4029 | } |
| 4030 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4031 | if (iwl_is_rfkill(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4032 | goto done; |
| 4033 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4034 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 4035 | !is_multicast_ether_addr(conf->bssid)) { |
| 4036 | /* If there is currently a HW scan going on in the background |
| 4037 | * then we need to cancel it else the RXON below will fail. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4038 | if (iwl4965_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4039 | IWL_WARNING("Aborted scan still in progress " |
| 4040 | "after 100ms\n"); |
| 4041 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 4042 | mutex_unlock(&priv->mutex); |
| 4043 | return -EAGAIN; |
| 4044 | } |
| 4045 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 4046 | |
| 4047 | /* TODO: Audit driver for usage of these members and see |
| 4048 | * if mac80211 deprecates them (priv->bssid looks like it |
| 4049 | * shouldn't be there, but I haven't scanned the IBSS code |
| 4050 | * to verify) - jpk */ |
| 4051 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 4052 | |
| 4053 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4054 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4055 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4056 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4057 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 4058 | iwl_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4059 | priv, priv->active_rxon.bssid_addr, 1); |
| 4060 | } |
| 4061 | |
| 4062 | } else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4063 | iwl4965_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4064 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4065 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4066 | } |
| 4067 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4068 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4069 | spin_lock_irqsave(&priv->lock, flags); |
| 4070 | if (!conf->ssid_len) |
| 4071 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 4072 | else |
| 4073 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 4074 | |
| 4075 | priv->essid_len = conf->ssid_len; |
| 4076 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4077 | |
| 4078 | IWL_DEBUG_MAC80211("leave\n"); |
| 4079 | mutex_unlock(&priv->mutex); |
| 4080 | |
| 4081 | return 0; |
| 4082 | } |
| 4083 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4084 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4085 | unsigned int changed_flags, |
| 4086 | unsigned int *total_flags, |
| 4087 | int mc_count, struct dev_addr_list *mc_list) |
| 4088 | { |
| 4089 | /* |
| 4090 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4091 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4092 | */ |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 4093 | struct iwl_priv *priv = hw->priv; |
| 4094 | int new_flags = 0; |
| 4095 | if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { |
| 4096 | if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { |
| 4097 | IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n", |
| 4098 | IEEE80211_IF_TYPE_MNTR, |
| 4099 | changed_flags, *total_flags); |
| 4100 | /* queue work 'cuz mac80211 is holding a lock which |
| 4101 | * prevents us from issuing (synchronous) f/w cmds */ |
| 4102 | queue_work(priv->workqueue, &priv->set_monitor); |
| 4103 | new_flags &= FIF_PROMISC_IN_BSS | |
| 4104 | FIF_OTHER_BSS | |
| 4105 | FIF_ALLMULTI; |
| 4106 | } |
| 4107 | } |
| 4108 | *total_flags = new_flags; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 4109 | } |
| 4110 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4111 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4112 | struct ieee80211_if_init_conf *conf) |
| 4113 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4114 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4115 | |
| 4116 | IWL_DEBUG_MAC80211("enter\n"); |
| 4117 | |
| 4118 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4119 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4120 | if (iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4121 | iwl4965_scan_cancel_timeout(priv, 100); |
| 4122 | cancel_delayed_work(&priv->post_associate); |
| 4123 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 4124 | iwl4965_commit_rxon(priv); |
| 4125 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 4126 | if (priv->vif == conf->vif) { |
| 4127 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4128 | memset(priv->bssid, 0, ETH_ALEN); |
| 4129 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 4130 | priv->essid_len = 0; |
| 4131 | } |
| 4132 | mutex_unlock(&priv->mutex); |
| 4133 | |
| 4134 | IWL_DEBUG_MAC80211("leave\n"); |
| 4135 | |
| 4136 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4137 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4138 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4139 | static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, |
| 4140 | struct ieee80211_vif *vif, |
| 4141 | struct ieee80211_bss_conf *bss_conf, |
| 4142 | u32 changes) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4143 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4144 | struct iwl_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4145 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4146 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
| 4147 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4148 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4149 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
| 4150 | bss_conf->use_short_preamble); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4151 | if (bss_conf->use_short_preamble) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4152 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4153 | else |
| 4154 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 4155 | } |
| 4156 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4157 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4158 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4159 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4160 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 4161 | else |
| 4162 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 4163 | } |
| 4164 | |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 4165 | if (changes & BSS_CHANGED_HT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4166 | IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 4167 | iwl4965_ht_conf(priv, bss_conf); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4168 | iwl_set_rxon_chain(priv); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 4169 | } |
| 4170 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4171 | if (changes & BSS_CHANGED_ASSOC) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4172 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4173 | /* This should never happen as this function should |
| 4174 | * never be called from interrupt context. */ |
| 4175 | if (WARN_ON_ONCE(in_interrupt())) |
| 4176 | return; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4177 | if (bss_conf->assoc) { |
| 4178 | priv->assoc_id = bss_conf->aid; |
| 4179 | priv->beacon_int = bss_conf->beacon_int; |
| 4180 | priv->timestamp = bss_conf->timestamp; |
| 4181 | priv->assoc_capability = bss_conf->assoc_capability; |
| 4182 | priv->next_scan_jiffies = jiffies + |
| 4183 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 4184 | mutex_lock(&priv->mutex); |
| 4185 | iwl4965_post_associate(priv); |
| 4186 | mutex_unlock(&priv->mutex); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4187 | } else { |
| 4188 | priv->assoc_id = 0; |
| 4189 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); |
| 4190 | } |
| 4191 | } else if (changes && iwl_is_associated(priv) && priv->assoc_id) { |
| 4192 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 4193 | iwl_send_rxon_assoc(priv); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4194 | } |
| 4195 | |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 4196 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4197 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4198 | 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] | 4199 | { |
| 4200 | int rc = 0; |
| 4201 | unsigned long flags; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4202 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4203 | |
| 4204 | IWL_DEBUG_MAC80211("enter\n"); |
| 4205 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4206 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4207 | spin_lock_irqsave(&priv->lock, flags); |
| 4208 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4209 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4210 | rc = -EIO; |
| 4211 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 4212 | goto out_unlock; |
| 4213 | } |
| 4214 | |
| 4215 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 4216 | rc = -EIO; |
| 4217 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 4218 | goto out_unlock; |
| 4219 | } |
| 4220 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4221 | /* we don't schedule scan within next_scan_jiffies period */ |
| 4222 | if (priv->next_scan_jiffies && |
| 4223 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 4224 | rc = -EAGAIN; |
| 4225 | goto out_unlock; |
| 4226 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4227 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4228 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 4229 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4230 | rc = -EAGAIN; |
| 4231 | goto out_unlock; |
| 4232 | } |
| 4233 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 4234 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4235 | iwl4965_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4236 | |
| 4237 | priv->one_direct_scan = 1; |
| 4238 | priv->direct_ssid_len = (u8) |
| 4239 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 4240 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4241 | } else |
| 4242 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4243 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4244 | rc = iwl4965_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4245 | |
| 4246 | IWL_DEBUG_MAC80211("leave\n"); |
| 4247 | |
| 4248 | out_unlock: |
| 4249 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4250 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4251 | |
| 4252 | return rc; |
| 4253 | } |
| 4254 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4255 | static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 4256 | struct ieee80211_key_conf *keyconf, const u8 *addr, |
| 4257 | u32 iv32, u16 *phase1key) |
| 4258 | { |
| 4259 | struct iwl_priv *priv = hw->priv; |
| 4260 | u8 sta_id = IWL_INVALID_STATION; |
| 4261 | unsigned long flags; |
| 4262 | __le16 key_flags = 0; |
| 4263 | int i; |
| 4264 | DECLARE_MAC_BUF(mac); |
| 4265 | |
| 4266 | IWL_DEBUG_MAC80211("enter\n"); |
| 4267 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 4268 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4269 | if (sta_id == IWL_INVALID_STATION) { |
| 4270 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 4271 | print_mac(mac, addr)); |
| 4272 | return; |
| 4273 | } |
| 4274 | |
| 4275 | iwl4965_scan_cancel_timeout(priv, 100); |
| 4276 | |
| 4277 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); |
| 4278 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 4279 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 4280 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 4281 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4282 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 4283 | |
| 4284 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 4285 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4286 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 4287 | priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; |
| 4288 | |
| 4289 | for (i = 0; i < 5; i++) |
| 4290 | priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = |
| 4291 | cpu_to_le16(phase1key[i]); |
| 4292 | |
| 4293 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 4294 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 4295 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 4296 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4297 | |
| 4298 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 4299 | |
| 4300 | IWL_DEBUG_MAC80211("leave\n"); |
| 4301 | } |
| 4302 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4303 | 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] | 4304 | const u8 *local_addr, const u8 *addr, |
| 4305 | struct ieee80211_key_conf *key) |
| 4306 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4307 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4308 | DECLARE_MAC_BUF(mac); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4309 | int ret = 0; |
| 4310 | u8 sta_id = IWL_INVALID_STATION; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4311 | u8 is_default_wep_key = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4312 | |
| 4313 | IWL_DEBUG_MAC80211("enter\n"); |
| 4314 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 4315 | if (priv->hw_params.sw_crypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4316 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 4317 | return -EOPNOTSUPP; |
| 4318 | } |
| 4319 | |
| 4320 | if (is_zero_ether_addr(addr)) |
| 4321 | /* only support pairwise keys */ |
| 4322 | return -EOPNOTSUPP; |
| 4323 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 4324 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4325 | if (sta_id == IWL_INVALID_STATION) { |
| 4326 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 4327 | print_mac(mac, addr)); |
| 4328 | return -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4329 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4330 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4331 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4332 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4333 | iwl4965_scan_cancel_timeout(priv, 100); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4334 | mutex_unlock(&priv->mutex); |
| 4335 | |
| 4336 | /* If we are getting WEP group key and we didn't receive any key mapping |
| 4337 | * so far, we are in legacy wep mode (group key only), otherwise we are |
| 4338 | * in 1X mode. |
| 4339 | * In legacy wep mode, we use another host command to the uCode */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 4340 | 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] | 4341 | priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 4342 | if (cmd == SET_KEY) |
| 4343 | is_default_wep_key = !priv->key_mapping_key; |
| 4344 | else |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 4345 | is_default_wep_key = |
| 4346 | (key->hw_key_idx == HW_KEY_DEFAULT); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4347 | } |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4348 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4349 | switch (cmd) { |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4350 | case SET_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4351 | if (is_default_wep_key) |
| 4352 | ret = iwl_set_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4353 | else |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 4354 | ret = iwl_set_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4355 | |
| 4356 | IWL_DEBUG_MAC80211("enable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4357 | break; |
| 4358 | case DISABLE_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4359 | if (is_default_wep_key) |
| 4360 | ret = iwl_remove_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4361 | else |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 4362 | ret = iwl_remove_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4363 | |
| 4364 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4365 | break; |
| 4366 | default: |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4367 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4371 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 4372 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4373 | } |
| 4374 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 4375 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4376 | const struct ieee80211_tx_queue_params *params) |
| 4377 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4378 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4379 | unsigned long flags; |
| 4380 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4381 | |
| 4382 | IWL_DEBUG_MAC80211("enter\n"); |
| 4383 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4384 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4385 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 4386 | return -EIO; |
| 4387 | } |
| 4388 | |
| 4389 | if (queue >= AC_NUM) { |
| 4390 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 4391 | return 0; |
| 4392 | } |
| 4393 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4394 | if (!priv->qos_data.qos_enable) { |
| 4395 | priv->qos_data.qos_active = 0; |
| 4396 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 4397 | return 0; |
| 4398 | } |
| 4399 | q = AC_NUM - 1 - queue; |
| 4400 | |
| 4401 | spin_lock_irqsave(&priv->lock, flags); |
| 4402 | |
| 4403 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 4404 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 4405 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 4406 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 4407 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4408 | |
| 4409 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 4410 | priv->qos_data.qos_active = 1; |
| 4411 | |
| 4412 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4413 | |
| 4414 | mutex_lock(&priv->mutex); |
| 4415 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4416 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4417 | else if (priv->assoc_id && iwl_is_associated(priv)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4418 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4419 | |
| 4420 | mutex_unlock(&priv->mutex); |
| 4421 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4422 | IWL_DEBUG_MAC80211("leave\n"); |
| 4423 | return 0; |
| 4424 | } |
| 4425 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4426 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4427 | struct ieee80211_tx_queue_stats *stats) |
| 4428 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4429 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4430 | int i, avail; |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 4431 | struct iwl_tx_queue *txq; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 4432 | struct iwl_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4433 | unsigned long flags; |
| 4434 | |
| 4435 | IWL_DEBUG_MAC80211("enter\n"); |
| 4436 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4437 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4438 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 4439 | return -EIO; |
| 4440 | } |
| 4441 | |
| 4442 | spin_lock_irqsave(&priv->lock, flags); |
| 4443 | |
| 4444 | for (i = 0; i < AC_NUM; i++) { |
| 4445 | txq = &priv->txq[i]; |
| 4446 | q = &txq->q; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 4447 | avail = iwl_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4448 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 4449 | stats[i].len = q->n_window - avail; |
| 4450 | stats[i].limit = q->n_window - q->high_mark; |
| 4451 | stats[i].count = q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4452 | |
| 4453 | } |
| 4454 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4455 | |
| 4456 | IWL_DEBUG_MAC80211("leave\n"); |
| 4457 | |
| 4458 | return 0; |
| 4459 | } |
| 4460 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4461 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4462 | struct ieee80211_low_level_stats *stats) |
| 4463 | { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 4464 | struct iwl_priv *priv = hw->priv; |
| 4465 | |
| 4466 | priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4467 | IWL_DEBUG_MAC80211("enter\n"); |
| 4468 | IWL_DEBUG_MAC80211("leave\n"); |
| 4469 | |
| 4470 | return 0; |
| 4471 | } |
| 4472 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4473 | static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4474 | { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 4475 | struct iwl_priv *priv; |
| 4476 | |
| 4477 | priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4478 | IWL_DEBUG_MAC80211("enter\n"); |
| 4479 | IWL_DEBUG_MAC80211("leave\n"); |
| 4480 | |
| 4481 | return 0; |
| 4482 | } |
| 4483 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4484 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4485 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4486 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4487 | unsigned long flags; |
| 4488 | |
| 4489 | mutex_lock(&priv->mutex); |
| 4490 | IWL_DEBUG_MAC80211("enter\n"); |
| 4491 | |
| 4492 | priv->lq_mngr.lq_ready = 0; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4493 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4494 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 4495 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4496 | spin_unlock_irqrestore(&priv->lock, flags); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4497 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4498 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4499 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4500 | |
| 4501 | cancel_delayed_work(&priv->post_associate); |
| 4502 | |
| 4503 | spin_lock_irqsave(&priv->lock, flags); |
| 4504 | priv->assoc_id = 0; |
| 4505 | priv->assoc_capability = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4506 | priv->assoc_station_added = 0; |
| 4507 | |
| 4508 | /* new association get rid of ibss beacon skb */ |
| 4509 | if (priv->ibss_beacon) |
| 4510 | dev_kfree_skb(priv->ibss_beacon); |
| 4511 | |
| 4512 | priv->ibss_beacon = NULL; |
| 4513 | |
| 4514 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 4515 | priv->timestamp = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4516 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 4517 | priv->beacon_int = 0; |
| 4518 | |
| 4519 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4520 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4521 | if (!iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4522 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 4523 | mutex_unlock(&priv->mutex); |
| 4524 | return; |
| 4525 | } |
| 4526 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4527 | /* we are restarting association process |
| 4528 | * clear RXON_FILTER_ASSOC_MSK bit |
| 4529 | */ |
| 4530 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4531 | iwl4965_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4532 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4533 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4534 | } |
| 4535 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4536 | iwl_power_update_mode(priv, 0); |
| 4537 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4538 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 4539 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 4540 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4541 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 4542 | mutex_unlock(&priv->mutex); |
| 4543 | return; |
| 4544 | } |
| 4545 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4546 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4547 | |
| 4548 | mutex_unlock(&priv->mutex); |
| 4549 | |
| 4550 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4551 | } |
| 4552 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 4553 | 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] | 4554 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4555 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4556 | unsigned long flags; |
| 4557 | |
| 4558 | mutex_lock(&priv->mutex); |
| 4559 | IWL_DEBUG_MAC80211("enter\n"); |
| 4560 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4561 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4562 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 4563 | mutex_unlock(&priv->mutex); |
| 4564 | return -EIO; |
| 4565 | } |
| 4566 | |
| 4567 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 4568 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 4569 | mutex_unlock(&priv->mutex); |
| 4570 | return -EIO; |
| 4571 | } |
| 4572 | |
| 4573 | spin_lock_irqsave(&priv->lock, flags); |
| 4574 | |
| 4575 | if (priv->ibss_beacon) |
| 4576 | dev_kfree_skb(priv->ibss_beacon); |
| 4577 | |
| 4578 | priv->ibss_beacon = skb; |
| 4579 | |
| 4580 | priv->assoc_id = 0; |
| 4581 | |
| 4582 | IWL_DEBUG_MAC80211("leave\n"); |
| 4583 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4584 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 4585 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4586 | |
| 4587 | queue_work(priv->workqueue, &priv->post_associate.work); |
| 4588 | |
| 4589 | mutex_unlock(&priv->mutex); |
| 4590 | |
| 4591 | return 0; |
| 4592 | } |
| 4593 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4594 | /***************************************************************************** |
| 4595 | * |
| 4596 | * sysfs attributes |
| 4597 | * |
| 4598 | *****************************************************************************/ |
| 4599 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4600 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4601 | |
| 4602 | /* |
| 4603 | * The following adds a new attribute to the sysfs representation |
| 4604 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 4605 | * used for controlling the debug level. |
| 4606 | * |
| 4607 | * See the level definitions in iwl for details. |
| 4608 | */ |
| 4609 | |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4610 | static ssize_t show_debug_level(struct device *d, |
| 4611 | struct device_attribute *attr, char *buf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4612 | { |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4613 | struct iwl_priv *priv = d->driver_data; |
| 4614 | |
| 4615 | return sprintf(buf, "0x%08X\n", priv->debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4616 | } |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4617 | static ssize_t store_debug_level(struct device *d, |
| 4618 | struct device_attribute *attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4619 | const char *buf, size_t count) |
| 4620 | { |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4621 | struct iwl_priv *priv = d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4622 | char *p = (char *)buf; |
| 4623 | u32 val; |
| 4624 | |
| 4625 | val = simple_strtoul(p, &p, 0); |
| 4626 | if (p == buf) |
| 4627 | printk(KERN_INFO DRV_NAME |
| 4628 | ": %s is not in hex or decimal form.\n", buf); |
| 4629 | else |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4630 | priv->debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4631 | |
| 4632 | return strnlen(buf, count); |
| 4633 | } |
| 4634 | |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4635 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 4636 | show_debug_level, store_debug_level); |
| 4637 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4638 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4639 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4640 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4641 | |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 4642 | static ssize_t show_version(struct device *d, |
| 4643 | struct device_attribute *attr, char *buf) |
| 4644 | { |
| 4645 | struct iwl_priv *priv = d->driver_data; |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 4646 | struct iwl_alive_resp *palive = &priv->card_alive; |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 4647 | |
| 4648 | if (palive->is_valid) |
| 4649 | return sprintf(buf, "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n" |
| 4650 | "fw type: 0x%01X 0x%01X\n", |
| 4651 | palive->ucode_major, palive->ucode_minor, |
| 4652 | palive->sw_rev[0], palive->sw_rev[1], |
| 4653 | palive->ver_type, palive->ver_subtype); |
| 4654 | |
| 4655 | else |
| 4656 | return sprintf(buf, "fw not loaded\n"); |
| 4657 | } |
| 4658 | |
| 4659 | static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL); |
| 4660 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4661 | static ssize_t show_temperature(struct device *d, |
| 4662 | struct device_attribute *attr, char *buf) |
| 4663 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4664 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4665 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4666 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4667 | return -EAGAIN; |
| 4668 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4669 | return sprintf(buf, "%d\n", iwl4965_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4670 | } |
| 4671 | |
| 4672 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 4673 | |
| 4674 | static ssize_t show_rs_window(struct device *d, |
| 4675 | struct device_attribute *attr, |
| 4676 | char *buf) |
| 4677 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4678 | struct iwl_priv *priv = d->driver_data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4679 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4680 | } |
| 4681 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 4682 | |
| 4683 | static ssize_t show_tx_power(struct device *d, |
| 4684 | struct device_attribute *attr, char *buf) |
| 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 | return sprintf(buf, "%d\n", priv->user_txpower_limit); |
| 4688 | } |
| 4689 | |
| 4690 | static ssize_t store_tx_power(struct device *d, |
| 4691 | struct device_attribute *attr, |
| 4692 | const char *buf, size_t count) |
| 4693 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4694 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4695 | char *p = (char *)buf; |
| 4696 | u32 val; |
| 4697 | |
| 4698 | val = simple_strtoul(p, &p, 10); |
| 4699 | if (p == buf) |
| 4700 | printk(KERN_INFO DRV_NAME |
| 4701 | ": %s is not in decimal form.\n", buf); |
| 4702 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4703 | iwl4965_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4704 | |
| 4705 | return count; |
| 4706 | } |
| 4707 | |
| 4708 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 4709 | |
| 4710 | static ssize_t show_flags(struct device *d, |
| 4711 | struct device_attribute *attr, char *buf) |
| 4712 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4713 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4714 | |
| 4715 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 4716 | } |
| 4717 | |
| 4718 | static ssize_t store_flags(struct device *d, |
| 4719 | struct device_attribute *attr, |
| 4720 | const char *buf, size_t count) |
| 4721 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4722 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4723 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 4724 | |
| 4725 | mutex_lock(&priv->mutex); |
| 4726 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 4727 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4728 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4729 | IWL_WARNING("Could not cancel scan.\n"); |
| 4730 | else { |
| 4731 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 4732 | flags); |
| 4733 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4734 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4735 | } |
| 4736 | } |
| 4737 | mutex_unlock(&priv->mutex); |
| 4738 | |
| 4739 | return count; |
| 4740 | } |
| 4741 | |
| 4742 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 4743 | |
| 4744 | static ssize_t show_filter_flags(struct device *d, |
| 4745 | struct device_attribute *attr, char *buf) |
| 4746 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4747 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4748 | |
| 4749 | return sprintf(buf, "0x%04X\n", |
| 4750 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 4751 | } |
| 4752 | |
| 4753 | static ssize_t store_filter_flags(struct device *d, |
| 4754 | struct device_attribute *attr, |
| 4755 | const char *buf, size_t count) |
| 4756 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4757 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4758 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 4759 | |
| 4760 | mutex_lock(&priv->mutex); |
| 4761 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 4762 | /* Cancel any currently running scans... */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4763 | if (iwl4965_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4764 | IWL_WARNING("Could not cancel scan.\n"); |
| 4765 | else { |
| 4766 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 4767 | "0x%04X\n", filter_flags); |
| 4768 | priv->staging_rxon.filter_flags = |
| 4769 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4770 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4771 | } |
| 4772 | } |
| 4773 | mutex_unlock(&priv->mutex); |
| 4774 | |
| 4775 | return count; |
| 4776 | } |
| 4777 | |
| 4778 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 4779 | store_filter_flags); |
| 4780 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4781 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4782 | |
| 4783 | static ssize_t show_measurement(struct device *d, |
| 4784 | struct device_attribute *attr, char *buf) |
| 4785 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4786 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4787 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4788 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 4789 | u8 *data = (u8 *) & measure_report; |
| 4790 | unsigned long flags; |
| 4791 | |
| 4792 | spin_lock_irqsave(&priv->lock, flags); |
| 4793 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 4794 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4795 | return 0; |
| 4796 | } |
| 4797 | memcpy(&measure_report, &priv->measure_report, size); |
| 4798 | priv->measurement_status = 0; |
| 4799 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4800 | |
| 4801 | while (size && (PAGE_SIZE - len)) { |
| 4802 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 4803 | PAGE_SIZE - len, 1); |
| 4804 | len = strlen(buf); |
| 4805 | if (PAGE_SIZE - len) |
| 4806 | buf[len++] = '\n'; |
| 4807 | |
| 4808 | ofs += 16; |
| 4809 | size -= min(size, 16U); |
| 4810 | } |
| 4811 | |
| 4812 | return len; |
| 4813 | } |
| 4814 | |
| 4815 | static ssize_t store_measurement(struct device *d, |
| 4816 | struct device_attribute *attr, |
| 4817 | const char *buf, size_t count) |
| 4818 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4819 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4820 | struct ieee80211_measurement_params params = { |
| 4821 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 4822 | .start_time = cpu_to_le64(priv->last_tsf), |
| 4823 | .duration = cpu_to_le16(1), |
| 4824 | }; |
| 4825 | u8 type = IWL_MEASURE_BASIC; |
| 4826 | u8 buffer[32]; |
| 4827 | u8 channel; |
| 4828 | |
| 4829 | if (count) { |
| 4830 | char *p = buffer; |
| 4831 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 4832 | channel = simple_strtoul(p, NULL, 0); |
| 4833 | if (channel) |
| 4834 | params.channel = channel; |
| 4835 | |
| 4836 | p = buffer; |
| 4837 | while (*p && *p != ' ') |
| 4838 | p++; |
| 4839 | if (*p) |
| 4840 | type = simple_strtoul(p + 1, NULL, 0); |
| 4841 | } |
| 4842 | |
| 4843 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 4844 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4845 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4846 | |
| 4847 | return count; |
| 4848 | } |
| 4849 | |
| 4850 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 4851 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4852 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4853 | |
| 4854 | static ssize_t store_retry_rate(struct device *d, |
| 4855 | struct device_attribute *attr, |
| 4856 | const char *buf, size_t count) |
| 4857 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4858 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4859 | |
| 4860 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 4861 | if (priv->retry_rate <= 0) |
| 4862 | priv->retry_rate = 1; |
| 4863 | |
| 4864 | return count; |
| 4865 | } |
| 4866 | |
| 4867 | static ssize_t show_retry_rate(struct device *d, |
| 4868 | struct device_attribute *attr, char *buf) |
| 4869 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4870 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4871 | return sprintf(buf, "%d", priv->retry_rate); |
| 4872 | } |
| 4873 | |
| 4874 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 4875 | store_retry_rate); |
| 4876 | |
| 4877 | static ssize_t store_power_level(struct device *d, |
| 4878 | struct device_attribute *attr, |
| 4879 | const char *buf, size_t count) |
| 4880 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4881 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4882 | int rc; |
| 4883 | int mode; |
| 4884 | |
| 4885 | mode = simple_strtoul(buf, NULL, 0); |
| 4886 | mutex_lock(&priv->mutex); |
| 4887 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4888 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4889 | rc = -EAGAIN; |
| 4890 | goto out; |
| 4891 | } |
| 4892 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4893 | rc = iwl_power_set_user_mode(priv, mode); |
| 4894 | if (rc) { |
| 4895 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 4896 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4897 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4898 | rc = count; |
| 4899 | |
| 4900 | out: |
| 4901 | mutex_unlock(&priv->mutex); |
| 4902 | return rc; |
| 4903 | } |
| 4904 | |
| 4905 | #define MAX_WX_STRING 80 |
| 4906 | |
| 4907 | /* Values are in microsecond */ |
| 4908 | static const s32 timeout_duration[] = { |
| 4909 | 350000, |
| 4910 | 250000, |
| 4911 | 75000, |
| 4912 | 37000, |
| 4913 | 25000, |
| 4914 | }; |
| 4915 | static const s32 period_duration[] = { |
| 4916 | 400000, |
| 4917 | 700000, |
| 4918 | 1000000, |
| 4919 | 1000000, |
| 4920 | 1000000 |
| 4921 | }; |
| 4922 | |
| 4923 | static ssize_t show_power_level(struct device *d, |
| 4924 | struct device_attribute *attr, char *buf) |
| 4925 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4926 | struct iwl_priv *priv = dev_get_drvdata(d); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4927 | int level = priv->power_data.power_mode; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4928 | char *p = buf; |
| 4929 | |
| 4930 | p += sprintf(p, "%d ", level); |
| 4931 | switch (level) { |
| 4932 | case IWL_POWER_MODE_CAM: |
| 4933 | case IWL_POWER_AC: |
| 4934 | p += sprintf(p, "(AC)"); |
| 4935 | break; |
| 4936 | case IWL_POWER_BATTERY: |
| 4937 | p += sprintf(p, "(BATTERY)"); |
| 4938 | break; |
| 4939 | default: |
| 4940 | p += sprintf(p, |
| 4941 | "(Timeout %dms, Period %dms)", |
| 4942 | timeout_duration[level - 1] / 1000, |
| 4943 | period_duration[level - 1] / 1000); |
| 4944 | } |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4945 | /* |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4946 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 4947 | p += sprintf(p, " OFF\n"); |
| 4948 | else |
| 4949 | p += sprintf(p, " \n"); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4950 | */ |
| 4951 | p += sprintf(p, " \n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4952 | return (p - buf + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4953 | } |
| 4954 | |
| 4955 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 4956 | store_power_level); |
| 4957 | |
| 4958 | static ssize_t show_channels(struct device *d, |
| 4959 | struct device_attribute *attr, char *buf) |
| 4960 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4961 | /* all this shit doesn't belong into sysfs anyway */ |
| 4962 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4963 | } |
| 4964 | |
| 4965 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 4966 | |
| 4967 | static ssize_t show_statistics(struct device *d, |
| 4968 | struct device_attribute *attr, char *buf) |
| 4969 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4970 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4971 | u32 size = sizeof(struct iwl4965_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4972 | u32 len = 0, ofs = 0; |
| 4973 | u8 *data = (u8 *) & priv->statistics; |
| 4974 | int rc = 0; |
| 4975 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4976 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4977 | return -EAGAIN; |
| 4978 | |
| 4979 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 4980 | rc = iwl_send_statistics_request(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4981 | mutex_unlock(&priv->mutex); |
| 4982 | |
| 4983 | if (rc) { |
| 4984 | len = sprintf(buf, |
| 4985 | "Error sending statistics request: 0x%08X\n", rc); |
| 4986 | return len; |
| 4987 | } |
| 4988 | |
| 4989 | while (size && (PAGE_SIZE - len)) { |
| 4990 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 4991 | PAGE_SIZE - len, 1); |
| 4992 | len = strlen(buf); |
| 4993 | if (PAGE_SIZE - len) |
| 4994 | buf[len++] = '\n'; |
| 4995 | |
| 4996 | ofs += 16; |
| 4997 | size -= min(size, 16U); |
| 4998 | } |
| 4999 | |
| 5000 | return len; |
| 5001 | } |
| 5002 | |
| 5003 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 5004 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5005 | static ssize_t show_status(struct device *d, |
| 5006 | struct device_attribute *attr, char *buf) |
| 5007 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5008 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 5009 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5010 | return -EAGAIN; |
| 5011 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 5012 | } |
| 5013 | |
| 5014 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 5015 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5016 | /***************************************************************************** |
| 5017 | * |
| 5018 | * driver setup and teardown |
| 5019 | * |
| 5020 | *****************************************************************************/ |
| 5021 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5022 | static void iwl4965_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5023 | { |
| 5024 | priv->workqueue = create_workqueue(DRV_NAME); |
| 5025 | |
| 5026 | init_waitqueue_head(&priv->wait_command_queue); |
| 5027 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5028 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 5029 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 5030 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
| 5031 | INIT_WORK(&priv->scan_completed, iwl4965_bg_scan_completed); |
| 5032 | INIT_WORK(&priv->request_scan, iwl4965_bg_request_scan); |
| 5033 | INIT_WORK(&priv->abort_scan, iwl4965_bg_abort_scan); |
| 5034 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 5035 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 5036 | INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5037 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 5038 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start); |
| 5039 | INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5040 | INIT_DELAYED_WORK(&priv->scan_check, iwl4965_bg_scan_check); |
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_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5043 | |
| 5044 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5045 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5046 | } |
| 5047 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5048 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5049 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5050 | iwl4965_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5051 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 5052 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5053 | cancel_delayed_work(&priv->scan_check); |
| 5054 | cancel_delayed_work(&priv->alive_start); |
| 5055 | cancel_delayed_work(&priv->post_associate); |
| 5056 | cancel_work_sync(&priv->beacon_update); |
| 5057 | } |
| 5058 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5059 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5060 | &dev_attr_channels.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5061 | &dev_attr_flags.attr, |
| 5062 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5063 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5064 | &dev_attr_measurement.attr, |
| 5065 | #endif |
| 5066 | &dev_attr_power_level.attr, |
| 5067 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5068 | &dev_attr_rs_window.attr, |
| 5069 | &dev_attr_statistics.attr, |
| 5070 | &dev_attr_status.attr, |
| 5071 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5072 | &dev_attr_tx_power.attr, |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 5073 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 5074 | &dev_attr_debug_level.attr, |
| 5075 | #endif |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 5076 | &dev_attr_version.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5077 | |
| 5078 | NULL |
| 5079 | }; |
| 5080 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5081 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5082 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5083 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5084 | }; |
| 5085 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5086 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 5087 | .tx = iwl4965_mac_tx, |
| 5088 | .start = iwl4965_mac_start, |
| 5089 | .stop = iwl4965_mac_stop, |
| 5090 | .add_interface = iwl4965_mac_add_interface, |
| 5091 | .remove_interface = iwl4965_mac_remove_interface, |
| 5092 | .config = iwl4965_mac_config, |
| 5093 | .config_interface = iwl4965_mac_config_interface, |
| 5094 | .configure_filter = iwl4965_configure_filter, |
| 5095 | .set_key = iwl4965_mac_set_key, |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 5096 | .update_tkip_key = iwl4965_mac_update_tkip_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5097 | .get_stats = iwl4965_mac_get_stats, |
| 5098 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 5099 | .conf_tx = iwl4965_mac_conf_tx, |
| 5100 | .get_tsf = iwl4965_mac_get_tsf, |
| 5101 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 5102 | .beacon_update = iwl4965_mac_beacon_update, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 5103 | .bss_info_changed = iwl4965_bss_info_changed, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5104 | #ifdef CONFIG_IWL4965_HT |
Ron Rindjunsky | 9ab4617 | 2007-12-25 17:00:38 +0200 | [diff] [blame] | 5105 | .ampdu_action = iwl4965_mac_ampdu_action, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 5106 | #endif /* CONFIG_IWL4965_HT */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5107 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5108 | }; |
| 5109 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5110 | 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] | 5111 | { |
| 5112 | int err = 0; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5113 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5114 | struct ieee80211_hw *hw; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 5115 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5116 | unsigned long flags; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5117 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5118 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5119 | /************************ |
| 5120 | * 1. Allocating HW data |
| 5121 | ************************/ |
| 5122 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5123 | /* Disabling hardware scan means that mac80211 will perform scans |
| 5124 | * "the hard way", rather than using device's scan. */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 5125 | if (cfg->mod_params->disable_hw_scan) { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 5126 | if (cfg->mod_params->debug & IWL_DL_INFO) |
| 5127 | dev_printk(KERN_DEBUG, &(pdev->dev), |
| 5128 | "Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5129 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5130 | } |
| 5131 | |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 5132 | hw = iwl_alloc_all(cfg, &iwl4965_hw_ops); |
| 5133 | if (!hw) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5134 | err = -ENOMEM; |
| 5135 | goto out; |
| 5136 | } |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 5137 | priv = hw->priv; |
| 5138 | /* At this point both hw and priv are allocated. */ |
| 5139 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5140 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 5141 | |
| 5142 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 5143 | priv->cfg = cfg; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5144 | priv->pci_dev = pdev; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5145 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 5146 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 5147 | priv->debug_level = priv->cfg->mod_params->debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5148 | atomic_set(&priv->restrict_refcnt, 0); |
| 5149 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5150 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5151 | /************************** |
| 5152 | * 2. Initializing PCI bus |
| 5153 | **************************/ |
| 5154 | if (pci_enable_device(pdev)) { |
| 5155 | err = -ENODEV; |
| 5156 | goto out_ieee80211_free_hw; |
| 5157 | } |
| 5158 | |
| 5159 | pci_set_master(pdev); |
| 5160 | |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5161 | err = pci_set_dma_mask(pdev, DMA_64BIT_MASK); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5162 | if (!err) |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5163 | err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); |
| 5164 | if (err) { |
| 5165 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 5166 | if (!err) |
| 5167 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 5168 | /* both attempts failed: */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5169 | if (err) { |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5170 | printk(KERN_WARNING "%s: No suitable DMA available.\n", |
| 5171 | DRV_NAME); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5172 | goto out_pci_disable_device; |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 5173 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5174 | } |
| 5175 | |
| 5176 | err = pci_request_regions(pdev, DRV_NAME); |
| 5177 | if (err) |
| 5178 | goto out_pci_disable_device; |
| 5179 | |
| 5180 | pci_set_drvdata(pdev, priv); |
| 5181 | |
| 5182 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 5183 | * PCI Tx retries from interfering with C3 CPU state */ |
| 5184 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 5185 | |
| 5186 | /*********************** |
| 5187 | * 3. Read REV register |
| 5188 | ***********************/ |
| 5189 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 5190 | if (!priv->hw_base) { |
| 5191 | err = -ENODEV; |
| 5192 | goto out_pci_release_regions; |
| 5193 | } |
| 5194 | |
| 5195 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 5196 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 5197 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 5198 | |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 5199 | iwl_hw_detect(priv); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5200 | printk(KERN_INFO DRV_NAME |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 5201 | ": Detected Intel Wireless WiFi Link %s REV=0x%X\n", |
| 5202 | priv->cfg->name, priv->hw_rev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5203 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 5204 | /* amp init */ |
| 5205 | err = priv->cfg->ops->lib->apm_ops.init(priv); |
| 5206 | if (err < 0) { |
| 5207 | IWL_DEBUG_INFO("Failed to init APMG\n"); |
| 5208 | goto out_iounmap; |
| 5209 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5210 | /***************** |
| 5211 | * 4. Read EEPROM |
| 5212 | *****************/ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5213 | /* Read the EEPROM */ |
| 5214 | err = iwl_eeprom_init(priv); |
| 5215 | if (err) { |
| 5216 | IWL_ERROR("Unable to init EEPROM\n"); |
| 5217 | goto out_iounmap; |
| 5218 | } |
Tomas Winkler | 8614f36 | 2008-04-23 17:14:55 -0700 | [diff] [blame] | 5219 | err = iwl_eeprom_check_version(priv); |
| 5220 | if (err) |
| 5221 | goto out_iounmap; |
| 5222 | |
Ron Rindjunsky | 0288301 | 2008-05-15 13:53:53 +0800 | [diff] [blame] | 5223 | /* extract MAC Address */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5224 | iwl_eeprom_get_mac(priv, priv->mac_addr); |
| 5225 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); |
| 5226 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 5227 | |
| 5228 | /************************ |
| 5229 | * 5. Setup HW constants |
| 5230 | ************************/ |
| 5231 | /* Device-specific setup */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 5232 | if (priv->cfg->ops->lib->set_hw_params(priv)) { |
| 5233 | IWL_ERROR("failed to set hw parameters\n"); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 5234 | goto out_free_eeprom; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5235 | } |
| 5236 | |
| 5237 | /******************* |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5238 | * 6. Setup priv |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5239 | *******************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5240 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5241 | err = iwl_init_drv(priv); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5242 | if (err) |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 5243 | goto out_free_eeprom; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5244 | /* At this point both hw and priv are initialized. */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5245 | |
| 5246 | /********************************** |
| 5247 | * 7. Initialize module parameters |
| 5248 | **********************************/ |
| 5249 | |
| 5250 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 5251 | if (priv->cfg->mod_params->disable) { |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5252 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 5253 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 5254 | } |
| 5255 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5256 | /******************** |
| 5257 | * 8. Setup services |
| 5258 | ********************/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5259 | spin_lock_irqsave(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5260 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5261 | spin_unlock_irqrestore(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5262 | |
| 5263 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
| 5264 | if (err) { |
| 5265 | IWL_ERROR("failed to create sysfs device attributes\n"); |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5266 | goto out_uninit_drv; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5267 | } |
| 5268 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5269 | |
| 5270 | iwl4965_setup_deferred_work(priv); |
| 5271 | iwl4965_setup_rx_handlers(priv); |
| 5272 | |
| 5273 | /******************** |
| 5274 | * 9. Conclude |
| 5275 | ********************/ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5276 | pci_save_state(pdev); |
| 5277 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5278 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5279 | /********************************** |
| 5280 | * 10. Setup and register mac80211 |
| 5281 | **********************************/ |
| 5282 | |
| 5283 | err = iwl_setup_mac(priv); |
| 5284 | if (err) |
| 5285 | goto out_remove_sysfs; |
| 5286 | |
| 5287 | err = iwl_dbgfs_register(priv, DRV_NAME); |
| 5288 | if (err) |
| 5289 | IWL_ERROR("failed to create debugfs files\n"); |
| 5290 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 5291 | /* notify iwlcore to init */ |
| 5292 | iwlcore_low_level_notify(priv, IWLCORE_INIT_EVT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5293 | return 0; |
| 5294 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5295 | out_remove_sysfs: |
| 5296 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5297 | out_uninit_drv: |
| 5298 | iwl_uninit_drv(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 5299 | out_free_eeprom: |
| 5300 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5301 | out_iounmap: |
| 5302 | pci_iounmap(pdev, priv->hw_base); |
| 5303 | out_pci_release_regions: |
| 5304 | pci_release_regions(pdev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 5305 | pci_set_drvdata(pdev, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5306 | out_pci_disable_device: |
| 5307 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5308 | out_ieee80211_free_hw: |
| 5309 | ieee80211_free_hw(priv->hw); |
| 5310 | out: |
| 5311 | return err; |
| 5312 | } |
| 5313 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 5314 | static void __devexit iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5315 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5316 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5317 | struct list_head *p, *q; |
| 5318 | int i; |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5319 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5320 | |
| 5321 | if (!priv) |
| 5322 | return; |
| 5323 | |
| 5324 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 5325 | |
Emmanuel Grumbach | 6724962 | 2008-05-29 16:35:26 +0800 | [diff] [blame^] | 5326 | iwl_dbgfs_unregister(priv); |
| 5327 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
| 5328 | |
Ron Rindjunsky | c4f5523 | 2008-03-28 16:21:10 -0700 | [diff] [blame] | 5329 | if (priv->mac80211_registered) { |
| 5330 | ieee80211_unregister_hw(priv->hw); |
| 5331 | priv->mac80211_registered = 0; |
| 5332 | } |
| 5333 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5334 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 5335 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5336 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5337 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5338 | /* make sure we flush any pending irq or |
| 5339 | * tasklet for the driver |
| 5340 | */ |
| 5341 | spin_lock_irqsave(&priv->lock, flags); |
| 5342 | iwl4965_disable_interrupts(priv); |
| 5343 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5344 | |
| 5345 | iwl_synchronize_irq(priv); |
| 5346 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5347 | /* Free MAC hash list for ADHOC */ |
| 5348 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) { |
| 5349 | list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) { |
| 5350 | list_del(p); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5351 | kfree(list_entry(p, struct iwl4965_ibss_seq, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5352 | } |
| 5353 | } |
| 5354 | |
Mohamed Abbas | c8381fd | 2008-03-28 16:21:05 -0700 | [diff] [blame] | 5355 | iwlcore_low_level_notify(priv, IWLCORE_REMOVE_EVT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5356 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5357 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5358 | |
| 5359 | if (priv->rxq.bd) |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 5360 | iwl_rx_queue_free(priv, &priv->rxq); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 5361 | iwl_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5362 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 5363 | iwlcore_clear_stations_table(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 5364 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5365 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5366 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 5367 | /*netif_stop_queue(dev); */ |
| 5368 | flush_workqueue(priv->workqueue); |
| 5369 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5370 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5371 | * priv->workqueue... so we can't take down the workqueue |
| 5372 | * until now... */ |
| 5373 | destroy_workqueue(priv->workqueue); |
| 5374 | priv->workqueue = NULL; |
| 5375 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5376 | pci_iounmap(pdev, priv->hw_base); |
| 5377 | pci_release_regions(pdev); |
| 5378 | pci_disable_device(pdev); |
| 5379 | pci_set_drvdata(pdev, NULL); |
| 5380 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 5381 | iwl_uninit_drv(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5382 | |
| 5383 | if (priv->ibss_beacon) |
| 5384 | dev_kfree_skb(priv->ibss_beacon); |
| 5385 | |
| 5386 | ieee80211_free_hw(priv->hw); |
| 5387 | } |
| 5388 | |
| 5389 | #ifdef CONFIG_PM |
| 5390 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5391 | 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] | 5392 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5393 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5394 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5395 | if (priv->is_open) { |
| 5396 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 5397 | iwl4965_mac_stop(priv->hw); |
| 5398 | priv->is_open = 1; |
| 5399 | } |
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_D3hot); |
| 5402 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5403 | return 0; |
| 5404 | } |
| 5405 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5406 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5407 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 5408 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5409 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5410 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5411 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5412 | if (priv->is_open) |
| 5413 | iwl4965_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5414 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5415 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5416 | return 0; |
| 5417 | } |
| 5418 | |
| 5419 | #endif /* CONFIG_PM */ |
| 5420 | |
| 5421 | /***************************************************************************** |
| 5422 | * |
| 5423 | * driver and module entry point |
| 5424 | * |
| 5425 | *****************************************************************************/ |
| 5426 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5427 | /* Hardware specific file defines the PCI IDs table for that hardware module */ |
| 5428 | static struct pci_device_id iwl_hw_card_ids[] = { |
| 5429 | {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)}, |
| 5430 | {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)}, |
Tomas Winkler | 5a6a256 | 2008-04-24 11:55:23 -0700 | [diff] [blame] | 5431 | #ifdef CONFIG_IWL5000 |
| 5432 | {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)}, |
| 5433 | {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)}, |
| 5434 | {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)}, |
| 5435 | #endif /* CONFIG_IWL5000 */ |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5436 | {0} |
| 5437 | }; |
| 5438 | MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); |
| 5439 | |
| 5440 | static struct pci_driver iwl_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5441 | .name = DRV_NAME, |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5442 | .id_table = iwl_hw_card_ids, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5443 | .probe = iwl4965_pci_probe, |
| 5444 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5445 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5446 | .suspend = iwl4965_pci_suspend, |
| 5447 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5448 | #endif |
| 5449 | }; |
| 5450 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5451 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5452 | { |
| 5453 | |
| 5454 | int ret; |
| 5455 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 5456 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5457 | |
| 5458 | ret = iwl4965_rate_control_register(); |
| 5459 | if (ret) { |
| 5460 | IWL_ERROR("Unable to register rate control algorithm: %d\n", ret); |
| 5461 | return ret; |
| 5462 | } |
| 5463 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5464 | ret = pci_register_driver(&iwl_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5465 | if (ret) { |
| 5466 | IWL_ERROR("Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5467 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5468 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5469 | |
| 5470 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5471 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5472 | error_register: |
| 5473 | iwl4965_rate_control_unregister(); |
| 5474 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5475 | } |
| 5476 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5477 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5478 | { |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 5479 | pci_unregister_driver(&iwl_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5480 | iwl4965_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5481 | } |
| 5482 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5483 | module_exit(iwl4965_exit); |
| 5484 | module_init(iwl4965_init); |