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