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 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 90 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 91 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 92 | * the functionality provided here |
| 93 | */ |
| 94 | |
| 95 | /**************************************************************/ |
| 96 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 97 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 98 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 99 | static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) |
| 100 | { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 101 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 102 | |
| 103 | if (hw_decrypt) |
| 104 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; |
| 105 | else |
| 106 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; |
| 107 | |
| 108 | } |
| 109 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 110 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 111 | * iwl4965_check_rxon_cmd - validate RXON structure is valid |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 112 | * |
| 113 | * NOTE: This is really only useful during development and can eventually |
| 114 | * be #ifdef'd out once the driver is stable and folks aren't actively |
| 115 | * making changes |
| 116 | */ |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 117 | static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 118 | { |
| 119 | int error = 0; |
| 120 | int counter = 1; |
| 121 | |
| 122 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { |
| 123 | error |= le32_to_cpu(rxon->flags & |
| 124 | (RXON_FLG_TGJ_NARROW_BAND_MSK | |
| 125 | RXON_FLG_RADAR_DETECT_MSK)); |
| 126 | if (error) |
| 127 | IWL_WARNING("check 24G fields %d | %d\n", |
| 128 | counter++, error); |
| 129 | } else { |
| 130 | error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ? |
| 131 | 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK); |
| 132 | if (error) |
| 133 | IWL_WARNING("check 52 fields %d | %d\n", |
| 134 | counter++, error); |
| 135 | error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK); |
| 136 | if (error) |
| 137 | IWL_WARNING("check 52 CCK %d | %d\n", |
| 138 | counter++, error); |
| 139 | } |
| 140 | error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1; |
| 141 | if (error) |
| 142 | IWL_WARNING("check mac addr %d | %d\n", counter++, error); |
| 143 | |
| 144 | /* make sure basic rates 6Mbps and 1Mbps are supported */ |
| 145 | error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) && |
| 146 | ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0)); |
| 147 | if (error) |
| 148 | IWL_WARNING("check basic rate %d | %d\n", counter++, error); |
| 149 | |
| 150 | error |= (le16_to_cpu(rxon->assoc_id) > 2007); |
| 151 | if (error) |
| 152 | IWL_WARNING("check assoc id %d | %d\n", counter++, error); |
| 153 | |
| 154 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) |
| 155 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)); |
| 156 | if (error) |
| 157 | IWL_WARNING("check CCK and short slot %d | %d\n", |
| 158 | counter++, error); |
| 159 | |
| 160 | error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) |
| 161 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)); |
| 162 | if (error) |
| 163 | IWL_WARNING("check CCK & auto detect %d | %d\n", |
| 164 | counter++, error); |
| 165 | |
| 166 | error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | |
| 167 | RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK); |
| 168 | if (error) |
| 169 | IWL_WARNING("check TGG and auto detect %d | %d\n", |
| 170 | counter++, error); |
| 171 | |
| 172 | if (error) |
| 173 | IWL_WARNING("Tuning to channel %d\n", |
| 174 | le16_to_cpu(rxon->channel)); |
| 175 | |
| 176 | if (error) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 177 | IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 178 | return -1; |
| 179 | } |
| 180 | return 0; |
| 181 | } |
| 182 | |
| 183 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 184 | * 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] | 185 | * @priv: staging_rxon is compared to active_rxon |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 186 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 187 | * If the RXON structure is changing enough to require a new tune, |
| 188 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that |
| 189 | * 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] | 190 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 191 | static int iwl4965_full_rxon_required(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 192 | { |
| 193 | |
| 194 | /* These items are only settable from the full RXON command */ |
Ron Rindjunsky | 5d1e232 | 2008-06-30 17:23:04 +0800 | [diff] [blame] | 195 | if (!(iwl_is_associated(priv)) || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 196 | compare_ether_addr(priv->staging_rxon.bssid_addr, |
| 197 | priv->active_rxon.bssid_addr) || |
| 198 | compare_ether_addr(priv->staging_rxon.node_addr, |
| 199 | priv->active_rxon.node_addr) || |
| 200 | compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, |
| 201 | priv->active_rxon.wlap_bssid_addr) || |
| 202 | (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || |
| 203 | (priv->staging_rxon.channel != priv->active_rxon.channel) || |
| 204 | (priv->staging_rxon.air_propagation != |
| 205 | priv->active_rxon.air_propagation) || |
| 206 | (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != |
| 207 | priv->active_rxon.ofdm_ht_single_stream_basic_rates) || |
| 208 | (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != |
| 209 | priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || |
| 210 | (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) || |
| 211 | (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id)) |
| 212 | return 1; |
| 213 | |
| 214 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can |
| 215 | * be updated with the RXON_ASSOC command -- however only some |
| 216 | * flag transitions are allowed using RXON_ASSOC */ |
| 217 | |
| 218 | /* Check if we are not switching bands */ |
| 219 | if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != |
| 220 | (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) |
| 221 | return 1; |
| 222 | |
| 223 | /* Check if we are switching association toggle */ |
| 224 | if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != |
| 225 | (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) |
| 226 | return 1; |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 231 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 232 | * iwl4965_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 233 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 234 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 235 | * the active_rxon structure is updated with the new data. This |
| 236 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 237 | * a HW tune is required based on the RXON structure changes. |
| 238 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 239 | static int iwl4965_commit_rxon(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 240 | { |
| 241 | /* cast away the const for active_rxon in this function */ |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 242 | struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 243 | DECLARE_MAC_BUF(mac); |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 244 | int ret; |
| 245 | bool new_assoc = |
| 246 | !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 247 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 248 | if (!iwl_is_alive(priv)) |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 249 | return -EBUSY; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 250 | |
| 251 | /* always get timestamp with Rx frame */ |
| 252 | priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; |
| 253 | |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 254 | ret = iwl4965_check_rxon_cmd(&priv->staging_rxon); |
| 255 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 256 | IWL_ERROR("Invalid RXON configuration. Not committing.\n"); |
| 257 | return -EINVAL; |
| 258 | } |
| 259 | |
| 260 | /* 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] | 261 | * iwl4965_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 262 | * and other flags for the current radio configuration. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 263 | if (!iwl4965_full_rxon_required(priv)) { |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 264 | ret = iwl_send_rxon_assoc(priv); |
| 265 | if (ret) { |
| 266 | IWL_ERROR("Error setting RXON_ASSOC (%d)\n", ret); |
| 267 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | /* station table will be cleared */ |
| 275 | priv->assoc_station_added = 0; |
| 276 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 277 | /* If we are currently associated and the new config requires |
| 278 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 279 | * we must clear the associated from the active configuration |
| 280 | * before we apply the new config */ |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 281 | if (iwl_is_associated(priv) && new_assoc) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 282 | IWL_DEBUG_INFO("Toggling associated bit on current RXON\n"); |
| 283 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 284 | |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 285 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 286 | sizeof(struct iwl_rxon_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 287 | &priv->active_rxon); |
| 288 | |
| 289 | /* If the mask clearing failed then we set |
| 290 | * active_rxon back to what it was previously */ |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 291 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 292 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 293 | IWL_ERROR("Error clearing ASSOC_MSK (%d)\n", ret); |
| 294 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 295 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | IWL_DEBUG_INFO("Sending RXON\n" |
| 299 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 300 | "* channel = %d\n" |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 301 | "* bssid = %s\n", |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 302 | (new_assoc ? "" : "out"), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 303 | le16_to_cpu(priv->staging_rxon.channel), |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 304 | print_mac(mac, priv->staging_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 305 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 306 | iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto); |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 307 | |
| 308 | /* Apply the new configuration |
| 309 | * RXON unassoc clears the station table in uCode, send it before |
| 310 | * we add the bcast station. If assoc bit is set, we will send RXON |
| 311 | * after having added the bcast and bssid station. |
| 312 | */ |
| 313 | if (!new_assoc) { |
| 314 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 315 | sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 316 | if (ret) { |
| 317 | IWL_ERROR("Error setting new RXON (%d)\n", ret); |
| 318 | return ret; |
| 319 | } |
| 320 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Emmanuel Grumbach | 37deb2a | 2008-06-30 17:23:08 +0800 | [diff] [blame] | 323 | iwl_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 324 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 325 | if (!priv->error_recovering) |
| 326 | priv->start_calib = 0; |
| 327 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 328 | iwl_init_sensitivity(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 329 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 330 | /* If we issue a new RXON command which required a tune then we must |
| 331 | * send a new TXPOWER command or we won't be able to Tx any frames */ |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 332 | ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true); |
| 333 | if (ret) { |
| 334 | IWL_ERROR("Error sending TX power (%d)\n", ret); |
| 335 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | /* Add the broadcast address so we can send broadcast frames */ |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 339 | if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) == |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 340 | IWL_INVALID_STATION) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 341 | IWL_ERROR("Error adding BROADCAST address for transmit.\n"); |
| 342 | return -EIO; |
| 343 | } |
| 344 | |
| 345 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 346 | * add the IWL_AP_ID to the station rate table */ |
Tomas Winkler | 9185159 | 2008-06-30 17:23:14 +0800 | [diff] [blame] | 347 | if (new_assoc) { |
| 348 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 349 | ret = iwl_rxon_add_station(priv, |
| 350 | priv->active_rxon.bssid_addr, 1); |
| 351 | if (ret == IWL_INVALID_STATION) { |
| 352 | IWL_ERROR("Error adding AP address for TX.\n"); |
| 353 | return -EIO; |
| 354 | } |
| 355 | priv->assoc_station_added = 1; |
| 356 | if (priv->default_wep_key && |
| 357 | iwl_send_static_wepkey_cmd(priv, 0)) |
| 358 | IWL_ERROR("Could not send WEP static key.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 359 | } |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 360 | |
| 361 | /* Apply the new configuration |
| 362 | * RXON assoc doesn't clear the station table in uCode, |
| 363 | */ |
| 364 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON, |
| 365 | sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); |
| 366 | if (ret) { |
| 367 | IWL_ERROR("Error setting new RXON (%d)\n", ret); |
| 368 | return ret; |
| 369 | } |
| 370 | memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 376 | void iwl4965_update_chain_flags(struct iwl_priv *priv) |
| 377 | { |
| 378 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 379 | iwl_set_rxon_chain(priv); |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 380 | iwl4965_commit_rxon(priv); |
| 381 | } |
| 382 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 383 | static int iwl4965_send_bt_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 384 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 385 | struct iwl4965_bt_cmd bt_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 386 | .flags = 3, |
| 387 | .lead_time = 0xAA, |
| 388 | .max_kill = 1, |
| 389 | .kill_ack_mask = 0, |
| 390 | .kill_cts_mask = 0, |
| 391 | }; |
| 392 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 393 | return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 394 | sizeof(struct iwl4965_bt_cmd), &bt_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 395 | } |
| 396 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 397 | static void iwl_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 398 | { |
| 399 | struct list_head *element; |
| 400 | |
| 401 | IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n", |
| 402 | priv->frames_count); |
| 403 | |
| 404 | while (!list_empty(&priv->free_frames)) { |
| 405 | element = priv->free_frames.next; |
| 406 | list_del(element); |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 407 | kfree(list_entry(element, struct iwl_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 408 | priv->frames_count--; |
| 409 | } |
| 410 | |
| 411 | if (priv->frames_count) { |
| 412 | IWL_WARNING("%d frames still in use. Did we lose one?\n", |
| 413 | priv->frames_count); |
| 414 | priv->frames_count = 0; |
| 415 | } |
| 416 | } |
| 417 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 418 | static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 419 | { |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 420 | struct iwl_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 421 | struct list_head *element; |
| 422 | if (list_empty(&priv->free_frames)) { |
| 423 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 424 | if (!frame) { |
| 425 | IWL_ERROR("Could not allocate frame!\n"); |
| 426 | return NULL; |
| 427 | } |
| 428 | |
| 429 | priv->frames_count++; |
| 430 | return frame; |
| 431 | } |
| 432 | |
| 433 | element = priv->free_frames.next; |
| 434 | list_del(element); |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 435 | return list_entry(element, struct iwl_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 438 | 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] | 439 | { |
| 440 | memset(frame, 0, sizeof(*frame)); |
| 441 | list_add(&frame->list, &priv->free_frames); |
| 442 | } |
| 443 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 444 | unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 445 | struct ieee80211_hdr *hdr, |
| 446 | const u8 *dest, int left) |
| 447 | { |
| 448 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 449 | if (!iwl_is_associated(priv) || !priv->ibss_beacon || |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 450 | ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) && |
| 451 | (priv->iw_mode != IEEE80211_IF_TYPE_AP))) |
| 452 | return 0; |
| 453 | |
| 454 | if (priv->ibss_beacon->len > left) |
| 455 | return 0; |
| 456 | |
| 457 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 458 | |
| 459 | return priv->ibss_beacon->len; |
| 460 | } |
| 461 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 462 | static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 463 | { |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 464 | int i; |
| 465 | int rate_mask; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 466 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 467 | /* Set rate mask*/ |
| 468 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 469 | rate_mask = priv->active_rate_basic & 0xF; |
| 470 | else |
| 471 | rate_mask = priv->active_rate_basic & 0xFF0; |
| 472 | |
| 473 | /* Find lowest valid rate */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 474 | for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID; |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 475 | i = iwl_rates[i].next_ieee) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 476 | if (rate_mask & (1 << i)) |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 477 | return iwl_rates[i].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 480 | /* No valid rate was found. Assign the lowest one */ |
| 481 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 482 | return IWL_RATE_1M_PLCP; |
| 483 | else |
| 484 | return IWL_RATE_6M_PLCP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 487 | static int iwl4965_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 488 | { |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 489 | struct iwl_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 490 | unsigned int frame_size; |
| 491 | int rc; |
| 492 | u8 rate; |
| 493 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 494 | frame = iwl_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 495 | |
| 496 | if (!frame) { |
| 497 | IWL_ERROR("Could not obtain free frame buffer for beacon " |
| 498 | "command.\n"); |
| 499 | return -ENOMEM; |
| 500 | } |
| 501 | |
Guy Cohen | 39e8850 | 2008-04-23 17:14:57 -0700 | [diff] [blame] | 502 | rate = iwl4965_rate_get_lowest_plcp(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 503 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 504 | frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 505 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 506 | rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 507 | &frame->u.cmd[0]); |
| 508 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 509 | iwl_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 510 | |
| 511 | return rc; |
| 512 | } |
| 513 | |
| 514 | /****************************************************************************** |
| 515 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 516 | * Misc. internal state and helper functions |
| 517 | * |
| 518 | ******************************************************************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 519 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 520 | static void iwl4965_ht_conf(struct iwl_priv *priv, |
| 521 | struct ieee80211_bss_conf *bss_conf) |
| 522 | { |
| 523 | struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf; |
| 524 | struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf; |
| 525 | struct iwl_ht_info *iwl_conf = &priv->current_ht_config; |
| 526 | |
| 527 | IWL_DEBUG_MAC80211("enter: \n"); |
| 528 | |
| 529 | iwl_conf->is_ht = bss_conf->assoc_ht; |
| 530 | |
| 531 | if (!iwl_conf->is_ht) |
| 532 | return; |
| 533 | |
| 534 | priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 535 | |
| 536 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20) |
Emmanuel Grumbach | a984101 | 2008-05-15 13:54:08 +0800 | [diff] [blame] | 537 | iwl_conf->sgf |= HT_SHORT_GI_20MHZ; |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 538 | if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40) |
Emmanuel Grumbach | a984101 | 2008-05-15 13:54:08 +0800 | [diff] [blame] | 539 | iwl_conf->sgf |= HT_SHORT_GI_40MHZ; |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 540 | |
| 541 | iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD); |
| 542 | iwl_conf->max_amsdu_size = |
| 543 | !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU); |
| 544 | |
| 545 | iwl_conf->supported_chan_width = |
| 546 | !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH); |
| 547 | iwl_conf->extension_chan_offset = |
| 548 | ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET; |
| 549 | /* If no above or below channel supplied disable FAT channel */ |
Emmanuel Grumbach | 963f551 | 2008-06-12 09:47:00 +0800 | [diff] [blame] | 550 | if (iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_ABOVE && |
| 551 | iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_BELOW) { |
| 552 | iwl_conf->extension_chan_offset = IEEE80211_HT_IE_CHA_SEC_NONE; |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 553 | iwl_conf->supported_chan_width = 0; |
Emmanuel Grumbach | 963f551 | 2008-06-12 09:47:00 +0800 | [diff] [blame] | 554 | } |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 555 | |
| 556 | iwl_conf->tx_mimo_ps_mode = |
| 557 | (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2); |
| 558 | memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16); |
| 559 | |
| 560 | iwl_conf->control_channel = ht_bss_conf->primary_channel; |
| 561 | iwl_conf->tx_chan_width = |
| 562 | !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH); |
| 563 | iwl_conf->ht_protection = |
| 564 | ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION; |
| 565 | iwl_conf->non_GF_STA_present = |
| 566 | !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT); |
| 567 | |
| 568 | IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel); |
| 569 | IWL_DEBUG_MAC80211("leave\n"); |
| 570 | } |
| 571 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 572 | /* |
| 573 | * QoS support |
| 574 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 575 | static int iwl4965_send_qos_params_command(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 576 | struct iwl4965_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 577 | { |
| 578 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 579 | return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 580 | sizeof(struct iwl4965_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 583 | static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 584 | { |
| 585 | unsigned long flags; |
| 586 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 587 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 588 | return; |
| 589 | |
| 590 | if (!priv->qos_data.qos_enable) |
| 591 | return; |
| 592 | |
| 593 | spin_lock_irqsave(&priv->lock, flags); |
| 594 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 595 | |
| 596 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 597 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 598 | priv->qos_data.def_qos_parm.qos_flags |= |
| 599 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 600 | if (priv->qos_data.qos_active) |
| 601 | priv->qos_data.def_qos_parm.qos_flags |= |
| 602 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 603 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 604 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 605 | 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] | 606 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 607 | spin_unlock_irqrestore(&priv->lock, flags); |
| 608 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 609 | if (force || iwl_is_associated(priv)) { |
Tomas Winkler | f1f1f5c | 2007-10-25 17:15:26 +0800 | [diff] [blame] | 610 | IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
| 611 | priv->qos_data.qos_active, |
| 612 | priv->qos_data.def_qos_parm.qos_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 613 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 614 | iwl4965_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 615 | &(priv->qos_data.def_qos_parm)); |
| 616 | } |
| 617 | } |
| 618 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 619 | #define MAX_UCODE_BEACON_INTERVAL 4096 |
| 620 | #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA) |
| 621 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 622 | static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 623 | { |
| 624 | u16 new_val = 0; |
| 625 | u16 beacon_factor = 0; |
| 626 | |
| 627 | beacon_factor = |
| 628 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 629 | / MAX_UCODE_BEACON_INTERVAL; |
| 630 | new_val = beacon_val / beacon_factor; |
| 631 | |
| 632 | return cpu_to_le16(new_val); |
| 633 | } |
| 634 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 635 | static void iwl4965_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 636 | { |
| 637 | u64 interval_tm_unit; |
| 638 | u64 tsf, result; |
| 639 | unsigned long flags; |
| 640 | struct ieee80211_conf *conf = NULL; |
| 641 | u16 beacon_int = 0; |
| 642 | |
| 643 | conf = ieee80211_get_hw_conf(priv->hw); |
| 644 | |
| 645 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 646 | priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32); |
| 647 | priv->rxon_timing.timestamp.dw[0] = |
| 648 | cpu_to_le32(priv->timestamp & 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 649 | |
| 650 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 651 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 652 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 653 | |
| 654 | beacon_int = priv->beacon_int; |
| 655 | spin_unlock_irqrestore(&priv->lock, flags); |
| 656 | |
| 657 | if (priv->iw_mode == IEEE80211_IF_TYPE_STA) { |
| 658 | if (beacon_int == 0) { |
| 659 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 660 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 661 | } else { |
| 662 | priv->rxon_timing.beacon_interval = |
| 663 | cpu_to_le16(beacon_int); |
| 664 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 665 | iwl4965_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 666 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 667 | } |
| 668 | |
| 669 | priv->rxon_timing.atim_window = 0; |
| 670 | } else { |
| 671 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 672 | iwl4965_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 673 | /* TODO: we need to get atim_window from upper stack |
| 674 | * for now we set to 0 */ |
| 675 | priv->rxon_timing.atim_window = 0; |
| 676 | } |
| 677 | |
| 678 | interval_tm_unit = |
| 679 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 680 | result = do_div(tsf, interval_tm_unit); |
| 681 | priv->rxon_timing.beacon_init_val = |
| 682 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 683 | |
| 684 | IWL_DEBUG_ASSOC |
| 685 | ("beacon interval %d beacon timer %d beacon tim %d\n", |
| 686 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 687 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 688 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 689 | } |
| 690 | |
Tomas Winkler | 82a66bb | 2008-05-29 16:35:28 +0800 | [diff] [blame] | 691 | static void iwl_set_flags_for_band(struct iwl_priv *priv, |
| 692 | enum ieee80211_band band) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 693 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 694 | if (band == IEEE80211_BAND_5GHZ) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 695 | priv->staging_rxon.flags &= |
| 696 | ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK |
| 697 | | RXON_FLG_CCK_MSK); |
| 698 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 699 | } else { |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 700 | /* Copied from iwl4965_post_associate() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 701 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 702 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 703 | else |
| 704 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 705 | |
| 706 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 707 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 708 | |
| 709 | priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; |
| 710 | priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; |
| 711 | priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | /* |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 716 | * initialize rxon structure with default values from eeprom |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 717 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 718 | static void iwl4965_connection_init_rx_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 719 | { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 720 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 721 | |
| 722 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
| 723 | |
| 724 | switch (priv->iw_mode) { |
| 725 | case IEEE80211_IF_TYPE_AP: |
| 726 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; |
| 727 | break; |
| 728 | |
| 729 | case IEEE80211_IF_TYPE_STA: |
| 730 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; |
| 731 | priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; |
| 732 | break; |
| 733 | |
| 734 | case IEEE80211_IF_TYPE_IBSS: |
| 735 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; |
| 736 | priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; |
| 737 | priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | |
| 738 | RXON_FILTER_ACCEPT_GRP_MSK; |
| 739 | break; |
| 740 | |
| 741 | case IEEE80211_IF_TYPE_MNTR: |
| 742 | priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER; |
| 743 | priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK | |
| 744 | RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; |
| 745 | break; |
Tomas Winkler | 69dc5d9 | 2008-03-25 16:33:41 -0700 | [diff] [blame] | 746 | default: |
| 747 | IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode); |
| 748 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | #if 0 |
| 752 | /* TODO: Figure out when short_preamble would be set and cache from |
| 753 | * that */ |
| 754 | if (!hw_to_local(priv->hw)->short_preamble) |
| 755 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 756 | else |
| 757 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 758 | #endif |
| 759 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 760 | ch_info = iwl_get_channel_info(priv, priv->band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 761 | le16_to_cpu(priv->staging_rxon.channel)); |
| 762 | |
| 763 | if (!ch_info) |
| 764 | ch_info = &priv->channel_info[0]; |
| 765 | |
| 766 | /* |
| 767 | * in some case A channels are all non IBSS |
| 768 | * in this case force B/G channel |
| 769 | */ |
| 770 | if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) && |
| 771 | !(is_channel_ibss(ch_info))) |
| 772 | ch_info = &priv->channel_info[0]; |
| 773 | |
| 774 | priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 775 | priv->band = ch_info->band; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 776 | |
Tomas Winkler | 82a66bb | 2008-05-29 16:35:28 +0800 | [diff] [blame] | 777 | iwl_set_flags_for_band(priv, priv->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 778 | |
| 779 | priv->staging_rxon.ofdm_basic_rates = |
| 780 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 781 | priv->staging_rxon.cck_basic_rates = |
| 782 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 783 | |
| 784 | priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 785 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 786 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 787 | memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN); |
| 788 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff; |
| 789 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff; |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 790 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 793 | static int iwl4965_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 794 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 795 | priv->iw_mode = mode; |
| 796 | |
Assaf Krauss | 398f9e7 | 2008-06-12 09:47:06 +0800 | [diff] [blame] | 797 | /* init channel/phymode to values given at driver init */ |
| 798 | iwl_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6); |
| 799 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 800 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 801 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 802 | |
Emmanuel Grumbach | 37deb2a | 2008-06-30 17:23:08 +0800 | [diff] [blame] | 803 | iwl_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 804 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 805 | /* dont commit rxon if rf-kill is on*/ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 806 | if (!iwl_is_ready_rf(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 807 | return -EAGAIN; |
| 808 | |
| 809 | cancel_delayed_work(&priv->scan_check); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 810 | if (iwl_scan_cancel_timeout(priv, 100)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 811 | IWL_WARNING("Aborted scan still in progress after 100ms\n"); |
| 812 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 813 | return -EAGAIN; |
| 814 | } |
| 815 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 816 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 817 | |
| 818 | return 0; |
| 819 | } |
| 820 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 821 | static void iwl4965_set_rate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 822 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 823 | const struct ieee80211_supported_band *hw = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 824 | struct ieee80211_rate *rate; |
| 825 | int i; |
| 826 | |
Emmanuel Grumbach | d1141df | 2008-04-21 15:42:00 -0700 | [diff] [blame] | 827 | hw = iwl_get_hw_mode(priv, priv->band); |
Saleem Abdulrasool | c4ba962 | 2007-11-18 23:59:08 -0800 | [diff] [blame] | 828 | if (!hw) { |
| 829 | IWL_ERROR("Failed to set rate: unable to get hw mode\n"); |
| 830 | return; |
| 831 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 832 | |
| 833 | priv->active_rate = 0; |
| 834 | priv->active_rate_basic = 0; |
| 835 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 836 | for (i = 0; i < hw->n_bitrates; i++) { |
| 837 | rate = &(hw->bitrates[i]); |
| 838 | if (rate->hw_value < IWL_RATE_COUNT) |
| 839 | priv->active_rate |= (1 << rate->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n", |
| 843 | priv->active_rate, priv->active_rate_basic); |
| 844 | |
| 845 | /* |
| 846 | * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK) |
| 847 | * otherwise set it to the default of all CCK rates and 6, 12, 24 for |
| 848 | * OFDM |
| 849 | */ |
| 850 | if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK) |
| 851 | priv->staging_rxon.cck_basic_rates = |
| 852 | ((priv->active_rate_basic & |
| 853 | IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF; |
| 854 | else |
| 855 | priv->staging_rxon.cck_basic_rates = |
| 856 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; |
| 857 | |
| 858 | if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK) |
| 859 | priv->staging_rxon.ofdm_basic_rates = |
| 860 | ((priv->active_rate_basic & |
| 861 | (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >> |
| 862 | IWL_FIRST_OFDM_RATE) & 0xFF; |
| 863 | else |
| 864 | priv->staging_rxon.ofdm_basic_rates = |
| 865 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; |
| 866 | } |
| 867 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 868 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 869 | |
| 870 | #include "iwl-spectrum.h" |
| 871 | |
| 872 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 873 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 874 | #define TIME_UNIT 1024 |
| 875 | |
| 876 | /* |
| 877 | * extended beacon time format |
| 878 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 879 | * the high 1 byte is the beacon counts |
| 880 | * the lower 3 bytes is the time in usec within one beacon interval |
| 881 | */ |
| 882 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 883 | static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 884 | { |
| 885 | u32 quot; |
| 886 | u32 rem; |
| 887 | u32 interval = beacon_interval * 1024; |
| 888 | |
| 889 | if (!interval || !usec) |
| 890 | return 0; |
| 891 | |
| 892 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 893 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 894 | |
| 895 | return (quot << 24) + rem; |
| 896 | } |
| 897 | |
| 898 | /* base is usually what we get from ucode with each received frame, |
| 899 | * the same as HW timer counter counting down |
| 900 | */ |
| 901 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 902 | 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] | 903 | { |
| 904 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 905 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 906 | u32 interval = beacon_interval * TIME_UNIT; |
| 907 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 908 | (addon & BEACON_TIME_MASK_HIGH); |
| 909 | |
| 910 | if (base_low > addon_low) |
| 911 | res += base_low - addon_low; |
| 912 | else if (base_low < addon_low) { |
| 913 | res += interval + base_low - addon_low; |
| 914 | res += (1 << 24); |
| 915 | } else |
| 916 | res += (1 << 24); |
| 917 | |
| 918 | return cpu_to_le32(res); |
| 919 | } |
| 920 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 921 | static int iwl4965_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 922 | struct ieee80211_measurement_params *params, |
| 923 | u8 type) |
| 924 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 925 | struct iwl4965_spectrum_cmd spectrum; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 926 | struct iwl_rx_packet *res; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 927 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 928 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 929 | .data = (void *)&spectrum, |
| 930 | .meta.flags = CMD_WANT_SKB, |
| 931 | }; |
| 932 | u32 add_time = le64_to_cpu(params->start_time); |
| 933 | int rc; |
| 934 | int spectrum_resp_status; |
| 935 | int duration = le16_to_cpu(params->duration); |
| 936 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 937 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 938 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 939 | iwl4965_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 940 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 941 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 942 | |
| 943 | memset(&spectrum, 0, sizeof(spectrum)); |
| 944 | |
| 945 | spectrum.channel_count = cpu_to_le16(1); |
| 946 | spectrum.flags = |
| 947 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 948 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 949 | cmd.len = sizeof(spectrum); |
| 950 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 951 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 952 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 953 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 954 | iwl4965_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 955 | add_time, |
| 956 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 957 | else |
| 958 | spectrum.start_time = 0; |
| 959 | |
| 960 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 961 | spectrum.channels[0].channel = params->channel; |
| 962 | spectrum.channels[0].type = type; |
| 963 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
| 964 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 965 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 966 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 967 | rc = iwl_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 968 | if (rc) |
| 969 | return rc; |
| 970 | |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 971 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 972 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 973 | IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n"); |
| 974 | rc = -EIO; |
| 975 | } |
| 976 | |
| 977 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 978 | switch (spectrum_resp_status) { |
| 979 | case 0: /* Command will be handled */ |
| 980 | if (res->u.spectrum.id != 0xff) { |
| 981 | IWL_DEBUG_INFO |
| 982 | ("Replaced existing measurement: %d\n", |
| 983 | res->u.spectrum.id); |
| 984 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 985 | } |
| 986 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 987 | rc = 0; |
| 988 | break; |
| 989 | |
| 990 | case 1: /* Command will not be handled */ |
| 991 | rc = -EAGAIN; |
| 992 | break; |
| 993 | } |
| 994 | |
| 995 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 996 | |
| 997 | return rc; |
| 998 | } |
| 999 | #endif |
| 1000 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1001 | /****************************************************************************** |
| 1002 | * |
| 1003 | * Generic RX handler implementations |
| 1004 | * |
| 1005 | ******************************************************************************/ |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1006 | static void iwl_rx_reply_alive(struct iwl_priv *priv, |
| 1007 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1008 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1009 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1010 | struct iwl_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1011 | struct delayed_work *pwork; |
| 1012 | |
| 1013 | palive = &pkt->u.alive_frame; |
| 1014 | |
| 1015 | IWL_DEBUG_INFO("Alive ucode status 0x%08X revision " |
| 1016 | "0x%01X 0x%01X\n", |
| 1017 | palive->is_valid, palive->ver_type, |
| 1018 | palive->ver_subtype); |
| 1019 | |
| 1020 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
| 1021 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 1022 | memcpy(&priv->card_alive_init, |
| 1023 | &pkt->u.alive_frame, |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1024 | sizeof(struct iwl_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1025 | pwork = &priv->init_alive_start; |
| 1026 | } else { |
| 1027 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 1028 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1029 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1030 | pwork = &priv->alive_start; |
| 1031 | } |
| 1032 | |
| 1033 | /* We delay the ALIVE response by 5ms to |
| 1034 | * give the HW RF Kill time to activate... */ |
| 1035 | if (palive->is_valid == UCODE_VALID_OK) |
| 1036 | queue_delayed_work(priv->workqueue, pwork, |
| 1037 | msecs_to_jiffies(5)); |
| 1038 | else |
| 1039 | IWL_WARNING("uCode did not respond OK.\n"); |
| 1040 | } |
| 1041 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1042 | static void iwl4965_rx_reply_error(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1043 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1044 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1045 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1046 | |
| 1047 | IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " |
| 1048 | "seq 0x%04X ser 0x%08X\n", |
| 1049 | le32_to_cpu(pkt->u.err_resp.error_type), |
| 1050 | get_cmd_string(pkt->u.err_resp.cmd_id), |
| 1051 | pkt->u.err_resp.cmd_id, |
| 1052 | le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num), |
| 1053 | le32_to_cpu(pkt->u.err_resp.error_info)); |
| 1054 | } |
| 1055 | |
| 1056 | #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x |
| 1057 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1058 | 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] | 1059 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1060 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 1061 | struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1062 | struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1063 | IWL_DEBUG_11H("CSA notif: channel %d, status %d\n", |
| 1064 | le16_to_cpu(csa->channel), le32_to_cpu(csa->status)); |
| 1065 | rxon->channel = csa->channel; |
| 1066 | priv->staging_rxon.channel = csa->channel; |
| 1067 | } |
| 1068 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1069 | static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1070 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1071 | { |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1072 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1073 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1074 | struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1075 | |
| 1076 | if (!report->state) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1077 | IWL_DEBUG(IWL_DL_11H, |
| 1078 | "Spectrum Measure Notification: Start\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1079 | return; |
| 1080 | } |
| 1081 | |
| 1082 | memcpy(&priv->measure_report, report, sizeof(*report)); |
| 1083 | priv->measurement_status |= MEASUREMENT_READY; |
| 1084 | #endif |
| 1085 | } |
| 1086 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1087 | static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1088 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1089 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1090 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1091 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1092 | struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1093 | IWL_DEBUG_RX("sleep mode: %d, src: %d\n", |
| 1094 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); |
| 1095 | #endif |
| 1096 | } |
| 1097 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1098 | static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1099 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1100 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1101 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1102 | IWL_DEBUG_RADIO("Dumping %d bytes of unhandled " |
| 1103 | "notification for %s:\n", |
| 1104 | le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd)); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1105 | 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] | 1106 | } |
| 1107 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1108 | static void iwl4965_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1109 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1110 | struct iwl_priv *priv = |
| 1111 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1112 | struct sk_buff *beacon; |
| 1113 | |
| 1114 | /* 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] | 1115 | beacon = ieee80211_beacon_get(priv->hw, priv->vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1116 | |
| 1117 | if (!beacon) { |
| 1118 | IWL_ERROR("update beacon failed\n"); |
| 1119 | return; |
| 1120 | } |
| 1121 | |
| 1122 | mutex_lock(&priv->mutex); |
| 1123 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 1124 | if (priv->ibss_beacon) |
| 1125 | dev_kfree_skb(priv->ibss_beacon); |
| 1126 | |
| 1127 | priv->ibss_beacon = beacon; |
| 1128 | mutex_unlock(&priv->mutex); |
| 1129 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1130 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 1133 | /** |
| 1134 | * iwl4965_bg_statistics_periodic - Timer callback to queue statistics |
| 1135 | * |
| 1136 | * This callback is provided in order to send a statistics request. |
| 1137 | * |
| 1138 | * This timer function is continually reset to execute within |
| 1139 | * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION |
| 1140 | * was received. We need to ensure we receive the statistics in order |
| 1141 | * to update the temperature used for calibrating the TXPOWER. |
| 1142 | */ |
| 1143 | static void iwl4965_bg_statistics_periodic(unsigned long data) |
| 1144 | { |
| 1145 | struct iwl_priv *priv = (struct iwl_priv *)data; |
| 1146 | |
| 1147 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 1148 | return; |
| 1149 | |
| 1150 | iwl_send_statistics_request(priv, CMD_ASYNC); |
| 1151 | } |
| 1152 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1153 | static void iwl4965_rx_beacon_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1154 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1155 | { |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1156 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1157 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1158 | struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status); |
Tomas Winkler | e7d326a | 2008-06-12 09:47:11 +0800 | [diff] [blame] | 1159 | u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1160 | |
| 1161 | IWL_DEBUG_RX("beacon status %x retries %d iss %d " |
| 1162 | "tsf %d %d rate %d\n", |
Tomas Winkler | 25a6572 | 2008-06-12 09:47:07 +0800 | [diff] [blame] | 1163 | le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1164 | beacon->beacon_notify_hdr.failure_frame, |
| 1165 | le32_to_cpu(beacon->ibss_mgr_status), |
| 1166 | le32_to_cpu(beacon->high_tsf), |
| 1167 | le32_to_cpu(beacon->low_tsf), rate); |
| 1168 | #endif |
| 1169 | |
| 1170 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 1171 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 1172 | queue_work(priv->workqueue, &priv->beacon_update); |
| 1173 | } |
| 1174 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1175 | /* Handle notification from uCode that card's power state is changing |
| 1176 | * due to software, hardware, or critical temperature RFKILL */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1177 | static void iwl4965_rx_card_state_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1178 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1179 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1180 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1181 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 1182 | unsigned long status = priv->status; |
| 1183 | |
| 1184 | IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n", |
| 1185 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 1186 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 1187 | |
| 1188 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
| 1189 | RF_CARD_DISABLED)) { |
| 1190 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1191 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1192 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 1193 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1194 | if (!iwl_grab_nic_access(priv)) { |
| 1195 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1196 | priv, HBUS_TARG_MBX_C, |
| 1197 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 1198 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1199 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | if (!(flags & RXON_CARD_DISABLED)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1203 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1204 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1205 | if (!iwl_grab_nic_access(priv)) { |
| 1206 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1207 | priv, HBUS_TARG_MBX_C, |
| 1208 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
| 1209 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1210 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | if (flags & RF_CARD_DISABLED) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1215 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1216 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1217 | iwl_read32(priv, CSR_UCODE_DRV_GP1); |
| 1218 | if (!iwl_grab_nic_access(priv)) |
| 1219 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | if (flags & HW_CARD_DISABLED) |
| 1224 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 1225 | else |
| 1226 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 1227 | |
| 1228 | |
| 1229 | if (flags & SW_CARD_DISABLED) |
| 1230 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 1231 | else |
| 1232 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 1233 | |
| 1234 | if (!(flags & RXON_CARD_DISABLED)) |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1235 | iwl_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1236 | |
| 1237 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 1238 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 1239 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 1240 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 1241 | queue_work(priv->workqueue, &priv->rf_kill); |
| 1242 | else |
| 1243 | wake_up_interruptible(&priv->wait_command_queue); |
| 1244 | } |
| 1245 | |
| 1246 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1247 | * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1248 | * |
| 1249 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 1250 | * to the host. |
| 1251 | * |
| 1252 | * This function chains into the hardware specific files for them to setup |
| 1253 | * any hardware specific handlers as well. |
| 1254 | */ |
Emmanuel Grumbach | 653fa4a | 2008-06-30 17:23:11 +0800 | [diff] [blame] | 1255 | static void iwl_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1256 | { |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 1257 | priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1258 | priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error; |
| 1259 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1260 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1261 | iwl4965_rx_spectrum_measure_notif; |
| 1262 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1263 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1264 | iwl4965_rx_pm_debug_statistics_notif; |
| 1265 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1266 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1267 | /* |
| 1268 | * The same handler is used for both the REPLY to a discrete |
| 1269 | * statistics request from the host as well as for the periodic |
| 1270 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1271 | */ |
Emmanuel Grumbach | 8f91aec | 2008-06-30 17:23:07 +0800 | [diff] [blame] | 1272 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics; |
| 1273 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics; |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1274 | |
| 1275 | iwl_setup_rx_scan_handlers(priv); |
| 1276 | |
Ron Rindjunsky | 37a4421 | 2008-05-29 16:35:18 +0800 | [diff] [blame] | 1277 | /* status change handler */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1278 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1279 | |
Tomas Winkler | c135475 | 2008-05-29 16:35:04 +0800 | [diff] [blame] | 1280 | priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] = |
| 1281 | iwl_rx_missed_beacon_notif; |
Ron Rindjunsky | 37a4421 | 2008-05-29 16:35:18 +0800 | [diff] [blame] | 1282 | /* Rx handlers */ |
Emmanuel Grumbach | 1781a07 | 2008-06-30 17:23:09 +0800 | [diff] [blame] | 1283 | priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy; |
| 1284 | priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx; |
Emmanuel Grumbach | 653fa4a | 2008-06-30 17:23:11 +0800 | [diff] [blame] | 1285 | /* block ack */ |
| 1286 | priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1287 | /* Set up hardware specific Rx handlers */ |
Emmanuel Grumbach | d4789ef | 2008-04-24 11:55:20 -0700 | [diff] [blame] | 1288 | priv->cfg->ops->lib->rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1289 | } |
| 1290 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1291 | /* |
| 1292 | * this should be called while priv->lock is locked |
| 1293 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1294 | static void __iwl_rx_replenish(struct iwl_priv *priv) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1295 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1296 | iwl_rx_allocate(priv); |
| 1297 | iwl_rx_queue_restock(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1301 | /** |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1302 | * iwl_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1303 | * |
| 1304 | * Uses the priv->rx_handlers callback function array to invoke |
| 1305 | * the appropriate handlers, including command responses, |
| 1306 | * frame-received notifications, and other notifications. |
| 1307 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1308 | void iwl_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1309 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1310 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1311 | struct iwl_rx_packet *pkt; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1312 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1313 | u32 r, i; |
| 1314 | int reclaim; |
| 1315 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1316 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 1317 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1318 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1319 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 1320 | * buffer that the driver may process (last buffer filled by ucode). */ |
Ron Rindjunsky | d67f548 | 2008-05-05 10:22:49 +0800 | [diff] [blame] | 1321 | r = priv->cfg->ops->lib->shared_mem_rx_idx(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1322 | i = rxq->read; |
| 1323 | |
| 1324 | /* Rx interrupt, but nothing sent from uCode */ |
| 1325 | if (i == r) |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1326 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1327 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1328 | if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1329 | fill_rx = 1; |
| 1330 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1331 | while (i != r) { |
| 1332 | rxb = rxq->queue[i]; |
| 1333 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1334 | /* 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] | 1335 | * then a bug has been introduced in the queue refilling |
| 1336 | * routines -- catch it here */ |
| 1337 | BUG_ON(rxb == NULL); |
| 1338 | |
| 1339 | rxq->queue[i] = NULL; |
| 1340 | |
| 1341 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1342 | priv->hw_params.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1343 | PCI_DMA_FROMDEVICE); |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1344 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1345 | |
| 1346 | /* Reclaim a command buffer only if this packet is a response |
| 1347 | * to a (driver-originated) command. |
| 1348 | * If the packet (e.g. Rx frame) originated from uCode, |
| 1349 | * there is no command buffer to reclaim. |
| 1350 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 1351 | * but apparently a few don't get set; catch them here. */ |
| 1352 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 1353 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1354 | (pkt->hdr.cmd != REPLY_RX) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 1355 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1356 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 1357 | (pkt->hdr.cmd != REPLY_TX); |
| 1358 | |
| 1359 | /* Based on type of command response or notification, |
| 1360 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1361 | * rx_handlers table. See iwl4965_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1362 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1363 | IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r, |
| 1364 | i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1365 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 1366 | } else { |
| 1367 | /* No handling needed */ |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1368 | IWL_DEBUG(IWL_DL_RX, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1369 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 1370 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 1371 | pkt->hdr.cmd); |
| 1372 | } |
| 1373 | |
| 1374 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1375 | /* Invoke any callbacks, transfer the skb to caller, and |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1376 | * fire off the (possibly) blocking iwl_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1377 | * as we reclaim the driver command queue */ |
| 1378 | if (rxb && rxb->skb) |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 1379 | iwl_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1380 | else |
| 1381 | IWL_WARNING("Claim null rxb?\n"); |
| 1382 | } |
| 1383 | |
| 1384 | /* For now we just don't re-use anything. We can tweak this |
| 1385 | * later to try and re-use notification packets and SKBs that |
| 1386 | * fail to Rx correctly */ |
| 1387 | if (rxb->skb != NULL) { |
| 1388 | priv->alloc_rxb_skb--; |
| 1389 | dev_kfree_skb_any(rxb->skb); |
| 1390 | rxb->skb = NULL; |
| 1391 | } |
| 1392 | |
| 1393 | pci_unmap_single(priv->pci_dev, rxb->dma_addr, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1394 | priv->hw_params.rx_buf_size, |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 1395 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1396 | spin_lock_irqsave(&rxq->lock, flags); |
| 1397 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 1398 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 1399 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1400 | /* If there are a lot of unused frames, |
| 1401 | * restock the Rx queue so ucode wont assert. */ |
| 1402 | if (fill_rx) { |
| 1403 | count++; |
| 1404 | if (count >= 8) { |
| 1405 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1406 | __iwl_rx_replenish(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1407 | count = 0; |
| 1408 | } |
| 1409 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1410 | } |
| 1411 | |
| 1412 | /* Backtrack one entry */ |
| 1413 | priv->rxq.read = i; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1414 | iwl_rx_queue_restock(priv); |
| 1415 | } |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1416 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1417 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1418 | static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1419 | { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 1420 | struct iwl_rxon_cmd *rxon = &priv->staging_rxon; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 1421 | DECLARE_MAC_BUF(mac); |
| 1422 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1423 | IWL_DEBUG_RADIO("RX CONFIG:\n"); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1424 | iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1425 | IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel)); |
| 1426 | IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags)); |
| 1427 | IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n", |
| 1428 | le32_to_cpu(rxon->filter_flags)); |
| 1429 | IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type); |
| 1430 | IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n", |
| 1431 | rxon->ofdm_basic_rates); |
| 1432 | 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] | 1433 | IWL_DEBUG_RADIO("u8[6] node_addr: %s\n", |
| 1434 | print_mac(mac, rxon->node_addr)); |
| 1435 | IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n", |
| 1436 | print_mac(mac, rxon->bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1437 | IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id)); |
| 1438 | } |
| 1439 | #endif |
| 1440 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1441 | static void iwl4965_enable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1442 | { |
| 1443 | IWL_DEBUG_ISR("Enabling interrupts\n"); |
| 1444 | set_bit(STATUS_INT_ENABLED, &priv->status); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1445 | iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1446 | } |
| 1447 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 1448 | /* call this function to flush any scheduled tasklet */ |
| 1449 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
| 1450 | { |
| 1451 | /* wait to make sure we flush pedding tasklet*/ |
| 1452 | synchronize_irq(priv->pci_dev->irq); |
| 1453 | tasklet_kill(&priv->irq_tasklet); |
| 1454 | } |
| 1455 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1456 | static inline void iwl4965_disable_interrupts(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1457 | { |
| 1458 | clear_bit(STATUS_INT_ENABLED, &priv->status); |
| 1459 | |
| 1460 | /* disable interrupts from uCode/NIC to host */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1461 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1462 | |
| 1463 | /* acknowledge/clear/reset any interrupts still pending |
| 1464 | * from uCode or flow handler (Rx/Tx DMA) */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1465 | iwl_write32(priv, CSR_INT, 0xffffffff); |
| 1466 | iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1467 | IWL_DEBUG_ISR("Disabled interrupts\n"); |
| 1468 | } |
| 1469 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1470 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1471 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1472 | * 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] | 1473 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1474 | static void iwl4965_irq_handle_error(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1475 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1476 | /* Set the FW error flag -- cleared on iwl4965_down */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1477 | set_bit(STATUS_FW_ERROR, &priv->status); |
| 1478 | |
| 1479 | /* Cancel currently queued command. */ |
| 1480 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 1481 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1482 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1483 | if (priv->debug_level & IWL_DL_FW_ERRORS) { |
Ester Kummer | ede0cba | 2008-05-29 16:34:46 +0800 | [diff] [blame] | 1484 | iwl_dump_nic_error_log(priv); |
Ester Kummer | 189a2b5 | 2008-05-15 13:54:18 +0800 | [diff] [blame] | 1485 | iwl_dump_nic_event_log(priv); |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1486 | iwl4965_print_rx_config_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1487 | } |
| 1488 | #endif |
| 1489 | |
| 1490 | wake_up_interruptible(&priv->wait_command_queue); |
| 1491 | |
| 1492 | /* Keep the restart process from trying to send host |
| 1493 | * commands by clearing the INIT status bit */ |
| 1494 | clear_bit(STATUS_READY, &priv->status); |
| 1495 | |
| 1496 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1497 | IWL_DEBUG(IWL_DL_FW_ERRORS, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1498 | "Restarting adapter due to uCode error.\n"); |
| 1499 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1500 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1501 | memcpy(&priv->recovery_rxon, &priv->active_rxon, |
| 1502 | sizeof(priv->recovery_rxon)); |
| 1503 | priv->error_recovering = 1; |
| 1504 | } |
Ester Kummer | 3a1081e | 2008-05-06 11:05:14 +0800 | [diff] [blame] | 1505 | if (priv->cfg->mod_params->restart_fw) |
| 1506 | queue_work(priv->workqueue, &priv->restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1507 | } |
| 1508 | } |
| 1509 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1510 | static void iwl4965_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1511 | { |
| 1512 | unsigned long flags; |
| 1513 | |
| 1514 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 1515 | sizeof(priv->staging_rxon)); |
| 1516 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1517 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1518 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 1519 | iwl_rxon_add_station(priv, priv->bssid, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1520 | |
| 1521 | spin_lock_irqsave(&priv->lock, flags); |
| 1522 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
| 1523 | priv->error_recovering = 0; |
| 1524 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1525 | } |
| 1526 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1527 | static void iwl4965_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1528 | { |
| 1529 | u32 inta, handled = 0; |
| 1530 | u32 inta_fh; |
| 1531 | unsigned long flags; |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1532 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1533 | u32 inta_mask; |
| 1534 | #endif |
| 1535 | |
| 1536 | spin_lock_irqsave(&priv->lock, flags); |
| 1537 | |
| 1538 | /* Ack/clear/reset pending uCode interrupts. |
| 1539 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 1540 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1541 | inta = iwl_read32(priv, CSR_INT); |
| 1542 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1543 | |
| 1544 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 1545 | * Any new interrupts that happen after this, either while we're |
| 1546 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1547 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 1548 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1549 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1550 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1551 | if (priv->debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1552 | /* just for debug */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1553 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1554 | IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 1555 | inta, inta_mask, inta_fh); |
| 1556 | } |
| 1557 | #endif |
| 1558 | |
| 1559 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 1560 | * atomic, make sure that inta covers all the interrupts that |
| 1561 | * we've discovered, even if FH interrupt came in just after |
| 1562 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 1563 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1564 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 1565 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1566 | inta |= CSR_INT_BIT_FH_TX; |
| 1567 | |
| 1568 | /* Now service all interrupt bits discovered above. */ |
| 1569 | if (inta & CSR_INT_BIT_HW_ERR) { |
| 1570 | IWL_ERROR("Microcode HW error detected. Restarting.\n"); |
| 1571 | |
| 1572 | /* Tell the device to stop sending interrupts */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1573 | iwl4965_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1574 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1575 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1576 | |
| 1577 | handled |= CSR_INT_BIT_HW_ERR; |
| 1578 | |
| 1579 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1580 | |
| 1581 | return; |
| 1582 | } |
| 1583 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1584 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1585 | if (priv->debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1586 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 1587 | if (inta & CSR_INT_BIT_SCD) |
| 1588 | IWL_DEBUG_ISR("Scheduler finished to transmit " |
| 1589 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1590 | |
| 1591 | /* Alive notification via Rx interrupt will do the real work */ |
| 1592 | if (inta & CSR_INT_BIT_ALIVE) |
| 1593 | IWL_DEBUG_ISR("Alive interrupt\n"); |
| 1594 | } |
| 1595 | #endif |
| 1596 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 1597 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1598 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1599 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1600 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 1601 | int hw_rf_kill = 0; |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1602 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1603 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 1604 | hw_rf_kill = 1; |
| 1605 | |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1606 | 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] | 1607 | hw_rf_kill ? "disable radio":"enable radio"); |
| 1608 | |
Emmanuel Grumbach | a9efa65 | 2008-06-30 17:23:25 +0800 | [diff] [blame^] | 1609 | /* driver only loads ucode once setting the interface up. |
| 1610 | * the driver as well won't allow loading if RFKILL is set |
| 1611 | * therefore no need to restart the driver from this handler |
| 1612 | */ |
| 1613 | if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) |
Zhu Yi | 53e4909 | 2007-12-06 16:08:44 +0800 | [diff] [blame] | 1614 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1615 | |
| 1616 | handled |= CSR_INT_BIT_RF_KILL; |
| 1617 | } |
| 1618 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1619 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1620 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 1621 | IWL_ERROR("Microcode CT kill error detected.\n"); |
| 1622 | handled |= CSR_INT_BIT_CT_KILL; |
| 1623 | } |
| 1624 | |
| 1625 | /* Error detected by uCode */ |
| 1626 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 1627 | IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", |
| 1628 | inta); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1629 | iwl4965_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1630 | handled |= CSR_INT_BIT_SW_ERR; |
| 1631 | } |
| 1632 | |
| 1633 | /* uCode wakes up after power-down sleep */ |
| 1634 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 1635 | IWL_DEBUG_ISR("Wakeup interrupt\n"); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1636 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Tomas Winkler | babcebf | 2008-05-15 13:54:00 +0800 | [diff] [blame] | 1637 | iwl_txq_update_write_ptr(priv, &priv->txq[0]); |
| 1638 | iwl_txq_update_write_ptr(priv, &priv->txq[1]); |
| 1639 | iwl_txq_update_write_ptr(priv, &priv->txq[2]); |
| 1640 | iwl_txq_update_write_ptr(priv, &priv->txq[3]); |
| 1641 | iwl_txq_update_write_ptr(priv, &priv->txq[4]); |
| 1642 | iwl_txq_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1643 | |
| 1644 | handled |= CSR_INT_BIT_WAKEUP; |
| 1645 | } |
| 1646 | |
| 1647 | /* All uCode command responses, including Tx command responses, |
| 1648 | * Rx "responses" (frame-received notification), and other |
| 1649 | * notifications from uCode come through here*/ |
| 1650 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1651 | iwl_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1652 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 1653 | } |
| 1654 | |
| 1655 | if (inta & CSR_INT_BIT_FH_TX) { |
| 1656 | IWL_DEBUG_ISR("Tx interrupt\n"); |
| 1657 | handled |= CSR_INT_BIT_FH_TX; |
Ron Rindjunsky | dbb983b | 2008-05-15 13:54:12 +0800 | [diff] [blame] | 1658 | /* FH finished to write, send event */ |
| 1659 | priv->ucode_write_complete = 1; |
| 1660 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | if (inta & ~handled) |
| 1664 | IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 1665 | |
| 1666 | if (inta & ~CSR_INI_SET_MASK) { |
| 1667 | IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", |
| 1668 | inta & ~CSR_INI_SET_MASK); |
| 1669 | IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); |
| 1670 | } |
| 1671 | |
| 1672 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 1673 | /* only Re-enable if diabled by irq */ |
| 1674 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 1675 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1676 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1677 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 1678 | if (priv->debug_level & (IWL_DL_ISR)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1679 | inta = iwl_read32(priv, CSR_INT); |
| 1680 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 1681 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1682 | IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
| 1683 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 1684 | } |
| 1685 | #endif |
| 1686 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1687 | } |
| 1688 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1689 | static irqreturn_t iwl4965_isr(int irq, void *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1690 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1691 | struct iwl_priv *priv = data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1692 | u32 inta, inta_mask; |
| 1693 | u32 inta_fh; |
| 1694 | if (!priv) |
| 1695 | return IRQ_NONE; |
| 1696 | |
| 1697 | spin_lock(&priv->lock); |
| 1698 | |
| 1699 | /* Disable (but don't clear!) interrupts here to avoid |
| 1700 | * back-to-back ISRs and sporadic interrupts from our NIC. |
| 1701 | * If we have something to service, the tasklet will re-enable ints. |
| 1702 | * 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] | 1703 | inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */ |
| 1704 | iwl_write32(priv, CSR_INT_MASK, 0x00000000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1705 | |
| 1706 | /* Discover which interrupts are active/pending */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1707 | inta = iwl_read32(priv, CSR_INT); |
| 1708 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1709 | |
| 1710 | /* Ignore interrupt if there's nothing in NIC to service. |
| 1711 | * This may be due to IRQ shared with another device, |
| 1712 | * or due to sporadic interrupts thrown from our NIC. */ |
| 1713 | if (!inta && !inta_fh) { |
| 1714 | IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n"); |
| 1715 | goto none; |
| 1716 | } |
| 1717 | |
| 1718 | if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 1719 | /* Hardware disappeared. It might have already raised |
| 1720 | * an interrupt */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1721 | IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta); |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 1722 | goto unplugged; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
| 1726 | inta, inta_mask, inta_fh); |
| 1727 | |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 1728 | inta &= ~CSR_INT_BIT_SCD; |
| 1729 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1730 | /* iwl4965_irq_tasklet() will service interrupts and re-enable them */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 1731 | if (likely(inta || inta_fh)) |
| 1732 | tasklet_schedule(&priv->irq_tasklet); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1733 | |
Oliver Neukum | 66fbb54 | 2007-11-15 09:31:10 +0800 | [diff] [blame] | 1734 | unplugged: |
| 1735 | spin_unlock(&priv->lock); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1736 | return IRQ_HANDLED; |
| 1737 | |
| 1738 | none: |
| 1739 | /* re-enable interrupts here since we don't have anything to service. */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 1740 | /* only Re-enable if diabled by irq */ |
| 1741 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 1742 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1743 | spin_unlock(&priv->lock); |
| 1744 | return IRQ_NONE; |
| 1745 | } |
| 1746 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1747 | /****************************************************************************** |
| 1748 | * |
| 1749 | * uCode download functions |
| 1750 | * |
| 1751 | ******************************************************************************/ |
| 1752 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1753 | static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1754 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 1755 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 1756 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 1757 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 1758 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 1759 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 1760 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 1763 | static void iwl4965_nic_start(struct iwl_priv *priv) |
| 1764 | { |
| 1765 | /* Remove all resets to allow NIC to operate */ |
| 1766 | iwl_write32(priv, CSR_RESET, 0); |
| 1767 | } |
| 1768 | |
| 1769 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1770 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1771 | * iwl4965_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1772 | * |
| 1773 | * Copy into buffers for card to fetch via bus-mastering |
| 1774 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1775 | static int iwl4965_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1776 | { |
Ron Rindjunsky | 14b3d33 | 2008-06-13 15:44:54 +0800 | [diff] [blame] | 1777 | struct iwl_ucode *ucode; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1778 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1779 | const struct firmware *ucode_raw; |
Tomas Winkler | 4bf775cd | 2008-03-04 18:09:31 -0800 | [diff] [blame] | 1780 | const char *name = priv->cfg->fw_name; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1781 | u8 *src; |
| 1782 | size_t len; |
| 1783 | u32 ver, inst_size, data_size, init_size, init_data_size, boot_size; |
| 1784 | |
| 1785 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 1786 | * request_firmware() is synchronous, file is in memory on return. */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1787 | ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev); |
| 1788 | if (ret < 0) { |
| 1789 | IWL_ERROR("%s firmware file req failed: Reason %d\n", |
| 1790 | name, ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1791 | goto error; |
| 1792 | } |
| 1793 | |
| 1794 | IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", |
| 1795 | name, ucode_raw->size); |
| 1796 | |
| 1797 | /* Make sure that we got at least our header! */ |
| 1798 | if (ucode_raw->size < sizeof(*ucode)) { |
| 1799 | IWL_ERROR("File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1800 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1801 | goto err_release; |
| 1802 | } |
| 1803 | |
| 1804 | /* Data from ucode file: header followed by uCode images */ |
| 1805 | ucode = (void *)ucode_raw->data; |
| 1806 | |
| 1807 | ver = le32_to_cpu(ucode->ver); |
| 1808 | inst_size = le32_to_cpu(ucode->inst_size); |
| 1809 | data_size = le32_to_cpu(ucode->data_size); |
| 1810 | init_size = le32_to_cpu(ucode->init_size); |
| 1811 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 1812 | boot_size = le32_to_cpu(ucode->boot_size); |
| 1813 | |
| 1814 | IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver); |
| 1815 | IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", |
| 1816 | inst_size); |
| 1817 | IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", |
| 1818 | data_size); |
| 1819 | IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", |
| 1820 | init_size); |
| 1821 | IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", |
| 1822 | init_data_size); |
| 1823 | IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", |
| 1824 | boot_size); |
| 1825 | |
| 1826 | /* Verify size of file vs. image size info in file's header */ |
| 1827 | if (ucode_raw->size < sizeof(*ucode) + |
| 1828 | inst_size + data_size + init_size + |
| 1829 | init_data_size + boot_size) { |
| 1830 | |
| 1831 | IWL_DEBUG_INFO("uCode file size %d too small\n", |
| 1832 | (int)ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1833 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1834 | goto err_release; |
| 1835 | } |
| 1836 | |
| 1837 | /* Verify that uCode images will fit in card's SRAM */ |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 1838 | if (inst_size > priv->hw_params.max_inst_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1839 | IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n", |
| 1840 | inst_size); |
| 1841 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1842 | goto err_release; |
| 1843 | } |
| 1844 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 1845 | if (data_size > priv->hw_params.max_data_size) { |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1846 | IWL_DEBUG_INFO("uCode data len %d too large to fit in\n", |
| 1847 | data_size); |
| 1848 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1849 | goto err_release; |
| 1850 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 1851 | if (init_size > priv->hw_params.max_inst_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1852 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1853 | ("uCode init instr len %d too large to fit in\n", |
| 1854 | init_size); |
| 1855 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1856 | goto err_release; |
| 1857 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 1858 | if (init_data_size > priv->hw_params.max_data_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1859 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1860 | ("uCode init data len %d too large to fit in\n", |
| 1861 | init_data_size); |
| 1862 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1863 | goto err_release; |
| 1864 | } |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 1865 | if (boot_size > priv->hw_params.max_bsm_size) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1866 | IWL_DEBUG_INFO |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1867 | ("uCode boot instr len %d too large to fit in\n", |
| 1868 | boot_size); |
| 1869 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1870 | goto err_release; |
| 1871 | } |
| 1872 | |
| 1873 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 1874 | |
| 1875 | /* Runtime instructions and 2 copies of data: |
| 1876 | * 1) unmodified from disk |
| 1877 | * 2) backup cache for save/restore during power-downs */ |
| 1878 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 1879 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1880 | |
| 1881 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 1882 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1883 | |
| 1884 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 1885 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1886 | |
| 1887 | /* Initialization instructions and data */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1888 | if (init_size && init_data_size) { |
| 1889 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 1890 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1891 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1892 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 1893 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1894 | |
| 1895 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 1896 | goto err_pci_alloc; |
| 1897 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1898 | |
| 1899 | /* Bootstrap (instructions only, no data) */ |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1900 | if (boot_size) { |
| 1901 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 1902 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1903 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1904 | if (!priv->ucode_boot.v_addr) |
| 1905 | goto err_pci_alloc; |
| 1906 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1907 | |
| 1908 | /* Copy images into buffers for card's bus-master reads ... */ |
| 1909 | |
| 1910 | /* Runtime instructions (first block of data in file) */ |
| 1911 | src = &ucode->data[0]; |
| 1912 | len = priv->ucode_code.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1913 | 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] | 1914 | memcpy(priv->ucode_code.v_addr, src, len); |
| 1915 | IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
| 1916 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 1917 | |
| 1918 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1919 | * NOTE: Copy into backup buffer will be done in iwl4965_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1920 | src = &ucode->data[inst_size]; |
| 1921 | len = priv->ucode_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1922 | 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] | 1923 | memcpy(priv->ucode_data.v_addr, src, len); |
| 1924 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 1925 | |
| 1926 | /* Initialization instructions (3rd block) */ |
| 1927 | if (init_size) { |
| 1928 | src = &ucode->data[inst_size + data_size]; |
| 1929 | len = priv->ucode_init.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1930 | IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n", |
| 1931 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1932 | memcpy(priv->ucode_init.v_addr, src, len); |
| 1933 | } |
| 1934 | |
| 1935 | /* Initialization data (4th block) */ |
| 1936 | if (init_data_size) { |
| 1937 | src = &ucode->data[inst_size + data_size + init_size]; |
| 1938 | len = priv->ucode_init_data.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1939 | IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n", |
| 1940 | len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1941 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 1942 | } |
| 1943 | |
| 1944 | /* Bootstrap instructions (5th block) */ |
| 1945 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 1946 | len = priv->ucode_boot.len; |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1947 | 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] | 1948 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 1949 | |
| 1950 | /* We have our copies now, allow OS release its copies */ |
| 1951 | release_firmware(ucode_raw); |
| 1952 | return 0; |
| 1953 | |
| 1954 | err_pci_alloc: |
| 1955 | IWL_ERROR("failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1956 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1957 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1958 | |
| 1959 | err_release: |
| 1960 | release_firmware(ucode_raw); |
| 1961 | |
| 1962 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 1963 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1966 | /** |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 1967 | * iwl_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1968 | * from protocol/runtime uCode (initialization uCode's |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 1969 | * Alive gets handled by iwl_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1970 | */ |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 1971 | static void iwl_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1972 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 1973 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1974 | |
| 1975 | IWL_DEBUG_INFO("Runtime Alive received.\n"); |
| 1976 | |
| 1977 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 1978 | /* We had an error bringing up the hardware, so take it |
| 1979 | * all the way back down so we can try again */ |
| 1980 | IWL_DEBUG_INFO("Alive failed.\n"); |
| 1981 | goto restart; |
| 1982 | } |
| 1983 | |
| 1984 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 1985 | * This is a paranoid check, because we would not have gotten the |
| 1986 | * "runtime" alive if code weren't properly loaded. */ |
Emmanuel Grumbach | b0692f2 | 2008-04-24 11:55:18 -0700 | [diff] [blame] | 1987 | if (iwl_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1988 | /* Runtime instruction load was bad; |
| 1989 | * take it all the way back down so we can try again */ |
| 1990 | IWL_DEBUG_INFO("Bad runtime uCode load.\n"); |
| 1991 | goto restart; |
| 1992 | } |
| 1993 | |
Emmanuel Grumbach | 37deb2a | 2008-06-30 17:23:08 +0800 | [diff] [blame] | 1994 | iwl_clear_stations_table(priv); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 1995 | ret = priv->cfg->ops->lib->alive_notify(priv); |
| 1996 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1997 | IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 1998 | ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1999 | goto restart; |
| 2000 | } |
| 2001 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2002 | /* After the ALIVE response, we can send host commands to 4965 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2003 | set_bit(STATUS_ALIVE, &priv->status); |
| 2004 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 2005 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2006 | return; |
| 2007 | |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 2008 | ieee80211_wake_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2009 | |
| 2010 | priv->active_rate = priv->rates_mask; |
| 2011 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 2012 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2013 | if (iwl_is_associated(priv)) { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 2014 | struct iwl_rxon_cmd *active_rxon = |
| 2015 | (struct iwl_rxon_cmd *)&priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2016 | |
| 2017 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 2018 | sizeof(priv->staging_rxon)); |
| 2019 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 2020 | } else { |
| 2021 | /* Initialize our rx_config data */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2022 | iwl4965_connection_init_rx_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2023 | memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN); |
| 2024 | } |
| 2025 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2026 | /* Configure Bluetooth device coexistence support */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2027 | iwl4965_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2028 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2029 | iwl_reset_run_time_calib(priv); |
| 2030 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2031 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2032 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2033 | |
| 2034 | /* At this point, the NIC is initialized and operational */ |
Emmanuel Grumbach | 47f4a58 | 2008-06-12 09:47:13 +0800 | [diff] [blame] | 2035 | iwl_rf_kill_ct_config(priv); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2036 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 2037 | iwl_leds_register(priv); |
| 2038 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2039 | IWL_DEBUG_INFO("ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 2040 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2041 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2042 | |
| 2043 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2044 | iwl4965_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2045 | |
Emmanuel Grumbach | 58d0f36 | 2008-06-12 09:47:19 +0800 | [diff] [blame] | 2046 | iwl_power_update_mode(priv, 1); |
Mohamed Abbas | 84363e6 | 2008-04-04 16:59:58 -0700 | [diff] [blame] | 2047 | ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC); |
Assaf Krauss | c46fbef | 2008-06-12 09:47:05 +0800 | [diff] [blame] | 2048 | |
| 2049 | if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status)) |
| 2050 | iwl4965_set_mode(priv, priv->iw_mode); |
| 2051 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2052 | return; |
| 2053 | |
| 2054 | restart: |
| 2055 | queue_work(priv->workqueue, &priv->restart); |
| 2056 | } |
| 2057 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 2058 | static void iwl_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2059 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2060 | static void __iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2061 | { |
| 2062 | unsigned long flags; |
| 2063 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2064 | |
| 2065 | IWL_DEBUG_INFO(DRV_NAME " is going down\n"); |
| 2066 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2067 | if (!exit_pending) |
| 2068 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 2069 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2070 | iwl_leds_unregister(priv); |
| 2071 | |
Emmanuel Grumbach | 37deb2a | 2008-06-30 17:23:08 +0800 | [diff] [blame] | 2072 | iwl_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2073 | |
| 2074 | /* Unblock any waiting calls */ |
| 2075 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 2076 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2077 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 2078 | * exiting the module */ |
| 2079 | if (!exit_pending) |
| 2080 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 2081 | |
| 2082 | /* stop and reset the on-board processor */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2083 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2084 | |
| 2085 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2086 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2087 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2088 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2089 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2090 | |
| 2091 | if (priv->mac80211_registered) |
| 2092 | ieee80211_stop_queues(priv->hw); |
| 2093 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2094 | /* If we have not previously called iwl4965_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2095 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 2096 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2097 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 2098 | STATUS_RF_KILL_HW | |
| 2099 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 2100 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 2101 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 2102 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2103 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
Mohamed Abbas | 052ec3f | 2008-06-30 17:23:15 +0800 | [diff] [blame] | 2104 | STATUS_IN_SUSPEND | |
| 2105 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 2106 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2107 | goto exit; |
| 2108 | } |
| 2109 | |
| 2110 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 2111 | * SUSPEND bits and continue taking the NIC down. */ |
| 2112 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 2113 | STATUS_RF_KILL_HW | |
| 2114 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 2115 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 2116 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 2117 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2118 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 2119 | STATUS_IN_SUSPEND | |
| 2120 | test_bit(STATUS_FW_ERROR, &priv->status) << |
Mohamed Abbas | 052ec3f | 2008-06-30 17:23:15 +0800 | [diff] [blame] | 2121 | STATUS_FW_ERROR | |
| 2122 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 2123 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2124 | |
| 2125 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2126 | iwl_clear_bit(priv, CSR_GP_CNTRL, |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2127 | CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2128 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2129 | |
Tomas Winkler | da1bc45 | 2008-05-29 16:35:00 +0800 | [diff] [blame] | 2130 | iwl_txq_ctx_stop(priv); |
Tomas Winkler | b3bbacb | 2008-05-29 16:35:01 +0800 | [diff] [blame] | 2131 | iwl_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2132 | |
| 2133 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2134 | if (!iwl_grab_nic_access(priv)) { |
| 2135 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2136 | APMG_CLK_VAL_DMA_CLK_RQT); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2137 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2138 | } |
| 2139 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2140 | |
| 2141 | udelay(5); |
| 2142 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 2143 | /* FIXME: apm_ops.suspend(priv) */ |
| 2144 | priv->cfg->ops->lib->apm_ops.reset(priv); |
Ron Rindjunsky | 399f4900 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 2145 | priv->cfg->ops->lib->free_shared_mem(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2146 | |
| 2147 | exit: |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 2148 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2149 | |
| 2150 | if (priv->ibss_beacon) |
| 2151 | dev_kfree_skb(priv->ibss_beacon); |
| 2152 | priv->ibss_beacon = NULL; |
| 2153 | |
| 2154 | /* clear out any free frames */ |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 2155 | iwl_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2156 | } |
| 2157 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2158 | static void iwl4965_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2159 | { |
| 2160 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2161 | __iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2162 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 2163 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 2164 | iwl_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | #define MAX_HW_RESTARTS 5 |
| 2168 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2169 | static int __iwl4965_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2170 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 2171 | int i; |
| 2172 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2173 | |
| 2174 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 2175 | IWL_WARNING("Exit pending; will not bring the NIC up\n"); |
| 2176 | return -EIO; |
| 2177 | } |
| 2178 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 2179 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
| 2180 | IWL_ERROR("ucode not available for device bringup\n"); |
| 2181 | return -EIO; |
| 2182 | } |
| 2183 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 2184 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2185 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 2186 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 2187 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Emmanuel Grumbach | 3bff19c | 2008-06-30 17:23:19 +0800 | [diff] [blame] | 2188 | else |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 2189 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
Emmanuel Grumbach | 3bff19c | 2008-06-30 17:23:19 +0800 | [diff] [blame] | 2190 | |
| 2191 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status) && |
| 2192 | iwl_is_rfkill(priv)) { |
| 2193 | iwl_rfkill_set_hw_state(priv); |
| 2194 | IWL_WARNING("Radio disabled by %s RF Kill switch\n", |
| 2195 | test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW"); |
| 2196 | return -ENODEV; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2197 | } |
| 2198 | |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2199 | iwl_rfkill_set_hw_state(priv); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2200 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2201 | |
Ron Rindjunsky | 399f4900 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 2202 | ret = priv->cfg->ops->lib->alloc_shared_mem(priv); |
| 2203 | if (ret) { |
| 2204 | IWL_ERROR("Unable to allocate shared memory\n"); |
| 2205 | return ret; |
| 2206 | } |
| 2207 | |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 2208 | ret = iwl_hw_nic_init(priv); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 2209 | if (ret) { |
| 2210 | IWL_ERROR("Unable to init nic\n"); |
| 2211 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | /* make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2215 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 2216 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2217 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 2218 | |
| 2219 | /* clear (again), then enable host interrupts */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2220 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2221 | iwl4965_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2222 | |
| 2223 | /* really make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2224 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 2225 | 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] | 2226 | |
| 2227 | /* Copy original ucode data image from disk into backup cache. |
| 2228 | * This will be used to initialize the on-board processor's |
| 2229 | * data SRAM for a clean start when the runtime program first loads. */ |
| 2230 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2231 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2232 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 2233 | /* We return success when we resume from suspend and rf_kill is on. */ |
Mohamed Abbas | 64e72c3 | 2008-06-12 09:47:03 +0800 | [diff] [blame] | 2234 | if (test_bit(STATUS_RF_KILL_HW, &priv->status) || |
| 2235 | test_bit(STATUS_RF_KILL_SW, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2236 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2237 | |
| 2238 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 2239 | |
Emmanuel Grumbach | 37deb2a | 2008-06-30 17:23:08 +0800 | [diff] [blame] | 2240 | iwl_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2241 | |
| 2242 | /* load bootstrap state machine, |
| 2243 | * load bootstrap program into processor's memory, |
| 2244 | * prepare to load the "initialize" uCode */ |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 2245 | ret = priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2246 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 2247 | if (ret) { |
| 2248 | IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2249 | continue; |
| 2250 | } |
| 2251 | |
Emmanuel Grumbach | f3d5b45 | 2008-06-12 09:47:04 +0800 | [diff] [blame] | 2252 | /* Clear out the uCode error bit if it is set */ |
| 2253 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 2254 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2255 | /* start card; "initialize" will load runtime ucode */ |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 2256 | iwl4965_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2257 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2258 | IWL_DEBUG_INFO(DRV_NAME " is coming up\n"); |
| 2259 | |
| 2260 | return 0; |
| 2261 | } |
| 2262 | |
| 2263 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2264 | __iwl4965_down(priv); |
Mohamed Abbas | 64e72c3 | 2008-06-12 09:47:03 +0800 | [diff] [blame] | 2265 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2266 | |
| 2267 | /* tried to restart and config the device for as long as our |
| 2268 | * patience could withstand */ |
| 2269 | IWL_ERROR("Unable to initialize device after %d attempts.\n", i); |
| 2270 | return -EIO; |
| 2271 | } |
| 2272 | |
| 2273 | |
| 2274 | /***************************************************************************** |
| 2275 | * |
| 2276 | * Workqueue callbacks |
| 2277 | * |
| 2278 | *****************************************************************************/ |
| 2279 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2280 | static void iwl_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2281 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2282 | struct iwl_priv *priv = |
| 2283 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2284 | |
| 2285 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2286 | return; |
| 2287 | |
| 2288 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | f3ccc08 | 2008-05-05 10:22:45 +0800 | [diff] [blame] | 2289 | priv->cfg->ops->lib->init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2290 | mutex_unlock(&priv->mutex); |
| 2291 | } |
| 2292 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2293 | static void iwl_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2294 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2295 | struct iwl_priv *priv = |
| 2296 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2297 | |
| 2298 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2299 | return; |
| 2300 | |
| 2301 | mutex_lock(&priv->mutex); |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2302 | iwl_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2303 | mutex_unlock(&priv->mutex); |
| 2304 | } |
| 2305 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2306 | static void iwl4965_bg_rf_kill(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2307 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2308 | struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2309 | |
| 2310 | wake_up_interruptible(&priv->wait_command_queue); |
| 2311 | |
| 2312 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2313 | return; |
| 2314 | |
| 2315 | mutex_lock(&priv->mutex); |
| 2316 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 2317 | if (!iwl_is_rfkill(priv)) { |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 2318 | IWL_DEBUG(IWL_DL_RF_KILL, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2319 | "HW and/or SW RF Kill no longer active, restarting " |
| 2320 | "device\n"); |
| 2321 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2322 | queue_work(priv->workqueue, &priv->restart); |
| 2323 | } else { |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2324 | /* make sure mac80211 stop sending Tx frame */ |
| 2325 | if (priv->mac80211_registered) |
| 2326 | ieee80211_stop_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2327 | |
| 2328 | if (!test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 2329 | IWL_DEBUG_RF_KILL("Can not turn radio back on - " |
| 2330 | "disabled by SW switch\n"); |
| 2331 | else |
| 2332 | IWL_WARNING("Radio Frequency Kill Switch is On:\n" |
| 2333 | "Kill switch must be turned off for " |
| 2334 | "wireless networking to work.\n"); |
| 2335 | } |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 2336 | iwl_rfkill_set_hw_state(priv); |
| 2337 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2338 | mutex_unlock(&priv->mutex); |
| 2339 | } |
| 2340 | |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 2341 | static void iwl4965_bg_set_monitor(struct work_struct *work) |
| 2342 | { |
| 2343 | struct iwl_priv *priv = container_of(work, |
| 2344 | struct iwl_priv, set_monitor); |
Assaf Krauss | c46fbef | 2008-06-12 09:47:05 +0800 | [diff] [blame] | 2345 | int ret; |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 2346 | |
| 2347 | IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n"); |
| 2348 | |
| 2349 | mutex_lock(&priv->mutex); |
| 2350 | |
Assaf Krauss | c46fbef | 2008-06-12 09:47:05 +0800 | [diff] [blame] | 2351 | ret = iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR); |
| 2352 | |
| 2353 | if (ret) { |
| 2354 | if (ret == -EAGAIN) |
| 2355 | IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n"); |
| 2356 | else |
| 2357 | IWL_ERROR("iwl4965_set_mode() failed ret = %d\n", ret); |
| 2358 | } |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 2359 | |
| 2360 | mutex_unlock(&priv->mutex); |
| 2361 | } |
| 2362 | |
Emmanuel Grumbach | 16e727e | 2008-06-12 09:46:52 +0800 | [diff] [blame] | 2363 | static void iwl_bg_run_time_calib_work(struct work_struct *work) |
| 2364 | { |
| 2365 | struct iwl_priv *priv = container_of(work, struct iwl_priv, |
| 2366 | run_time_calib_work); |
| 2367 | |
| 2368 | mutex_lock(&priv->mutex); |
| 2369 | |
| 2370 | if (test_bit(STATUS_EXIT_PENDING, &priv->status) || |
| 2371 | test_bit(STATUS_SCANNING, &priv->status)) { |
| 2372 | mutex_unlock(&priv->mutex); |
| 2373 | return; |
| 2374 | } |
| 2375 | |
| 2376 | if (priv->start_calib) { |
| 2377 | iwl_chain_noise_calibration(priv, &priv->statistics); |
| 2378 | |
| 2379 | iwl_sensitivity_calibration(priv, &priv->statistics); |
| 2380 | } |
| 2381 | |
| 2382 | mutex_unlock(&priv->mutex); |
| 2383 | return; |
| 2384 | } |
| 2385 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2386 | static void iwl4965_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2387 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2388 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2389 | |
| 2390 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2391 | return; |
| 2392 | |
| 2393 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2394 | __iwl4965_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2395 | mutex_unlock(&priv->mutex); |
| 2396 | } |
| 2397 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2398 | static void iwl4965_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2399 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2400 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2401 | |
| 2402 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2403 | return; |
| 2404 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2405 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2406 | queue_work(priv->workqueue, &priv->up); |
| 2407 | } |
| 2408 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2409 | static void iwl4965_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2410 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2411 | struct iwl_priv *priv = |
| 2412 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2413 | |
| 2414 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2415 | return; |
| 2416 | |
| 2417 | mutex_lock(&priv->mutex); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2418 | iwl_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2419 | mutex_unlock(&priv->mutex); |
| 2420 | } |
| 2421 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2422 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 2423 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 2424 | static void iwl4965_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2425 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2426 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2427 | int ret = 0; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2428 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2429 | |
| 2430 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 2431 | IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__); |
| 2432 | return; |
| 2433 | } |
| 2434 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2435 | IWL_DEBUG_ASSOC("Associated as %d to: %s\n", |
| 2436 | priv->assoc_id, |
| 2437 | print_mac(mac, priv->active_rxon.bssid_addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2438 | |
| 2439 | |
| 2440 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2441 | return; |
| 2442 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2443 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 2444 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 2445 | return; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 2446 | |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 2447 | iwl_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 2448 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2449 | conf = ieee80211_get_hw_conf(priv->hw); |
| 2450 | |
| 2451 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2452 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2453 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2454 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 2455 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2456 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2457 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2458 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2459 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 2460 | "Attempting to continue.\n"); |
| 2461 | |
| 2462 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 2463 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 2464 | if (priv->current_ht_config.is_ht) |
Tomas Winkler | 47c5196 | 2008-05-05 10:22:41 +0800 | [diff] [blame] | 2465 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
Ron Rindjunsky | 4f85f5b | 2008-06-09 22:54:35 +0300 | [diff] [blame] | 2466 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 2467 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2468 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 2469 | |
| 2470 | IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n", |
| 2471 | priv->assoc_id, priv->beacon_int); |
| 2472 | |
| 2473 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 2474 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2475 | else |
| 2476 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2477 | |
| 2478 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 2479 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 2480 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
| 2481 | else |
| 2482 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2483 | |
| 2484 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 2485 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
| 2486 | |
| 2487 | } |
| 2488 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2489 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2490 | |
| 2491 | switch (priv->iw_mode) { |
| 2492 | case IEEE80211_IF_TYPE_STA: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2493 | break; |
| 2494 | |
| 2495 | case IEEE80211_IF_TYPE_IBSS: |
| 2496 | |
Assaf Krauss | c46fbef | 2008-06-12 09:47:05 +0800 | [diff] [blame] | 2497 | /* assume default assoc id */ |
| 2498 | priv->assoc_id = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2499 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 2500 | iwl_rxon_add_station(priv, priv->bssid, 0); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2501 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2502 | |
| 2503 | break; |
| 2504 | |
| 2505 | default: |
| 2506 | IWL_ERROR("%s Should not be called in %d mode\n", |
| 2507 | __FUNCTION__, priv->iw_mode); |
| 2508 | break; |
| 2509 | } |
| 2510 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2511 | /* Enable Rx differential gain and sensitivity calibrations */ |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 2512 | iwl_chain_noise_reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2513 | priv->start_calib = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2514 | |
| 2515 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 2516 | priv->assoc_station_added = 1; |
| 2517 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2518 | iwl4965_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 2519 | |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 2520 | iwl_power_update_mode(priv, 0); |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2521 | /* we have just associated, don't start scan too early */ |
| 2522 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 2523 | } |
| 2524 | |
| 2525 | |
| 2526 | static void iwl4965_bg_post_associate(struct work_struct *data) |
| 2527 | { |
| 2528 | struct iwl_priv *priv = container_of(data, struct iwl_priv, |
| 2529 | post_associate.work); |
| 2530 | |
| 2531 | mutex_lock(&priv->mutex); |
| 2532 | iwl4965_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2533 | mutex_unlock(&priv->mutex); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 2534 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2535 | } |
| 2536 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 2537 | static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf); |
| 2538 | |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 2539 | static void iwl_bg_scan_completed(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2540 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2541 | struct iwl_priv *priv = |
| 2542 | container_of(work, struct iwl_priv, scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2543 | |
Tomas Winkler | 630fe9b | 2008-06-12 09:47:08 +0800 | [diff] [blame] | 2544 | IWL_DEBUG_SCAN("SCAN complete scan\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2545 | |
| 2546 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2547 | return; |
| 2548 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 2549 | if (test_bit(STATUS_CONF_PENDING, &priv->status)) |
| 2550 | iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw)); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 2551 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2552 | ieee80211_scan_completed(priv->hw); |
| 2553 | |
| 2554 | /* Since setting the TXPOWER may have been deferred while |
| 2555 | * performing the scan, fire one off */ |
| 2556 | mutex_lock(&priv->mutex); |
Tomas Winkler | 630fe9b | 2008-06-12 09:47:08 +0800 | [diff] [blame] | 2557 | iwl_set_tx_power(priv, priv->tx_power_user_lmt, true); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2558 | mutex_unlock(&priv->mutex); |
| 2559 | } |
| 2560 | |
| 2561 | /***************************************************************************** |
| 2562 | * |
| 2563 | * mac80211 entry point functions |
| 2564 | * |
| 2565 | *****************************************************************************/ |
| 2566 | |
Emmanuel Grumbach | 154b25c | 2008-06-30 17:23:24 +0800 | [diff] [blame] | 2567 | #define UCODE_READY_TIMEOUT (4 * HZ) |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2568 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2569 | static int iwl4965_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2570 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2571 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2572 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2573 | |
| 2574 | IWL_DEBUG_MAC80211("enter\n"); |
| 2575 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2576 | if (pci_enable_device(priv->pci_dev)) { |
| 2577 | IWL_ERROR("Fail to pci_enable_device\n"); |
| 2578 | return -ENODEV; |
| 2579 | } |
| 2580 | pci_restore_state(priv->pci_dev); |
| 2581 | pci_enable_msi(priv->pci_dev); |
| 2582 | |
| 2583 | ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED, |
| 2584 | DRV_NAME, priv); |
| 2585 | if (ret) { |
| 2586 | IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 2587 | goto out_disable_msi; |
| 2588 | } |
| 2589 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2590 | /* we should be verifying the device is ready to be opened */ |
| 2591 | mutex_lock(&priv->mutex); |
| 2592 | |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 2593 | memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd)); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2594 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 2595 | * ucode filename and max sizes are card-specific. */ |
| 2596 | |
| 2597 | if (!priv->ucode_code.len) { |
| 2598 | ret = iwl4965_read_ucode(priv); |
| 2599 | if (ret) { |
| 2600 | IWL_ERROR("Could not read microcode: %d\n", ret); |
| 2601 | mutex_unlock(&priv->mutex); |
| 2602 | goto out_release_irq; |
| 2603 | } |
| 2604 | } |
| 2605 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 2606 | ret = __iwl4965_up(priv); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2607 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2608 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2609 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 2610 | if (ret) |
| 2611 | goto out_release_irq; |
| 2612 | |
| 2613 | IWL_DEBUG_INFO("Start UP work done.\n"); |
| 2614 | |
| 2615 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 2616 | return 0; |
| 2617 | |
Ron Rindjunsky | fe9b6b7 | 2008-05-29 16:35:06 +0800 | [diff] [blame] | 2618 | /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2619 | * mac80211 will not be run successfully. */ |
Emmanuel Grumbach | 154b25c | 2008-06-30 17:23:24 +0800 | [diff] [blame] | 2620 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 2621 | test_bit(STATUS_READY, &priv->status), |
| 2622 | UCODE_READY_TIMEOUT); |
| 2623 | if (!ret) { |
| 2624 | if (!test_bit(STATUS_READY, &priv->status)) { |
| 2625 | IWL_ERROR("START_ALIVE timeout after %dms.\n", |
| 2626 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
| 2627 | ret = -ETIMEDOUT; |
| 2628 | goto out_release_irq; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2629 | } |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2630 | |
Ron Rindjunsky | fe9b6b7 | 2008-05-29 16:35:06 +0800 | [diff] [blame] | 2631 | priv->is_open = 1; |
| 2632 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2633 | IWL_DEBUG_MAC80211("leave\n"); |
| 2634 | return 0; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2635 | |
| 2636 | out_release_irq: |
| 2637 | free_irq(priv->pci_dev->irq, priv); |
| 2638 | out_disable_msi: |
| 2639 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 2640 | pci_disable_device(priv->pci_dev); |
| 2641 | priv->is_open = 0; |
| 2642 | IWL_DEBUG_MAC80211("leave - failed\n"); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2643 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2644 | } |
| 2645 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2646 | static void iwl4965_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2647 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2648 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2649 | |
| 2650 | IWL_DEBUG_MAC80211("enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 2651 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 2652 | if (!priv->is_open) { |
| 2653 | IWL_DEBUG_MAC80211("leave - skip\n"); |
| 2654 | return; |
| 2655 | } |
| 2656 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2657 | priv->is_open = 0; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2658 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 2659 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 2660 | /* stop mac, cancel any scan request and clear |
| 2661 | * RXON_FILTER_ASSOC_MSK BIT |
| 2662 | */ |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2663 | mutex_lock(&priv->mutex); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 2664 | iwl_scan_cancel_timeout(priv, 100); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2665 | cancel_delayed_work(&priv->post_associate); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2666 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2667 | } |
| 2668 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2669 | iwl4965_down(priv); |
| 2670 | |
| 2671 | flush_workqueue(priv->workqueue); |
| 2672 | free_irq(priv->pci_dev->irq, priv); |
| 2673 | pci_disable_msi(priv->pci_dev); |
| 2674 | pci_save_state(priv->pci_dev); |
| 2675 | pci_disable_device(priv->pci_dev); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 2676 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2677 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2680 | 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] | 2681 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2682 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2683 | |
| 2684 | IWL_DEBUG_MAC80211("enter\n"); |
| 2685 | |
| 2686 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 2687 | IWL_DEBUG_MAC80211("leave - monitor\n"); |
| 2688 | return -1; |
| 2689 | } |
| 2690 | |
| 2691 | 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] | 2692 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2693 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2694 | if (iwl_tx_skb(priv, skb)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2695 | dev_kfree_skb_any(skb); |
| 2696 | |
| 2697 | IWL_DEBUG_MAC80211("leave\n"); |
| 2698 | return 0; |
| 2699 | } |
| 2700 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2701 | static int iwl4965_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2702 | struct ieee80211_if_init_conf *conf) |
| 2703 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2704 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2705 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2706 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2707 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 2708 | IWL_DEBUG_MAC80211("enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2709 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 2710 | if (priv->vif) { |
| 2711 | IWL_DEBUG_MAC80211("leave - vif != NULL\n"); |
Reinette Chatre | 75849d2 | 2008-01-23 10:15:17 -0800 | [diff] [blame] | 2712 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 2716 | priv->vif = conf->vif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2717 | |
| 2718 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2719 | |
| 2720 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 2721 | |
| 2722 | if (conf->mac_addr) { |
| 2723 | IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr)); |
| 2724 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 2725 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2726 | |
Assaf Krauss | c46fbef | 2008-06-12 09:47:05 +0800 | [diff] [blame] | 2727 | if (iwl4965_set_mode(priv, conf->type) == -EAGAIN) |
| 2728 | /* we are not ready, will run again when ready */ |
| 2729 | set_bit(STATUS_MODE_PENDING, &priv->status); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2730 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2731 | mutex_unlock(&priv->mutex); |
| 2732 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2733 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2734 | return 0; |
| 2735 | } |
| 2736 | |
| 2737 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2738 | * iwl4965_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2739 | * |
| 2740 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 2741 | * be set inappropriately and the driver currently sets the hardware up to |
| 2742 | * use it whenever needed. |
| 2743 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2744 | 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] | 2745 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2746 | struct iwl_priv *priv = hw->priv; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 2747 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2748 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 2749 | int ret = 0; |
Tomas Winkler | 82a66bb | 2008-05-29 16:35:28 +0800 | [diff] [blame] | 2750 | u16 channel; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2751 | |
| 2752 | mutex_lock(&priv->mutex); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2753 | IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2754 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2755 | priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP); |
| 2756 | |
Emmanuel Grumbach | 14a08a7 | 2008-06-13 15:44:55 +0800 | [diff] [blame] | 2757 | if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) { |
Mohamed Abbas | 64e72c3 | 2008-06-12 09:47:03 +0800 | [diff] [blame] | 2758 | IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n"); |
Emmanuel Grumbach | 14a08a7 | 2008-06-13 15:44:55 +0800 | [diff] [blame] | 2759 | goto out; |
Mohamed Abbas | 64e72c3 | 2008-06-12 09:47:03 +0800 | [diff] [blame] | 2760 | } |
| 2761 | |
Emmanuel Grumbach | 14a08a7 | 2008-06-13 15:44:55 +0800 | [diff] [blame] | 2762 | if (!conf->radio_enabled) |
| 2763 | iwl_radio_kill_sw_disable_radio(priv); |
| 2764 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 2765 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2766 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 2767 | ret = -EIO; |
| 2768 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2769 | } |
| 2770 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 2771 | if (unlikely(!priv->cfg->mod_params->disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2772 | test_bit(STATUS_SCANNING, &priv->status))) { |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 2773 | IWL_DEBUG_MAC80211("leave - scanning\n"); |
| 2774 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2775 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 2776 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
Tomas Winkler | 82a66bb | 2008-05-29 16:35:28 +0800 | [diff] [blame] | 2779 | channel = ieee80211_frequency_to_channel(conf->channel->center_freq); |
| 2780 | ch_info = iwl_get_channel_info(priv, conf->channel->band, channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2781 | if (!is_channel_valid(ch_info)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2782 | IWL_DEBUG_MAC80211("leave - invalid channel\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 2783 | ret = -EINVAL; |
| 2784 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2785 | } |
| 2786 | |
Assaf Krauss | 398f9e7 | 2008-06-12 09:47:06 +0800 | [diff] [blame] | 2787 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS && |
| 2788 | !is_channel_ibss(ch_info)) { |
| 2789 | IWL_ERROR("channel %d in band %d not IBSS channel\n", |
| 2790 | conf->channel->hw_value, conf->channel->band); |
| 2791 | ret = -EINVAL; |
| 2792 | goto out; |
| 2793 | } |
| 2794 | |
Tomas Winkler | 82a66bb | 2008-05-29 16:35:28 +0800 | [diff] [blame] | 2795 | spin_lock_irqsave(&priv->lock, flags); |
| 2796 | |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 2797 | /* if we are switching from ht to 2.4 clear flags |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2798 | * from any ht related info since 2.4 does not |
| 2799 | * support ht */ |
Tomas Winkler | 82a66bb | 2008-05-29 16:35:28 +0800 | [diff] [blame] | 2800 | if ((le16_to_cpu(priv->staging_rxon.channel) != channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2801 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 2802 | && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) |
| 2803 | #endif |
| 2804 | ) |
| 2805 | priv->staging_rxon.flags = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2806 | |
Tomas Winkler | 82a66bb | 2008-05-29 16:35:28 +0800 | [diff] [blame] | 2807 | iwl_set_rxon_channel(priv, conf->channel->band, channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2808 | |
Tomas Winkler | 82a66bb | 2008-05-29 16:35:28 +0800 | [diff] [blame] | 2809 | iwl_set_flags_for_band(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2810 | |
| 2811 | /* The list of supported rates and rate mask can be different |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2812 | * for each band; since the band may have changed, reset |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2813 | * the rate mask to what mac80211 lists */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2814 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2815 | |
| 2816 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2817 | |
| 2818 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 2819 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2820 | iwl4965_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 2821 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2822 | } |
| 2823 | #endif |
| 2824 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2825 | if (!conf->radio_enabled) { |
| 2826 | IWL_DEBUG_MAC80211("leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 2827 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2828 | } |
| 2829 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 2830 | if (iwl_is_rfkill(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2831 | IWL_DEBUG_MAC80211("leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 2832 | ret = -EIO; |
| 2833 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2834 | } |
| 2835 | |
Tomas Winkler | 630fe9b | 2008-06-12 09:47:08 +0800 | [diff] [blame] | 2836 | IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n", |
| 2837 | priv->tx_power_user_lmt, conf->power_level); |
| 2838 | |
| 2839 | iwl_set_tx_power(priv, conf->power_level, false); |
| 2840 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2841 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2842 | |
| 2843 | if (memcmp(&priv->active_rxon, |
| 2844 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2845 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2846 | else |
| 2847 | IWL_DEBUG_INFO("No re-sending same RXON configuration.\n"); |
| 2848 | |
| 2849 | IWL_DEBUG_MAC80211("leave\n"); |
| 2850 | |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 2851 | out: |
| 2852 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2853 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 2854 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2855 | } |
| 2856 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2857 | static void iwl4965_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2858 | { |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2859 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2860 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 2861 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2862 | return; |
| 2863 | |
| 2864 | /* The following should be done only at AP bring up */ |
Ron Rindjunsky | 5d1e232 | 2008-06-30 17:23:04 +0800 | [diff] [blame] | 2865 | if (!(iwl_is_associated(priv))) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2866 | |
| 2867 | /* RXON - unassoc (to set timing command) */ |
| 2868 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2869 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2870 | |
| 2871 | /* RXON Timing */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2872 | memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd)); |
| 2873 | iwl4965_setup_rxon_timing(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2874 | ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2875 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2876 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2877 | IWL_WARNING("REPLY_RXON_TIMING failed - " |
| 2878 | "Attempting to continue.\n"); |
| 2879 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 2880 | iwl_set_rxon_chain(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2881 | |
| 2882 | /* FIXME: what should be the assoc_id for AP? */ |
| 2883 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
| 2884 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 2885 | priv->staging_rxon.flags |= |
| 2886 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2887 | else |
| 2888 | priv->staging_rxon.flags &= |
| 2889 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 2890 | |
| 2891 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
| 2892 | if (priv->assoc_capability & |
| 2893 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
| 2894 | priv->staging_rxon.flags |= |
| 2895 | RXON_FLG_SHORT_SLOT_MSK; |
| 2896 | else |
| 2897 | priv->staging_rxon.flags &= |
| 2898 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 2899 | |
| 2900 | if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) |
| 2901 | priv->staging_rxon.flags &= |
| 2902 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 2903 | } |
| 2904 | /* restore RXON assoc */ |
| 2905 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2906 | iwl4965_commit_rxon(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2907 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 2908 | iwl_rxon_add_station(priv, iwl_bcast_addr, 0); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 2909 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2910 | iwl4965_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2911 | |
| 2912 | /* FIXME - we need to add code here to detect a totally new |
| 2913 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 2914 | * clear sta table, add BCAST sta... */ |
| 2915 | } |
| 2916 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 2917 | static int iwl4965_mac_config_interface(struct ieee80211_hw *hw, |
| 2918 | struct ieee80211_vif *vif, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2919 | struct ieee80211_if_conf *conf) |
| 2920 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2921 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2922 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2923 | unsigned long flags; |
| 2924 | int rc; |
| 2925 | |
| 2926 | if (conf == NULL) |
| 2927 | return -EIO; |
| 2928 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 2929 | if (priv->vif != vif) { |
| 2930 | IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 2931 | return 0; |
| 2932 | } |
| 2933 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2934 | if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) && |
| 2935 | (!conf->beacon || !conf->ssid_len)) { |
| 2936 | IWL_DEBUG_MAC80211 |
| 2937 | ("Leaving in AP mode because HostAPD is not ready.\n"); |
| 2938 | return 0; |
| 2939 | } |
| 2940 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 2941 | if (!iwl_is_alive(priv)) |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2942 | return -EAGAIN; |
| 2943 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2944 | mutex_lock(&priv->mutex); |
| 2945 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2946 | if (conf->bssid) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2947 | IWL_DEBUG_MAC80211("bssid: %s\n", |
| 2948 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2949 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 2950 | /* |
| 2951 | * very dubious code was here; the probe filtering flag is never set: |
| 2952 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2953 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 2954 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 2955 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2956 | |
| 2957 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { |
| 2958 | if (!conf->bssid) { |
| 2959 | conf->bssid = priv->mac_addr; |
| 2960 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2961 | IWL_DEBUG_MAC80211("bssid was set to: %s\n", |
| 2962 | print_mac(mac, conf->bssid)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2963 | } |
| 2964 | if (priv->ibss_beacon) |
| 2965 | dev_kfree_skb(priv->ibss_beacon); |
| 2966 | |
| 2967 | priv->ibss_beacon = conf->beacon; |
| 2968 | } |
| 2969 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 2970 | if (iwl_is_rfkill(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 2971 | goto done; |
| 2972 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2973 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 2974 | !is_multicast_ether_addr(conf->bssid)) { |
| 2975 | /* If there is currently a HW scan going on in the background |
| 2976 | * then we need to cancel it else the RXON below will fail. */ |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 2977 | if (iwl_scan_cancel_timeout(priv, 100)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2978 | IWL_WARNING("Aborted scan still in progress " |
| 2979 | "after 100ms\n"); |
| 2980 | IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); |
| 2981 | mutex_unlock(&priv->mutex); |
| 2982 | return -EAGAIN; |
| 2983 | } |
| 2984 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
| 2985 | |
| 2986 | /* TODO: Audit driver for usage of these members and see |
| 2987 | * if mac80211 deprecates them (priv->bssid looks like it |
| 2988 | * shouldn't be there, but I haven't scanned the IBSS code |
| 2989 | * to verify) - jpk */ |
| 2990 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 2991 | |
| 2992 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2993 | iwl4965_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2994 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2995 | rc = iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2996 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 2997 | iwl_rxon_add_station( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2998 | priv, priv->active_rxon.bssid_addr, 1); |
| 2999 | } |
| 3000 | |
| 3001 | } else { |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 3002 | iwl_scan_cancel_timeout(priv, 100); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3003 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3004 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3005 | } |
| 3006 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 3007 | done: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3008 | spin_lock_irqsave(&priv->lock, flags); |
| 3009 | if (!conf->ssid_len) |
| 3010 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 3011 | else |
| 3012 | memcpy(priv->essid, conf->ssid, conf->ssid_len); |
| 3013 | |
| 3014 | priv->essid_len = conf->ssid_len; |
| 3015 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3016 | |
| 3017 | IWL_DEBUG_MAC80211("leave\n"); |
| 3018 | mutex_unlock(&priv->mutex); |
| 3019 | |
| 3020 | return 0; |
| 3021 | } |
| 3022 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3023 | static void iwl4965_configure_filter(struct ieee80211_hw *hw, |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 3024 | unsigned int changed_flags, |
| 3025 | unsigned int *total_flags, |
| 3026 | int mc_count, struct dev_addr_list *mc_list) |
| 3027 | { |
| 3028 | /* |
| 3029 | * XXX: dummy |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3030 | * see also iwl4965_connection_init_rx_config |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 3031 | */ |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 3032 | struct iwl_priv *priv = hw->priv; |
| 3033 | int new_flags = 0; |
| 3034 | if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { |
| 3035 | if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) { |
| 3036 | IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n", |
| 3037 | IEEE80211_IF_TYPE_MNTR, |
| 3038 | changed_flags, *total_flags); |
| 3039 | /* queue work 'cuz mac80211 is holding a lock which |
| 3040 | * prevents us from issuing (synchronous) f/w cmds */ |
| 3041 | queue_work(priv->workqueue, &priv->set_monitor); |
| 3042 | new_flags &= FIF_PROMISC_IN_BSS | |
| 3043 | FIF_OTHER_BSS | |
| 3044 | FIF_ALLMULTI; |
| 3045 | } |
| 3046 | } |
| 3047 | *total_flags = new_flags; |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 3048 | } |
| 3049 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3050 | static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3051 | struct ieee80211_if_init_conf *conf) |
| 3052 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3053 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3054 | |
| 3055 | IWL_DEBUG_MAC80211("enter\n"); |
| 3056 | |
| 3057 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 3058 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3059 | if (iwl_is_ready_rf(priv)) { |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 3060 | iwl_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 3061 | cancel_delayed_work(&priv->post_associate); |
| 3062 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 3063 | iwl4965_commit_rxon(priv); |
| 3064 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3065 | if (priv->vif == conf->vif) { |
| 3066 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3067 | memset(priv->bssid, 0, ETH_ALEN); |
| 3068 | memset(priv->essid, 0, IW_ESSID_MAX_SIZE); |
| 3069 | priv->essid_len = 0; |
| 3070 | } |
| 3071 | mutex_unlock(&priv->mutex); |
| 3072 | |
| 3073 | IWL_DEBUG_MAC80211("leave\n"); |
| 3074 | |
| 3075 | } |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 3076 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3077 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 3078 | static void iwl4965_bss_info_changed(struct ieee80211_hw *hw, |
| 3079 | struct ieee80211_vif *vif, |
| 3080 | struct ieee80211_bss_conf *bss_conf, |
| 3081 | u32 changes) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 3082 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3083 | struct iwl_priv *priv = hw->priv; |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 3084 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3085 | IWL_DEBUG_MAC80211("changes = 0x%X\n", changes); |
| 3086 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 3087 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3088 | IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n", |
| 3089 | bss_conf->use_short_preamble); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 3090 | if (bss_conf->use_short_preamble) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 3091 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3092 | else |
| 3093 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3094 | } |
| 3095 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 3096 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3097 | IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3098 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 3099 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
| 3100 | else |
| 3101 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
| 3102 | } |
| 3103 | |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 3104 | if (changes & BSS_CHANGED_HT) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3105 | IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 3106 | iwl4965_ht_conf(priv, bss_conf); |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 3107 | iwl_set_rxon_chain(priv); |
Tomas Winkler | 98952d5 | 2008-03-28 16:33:33 -0700 | [diff] [blame] | 3108 | } |
| 3109 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 3110 | if (changes & BSS_CHANGED_ASSOC) { |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3111 | IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc); |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3112 | /* This should never happen as this function should |
| 3113 | * never be called from interrupt context. */ |
| 3114 | if (WARN_ON_ONCE(in_interrupt())) |
| 3115 | return; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3116 | if (bss_conf->assoc) { |
| 3117 | priv->assoc_id = bss_conf->aid; |
| 3118 | priv->beacon_int = bss_conf->beacon_int; |
| 3119 | priv->timestamp = bss_conf->timestamp; |
| 3120 | priv->assoc_capability = bss_conf->assoc_capability; |
| 3121 | priv->next_scan_jiffies = jiffies + |
| 3122 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3123 | mutex_lock(&priv->mutex); |
| 3124 | iwl4965_post_associate(priv); |
| 3125 | mutex_unlock(&priv->mutex); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3126 | } else { |
| 3127 | priv->assoc_id = 0; |
| 3128 | IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc); |
| 3129 | } |
| 3130 | } else if (changes && iwl_is_associated(priv) && priv->assoc_id) { |
| 3131 | IWL_DEBUG_MAC80211("Associated Changes %d\n", changes); |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 3132 | iwl_send_rxon_assoc(priv); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 3133 | } |
| 3134 | |
Tomas Winkler | 220173b | 2007-10-16 00:50:25 +0200 | [diff] [blame] | 3135 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3136 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3137 | 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] | 3138 | { |
| 3139 | int rc = 0; |
| 3140 | unsigned long flags; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3141 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3142 | |
| 3143 | IWL_DEBUG_MAC80211("enter\n"); |
| 3144 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3145 | mutex_lock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3146 | spin_lock_irqsave(&priv->lock, flags); |
| 3147 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3148 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3149 | rc = -EIO; |
| 3150 | IWL_DEBUG_MAC80211("leave - not ready or exit pending\n"); |
| 3151 | goto out_unlock; |
| 3152 | } |
| 3153 | |
| 3154 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */ |
| 3155 | rc = -EIO; |
| 3156 | IWL_ERROR("ERROR: APs don't scan\n"); |
| 3157 | goto out_unlock; |
| 3158 | } |
| 3159 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3160 | /* we don't schedule scan within next_scan_jiffies period */ |
| 3161 | if (priv->next_scan_jiffies && |
| 3162 | time_after(priv->next_scan_jiffies, jiffies)) { |
| 3163 | rc = -EAGAIN; |
| 3164 | goto out_unlock; |
| 3165 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3166 | /* if we just finished scan ask for delay */ |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3167 | if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies + |
| 3168 | IWL_DELAY_NEXT_SCAN, jiffies)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3169 | rc = -EAGAIN; |
| 3170 | goto out_unlock; |
| 3171 | } |
| 3172 | if (len) { |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3173 | IWL_DEBUG_SCAN("direct scan for %s [%d]\n ", |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 3174 | iwl_escape_essid(ssid, len), (int)len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3175 | |
| 3176 | priv->one_direct_scan = 1; |
| 3177 | priv->direct_ssid_len = (u8) |
| 3178 | min((u8) len, (u8) IW_ESSID_MAX_SIZE); |
| 3179 | memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 3180 | } else |
| 3181 | priv->one_direct_scan = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3182 | |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 3183 | rc = iwl_scan_initiate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3184 | |
| 3185 | IWL_DEBUG_MAC80211("leave\n"); |
| 3186 | |
| 3187 | out_unlock: |
| 3188 | spin_unlock_irqrestore(&priv->lock, flags); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3189 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3190 | |
| 3191 | return rc; |
| 3192 | } |
| 3193 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 3194 | static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw, |
| 3195 | struct ieee80211_key_conf *keyconf, const u8 *addr, |
| 3196 | u32 iv32, u16 *phase1key) |
| 3197 | { |
| 3198 | struct iwl_priv *priv = hw->priv; |
| 3199 | u8 sta_id = IWL_INVALID_STATION; |
| 3200 | unsigned long flags; |
| 3201 | __le16 key_flags = 0; |
| 3202 | int i; |
| 3203 | DECLARE_MAC_BUF(mac); |
| 3204 | |
| 3205 | IWL_DEBUG_MAC80211("enter\n"); |
| 3206 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 3207 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 3208 | if (sta_id == IWL_INVALID_STATION) { |
| 3209 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 3210 | print_mac(mac, addr)); |
| 3211 | return; |
| 3212 | } |
| 3213 | |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 3214 | iwl_scan_cancel_timeout(priv, 100); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 3215 | |
| 3216 | key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK); |
| 3217 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 3218 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 3219 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3220 | if (sta_id == priv->hw_params.bcast_sta_id) |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 3221 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 3222 | |
| 3223 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 3224 | |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 3225 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 3226 | priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32; |
| 3227 | |
| 3228 | for (i = 0; i < 5; i++) |
| 3229 | priv->stations[sta_id].sta.key.tkip_rx_ttak[i] = |
| 3230 | cpu_to_le16(phase1key[i]); |
| 3231 | |
| 3232 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 3233 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3234 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 3235 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 3236 | |
| 3237 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 3238 | |
| 3239 | IWL_DEBUG_MAC80211("leave\n"); |
| 3240 | } |
| 3241 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3242 | 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] | 3243 | const u8 *local_addr, const u8 *addr, |
| 3244 | struct ieee80211_key_conf *key) |
| 3245 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3246 | struct iwl_priv *priv = hw->priv; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3247 | DECLARE_MAC_BUF(mac); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3248 | int ret = 0; |
| 3249 | u8 sta_id = IWL_INVALID_STATION; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3250 | u8 is_default_wep_key = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3251 | |
| 3252 | IWL_DEBUG_MAC80211("enter\n"); |
| 3253 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 3254 | if (priv->hw_params.sw_crypto) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3255 | IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); |
| 3256 | return -EOPNOTSUPP; |
| 3257 | } |
| 3258 | |
| 3259 | if (is_zero_ether_addr(addr)) |
| 3260 | /* only support pairwise keys */ |
| 3261 | return -EOPNOTSUPP; |
| 3262 | |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 3263 | sta_id = iwl_find_station(priv, addr); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3264 | if (sta_id == IWL_INVALID_STATION) { |
| 3265 | IWL_DEBUG_MAC80211("leave - %s not in station map.\n", |
| 3266 | print_mac(mac, addr)); |
| 3267 | return -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3268 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3269 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3270 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3271 | mutex_lock(&priv->mutex); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 3272 | iwl_scan_cancel_timeout(priv, 100); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3273 | mutex_unlock(&priv->mutex); |
| 3274 | |
| 3275 | /* If we are getting WEP group key and we didn't receive any key mapping |
| 3276 | * so far, we are in legacy wep mode (group key only), otherwise we are |
| 3277 | * in 1X mode. |
| 3278 | * In legacy wep mode, we use another host command to the uCode */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3279 | 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] | 3280 | priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
| 3281 | if (cmd == SET_KEY) |
| 3282 | is_default_wep_key = !priv->key_mapping_key; |
| 3283 | else |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 3284 | is_default_wep_key = |
| 3285 | (key->hw_key_idx == HW_KEY_DEFAULT); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3286 | } |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3287 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3288 | switch (cmd) { |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3289 | case SET_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3290 | if (is_default_wep_key) |
| 3291 | ret = iwl_set_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3292 | else |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 3293 | ret = iwl_set_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3294 | |
| 3295 | IWL_DEBUG_MAC80211("enable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3296 | break; |
| 3297 | case DISABLE_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3298 | if (is_default_wep_key) |
| 3299 | ret = iwl_remove_default_wep_key(priv, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3300 | else |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 3301 | ret = iwl_remove_dynamic_key(priv, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3302 | |
| 3303 | IWL_DEBUG_MAC80211("disable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3304 | break; |
| 3305 | default: |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3306 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3307 | } |
| 3308 | |
| 3309 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3310 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3311 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 3314 | static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3315 | const struct ieee80211_tx_queue_params *params) |
| 3316 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3317 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3318 | unsigned long flags; |
| 3319 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3320 | |
| 3321 | IWL_DEBUG_MAC80211("enter\n"); |
| 3322 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3323 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3324 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 3325 | return -EIO; |
| 3326 | } |
| 3327 | |
| 3328 | if (queue >= AC_NUM) { |
| 3329 | IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue); |
| 3330 | return 0; |
| 3331 | } |
| 3332 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3333 | if (!priv->qos_data.qos_enable) { |
| 3334 | priv->qos_data.qos_active = 0; |
| 3335 | IWL_DEBUG_MAC80211("leave - qos not enabled\n"); |
| 3336 | return 0; |
| 3337 | } |
| 3338 | q = AC_NUM - 1 - queue; |
| 3339 | |
| 3340 | spin_lock_irqsave(&priv->lock, flags); |
| 3341 | |
| 3342 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 3343 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 3344 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 3345 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 3346 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3347 | |
| 3348 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 3349 | priv->qos_data.qos_active = 1; |
| 3350 | |
| 3351 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3352 | |
| 3353 | mutex_lock(&priv->mutex); |
| 3354 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3355 | iwl4965_activate_qos(priv, 1); |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3356 | else if (priv->assoc_id && iwl_is_associated(priv)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3357 | iwl4965_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3358 | |
| 3359 | mutex_unlock(&priv->mutex); |
| 3360 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3361 | IWL_DEBUG_MAC80211("leave\n"); |
| 3362 | return 0; |
| 3363 | } |
| 3364 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3365 | static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3366 | struct ieee80211_tx_queue_stats *stats) |
| 3367 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3368 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3369 | int i, avail; |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 3370 | struct iwl_tx_queue *txq; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 3371 | struct iwl_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3372 | unsigned long flags; |
| 3373 | |
| 3374 | IWL_DEBUG_MAC80211("enter\n"); |
| 3375 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3376 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3377 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 3378 | return -EIO; |
| 3379 | } |
| 3380 | |
| 3381 | spin_lock_irqsave(&priv->lock, flags); |
| 3382 | |
| 3383 | for (i = 0; i < AC_NUM; i++) { |
| 3384 | txq = &priv->txq[i]; |
| 3385 | q = &txq->q; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 3386 | avail = iwl_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3387 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 3388 | stats[i].len = q->n_window - avail; |
| 3389 | stats[i].limit = q->n_window - q->high_mark; |
| 3390 | stats[i].count = q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3391 | |
| 3392 | } |
| 3393 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3394 | |
| 3395 | IWL_DEBUG_MAC80211("leave\n"); |
| 3396 | |
| 3397 | return 0; |
| 3398 | } |
| 3399 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3400 | static int iwl4965_mac_get_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3401 | struct ieee80211_low_level_stats *stats) |
| 3402 | { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 3403 | struct iwl_priv *priv = hw->priv; |
| 3404 | |
| 3405 | priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3406 | IWL_DEBUG_MAC80211("enter\n"); |
| 3407 | IWL_DEBUG_MAC80211("leave\n"); |
| 3408 | |
| 3409 | return 0; |
| 3410 | } |
| 3411 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3412 | static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3413 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3414 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3415 | unsigned long flags; |
| 3416 | |
| 3417 | mutex_lock(&priv->mutex); |
| 3418 | IWL_DEBUG_MAC80211("enter\n"); |
| 3419 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3420 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 3421 | memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3422 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3423 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 3424 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3425 | |
| 3426 | cancel_delayed_work(&priv->post_associate); |
| 3427 | |
| 3428 | spin_lock_irqsave(&priv->lock, flags); |
| 3429 | priv->assoc_id = 0; |
| 3430 | priv->assoc_capability = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3431 | priv->assoc_station_added = 0; |
| 3432 | |
| 3433 | /* new association get rid of ibss beacon skb */ |
| 3434 | if (priv->ibss_beacon) |
| 3435 | dev_kfree_skb(priv->ibss_beacon); |
| 3436 | |
| 3437 | priv->ibss_beacon = NULL; |
| 3438 | |
| 3439 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3440 | priv->timestamp = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3441 | if ((priv->iw_mode == IEEE80211_IF_TYPE_STA)) |
| 3442 | priv->beacon_int = 0; |
| 3443 | |
| 3444 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3445 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3446 | if (!iwl_is_ready_rf(priv)) { |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 3447 | IWL_DEBUG_MAC80211("leave - not ready\n"); |
| 3448 | mutex_unlock(&priv->mutex); |
| 3449 | return; |
| 3450 | } |
| 3451 | |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3452 | /* we are restarting association process |
| 3453 | * clear RXON_FILTER_ASSOC_MSK bit |
| 3454 | */ |
| 3455 | if (priv->iw_mode != IEEE80211_IF_TYPE_AP) { |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 3456 | iwl_scan_cancel_timeout(priv, 100); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3457 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3458 | iwl4965_commit_rxon(priv); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3459 | } |
| 3460 | |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 3461 | iwl_power_update_mode(priv, 0); |
| 3462 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3463 | /* Per mac80211.h: This is only used in IBSS mode... */ |
| 3464 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3465 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3466 | IWL_DEBUG_MAC80211("leave - not in IBSS\n"); |
| 3467 | mutex_unlock(&priv->mutex); |
| 3468 | return; |
| 3469 | } |
| 3470 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3471 | iwl4965_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3472 | |
| 3473 | mutex_unlock(&priv->mutex); |
| 3474 | |
| 3475 | IWL_DEBUG_MAC80211("leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3476 | } |
| 3477 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 3478 | 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] | 3479 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3480 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3481 | unsigned long flags; |
Assaf Krauss | 2ff75b7 | 2008-06-30 17:23:17 +0800 | [diff] [blame] | 3482 | __le64 timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3483 | |
| 3484 | mutex_lock(&priv->mutex); |
| 3485 | IWL_DEBUG_MAC80211("enter\n"); |
| 3486 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3487 | if (!iwl_is_ready_rf(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3488 | IWL_DEBUG_MAC80211("leave - RF not ready\n"); |
| 3489 | mutex_unlock(&priv->mutex); |
| 3490 | return -EIO; |
| 3491 | } |
| 3492 | |
| 3493 | if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) { |
| 3494 | IWL_DEBUG_MAC80211("leave - not IBSS\n"); |
| 3495 | mutex_unlock(&priv->mutex); |
| 3496 | return -EIO; |
| 3497 | } |
| 3498 | |
| 3499 | spin_lock_irqsave(&priv->lock, flags); |
| 3500 | |
| 3501 | if (priv->ibss_beacon) |
| 3502 | dev_kfree_skb(priv->ibss_beacon); |
| 3503 | |
| 3504 | priv->ibss_beacon = skb; |
| 3505 | |
| 3506 | priv->assoc_id = 0; |
Assaf Krauss | 2ff75b7 | 2008-06-30 17:23:17 +0800 | [diff] [blame] | 3507 | timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp; |
| 3508 | priv->timestamp = le64_to_cpu(timestamp) + (priv->beacon_int * 1000); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3509 | |
| 3510 | IWL_DEBUG_MAC80211("leave\n"); |
| 3511 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3512 | |
Ron Rindjunsky | c7de35c | 2008-04-23 17:15:05 -0700 | [diff] [blame] | 3513 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3514 | |
Assaf Krauss | c46fbef | 2008-06-12 09:47:05 +0800 | [diff] [blame] | 3515 | iwl4965_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3516 | |
| 3517 | mutex_unlock(&priv->mutex); |
| 3518 | |
| 3519 | return 0; |
| 3520 | } |
| 3521 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3522 | /***************************************************************************** |
| 3523 | * |
| 3524 | * sysfs attributes |
| 3525 | * |
| 3526 | *****************************************************************************/ |
| 3527 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3528 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3529 | |
| 3530 | /* |
| 3531 | * The following adds a new attribute to the sysfs representation |
| 3532 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 3533 | * used for controlling the debug level. |
| 3534 | * |
| 3535 | * See the level definitions in iwl for details. |
| 3536 | */ |
| 3537 | |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 3538 | static ssize_t show_debug_level(struct device *d, |
| 3539 | struct device_attribute *attr, char *buf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3540 | { |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 3541 | struct iwl_priv *priv = d->driver_data; |
| 3542 | |
| 3543 | return sprintf(buf, "0x%08X\n", priv->debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3544 | } |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 3545 | static ssize_t store_debug_level(struct device *d, |
| 3546 | struct device_attribute *attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3547 | const char *buf, size_t count) |
| 3548 | { |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 3549 | struct iwl_priv *priv = d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3550 | char *p = (char *)buf; |
| 3551 | u32 val; |
| 3552 | |
| 3553 | val = simple_strtoul(p, &p, 0); |
| 3554 | if (p == buf) |
| 3555 | printk(KERN_INFO DRV_NAME |
| 3556 | ": %s is not in hex or decimal form.\n", buf); |
| 3557 | else |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 3558 | priv->debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3559 | |
| 3560 | return strnlen(buf, count); |
| 3561 | } |
| 3562 | |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 3563 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 3564 | show_debug_level, store_debug_level); |
| 3565 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3566 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3567 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3568 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3569 | |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 3570 | static ssize_t show_version(struct device *d, |
| 3571 | struct device_attribute *attr, char *buf) |
| 3572 | { |
| 3573 | struct iwl_priv *priv = d->driver_data; |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 3574 | struct iwl_alive_resp *palive = &priv->card_alive; |
Tomas Winkler | f236a26 | 2008-06-30 17:23:02 +0800 | [diff] [blame] | 3575 | ssize_t pos = 0; |
| 3576 | u16 eeprom_ver; |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 3577 | |
| 3578 | if (palive->is_valid) |
Tomas Winkler | f236a26 | 2008-06-30 17:23:02 +0800 | [diff] [blame] | 3579 | pos += sprintf(buf + pos, |
| 3580 | "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n" |
| 3581 | "fw type: 0x%01X 0x%01X\n", |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 3582 | palive->ucode_major, palive->ucode_minor, |
| 3583 | palive->sw_rev[0], palive->sw_rev[1], |
| 3584 | palive->ver_type, palive->ver_subtype); |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 3585 | else |
Tomas Winkler | f236a26 | 2008-06-30 17:23:02 +0800 | [diff] [blame] | 3586 | pos += sprintf(buf + pos, "fw not loaded\n"); |
| 3587 | |
| 3588 | if (priv->eeprom) { |
| 3589 | eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION); |
| 3590 | pos += sprintf(buf + pos, "EEPROM version: 0x%x\n", |
| 3591 | eeprom_ver); |
| 3592 | } else { |
| 3593 | pos += sprintf(buf + pos, "EEPROM not initialzed\n"); |
| 3594 | } |
| 3595 | |
| 3596 | return pos; |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 3597 | } |
| 3598 | |
| 3599 | static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL); |
| 3600 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3601 | static ssize_t show_temperature(struct device *d, |
| 3602 | struct device_attribute *attr, char *buf) |
| 3603 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3604 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3605 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3606 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3607 | return -EAGAIN; |
| 3608 | |
Emmanuel Grumbach | 91dbc5b | 2008-06-12 09:47:14 +0800 | [diff] [blame] | 3609 | return sprintf(buf, "%d\n", priv->temperature); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3610 | } |
| 3611 | |
| 3612 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 3613 | |
| 3614 | static ssize_t show_rs_window(struct device *d, |
| 3615 | struct device_attribute *attr, |
| 3616 | char *buf) |
| 3617 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3618 | struct iwl_priv *priv = d->driver_data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3619 | return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3620 | } |
| 3621 | static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL); |
| 3622 | |
| 3623 | static ssize_t show_tx_power(struct device *d, |
| 3624 | struct device_attribute *attr, char *buf) |
| 3625 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3626 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Tomas Winkler | 630fe9b | 2008-06-12 09:47:08 +0800 | [diff] [blame] | 3627 | return sprintf(buf, "%d\n", priv->tx_power_user_lmt); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3628 | } |
| 3629 | |
| 3630 | static ssize_t store_tx_power(struct device *d, |
| 3631 | struct device_attribute *attr, |
| 3632 | const char *buf, size_t count) |
| 3633 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3634 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3635 | char *p = (char *)buf; |
| 3636 | u32 val; |
| 3637 | |
| 3638 | val = simple_strtoul(p, &p, 10); |
| 3639 | if (p == buf) |
| 3640 | printk(KERN_INFO DRV_NAME |
| 3641 | ": %s is not in decimal form.\n", buf); |
| 3642 | else |
Tomas Winkler | 630fe9b | 2008-06-12 09:47:08 +0800 | [diff] [blame] | 3643 | iwl_set_tx_power(priv, val, false); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3644 | |
| 3645 | return count; |
| 3646 | } |
| 3647 | |
| 3648 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 3649 | |
| 3650 | static ssize_t show_flags(struct device *d, |
| 3651 | struct device_attribute *attr, char *buf) |
| 3652 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3653 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3654 | |
| 3655 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
| 3656 | } |
| 3657 | |
| 3658 | static ssize_t store_flags(struct device *d, |
| 3659 | struct device_attribute *attr, |
| 3660 | const char *buf, size_t count) |
| 3661 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3662 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3663 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 3664 | |
| 3665 | mutex_lock(&priv->mutex); |
| 3666 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
| 3667 | /* Cancel any currently running scans... */ |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 3668 | if (iwl_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3669 | IWL_WARNING("Could not cancel scan.\n"); |
| 3670 | else { |
| 3671 | IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n", |
| 3672 | flags); |
| 3673 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3674 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3675 | } |
| 3676 | } |
| 3677 | mutex_unlock(&priv->mutex); |
| 3678 | |
| 3679 | return count; |
| 3680 | } |
| 3681 | |
| 3682 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 3683 | |
| 3684 | static ssize_t show_filter_flags(struct device *d, |
| 3685 | struct device_attribute *attr, char *buf) |
| 3686 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3687 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3688 | |
| 3689 | return sprintf(buf, "0x%04X\n", |
| 3690 | le32_to_cpu(priv->active_rxon.filter_flags)); |
| 3691 | } |
| 3692 | |
| 3693 | static ssize_t store_filter_flags(struct device *d, |
| 3694 | struct device_attribute *attr, |
| 3695 | const char *buf, size_t count) |
| 3696 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3697 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3698 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 3699 | |
| 3700 | mutex_lock(&priv->mutex); |
| 3701 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
| 3702 | /* Cancel any currently running scans... */ |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 3703 | if (iwl_scan_cancel_timeout(priv, 100)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3704 | IWL_WARNING("Could not cancel scan.\n"); |
| 3705 | else { |
| 3706 | IWL_DEBUG_INFO("Committing rxon.filter_flags = " |
| 3707 | "0x%04X\n", filter_flags); |
| 3708 | priv->staging_rxon.filter_flags = |
| 3709 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3710 | iwl4965_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3711 | } |
| 3712 | } |
| 3713 | mutex_unlock(&priv->mutex); |
| 3714 | |
| 3715 | return count; |
| 3716 | } |
| 3717 | |
| 3718 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 3719 | store_filter_flags); |
| 3720 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3721 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3722 | |
| 3723 | static ssize_t show_measurement(struct device *d, |
| 3724 | struct device_attribute *attr, char *buf) |
| 3725 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3726 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3727 | struct iwl4965_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3728 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
| 3729 | u8 *data = (u8 *) & measure_report; |
| 3730 | unsigned long flags; |
| 3731 | |
| 3732 | spin_lock_irqsave(&priv->lock, flags); |
| 3733 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 3734 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3735 | return 0; |
| 3736 | } |
| 3737 | memcpy(&measure_report, &priv->measure_report, size); |
| 3738 | priv->measurement_status = 0; |
| 3739 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3740 | |
| 3741 | while (size && (PAGE_SIZE - len)) { |
| 3742 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 3743 | PAGE_SIZE - len, 1); |
| 3744 | len = strlen(buf); |
| 3745 | if (PAGE_SIZE - len) |
| 3746 | buf[len++] = '\n'; |
| 3747 | |
| 3748 | ofs += 16; |
| 3749 | size -= min(size, 16U); |
| 3750 | } |
| 3751 | |
| 3752 | return len; |
| 3753 | } |
| 3754 | |
| 3755 | static ssize_t store_measurement(struct device *d, |
| 3756 | struct device_attribute *attr, |
| 3757 | const char *buf, size_t count) |
| 3758 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3759 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3760 | struct ieee80211_measurement_params params = { |
| 3761 | .channel = le16_to_cpu(priv->active_rxon.channel), |
| 3762 | .start_time = cpu_to_le64(priv->last_tsf), |
| 3763 | .duration = cpu_to_le16(1), |
| 3764 | }; |
| 3765 | u8 type = IWL_MEASURE_BASIC; |
| 3766 | u8 buffer[32]; |
| 3767 | u8 channel; |
| 3768 | |
| 3769 | if (count) { |
| 3770 | char *p = buffer; |
| 3771 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 3772 | channel = simple_strtoul(p, NULL, 0); |
| 3773 | if (channel) |
| 3774 | params.channel = channel; |
| 3775 | |
| 3776 | p = buffer; |
| 3777 | while (*p && *p != ' ') |
| 3778 | p++; |
| 3779 | if (*p) |
| 3780 | type = simple_strtoul(p + 1, NULL, 0); |
| 3781 | } |
| 3782 | |
| 3783 | IWL_DEBUG_INFO("Invoking measurement of type %d on " |
| 3784 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3785 | iwl4965_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3786 | |
| 3787 | return count; |
| 3788 | } |
| 3789 | |
| 3790 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 3791 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3792 | #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3793 | |
| 3794 | static ssize_t store_retry_rate(struct device *d, |
| 3795 | struct device_attribute *attr, |
| 3796 | const char *buf, size_t count) |
| 3797 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3798 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3799 | |
| 3800 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 3801 | if (priv->retry_rate <= 0) |
| 3802 | priv->retry_rate = 1; |
| 3803 | |
| 3804 | return count; |
| 3805 | } |
| 3806 | |
| 3807 | static ssize_t show_retry_rate(struct device *d, |
| 3808 | struct device_attribute *attr, char *buf) |
| 3809 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3810 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3811 | return sprintf(buf, "%d", priv->retry_rate); |
| 3812 | } |
| 3813 | |
| 3814 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 3815 | store_retry_rate); |
| 3816 | |
| 3817 | static ssize_t store_power_level(struct device *d, |
| 3818 | struct device_attribute *attr, |
| 3819 | const char *buf, size_t count) |
| 3820 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3821 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3822 | int rc; |
| 3823 | int mode; |
| 3824 | |
| 3825 | mode = simple_strtoul(buf, NULL, 0); |
| 3826 | mutex_lock(&priv->mutex); |
| 3827 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3828 | if (!iwl_is_ready(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3829 | rc = -EAGAIN; |
| 3830 | goto out; |
| 3831 | } |
| 3832 | |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 3833 | rc = iwl_power_set_user_mode(priv, mode); |
| 3834 | if (rc) { |
| 3835 | IWL_DEBUG_MAC80211("failed setting power mode.\n"); |
| 3836 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3837 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3838 | rc = count; |
| 3839 | |
| 3840 | out: |
| 3841 | mutex_unlock(&priv->mutex); |
| 3842 | return rc; |
| 3843 | } |
| 3844 | |
| 3845 | #define MAX_WX_STRING 80 |
| 3846 | |
| 3847 | /* Values are in microsecond */ |
| 3848 | static const s32 timeout_duration[] = { |
| 3849 | 350000, |
| 3850 | 250000, |
| 3851 | 75000, |
| 3852 | 37000, |
| 3853 | 25000, |
| 3854 | }; |
| 3855 | static const s32 period_duration[] = { |
| 3856 | 400000, |
| 3857 | 700000, |
| 3858 | 1000000, |
| 3859 | 1000000, |
| 3860 | 1000000 |
| 3861 | }; |
| 3862 | |
| 3863 | static ssize_t show_power_level(struct device *d, |
| 3864 | struct device_attribute *attr, char *buf) |
| 3865 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3866 | struct iwl_priv *priv = dev_get_drvdata(d); |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 3867 | int level = priv->power_data.power_mode; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3868 | char *p = buf; |
| 3869 | |
| 3870 | p += sprintf(p, "%d ", level); |
| 3871 | switch (level) { |
| 3872 | case IWL_POWER_MODE_CAM: |
| 3873 | case IWL_POWER_AC: |
| 3874 | p += sprintf(p, "(AC)"); |
| 3875 | break; |
| 3876 | case IWL_POWER_BATTERY: |
| 3877 | p += sprintf(p, "(BATTERY)"); |
| 3878 | break; |
| 3879 | default: |
| 3880 | p += sprintf(p, |
| 3881 | "(Timeout %dms, Period %dms)", |
| 3882 | timeout_duration[level - 1] / 1000, |
| 3883 | period_duration[level - 1] / 1000); |
| 3884 | } |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 3885 | /* |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3886 | if (!(priv->power_mode & IWL_POWER_ENABLED)) |
| 3887 | p += sprintf(p, " OFF\n"); |
| 3888 | else |
| 3889 | p += sprintf(p, " \n"); |
Mohamed Abbas | 5da4b55f | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 3890 | */ |
| 3891 | p += sprintf(p, " \n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3892 | return (p - buf + 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3893 | } |
| 3894 | |
| 3895 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level, |
| 3896 | store_power_level); |
| 3897 | |
| 3898 | static ssize_t show_channels(struct device *d, |
| 3899 | struct device_attribute *attr, char *buf) |
| 3900 | { |
Ester Kummer | 5d72a1f | 2008-06-13 15:44:53 +0800 | [diff] [blame] | 3901 | |
| 3902 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 3903 | struct ieee80211_channel *channels = NULL; |
| 3904 | const struct ieee80211_supported_band *supp_band = NULL; |
| 3905 | int len = 0, i; |
| 3906 | int count = 0; |
| 3907 | |
| 3908 | if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status)) |
| 3909 | return -EAGAIN; |
| 3910 | |
| 3911 | supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ); |
| 3912 | channels = supp_band->channels; |
| 3913 | count = supp_band->n_channels; |
| 3914 | |
| 3915 | len += sprintf(&buf[len], |
| 3916 | "Displaying %d channels in 2.4GHz band " |
| 3917 | "(802.11bg):\n", count); |
| 3918 | |
| 3919 | for (i = 0; i < count; i++) |
| 3920 | len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n", |
| 3921 | ieee80211_frequency_to_channel( |
| 3922 | channels[i].center_freq), |
| 3923 | channels[i].max_power, |
| 3924 | channels[i].flags & IEEE80211_CHAN_RADAR ? |
| 3925 | " (IEEE 802.11h required)" : "", |
| 3926 | (!(channels[i].flags & IEEE80211_CHAN_NO_IBSS) |
| 3927 | || (channels[i].flags & |
| 3928 | IEEE80211_CHAN_RADAR)) ? "" : |
| 3929 | ", IBSS", |
| 3930 | channels[i].flags & |
| 3931 | IEEE80211_CHAN_PASSIVE_SCAN ? |
| 3932 | "passive only" : "active/passive"); |
| 3933 | |
| 3934 | supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ); |
| 3935 | channels = supp_band->channels; |
| 3936 | count = supp_band->n_channels; |
| 3937 | |
| 3938 | len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band " |
| 3939 | "(802.11a):\n", count); |
| 3940 | |
| 3941 | for (i = 0; i < count; i++) |
| 3942 | len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n", |
| 3943 | ieee80211_frequency_to_channel( |
| 3944 | channels[i].center_freq), |
| 3945 | channels[i].max_power, |
| 3946 | channels[i].flags & IEEE80211_CHAN_RADAR ? |
| 3947 | " (IEEE 802.11h required)" : "", |
| 3948 | ((channels[i].flags & IEEE80211_CHAN_NO_IBSS) |
| 3949 | || (channels[i].flags & |
| 3950 | IEEE80211_CHAN_RADAR)) ? "" : |
| 3951 | ", IBSS", |
| 3952 | channels[i].flags & |
| 3953 | IEEE80211_CHAN_PASSIVE_SCAN ? |
| 3954 | "passive only" : "active/passive"); |
| 3955 | |
| 3956 | return len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3957 | } |
| 3958 | |
| 3959 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 3960 | |
| 3961 | static ssize_t show_statistics(struct device *d, |
| 3962 | struct device_attribute *attr, char *buf) |
| 3963 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3964 | struct iwl_priv *priv = dev_get_drvdata(d); |
Emmanuel Grumbach | 8f91aec | 2008-06-30 17:23:07 +0800 | [diff] [blame] | 3965 | u32 size = sizeof(struct iwl_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3966 | u32 len = 0, ofs = 0; |
| 3967 | u8 *data = (u8 *) & priv->statistics; |
| 3968 | int rc = 0; |
| 3969 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 3970 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3971 | return -EAGAIN; |
| 3972 | |
| 3973 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 3974 | rc = iwl_send_statistics_request(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3975 | mutex_unlock(&priv->mutex); |
| 3976 | |
| 3977 | if (rc) { |
| 3978 | len = sprintf(buf, |
| 3979 | "Error sending statistics request: 0x%08X\n", rc); |
| 3980 | return len; |
| 3981 | } |
| 3982 | |
| 3983 | while (size && (PAGE_SIZE - len)) { |
| 3984 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 3985 | PAGE_SIZE - len, 1); |
| 3986 | len = strlen(buf); |
| 3987 | if (PAGE_SIZE - len) |
| 3988 | buf[len++] = '\n'; |
| 3989 | |
| 3990 | ofs += 16; |
| 3991 | size -= min(size, 16U); |
| 3992 | } |
| 3993 | |
| 3994 | return len; |
| 3995 | } |
| 3996 | |
| 3997 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 3998 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3999 | static ssize_t show_status(struct device *d, |
| 4000 | struct device_attribute *attr, char *buf) |
| 4001 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4002 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 4003 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4004 | return -EAGAIN; |
| 4005 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 4006 | } |
| 4007 | |
| 4008 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 4009 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4010 | /***************************************************************************** |
| 4011 | * |
| 4012 | * driver setup and teardown |
| 4013 | * |
| 4014 | *****************************************************************************/ |
| 4015 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 4016 | static void iwl_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4017 | { |
| 4018 | priv->workqueue = create_workqueue(DRV_NAME); |
| 4019 | |
| 4020 | init_waitqueue_head(&priv->wait_command_queue); |
| 4021 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4022 | INIT_WORK(&priv->up, iwl4965_bg_up); |
| 4023 | INIT_WORK(&priv->restart, iwl4965_bg_restart); |
| 4024 | INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4025 | INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill); |
| 4026 | INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update); |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 4027 | INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor); |
Emmanuel Grumbach | 16e727e | 2008-06-12 09:46:52 +0800 | [diff] [blame] | 4028 | 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] | 4029 | INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate); |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 4030 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start); |
| 4031 | INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 4032 | |
| 4033 | /* FIXME : remove when resolved PENDING */ |
| 4034 | INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed); |
| 4035 | iwl_setup_scan_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4036 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 4037 | if (priv->cfg->ops->lib->setup_deferred_work) |
| 4038 | priv->cfg->ops->lib->setup_deferred_work(priv); |
| 4039 | |
| 4040 | init_timer(&priv->statistics_periodic); |
| 4041 | priv->statistics_periodic.data = (unsigned long)priv; |
| 4042 | priv->statistics_periodic.function = iwl4965_bg_statistics_periodic; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4043 | |
| 4044 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4045 | iwl4965_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4046 | } |
| 4047 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 4048 | static void iwl_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4049 | { |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 4050 | if (priv->cfg->ops->lib->cancel_deferred_work) |
| 4051 | priv->cfg->ops->lib->cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4052 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 4053 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4054 | cancel_delayed_work(&priv->scan_check); |
| 4055 | cancel_delayed_work(&priv->alive_start); |
| 4056 | cancel_delayed_work(&priv->post_associate); |
| 4057 | cancel_work_sync(&priv->beacon_update); |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 4058 | del_timer_sync(&priv->statistics_periodic); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4059 | } |
| 4060 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4061 | static struct attribute *iwl4965_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4062 | &dev_attr_channels.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4063 | &dev_attr_flags.attr, |
| 4064 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4065 | #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4066 | &dev_attr_measurement.attr, |
| 4067 | #endif |
| 4068 | &dev_attr_power_level.attr, |
| 4069 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4070 | &dev_attr_rs_window.attr, |
| 4071 | &dev_attr_statistics.attr, |
| 4072 | &dev_attr_status.attr, |
| 4073 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4074 | &dev_attr_tx_power.attr, |
Ester Kummer | 8cf769c | 2008-05-06 11:05:11 +0800 | [diff] [blame] | 4075 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 4076 | &dev_attr_debug_level.attr, |
| 4077 | #endif |
Tomas Winkler | bc6f59b | 2008-05-06 11:05:13 +0800 | [diff] [blame] | 4078 | &dev_attr_version.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4079 | |
| 4080 | NULL |
| 4081 | }; |
| 4082 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4083 | static struct attribute_group iwl4965_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4084 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4085 | .attrs = iwl4965_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4086 | }; |
| 4087 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4088 | static struct ieee80211_ops iwl4965_hw_ops = { |
| 4089 | .tx = iwl4965_mac_tx, |
| 4090 | .start = iwl4965_mac_start, |
| 4091 | .stop = iwl4965_mac_stop, |
| 4092 | .add_interface = iwl4965_mac_add_interface, |
| 4093 | .remove_interface = iwl4965_mac_remove_interface, |
| 4094 | .config = iwl4965_mac_config, |
| 4095 | .config_interface = iwl4965_mac_config_interface, |
| 4096 | .configure_filter = iwl4965_configure_filter, |
| 4097 | .set_key = iwl4965_mac_set_key, |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 4098 | .update_tkip_key = iwl4965_mac_update_tkip_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4099 | .get_stats = iwl4965_mac_get_stats, |
| 4100 | .get_tx_stats = iwl4965_mac_get_tx_stats, |
| 4101 | .conf_tx = iwl4965_mac_conf_tx, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4102 | .reset_tsf = iwl4965_mac_reset_tsf, |
| 4103 | .beacon_update = iwl4965_mac_beacon_update, |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 4104 | .bss_info_changed = iwl4965_bss_info_changed, |
Ron Rindjunsky | 9ab4617 | 2007-12-25 17:00:38 +0200 | [diff] [blame] | 4105 | .ampdu_action = iwl4965_mac_ampdu_action, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4106 | .hw_scan = iwl4965_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4107 | }; |
| 4108 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4109 | 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] | 4110 | { |
| 4111 | int err = 0; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4112 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4113 | struct ieee80211_hw *hw; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4114 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4115 | unsigned long flags; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4116 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4117 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4118 | /************************ |
| 4119 | * 1. Allocating HW data |
| 4120 | ************************/ |
| 4121 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4122 | /* Disabling hardware scan means that mac80211 will perform scans |
| 4123 | * "the hard way", rather than using device's scan. */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 4124 | if (cfg->mod_params->disable_hw_scan) { |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 4125 | if (cfg->mod_params->debug & IWL_DL_INFO) |
| 4126 | dev_printk(KERN_DEBUG, &(pdev->dev), |
| 4127 | "Disabling hw_scan\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4128 | iwl4965_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4129 | } |
| 4130 | |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 4131 | hw = iwl_alloc_all(cfg, &iwl4965_hw_ops); |
| 4132 | if (!hw) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4133 | err = -ENOMEM; |
| 4134 | goto out; |
| 4135 | } |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 4136 | priv = hw->priv; |
| 4137 | /* At this point both hw and priv are allocated. */ |
| 4138 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4139 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 4140 | |
| 4141 | IWL_DEBUG_INFO("*** LOAD DRIVER ***\n"); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4142 | priv->cfg = cfg; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4143 | priv->pci_dev = pdev; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4144 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 4145 | #ifdef CONFIG_IWLWIFI_DEBUG |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 4146 | priv->debug_level = priv->cfg->mod_params->debug; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4147 | atomic_set(&priv->restrict_refcnt, 0); |
| 4148 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4149 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4150 | /************************** |
| 4151 | * 2. Initializing PCI bus |
| 4152 | **************************/ |
| 4153 | if (pci_enable_device(pdev)) { |
| 4154 | err = -ENODEV; |
| 4155 | goto out_ieee80211_free_hw; |
| 4156 | } |
| 4157 | |
| 4158 | pci_set_master(pdev); |
| 4159 | |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 4160 | err = pci_set_dma_mask(pdev, DMA_64BIT_MASK); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4161 | if (!err) |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 4162 | err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK); |
| 4163 | if (err) { |
| 4164 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 4165 | if (!err) |
| 4166 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 4167 | /* both attempts failed: */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4168 | if (err) { |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 4169 | printk(KERN_WARNING "%s: No suitable DMA available.\n", |
| 4170 | DRV_NAME); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4171 | goto out_pci_disable_device; |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 4172 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4173 | } |
| 4174 | |
| 4175 | err = pci_request_regions(pdev, DRV_NAME); |
| 4176 | if (err) |
| 4177 | goto out_pci_disable_device; |
| 4178 | |
| 4179 | pci_set_drvdata(pdev, priv); |
| 4180 | |
| 4181 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 4182 | * PCI Tx retries from interfering with C3 CPU state */ |
| 4183 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 4184 | |
| 4185 | /*********************** |
| 4186 | * 3. Read REV register |
| 4187 | ***********************/ |
| 4188 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 4189 | if (!priv->hw_base) { |
| 4190 | err = -ENODEV; |
| 4191 | goto out_pci_release_regions; |
| 4192 | } |
| 4193 | |
| 4194 | IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n", |
| 4195 | (unsigned long long) pci_resource_len(pdev, 0)); |
| 4196 | IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); |
| 4197 | |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 4198 | iwl_hw_detect(priv); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4199 | printk(KERN_INFO DRV_NAME |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 4200 | ": Detected Intel Wireless WiFi Link %s REV=0x%X\n", |
| 4201 | priv->cfg->name, priv->hw_rev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4202 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 4203 | /* amp init */ |
| 4204 | err = priv->cfg->ops->lib->apm_ops.init(priv); |
| 4205 | if (err < 0) { |
| 4206 | IWL_DEBUG_INFO("Failed to init APMG\n"); |
| 4207 | goto out_iounmap; |
| 4208 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4209 | /***************** |
| 4210 | * 4. Read EEPROM |
| 4211 | *****************/ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4212 | /* Read the EEPROM */ |
| 4213 | err = iwl_eeprom_init(priv); |
| 4214 | if (err) { |
| 4215 | IWL_ERROR("Unable to init EEPROM\n"); |
| 4216 | goto out_iounmap; |
| 4217 | } |
Tomas Winkler | 8614f36 | 2008-04-23 17:14:55 -0700 | [diff] [blame] | 4218 | err = iwl_eeprom_check_version(priv); |
| 4219 | if (err) |
| 4220 | goto out_iounmap; |
| 4221 | |
Ron Rindjunsky | 0288301 | 2008-05-15 13:53:53 +0800 | [diff] [blame] | 4222 | /* extract MAC Address */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4223 | iwl_eeprom_get_mac(priv, priv->mac_addr); |
| 4224 | IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr)); |
| 4225 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 4226 | |
| 4227 | /************************ |
| 4228 | * 5. Setup HW constants |
| 4229 | ************************/ |
Ron Rindjunsky | da154e3 | 2008-06-30 17:23:20 +0800 | [diff] [blame] | 4230 | if (iwl_set_hw_params(priv)) { |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 4231 | IWL_ERROR("failed to set hw parameters\n"); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 4232 | goto out_free_eeprom; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4233 | } |
| 4234 | |
| 4235 | /******************* |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 4236 | * 6. Setup priv |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4237 | *******************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4238 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 4239 | err = iwl_init_drv(priv); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4240 | if (err) |
Ron Rindjunsky | 399f4900 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 4241 | goto out_free_eeprom; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4242 | /* At this point both hw and priv are initialized. */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4243 | |
| 4244 | /********************************** |
| 4245 | * 7. Initialize module parameters |
| 4246 | **********************************/ |
| 4247 | |
| 4248 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 4249 | if (priv->cfg->mod_params->disable) { |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4250 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 4251 | IWL_DEBUG_INFO("Radio disabled.\n"); |
| 4252 | } |
| 4253 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4254 | /******************** |
| 4255 | * 8. Setup services |
| 4256 | ********************/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4257 | spin_lock_irqsave(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4258 | iwl4965_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4259 | spin_unlock_irqrestore(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4260 | |
| 4261 | err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
| 4262 | if (err) { |
| 4263 | IWL_ERROR("failed to create sysfs device attributes\n"); |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 4264 | goto out_uninit_drv; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4265 | } |
| 4266 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4267 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 4268 | iwl_setup_deferred_work(priv); |
Emmanuel Grumbach | 653fa4a | 2008-06-30 17:23:11 +0800 | [diff] [blame] | 4269 | iwl_setup_rx_handlers(priv); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4270 | |
| 4271 | /******************** |
| 4272 | * 9. Conclude |
| 4273 | ********************/ |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4274 | pci_save_state(pdev); |
| 4275 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4276 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 4277 | /********************************** |
| 4278 | * 10. Setup and register mac80211 |
| 4279 | **********************************/ |
| 4280 | |
| 4281 | err = iwl_setup_mac(priv); |
| 4282 | if (err) |
| 4283 | goto out_remove_sysfs; |
| 4284 | |
| 4285 | err = iwl_dbgfs_register(priv, DRV_NAME); |
| 4286 | if (err) |
| 4287 | IWL_ERROR("failed to create debugfs files\n"); |
| 4288 | |
Emmanuel Grumbach | 58d0f36 | 2008-06-12 09:47:19 +0800 | [diff] [blame] | 4289 | err = iwl_rfkill_init(priv); |
| 4290 | if (err) |
| 4291 | IWL_ERROR("Unable to initialize RFKILL system. " |
| 4292 | "Ignoring error: %d\n", err); |
| 4293 | iwl_power_initialize(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4294 | return 0; |
| 4295 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4296 | out_remove_sysfs: |
| 4297 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 4298 | out_uninit_drv: |
| 4299 | iwl_uninit_drv(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 4300 | out_free_eeprom: |
| 4301 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4302 | out_iounmap: |
| 4303 | pci_iounmap(pdev, priv->hw_base); |
| 4304 | out_pci_release_regions: |
| 4305 | pci_release_regions(pdev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4306 | pci_set_drvdata(pdev, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4307 | out_pci_disable_device: |
| 4308 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4309 | out_ieee80211_free_hw: |
| 4310 | ieee80211_free_hw(priv->hw); |
| 4311 | out: |
| 4312 | return err; |
| 4313 | } |
| 4314 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 4315 | static void __devexit iwl4965_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4316 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4317 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4318 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4319 | |
| 4320 | if (!priv) |
| 4321 | return; |
| 4322 | |
| 4323 | IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n"); |
| 4324 | |
Emmanuel Grumbach | 6724962 | 2008-05-29 16:35:26 +0800 | [diff] [blame] | 4325 | iwl_dbgfs_unregister(priv); |
| 4326 | sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group); |
| 4327 | |
Ron Rindjunsky | c4f5523 | 2008-03-28 16:21:10 -0700 | [diff] [blame] | 4328 | if (priv->mac80211_registered) { |
| 4329 | ieee80211_unregister_hw(priv->hw); |
| 4330 | priv->mac80211_registered = 0; |
| 4331 | } |
| 4332 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4333 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 4334 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4335 | iwl4965_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4336 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4337 | /* make sure we flush any pending irq or |
| 4338 | * tasklet for the driver |
| 4339 | */ |
| 4340 | spin_lock_irqsave(&priv->lock, flags); |
| 4341 | iwl4965_disable_interrupts(priv); |
| 4342 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4343 | |
| 4344 | iwl_synchronize_irq(priv); |
| 4345 | |
Emmanuel Grumbach | 58d0f36 | 2008-06-12 09:47:19 +0800 | [diff] [blame] | 4346 | iwl_rfkill_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4347 | iwl4965_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4348 | |
| 4349 | if (priv->rxq.bd) |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 4350 | iwl_rx_queue_free(priv, &priv->rxq); |
Ron Rindjunsky | 1053d35 | 2008-05-05 10:22:43 +0800 | [diff] [blame] | 4351 | iwl_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4352 | |
Emmanuel Grumbach | 37deb2a | 2008-06-30 17:23:08 +0800 | [diff] [blame] | 4353 | iwl_clear_stations_table(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 4354 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4355 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4356 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4357 | /*netif_stop_queue(dev); */ |
| 4358 | flush_workqueue(priv->workqueue); |
| 4359 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4360 | /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4361 | * priv->workqueue... so we can't take down the workqueue |
| 4362 | * until now... */ |
| 4363 | destroy_workqueue(priv->workqueue); |
| 4364 | priv->workqueue = NULL; |
| 4365 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4366 | pci_iounmap(pdev, priv->hw_base); |
| 4367 | pci_release_regions(pdev); |
| 4368 | pci_disable_device(pdev); |
| 4369 | pci_set_drvdata(pdev, NULL); |
| 4370 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 4371 | iwl_uninit_drv(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4372 | |
| 4373 | if (priv->ibss_beacon) |
| 4374 | dev_kfree_skb(priv->ibss_beacon); |
| 4375 | |
| 4376 | ieee80211_free_hw(priv->hw); |
| 4377 | } |
| 4378 | |
| 4379 | #ifdef CONFIG_PM |
| 4380 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4381 | 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] | 4382 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4383 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4384 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4385 | if (priv->is_open) { |
| 4386 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 4387 | iwl4965_mac_stop(priv->hw); |
| 4388 | priv->is_open = 1; |
| 4389 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4390 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4391 | pci_set_power_state(pdev, PCI_D3hot); |
| 4392 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4393 | return 0; |
| 4394 | } |
| 4395 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4396 | static int iwl4965_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4397 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4398 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4399 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4400 | pci_set_power_state(pdev, PCI_D0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4401 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4402 | if (priv->is_open) |
| 4403 | iwl4965_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4404 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 4405 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4406 | return 0; |
| 4407 | } |
| 4408 | |
| 4409 | #endif /* CONFIG_PM */ |
| 4410 | |
| 4411 | /***************************************************************************** |
| 4412 | * |
| 4413 | * driver and module entry point |
| 4414 | * |
| 4415 | *****************************************************************************/ |
| 4416 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 4417 | /* Hardware specific file defines the PCI IDs table for that hardware module */ |
| 4418 | static struct pci_device_id iwl_hw_card_ids[] = { |
| 4419 | {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)}, |
| 4420 | {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)}, |
Tomas Winkler | 5a6a256 | 2008-04-24 11:55:23 -0700 | [diff] [blame] | 4421 | #ifdef CONFIG_IWL5000 |
| 4422 | {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)}, |
| 4423 | {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)}, |
| 4424 | {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)}, |
| 4425 | #endif /* CONFIG_IWL5000 */ |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 4426 | {0} |
| 4427 | }; |
| 4428 | MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); |
| 4429 | |
| 4430 | static struct pci_driver iwl_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4431 | .name = DRV_NAME, |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 4432 | .id_table = iwl_hw_card_ids, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4433 | .probe = iwl4965_pci_probe, |
| 4434 | .remove = __devexit_p(iwl4965_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4435 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4436 | .suspend = iwl4965_pci_suspend, |
| 4437 | .resume = iwl4965_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4438 | #endif |
| 4439 | }; |
| 4440 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4441 | static int __init iwl4965_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4442 | { |
| 4443 | |
| 4444 | int ret; |
| 4445 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 4446 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4447 | |
| 4448 | ret = iwl4965_rate_control_register(); |
| 4449 | if (ret) { |
| 4450 | IWL_ERROR("Unable to register rate control algorithm: %d\n", ret); |
| 4451 | return ret; |
| 4452 | } |
| 4453 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 4454 | ret = pci_register_driver(&iwl_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4455 | if (ret) { |
| 4456 | IWL_ERROR("Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4457 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4458 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4459 | |
| 4460 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4461 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4462 | error_register: |
| 4463 | iwl4965_rate_control_unregister(); |
| 4464 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4465 | } |
| 4466 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4467 | static void __exit iwl4965_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4468 | { |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 4469 | pci_unregister_driver(&iwl_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4470 | iwl4965_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4471 | } |
| 4472 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4473 | module_exit(iwl4965_exit); |
| 4474 | module_init(iwl4965_init); |