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