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