Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | 1f44780 | 2010-01-15 13:43:41 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2010 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: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 30 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 31 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 32 | #include <linux/kernel.h> |
| 33 | #include <linux/module.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 34 | #include <linux/init.h> |
| 35 | #include <linux/pci.h> |
John W. Linville | 1a7123c | 2010-08-05 14:39:31 -0400 | [diff] [blame] | 36 | #include <linux/pci-aspm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 38 | #include <linux/dma-mapping.h> |
| 39 | #include <linux/delay.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 40 | #include <linux/sched.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 41 | #include <linux/skbuff.h> |
| 42 | #include <linux/netdevice.h> |
| 43 | #include <linux/wireless.h> |
| 44 | #include <linux/firmware.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 45 | #include <linux/etherdevice.h> |
| 46 | #include <linux/if_arp.h> |
| 47 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 48 | #include <net/mac80211.h> |
| 49 | |
| 50 | #include <asm/div64.h> |
| 51 | |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 52 | #define DRV_NAME "iwlagn" |
| 53 | |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 54 | #include "iwl-eeprom.h" |
Tomas Winkler | 3e0d4cb | 2008-04-24 11:55:38 -0700 | [diff] [blame] | 55 | #include "iwl-dev.h" |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 56 | #include "iwl-core.h" |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 57 | #include "iwl-io.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 58 | #include "iwl-helpers.h" |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 59 | #include "iwl-sta.h" |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 60 | #include "iwl-calib.h" |
Johannes Berg | a117512 | 2010-01-21 06:21:10 -0800 | [diff] [blame] | 61 | #include "iwl-agn.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 62 | |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 63 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 64 | /****************************************************************************** |
| 65 | * |
| 66 | * module boiler plate |
| 67 | * |
| 68 | ******************************************************************************/ |
| 69 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 70 | /* |
| 71 | * module name, copyright, version, etc. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 72 | */ |
Tomas Winkler | d783b06 | 2008-07-18 13:53:02 +0800 | [diff] [blame] | 73 | #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 74 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 75 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 76 | #define VD "d" |
| 77 | #else |
| 78 | #define VD |
| 79 | #endif |
| 80 | |
Reinette Chatre | 81963d6 | 2010-01-22 14:22:57 -0800 | [diff] [blame] | 81 | #define DRV_VERSION IWLWIFI_VERSION VD |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 82 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 83 | |
| 84 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 85 | MODULE_VERSION(DRV_VERSION); |
Tomas Winkler | a7b7520 | 2008-12-11 10:33:41 -0800 | [diff] [blame] | 86 | MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 87 | MODULE_LICENSE("GPL"); |
Tomas Winkler | 4fc22b2 | 2008-07-21 18:54:42 +0300 | [diff] [blame] | 88 | MODULE_ALIAS("iwl4965"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 89 | |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 90 | static int iwlagn_ant_coupling; |
Wey-Yi Guy | f37837c | 2010-08-23 07:57:12 -0700 | [diff] [blame] | 91 | static bool iwlagn_bt_ch_announce = 1; |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 92 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 93 | /** |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 94 | * iwl_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 95 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 96 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 97 | * the active_rxon structure is updated with the new data. This |
| 98 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 99 | * a HW tune is required based on the RXON structure changes. |
| 100 | */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 101 | int iwl_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 102 | { |
| 103 | /* cast away the const for active_rxon in this function */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 104 | struct iwl_rxon_cmd *active_rxon = (void *)&ctx->active; |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 105 | int ret; |
| 106 | bool new_assoc = |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 107 | !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 108 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 109 | if (!iwl_is_alive(priv)) |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 110 | return -EBUSY; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 111 | |
| 112 | /* always get timestamp with Rx frame */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 113 | ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 114 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 115 | ret = iwl_check_rxon_cmd(priv, ctx); |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 116 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 117 | IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 118 | return -EINVAL; |
| 119 | } |
| 120 | |
Wey-Yi Guy | 0924e519 | 2009-11-06 14:52:54 -0800 | [diff] [blame] | 121 | /* |
| 122 | * receive commit_rxon request |
| 123 | * abort any previous channel switch if still in process |
| 124 | */ |
| 125 | if (priv->switch_rxon.switch_in_progress && |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 126 | (priv->switch_rxon.channel != ctx->staging.channel)) { |
Wey-Yi Guy | 0924e519 | 2009-11-06 14:52:54 -0800 | [diff] [blame] | 127 | IWL_DEBUG_11H(priv, "abort channel switch on %d\n", |
| 128 | le16_to_cpu(priv->switch_rxon.channel)); |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 129 | iwl_chswitch_done(priv, false); |
Wey-Yi Guy | 0924e519 | 2009-11-06 14:52:54 -0800 | [diff] [blame] | 130 | } |
| 131 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 132 | /* If we don't need to send a full RXON, we can use |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 133 | * iwl_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 134 | * and other flags for the current radio configuration. */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 135 | if (!iwl_full_rxon_required(priv, ctx)) { |
| 136 | ret = iwl_send_rxon_assoc(priv, ctx); |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 137 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 138 | IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret); |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 139 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 142 | memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon)); |
| 143 | iwl_print_rx_config_cmd(priv, ctx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 144 | return 0; |
| 145 | } |
| 146 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 147 | /* If we are currently associated and the new config requires |
| 148 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 149 | * we must clear the associated from the active configuration |
| 150 | * before we apply the new config */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 151 | if (iwl_is_associated_ctx(ctx) && new_assoc) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 152 | IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 153 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 154 | |
Johannes Berg | 8f2d3d2 | 2010-08-23 10:46:37 +0200 | [diff] [blame] | 155 | ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd, |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 156 | sizeof(struct iwl_rxon_cmd), |
| 157 | active_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 158 | |
| 159 | /* If the mask clearing failed then we set |
| 160 | * active_rxon back to what it was previously */ |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 161 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 162 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 163 | IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret); |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 164 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 165 | } |
Johannes Berg | dcef732 | 2010-08-27 08:55:52 -0700 | [diff] [blame] | 166 | iwl_clear_ucode_stations(priv, ctx); |
| 167 | iwl_restore_stations(priv, ctx); |
Johannes Berg | c10afb6 | 2010-08-23 10:46:43 +0200 | [diff] [blame] | 168 | ret = iwl_restore_default_wep_keys(priv, ctx); |
Johannes Berg | 335348b | 2010-03-30 10:11:46 -0700 | [diff] [blame] | 169 | if (ret) { |
| 170 | IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret); |
| 171 | return ret; |
| 172 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 175 | IWL_DEBUG_INFO(priv, "Sending RXON\n" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 176 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 177 | "* channel = %d\n" |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 178 | "* bssid = %pM\n", |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 179 | (new_assoc ? "" : "out"), |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 180 | le16_to_cpu(ctx->staging.channel), |
| 181 | ctx->staging.bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 182 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 183 | iwl_set_rxon_hwcrypto(priv, ctx, !priv->cfg->mod_params->sw_crypto); |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 184 | |
| 185 | /* Apply the new configuration |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 186 | * RXON unassoc clears the station table in uCode so restoration of |
| 187 | * stations is needed after it (the RXON command) completes |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 188 | */ |
| 189 | if (!new_assoc) { |
Johannes Berg | 8f2d3d2 | 2010-08-23 10:46:37 +0200 | [diff] [blame] | 190 | ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd, |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 191 | sizeof(struct iwl_rxon_cmd), &ctx->staging); |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 192 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 193 | IWL_ERR(priv, "Error setting new RXON (%d)\n", ret); |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 194 | return ret; |
| 195 | } |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 196 | IWL_DEBUG_INFO(priv, "Return from !new_assoc RXON.\n"); |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 197 | memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon)); |
Johannes Berg | dcef732 | 2010-08-27 08:55:52 -0700 | [diff] [blame] | 198 | iwl_clear_ucode_stations(priv, ctx); |
| 199 | iwl_restore_stations(priv, ctx); |
Johannes Berg | c10afb6 | 2010-08-23 10:46:43 +0200 | [diff] [blame] | 200 | ret = iwl_restore_default_wep_keys(priv, ctx); |
Johannes Berg | 335348b | 2010-03-30 10:11:46 -0700 | [diff] [blame] | 201 | if (ret) { |
| 202 | IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret); |
| 203 | return ret; |
| 204 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Johannes Berg | 19cc108 | 2009-05-08 13:44:36 -0700 | [diff] [blame] | 207 | priv->start_calib = 0; |
Tomas Winkler | 9185159 | 2008-06-30 17:23:14 +0800 | [diff] [blame] | 208 | if (new_assoc) { |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 209 | /* Apply the new configuration |
| 210 | * RXON assoc doesn't clear the station table in uCode, |
| 211 | */ |
Johannes Berg | 8f2d3d2 | 2010-08-23 10:46:37 +0200 | [diff] [blame] | 212 | ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd, |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 213 | sizeof(struct iwl_rxon_cmd), &ctx->staging); |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 214 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 215 | IWL_ERR(priv, "Error setting new RXON (%d)\n", ret); |
Emmanuel Grumbach | 43d59b3 | 2008-06-30 17:23:06 +0800 | [diff] [blame] | 216 | return ret; |
| 217 | } |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 218 | memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 219 | } |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 220 | iwl_print_rx_config_cmd(priv, ctx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 221 | |
Zhu Yi | 36da7d7 | 2008-07-11 11:53:40 +0800 | [diff] [blame] | 222 | iwl_init_sensitivity(priv); |
| 223 | |
| 224 | /* If we issue a new RXON command which required a tune then we must |
| 225 | * send a new TXPOWER command or we won't be able to Tx any frames */ |
| 226 | ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true); |
| 227 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 228 | IWL_ERR(priv, "Error sending TX power (%d)\n", ret); |
Zhu Yi | 36da7d7 | 2008-07-11 11:53:40 +0800 | [diff] [blame] | 229 | return ret; |
| 230 | } |
| 231 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 232 | return 0; |
| 233 | } |
| 234 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 235 | void iwl_update_chain_flags(struct iwl_priv *priv) |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 236 | { |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 237 | struct iwl_rxon_context *ctx; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 238 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 239 | if (priv->cfg->ops->hcmd->set_rxon_chain) { |
| 240 | for_each_context(priv, ctx) { |
| 241 | priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx); |
| 242 | iwlcore_commit_rxon(priv, ctx); |
| 243 | } |
| 244 | } |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 247 | static void iwl_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 248 | { |
| 249 | struct list_head *element; |
| 250 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 251 | IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 252 | priv->frames_count); |
| 253 | |
| 254 | while (!list_empty(&priv->free_frames)) { |
| 255 | element = priv->free_frames.next; |
| 256 | list_del(element); |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 257 | kfree(list_entry(element, struct iwl_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 258 | priv->frames_count--; |
| 259 | } |
| 260 | |
| 261 | if (priv->frames_count) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 262 | IWL_WARN(priv, "%d frames still in use. Did we lose one?\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 263 | priv->frames_count); |
| 264 | priv->frames_count = 0; |
| 265 | } |
| 266 | } |
| 267 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 268 | static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 269 | { |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 270 | struct iwl_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 271 | struct list_head *element; |
| 272 | if (list_empty(&priv->free_frames)) { |
| 273 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 274 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 275 | IWL_ERR(priv, "Could not allocate frame!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 276 | return NULL; |
| 277 | } |
| 278 | |
| 279 | priv->frames_count++; |
| 280 | return frame; |
| 281 | } |
| 282 | |
| 283 | element = priv->free_frames.next; |
| 284 | list_del(element); |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 285 | return list_entry(element, struct iwl_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 288 | 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] | 289 | { |
| 290 | memset(frame, 0, sizeof(*frame)); |
| 291 | list_add(&frame->list, &priv->free_frames); |
| 292 | } |
| 293 | |
Daniel C Halperin | 47ff65c | 2009-11-13 11:56:33 -0800 | [diff] [blame] | 294 | static u32 iwl_fill_beacon_frame(struct iwl_priv *priv, |
Tomas Winkler | 4bf64ef | 2008-07-18 13:53:03 +0800 | [diff] [blame] | 295 | struct ieee80211_hdr *hdr, |
Rami Rosen | 73ec1cc | 2008-12-16 09:37:07 +0200 | [diff] [blame] | 296 | int left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 297 | { |
Johannes Berg | 6abbe55 | 2010-07-15 05:59:07 -0700 | [diff] [blame] | 298 | if (!priv->ibss_beacon) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 299 | return 0; |
| 300 | |
| 301 | if (priv->ibss_beacon->len > left) |
| 302 | return 0; |
| 303 | |
| 304 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 305 | |
| 306 | return priv->ibss_beacon->len; |
| 307 | } |
| 308 | |
Daniel C Halperin | 47ff65c | 2009-11-13 11:56:33 -0800 | [diff] [blame] | 309 | /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */ |
| 310 | static void iwl_set_beacon_tim(struct iwl_priv *priv, |
| 311 | struct iwl_tx_beacon_cmd *tx_beacon_cmd, |
| 312 | u8 *beacon, u32 frame_size) |
| 313 | { |
| 314 | u16 tim_idx; |
| 315 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon; |
| 316 | |
| 317 | /* |
| 318 | * The index is relative to frame start but we start looking at the |
| 319 | * variable-length part of the beacon. |
| 320 | */ |
| 321 | tim_idx = mgmt->u.beacon.variable - beacon; |
| 322 | |
| 323 | /* Parse variable-length elements of beacon to find WLAN_EID_TIM */ |
| 324 | while ((tim_idx < (frame_size - 2)) && |
| 325 | (beacon[tim_idx] != WLAN_EID_TIM)) |
| 326 | tim_idx += beacon[tim_idx+1] + 2; |
| 327 | |
| 328 | /* If TIM field was found, set variables */ |
| 329 | if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) { |
| 330 | tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx); |
| 331 | tx_beacon_cmd->tim_size = beacon[tim_idx+1]; |
| 332 | } else |
| 333 | IWL_WARN(priv, "Unable to find TIM Element in beacon\n"); |
| 334 | } |
| 335 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 336 | static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv, |
Daniel C Halperin | 47ff65c | 2009-11-13 11:56:33 -0800 | [diff] [blame] | 337 | struct iwl_frame *frame) |
Tomas Winkler | 4bf64ef | 2008-07-18 13:53:03 +0800 | [diff] [blame] | 338 | { |
| 339 | struct iwl_tx_beacon_cmd *tx_beacon_cmd; |
Daniel C Halperin | 47ff65c | 2009-11-13 11:56:33 -0800 | [diff] [blame] | 340 | u32 frame_size; |
| 341 | u32 rate_flags; |
| 342 | u32 rate; |
| 343 | /* |
| 344 | * We have to set up the TX command, the TX Beacon command, and the |
| 345 | * beacon contents. |
| 346 | */ |
Tomas Winkler | 4bf64ef | 2008-07-18 13:53:03 +0800 | [diff] [blame] | 347 | |
Johannes Berg | 76d0481 | 2010-08-23 10:46:47 +0200 | [diff] [blame] | 348 | lockdep_assert_held(&priv->mutex); |
| 349 | |
| 350 | if (!priv->beacon_ctx) { |
| 351 | IWL_ERR(priv, "trying to build beacon w/o beacon context!\n"); |
| 352 | return -EINVAL; |
| 353 | } |
| 354 | |
Daniel C Halperin | 47ff65c | 2009-11-13 11:56:33 -0800 | [diff] [blame] | 355 | /* Initialize memory */ |
Tomas Winkler | 4bf64ef | 2008-07-18 13:53:03 +0800 | [diff] [blame] | 356 | tx_beacon_cmd = &frame->u.beacon; |
| 357 | memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd)); |
| 358 | |
Daniel C Halperin | 47ff65c | 2009-11-13 11:56:33 -0800 | [diff] [blame] | 359 | /* Set up TX beacon contents */ |
Tomas Winkler | 4bf64ef | 2008-07-18 13:53:03 +0800 | [diff] [blame] | 360 | frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame, |
Tomas Winkler | 4bf64ef | 2008-07-18 13:53:03 +0800 | [diff] [blame] | 361 | sizeof(frame->u) - sizeof(*tx_beacon_cmd)); |
Daniel C Halperin | 47ff65c | 2009-11-13 11:56:33 -0800 | [diff] [blame] | 362 | if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE)) |
| 363 | return 0; |
Tomas Winkler | 4bf64ef | 2008-07-18 13:53:03 +0800 | [diff] [blame] | 364 | |
Daniel C Halperin | 47ff65c | 2009-11-13 11:56:33 -0800 | [diff] [blame] | 365 | /* Set up TX command fields */ |
Tomas Winkler | 4bf64ef | 2008-07-18 13:53:03 +0800 | [diff] [blame] | 366 | tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size); |
Johannes Berg | 76d0481 | 2010-08-23 10:46:47 +0200 | [diff] [blame] | 367 | tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id; |
Daniel C Halperin | 47ff65c | 2009-11-13 11:56:33 -0800 | [diff] [blame] | 368 | tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
Tomas Winkler | 4bf64ef | 2008-07-18 13:53:03 +0800 | [diff] [blame] | 369 | tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK | |
Daniel C Halperin | 47ff65c | 2009-11-13 11:56:33 -0800 | [diff] [blame] | 370 | TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK; |
| 371 | |
| 372 | /* Set up TX beacon command fields */ |
| 373 | iwl_set_beacon_tim(priv, tx_beacon_cmd, (u8 *)tx_beacon_cmd->frame, |
| 374 | frame_size); |
| 375 | |
| 376 | /* Set up packet rate and flags */ |
Johannes Berg | 76d0481 | 2010-08-23 10:46:47 +0200 | [diff] [blame] | 377 | rate = iwl_rate_get_lowest_plcp(priv, priv->beacon_ctx); |
Johannes Berg | 0e1654f | 2010-05-18 02:48:36 -0700 | [diff] [blame] | 378 | priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant, |
| 379 | priv->hw_params.valid_tx_ant); |
Daniel C Halperin | 47ff65c | 2009-11-13 11:56:33 -0800 | [diff] [blame] | 380 | rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant); |
| 381 | if ((rate >= IWL_FIRST_CCK_RATE) && (rate <= IWL_LAST_CCK_RATE)) |
| 382 | rate_flags |= RATE_MCS_CCK_MSK; |
| 383 | tx_beacon_cmd->tx.rate_n_flags = iwl_hw_set_rate_n_flags(rate, |
| 384 | rate_flags); |
Tomas Winkler | 4bf64ef | 2008-07-18 13:53:03 +0800 | [diff] [blame] | 385 | |
| 386 | return sizeof(*tx_beacon_cmd) + frame_size; |
| 387 | } |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 388 | static int iwl_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 389 | { |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 390 | struct iwl_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 391 | unsigned int frame_size; |
| 392 | int rc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 393 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 394 | frame = iwl_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 395 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 396 | IWL_ERR(priv, "Could not obtain free frame buffer for beacon " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 397 | "command.\n"); |
| 398 | return -ENOMEM; |
| 399 | } |
| 400 | |
Daniel C Halperin | 47ff65c | 2009-11-13 11:56:33 -0800 | [diff] [blame] | 401 | frame_size = iwl_hw_get_beacon_cmd(priv, frame); |
| 402 | if (!frame_size) { |
| 403 | IWL_ERR(priv, "Error configuring the beacon command\n"); |
| 404 | iwl_free_frame(priv, frame); |
| 405 | return -EINVAL; |
| 406 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 407 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 408 | rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 409 | &frame->u.cmd[0]); |
| 410 | |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 411 | iwl_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 412 | |
| 413 | return rc; |
| 414 | } |
| 415 | |
Samuel Ortiz | 7aaa1d7 | 2009-01-19 15:30:26 -0800 | [diff] [blame] | 416 | static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx) |
| 417 | { |
| 418 | struct iwl_tfd_tb *tb = &tfd->tbs[idx]; |
| 419 | |
| 420 | dma_addr_t addr = get_unaligned_le32(&tb->lo); |
| 421 | if (sizeof(dma_addr_t) > sizeof(u32)) |
| 422 | addr |= |
| 423 | ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16; |
| 424 | |
| 425 | return addr; |
| 426 | } |
| 427 | |
| 428 | static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx) |
| 429 | { |
| 430 | struct iwl_tfd_tb *tb = &tfd->tbs[idx]; |
| 431 | |
| 432 | return le16_to_cpu(tb->hi_n_len) >> 4; |
| 433 | } |
| 434 | |
| 435 | static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx, |
| 436 | dma_addr_t addr, u16 len) |
| 437 | { |
| 438 | struct iwl_tfd_tb *tb = &tfd->tbs[idx]; |
| 439 | u16 hi_n_len = len << 4; |
| 440 | |
| 441 | put_unaligned_le32(addr, &tb->lo); |
| 442 | if (sizeof(dma_addr_t) > sizeof(u32)) |
| 443 | hi_n_len |= ((addr >> 16) >> 16) & 0xF; |
| 444 | |
| 445 | tb->hi_n_len = cpu_to_le16(hi_n_len); |
| 446 | |
| 447 | tfd->num_tbs = idx + 1; |
| 448 | } |
| 449 | |
| 450 | static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd) |
| 451 | { |
| 452 | return tfd->num_tbs & 0x1f; |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr] |
| 457 | * @priv - driver private data |
| 458 | * @txq - tx queue |
| 459 | * |
| 460 | * Does NOT advance any TFD circular buffer read/write indexes |
| 461 | * Does NOT free the TFD itself (which is within circular buffer) |
| 462 | */ |
| 463 | void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq) |
| 464 | { |
Samuel Ortiz | 59606ff | 2009-01-23 13:45:13 -0800 | [diff] [blame] | 465 | struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds; |
Samuel Ortiz | 7aaa1d7 | 2009-01-19 15:30:26 -0800 | [diff] [blame] | 466 | struct iwl_tfd *tfd; |
| 467 | struct pci_dev *dev = priv->pci_dev; |
| 468 | int index = txq->q.read_ptr; |
| 469 | int i; |
| 470 | int num_tbs; |
| 471 | |
| 472 | tfd = &tfd_tmp[index]; |
| 473 | |
| 474 | /* Sanity check on number of chunks */ |
| 475 | num_tbs = iwl_tfd_get_num_tbs(tfd); |
| 476 | |
| 477 | if (num_tbs >= IWL_NUM_OF_TBS) { |
| 478 | IWL_ERR(priv, "Too many chunks: %i\n", num_tbs); |
| 479 | /* @todo issue fatal error, it is quite serious situation */ |
| 480 | return; |
| 481 | } |
| 482 | |
| 483 | /* Unmap tx_cmd */ |
| 484 | if (num_tbs) |
| 485 | pci_unmap_single(dev, |
FUJITA Tomonori | 2e72444 | 2010-06-03 14:19:20 +0900 | [diff] [blame] | 486 | dma_unmap_addr(&txq->meta[index], mapping), |
| 487 | dma_unmap_len(&txq->meta[index], len), |
Fenghua Yu | 96891ce | 2009-02-18 15:54:33 -0800 | [diff] [blame] | 488 | PCI_DMA_BIDIRECTIONAL); |
Samuel Ortiz | 7aaa1d7 | 2009-01-19 15:30:26 -0800 | [diff] [blame] | 489 | |
| 490 | /* Unmap chunks, if any. */ |
Johannes Berg | ff0d91c | 2010-05-17 02:37:34 -0700 | [diff] [blame] | 491 | for (i = 1; i < num_tbs; i++) |
Samuel Ortiz | 7aaa1d7 | 2009-01-19 15:30:26 -0800 | [diff] [blame] | 492 | pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i), |
| 493 | iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE); |
| 494 | |
Johannes Berg | ff0d91c | 2010-05-17 02:37:34 -0700 | [diff] [blame] | 495 | /* free SKB */ |
| 496 | if (txq->txb) { |
| 497 | struct sk_buff *skb; |
Johannes Berg | 6f80240 | 2010-05-17 02:37:32 -0700 | [diff] [blame] | 498 | |
Johannes Berg | ff0d91c | 2010-05-17 02:37:34 -0700 | [diff] [blame] | 499 | skb = txq->txb[txq->q.read_ptr].skb; |
Johannes Berg | 6f80240 | 2010-05-17 02:37:32 -0700 | [diff] [blame] | 500 | |
Johannes Berg | ff0d91c | 2010-05-17 02:37:34 -0700 | [diff] [blame] | 501 | /* can be called from irqs-disabled context */ |
| 502 | if (skb) { |
| 503 | dev_kfree_skb_any(skb); |
| 504 | txq->txb[txq->q.read_ptr].skb = NULL; |
Samuel Ortiz | 7aaa1d7 | 2009-01-19 15:30:26 -0800 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, |
| 510 | struct iwl_tx_queue *txq, |
| 511 | dma_addr_t addr, u16 len, |
| 512 | u8 reset, u8 pad) |
| 513 | { |
| 514 | struct iwl_queue *q; |
Samuel Ortiz | 59606ff | 2009-01-23 13:45:13 -0800 | [diff] [blame] | 515 | struct iwl_tfd *tfd, *tfd_tmp; |
Samuel Ortiz | 7aaa1d7 | 2009-01-19 15:30:26 -0800 | [diff] [blame] | 516 | u32 num_tbs; |
| 517 | |
| 518 | q = &txq->q; |
Samuel Ortiz | 59606ff | 2009-01-23 13:45:13 -0800 | [diff] [blame] | 519 | tfd_tmp = (struct iwl_tfd *)txq->tfds; |
| 520 | tfd = &tfd_tmp[q->write_ptr]; |
Samuel Ortiz | 7aaa1d7 | 2009-01-19 15:30:26 -0800 | [diff] [blame] | 521 | |
| 522 | if (reset) |
| 523 | memset(tfd, 0, sizeof(*tfd)); |
| 524 | |
| 525 | num_tbs = iwl_tfd_get_num_tbs(tfd); |
| 526 | |
| 527 | /* Each TFD can point to a maximum 20 Tx buffers */ |
| 528 | if (num_tbs >= IWL_NUM_OF_TBS) { |
| 529 | IWL_ERR(priv, "Error can not send more than %d chunks\n", |
| 530 | IWL_NUM_OF_TBS); |
| 531 | return -EINVAL; |
| 532 | } |
| 533 | |
| 534 | BUG_ON(addr & ~DMA_BIT_MASK(36)); |
| 535 | if (unlikely(addr & ~IWL_TX_DMA_MASK)) |
| 536 | IWL_ERR(priv, "Unaligned address = %llx\n", |
| 537 | (unsigned long long)addr); |
| 538 | |
| 539 | iwl_tfd_set_tb(tfd, num_tbs, addr, len); |
| 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | |
Samuel Ortiz | a8e74e27 | 2009-01-23 13:45:14 -0800 | [diff] [blame] | 544 | /* |
| 545 | * Tell nic where to find circular buffer of Tx Frame Descriptors for |
| 546 | * given Tx queue, and enable the DMA channel used for that queue. |
| 547 | * |
| 548 | * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA |
| 549 | * channels supported in hardware. |
| 550 | */ |
| 551 | int iwl_hw_tx_queue_init(struct iwl_priv *priv, |
| 552 | struct iwl_tx_queue *txq) |
| 553 | { |
Samuel Ortiz | a8e74e27 | 2009-01-23 13:45:14 -0800 | [diff] [blame] | 554 | int txq_id = txq->q.id; |
| 555 | |
Samuel Ortiz | a8e74e27 | 2009-01-23 13:45:14 -0800 | [diff] [blame] | 556 | /* Circular buffer (TFD queue in DRAM) physical base address */ |
| 557 | iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id), |
| 558 | txq->q.dma_addr >> 8); |
| 559 | |
Samuel Ortiz | a8e74e27 | 2009-01-23 13:45:14 -0800 | [diff] [blame] | 560 | return 0; |
| 561 | } |
| 562 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 563 | /****************************************************************************** |
| 564 | * |
| 565 | * Generic RX handler implementations |
| 566 | * |
| 567 | ******************************************************************************/ |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 568 | static void iwl_rx_reply_alive(struct iwl_priv *priv, |
| 569 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 570 | { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 571 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 572 | struct iwl_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 573 | struct delayed_work *pwork; |
| 574 | |
| 575 | palive = &pkt->u.alive_frame; |
| 576 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 577 | IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 578 | "0x%01X 0x%01X\n", |
| 579 | palive->is_valid, palive->ver_type, |
| 580 | palive->ver_subtype); |
| 581 | |
| 582 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 583 | IWL_DEBUG_INFO(priv, "Initialization Alive received.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 584 | memcpy(&priv->card_alive_init, |
| 585 | &pkt->u.alive_frame, |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 586 | sizeof(struct iwl_init_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 587 | pwork = &priv->init_alive_start; |
| 588 | } else { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 589 | IWL_DEBUG_INFO(priv, "Runtime Alive received.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 590 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 591 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 592 | pwork = &priv->alive_start; |
| 593 | } |
| 594 | |
| 595 | /* We delay the ALIVE response by 5ms to |
| 596 | * give the HW RF Kill time to activate... */ |
| 597 | if (palive->is_valid == UCODE_VALID_OK) |
| 598 | queue_delayed_work(priv->workqueue, pwork, |
| 599 | msecs_to_jiffies(5)); |
| 600 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 601 | IWL_WARN(priv, "uCode did not respond OK.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 602 | } |
| 603 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 604 | static void iwl_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 605 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 606 | struct iwl_priv *priv = |
| 607 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 608 | struct sk_buff *beacon; |
| 609 | |
Johannes Berg | 76d0481 | 2010-08-23 10:46:47 +0200 | [diff] [blame] | 610 | mutex_lock(&priv->mutex); |
| 611 | if (!priv->beacon_ctx) { |
| 612 | IWL_ERR(priv, "updating beacon w/o beacon context!\n"); |
| 613 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Johannes Berg | 60744f6 | 2010-08-23 10:46:50 +0200 | [diff] [blame] | 616 | if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) { |
| 617 | /* |
| 618 | * The ucode will send beacon notifications even in |
| 619 | * IBSS mode, but we don't want to process them. But |
| 620 | * we need to defer the type check to here due to |
| 621 | * requiring locking around the beacon_ctx access. |
| 622 | */ |
| 623 | goto out; |
| 624 | } |
| 625 | |
Johannes Berg | 76d0481 | 2010-08-23 10:46:47 +0200 | [diff] [blame] | 626 | /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ |
| 627 | beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif); |
| 628 | if (!beacon) { |
| 629 | IWL_ERR(priv, "update beacon failed\n"); |
| 630 | goto out; |
| 631 | } |
| 632 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 633 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 634 | if (priv->ibss_beacon) |
| 635 | dev_kfree_skb(priv->ibss_beacon); |
| 636 | |
| 637 | priv->ibss_beacon = beacon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 638 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 639 | iwl_send_beacon_cmd(priv); |
Johannes Berg | 76d0481 | 2010-08-23 10:46:47 +0200 | [diff] [blame] | 640 | out: |
| 641 | mutex_unlock(&priv->mutex); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 642 | } |
| 643 | |
Wey-Yi Guy | fbba941 | 2010-08-23 07:57:10 -0700 | [diff] [blame] | 644 | static void iwl_bg_bt_runtime_config(struct work_struct *work) |
| 645 | { |
| 646 | struct iwl_priv *priv = |
| 647 | container_of(work, struct iwl_priv, bt_runtime_config); |
| 648 | |
| 649 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 650 | return; |
| 651 | |
| 652 | /* dont send host command if rf-kill is on */ |
| 653 | if (!iwl_is_ready_rf(priv)) |
| 654 | return; |
| 655 | priv->cfg->ops->hcmd->send_bt_config(priv); |
| 656 | } |
| 657 | |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 658 | static void iwl_bg_bt_full_concurrency(struct work_struct *work) |
| 659 | { |
| 660 | struct iwl_priv *priv = |
| 661 | container_of(work, struct iwl_priv, bt_full_concurrency); |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 662 | struct iwl_rxon_context *ctx; |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 663 | |
| 664 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 665 | return; |
| 666 | |
| 667 | /* dont send host command if rf-kill is on */ |
| 668 | if (!iwl_is_ready_rf(priv)) |
| 669 | return; |
| 670 | |
| 671 | IWL_DEBUG_INFO(priv, "BT coex in %s mode\n", |
| 672 | priv->bt_full_concurrent ? |
| 673 | "full concurrency" : "3-wire"); |
| 674 | |
| 675 | /* |
| 676 | * LQ & RXON updated cmds must be sent before BT Config cmd |
| 677 | * to avoid 3-wire collisions |
| 678 | */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 679 | mutex_lock(&priv->mutex); |
| 680 | for_each_context(priv, ctx) { |
| 681 | if (priv->cfg->ops->hcmd->set_rxon_chain) |
| 682 | priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx); |
| 683 | iwlcore_commit_rxon(priv, ctx); |
| 684 | } |
| 685 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 686 | |
| 687 | priv->cfg->ops->hcmd->send_bt_config(priv); |
| 688 | } |
| 689 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 690 | /** |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 691 | * iwl_bg_statistics_periodic - Timer callback to queue statistics |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 692 | * |
| 693 | * This callback is provided in order to send a statistics request. |
| 694 | * |
| 695 | * This timer function is continually reset to execute within |
| 696 | * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION |
| 697 | * was received. We need to ensure we receive the statistics in order |
| 698 | * to update the temperature used for calibrating the TXPOWER. |
| 699 | */ |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 700 | static void iwl_bg_statistics_periodic(unsigned long data) |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 701 | { |
| 702 | struct iwl_priv *priv = (struct iwl_priv *)data; |
| 703 | |
| 704 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 705 | return; |
| 706 | |
Mohamed Abbas | 61780ee | 2008-10-29 14:05:49 -0700 | [diff] [blame] | 707 | /* dont send host command if rf-kill is on */ |
| 708 | if (!iwl_is_ready_rf(priv)) |
| 709 | return; |
| 710 | |
Wey-Yi Guy | ef8d552 | 2009-11-13 11:56:28 -0800 | [diff] [blame] | 711 | iwl_send_statistics_request(priv, CMD_ASYNC, false); |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 712 | } |
| 713 | |
Wey-Yi Guy | a9e1cb6 | 2009-12-10 14:37:26 -0800 | [diff] [blame] | 714 | |
| 715 | static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base, |
| 716 | u32 start_idx, u32 num_events, |
| 717 | u32 mode) |
| 718 | { |
| 719 | u32 i; |
| 720 | u32 ptr; /* SRAM byte address of log data */ |
| 721 | u32 ev, time, data; /* event log data */ |
| 722 | unsigned long reg_flags; |
| 723 | |
| 724 | if (mode == 0) |
| 725 | ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32)); |
| 726 | else |
| 727 | ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32)); |
| 728 | |
| 729 | /* Make sure device is powered up for SRAM reads */ |
| 730 | spin_lock_irqsave(&priv->reg_lock, reg_flags); |
| 731 | if (iwl_grab_nic_access(priv)) { |
| 732 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); |
| 733 | return; |
| 734 | } |
| 735 | |
| 736 | /* Set starting address; reads will auto-increment */ |
| 737 | _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr); |
| 738 | rmb(); |
| 739 | |
| 740 | /* |
| 741 | * "time" is actually "data" for mode 0 (no timestamp). |
| 742 | * place event id # at far right for easier visual parsing. |
| 743 | */ |
| 744 | for (i = 0; i < num_events; i++) { |
| 745 | ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
| 746 | time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
| 747 | if (mode == 0) { |
| 748 | trace_iwlwifi_dev_ucode_cont_event(priv, |
| 749 | 0, time, ev); |
| 750 | } else { |
| 751 | data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
| 752 | trace_iwlwifi_dev_ucode_cont_event(priv, |
| 753 | time, data, ev); |
| 754 | } |
| 755 | } |
| 756 | /* Allow device to power down */ |
| 757 | iwl_release_nic_access(priv); |
| 758 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); |
| 759 | } |
| 760 | |
Johannes Berg | 875295f | 2010-01-22 14:22:55 -0800 | [diff] [blame] | 761 | static void iwl_continuous_event_trace(struct iwl_priv *priv) |
Wey-Yi Guy | a9e1cb6 | 2009-12-10 14:37:26 -0800 | [diff] [blame] | 762 | { |
| 763 | u32 capacity; /* event log capacity in # entries */ |
| 764 | u32 base; /* SRAM byte address of event log header */ |
| 765 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 766 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 767 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 768 | |
| 769 | if (priv->ucode_type == UCODE_INIT) |
| 770 | base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr); |
| 771 | else |
| 772 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 773 | if (priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) { |
| 774 | capacity = iwl_read_targ_mem(priv, base); |
| 775 | num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 776 | mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 777 | next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32))); |
| 778 | } else |
| 779 | return; |
| 780 | |
| 781 | if (num_wraps == priv->event_log.num_wraps) { |
| 782 | iwl_print_cont_event_trace(priv, |
| 783 | base, priv->event_log.next_entry, |
| 784 | next_entry - priv->event_log.next_entry, |
| 785 | mode); |
| 786 | priv->event_log.non_wraps_count++; |
| 787 | } else { |
| 788 | if ((num_wraps - priv->event_log.num_wraps) > 1) |
| 789 | priv->event_log.wraps_more_count++; |
| 790 | else |
| 791 | priv->event_log.wraps_once_count++; |
| 792 | trace_iwlwifi_dev_ucode_wrap_event(priv, |
| 793 | num_wraps - priv->event_log.num_wraps, |
| 794 | next_entry, priv->event_log.next_entry); |
| 795 | if (next_entry < priv->event_log.next_entry) { |
| 796 | iwl_print_cont_event_trace(priv, base, |
| 797 | priv->event_log.next_entry, |
| 798 | capacity - priv->event_log.next_entry, |
| 799 | mode); |
| 800 | |
| 801 | iwl_print_cont_event_trace(priv, base, 0, |
| 802 | next_entry, mode); |
| 803 | } else { |
| 804 | iwl_print_cont_event_trace(priv, base, |
| 805 | next_entry, capacity - next_entry, |
| 806 | mode); |
| 807 | |
| 808 | iwl_print_cont_event_trace(priv, base, 0, |
| 809 | next_entry, mode); |
| 810 | } |
| 811 | } |
| 812 | priv->event_log.num_wraps = num_wraps; |
| 813 | priv->event_log.next_entry = next_entry; |
| 814 | } |
| 815 | |
| 816 | /** |
| 817 | * iwl_bg_ucode_trace - Timer callback to log ucode event |
| 818 | * |
| 819 | * The timer is continually set to execute every |
| 820 | * UCODE_TRACE_PERIOD milliseconds after the last timer expired |
| 821 | * this function is to perform continuous uCode event logging operation |
| 822 | * if enabled |
| 823 | */ |
| 824 | static void iwl_bg_ucode_trace(unsigned long data) |
| 825 | { |
| 826 | struct iwl_priv *priv = (struct iwl_priv *)data; |
| 827 | |
| 828 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 829 | return; |
| 830 | |
| 831 | if (priv->event_log.ucode_trace) { |
| 832 | iwl_continuous_event_trace(priv); |
| 833 | /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */ |
| 834 | mod_timer(&priv->ucode_trace, |
| 835 | jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD)); |
| 836 | } |
| 837 | } |
| 838 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 839 | static void iwl_rx_beacon_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 840 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 841 | { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 842 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Tomas Winkler | 2aa6ab8 | 2008-12-11 10:33:40 -0800 | [diff] [blame] | 843 | struct iwl4965_beacon_notif *beacon = |
| 844 | (struct iwl4965_beacon_notif *)pkt->u.raw; |
Johannes Berg | a85d7cc | 2010-07-31 08:34:10 -0700 | [diff] [blame] | 845 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | e7d326ac | 2008-06-12 09:47:11 +0800 | [diff] [blame] | 846 | 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] | 847 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 848 | IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 849 | "tsf %d %d rate %d\n", |
Tomas Winkler | 25a6572 | 2008-06-12 09:47:07 +0800 | [diff] [blame] | 850 | le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 851 | beacon->beacon_notify_hdr.failure_frame, |
| 852 | le32_to_cpu(beacon->ibss_mgr_status), |
| 853 | le32_to_cpu(beacon->high_tsf), |
| 854 | le32_to_cpu(beacon->low_tsf), rate); |
| 855 | #endif |
| 856 | |
Johannes Berg | a85d7cc | 2010-07-31 08:34:10 -0700 | [diff] [blame] | 857 | priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status); |
| 858 | |
Johannes Berg | 60744f6 | 2010-08-23 10:46:50 +0200 | [diff] [blame] | 859 | if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 860 | queue_work(priv->workqueue, &priv->beacon_update); |
| 861 | } |
| 862 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 863 | /* Handle notification from uCode that card's power state is changing |
| 864 | * due to software, hardware, or critical temperature RFKILL */ |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 865 | static void iwl_rx_card_state_notif(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 866 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 867 | { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 868 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 869 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 870 | unsigned long status = priv->status; |
| 871 | |
Wey-Yi Guy | 3a41bbd | 2009-12-10 14:37:24 -0800 | [diff] [blame] | 872 | IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 873 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
Wey-Yi Guy | 3a41bbd | 2009-12-10 14:37:24 -0800 | [diff] [blame] | 874 | (flags & SW_CARD_DISABLED) ? "Kill" : "On", |
| 875 | (flags & CT_CARD_DISABLED) ? |
| 876 | "Reached" : "Not reached"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 877 | |
| 878 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | |
Wey-Yi Guy | 3a41bbd | 2009-12-10 14:37:24 -0800 | [diff] [blame] | 879 | CT_CARD_DISABLED)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 880 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 881 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 882 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 883 | |
Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 884 | iwl_write_direct32(priv, HBUS_TARG_MBX_C, |
| 885 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 886 | |
| 887 | if (!(flags & RXON_CARD_DISABLED)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 888 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 889 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 890 | iwl_write_direct32(priv, HBUS_TARG_MBX_C, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 891 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 892 | } |
Wey-Yi Guy | 3a41bbd | 2009-12-10 14:37:24 -0800 | [diff] [blame] | 893 | if (flags & CT_CARD_DISABLED) |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 894 | iwl_tt_enter_ct_kill(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 895 | } |
Wey-Yi Guy | 3a41bbd | 2009-12-10 14:37:24 -0800 | [diff] [blame] | 896 | if (!(flags & CT_CARD_DISABLED)) |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 897 | iwl_tt_exit_ct_kill(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 898 | |
| 899 | if (flags & HW_CARD_DISABLED) |
| 900 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 901 | else |
| 902 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 903 | |
| 904 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 905 | if (!(flags & RXON_CARD_DISABLED)) |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 906 | iwl_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 907 | |
| 908 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
Johannes Berg | a60e77e | 2009-06-04 18:26:06 +0200 | [diff] [blame] | 909 | test_bit(STATUS_RF_KILL_HW, &priv->status))) |
| 910 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, |
| 911 | test_bit(STATUS_RF_KILL_HW, &priv->status)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 912 | else |
| 913 | wake_up_interruptible(&priv->wait_command_queue); |
| 914 | } |
| 915 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 916 | int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src) |
Tomas Winkler | e2e3c57 | 2008-07-18 13:53:04 +0800 | [diff] [blame] | 917 | { |
Tomas Winkler | e2e3c57 | 2008-07-18 13:53:04 +0800 | [diff] [blame] | 918 | if (src == IWL_PWR_SRC_VAUX) { |
Tomas Winkler | 3fdb68d | 2009-02-10 15:19:02 -0800 | [diff] [blame] | 919 | if (pci_pme_capable(priv->pci_dev, PCI_D3cold)) |
Tomas Winkler | e2e3c57 | 2008-07-18 13:53:04 +0800 | [diff] [blame] | 920 | iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, |
| 921 | APMG_PS_CTRL_VAL_PWR_SRC_VAUX, |
| 922 | ~APMG_PS_CTRL_MSK_PWR_SRC); |
| 923 | } else { |
| 924 | iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, |
| 925 | APMG_PS_CTRL_VAL_PWR_SRC_VMAIN, |
| 926 | ~APMG_PS_CTRL_MSK_PWR_SRC); |
| 927 | } |
| 928 | |
Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 929 | return 0; |
Tomas Winkler | e2e3c57 | 2008-07-18 13:53:04 +0800 | [diff] [blame] | 930 | } |
| 931 | |
Wey-Yi Guy | 6555063 | 2010-06-24 13:18:35 -0700 | [diff] [blame] | 932 | static void iwl_bg_tx_flush(struct work_struct *work) |
| 933 | { |
| 934 | struct iwl_priv *priv = |
| 935 | container_of(work, struct iwl_priv, tx_flush); |
| 936 | |
| 937 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 938 | return; |
| 939 | |
| 940 | /* do nothing if rf-kill is on */ |
| 941 | if (!iwl_is_ready_rf(priv)) |
| 942 | return; |
| 943 | |
| 944 | if (priv->cfg->ops->lib->txfifo_flush) { |
| 945 | IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n"); |
| 946 | iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL); |
| 947 | } |
| 948 | } |
| 949 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 950 | /** |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 951 | * iwl_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 952 | * |
| 953 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 954 | * to the host. |
| 955 | * |
| 956 | * This function chains into the hardware specific files for them to setup |
| 957 | * any hardware specific handlers as well. |
| 958 | */ |
Emmanuel Grumbach | 653fa4a | 2008-06-30 17:23:11 +0800 | [diff] [blame] | 959 | static void iwl_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 960 | { |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 961 | priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive; |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 962 | priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error; |
| 963 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa; |
Reinette Chatre | 81963d6 | 2010-01-22 14:22:57 -0800 | [diff] [blame] | 964 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
| 965 | iwl_rx_spectrum_measure_notif; |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 966 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 967 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 968 | iwl_rx_pm_debug_statistics_notif; |
| 969 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 970 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 971 | /* |
| 972 | * The same handler is used for both the REPLY to a discrete |
| 973 | * statistics request from the host as well as for the periodic |
| 974 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 975 | */ |
Wey-Yi Guy | ef8d552 | 2009-11-13 11:56:28 -0800 | [diff] [blame] | 976 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_reply_statistics; |
Emmanuel Grumbach | 8f91aec | 2008-06-30 17:23:07 +0800 | [diff] [blame] | 977 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics; |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 978 | |
| 979 | iwl_setup_rx_scan_handlers(priv); |
| 980 | |
Ron Rindjunsky | 37a4421 | 2008-05-29 16:35:18 +0800 | [diff] [blame] | 981 | /* status change handler */ |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 982 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 983 | |
Tomas Winkler | c135475 | 2008-05-29 16:35:04 +0800 | [diff] [blame] | 984 | priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] = |
| 985 | iwl_rx_missed_beacon_notif; |
Ron Rindjunsky | 37a4421 | 2008-05-29 16:35:18 +0800 | [diff] [blame] | 986 | /* Rx handlers */ |
Wey-Yi Guy | 8d80108 | 2010-03-17 13:34:36 -0700 | [diff] [blame] | 987 | priv->rx_handlers[REPLY_RX_PHY_CMD] = iwlagn_rx_reply_rx_phy; |
| 988 | priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwlagn_rx_reply_rx; |
Emmanuel Grumbach | 653fa4a | 2008-06-30 17:23:11 +0800 | [diff] [blame] | 989 | /* block ack */ |
Wey-Yi Guy | 74bcdb3 | 2010-03-17 13:34:34 -0700 | [diff] [blame] | 990 | priv->rx_handlers[REPLY_COMPRESSED_BA] = iwlagn_rx_reply_compressed_ba; |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 991 | /* Set up hardware specific Rx handlers */ |
Emmanuel Grumbach | d4789ef | 2008-04-24 11:55:20 -0700 | [diff] [blame] | 992 | priv->cfg->ops->lib->rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 995 | /** |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 996 | * iwl_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 997 | * |
| 998 | * Uses the priv->rx_handlers callback function array to invoke |
| 999 | * the appropriate handlers, including command responses, |
| 1000 | * frame-received notifications, and other notifications. |
| 1001 | */ |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1002 | void iwl_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1003 | { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1004 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 1005 | struct iwl_rx_packet *pkt; |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1006 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1007 | u32 r, i; |
| 1008 | int reclaim; |
| 1009 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1010 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 1011 | u32 count = 8; |
Mohamed Abbas | 4752c93 | 2009-05-22 11:01:51 -0700 | [diff] [blame] | 1012 | int total_empty; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1013 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1014 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 1015 | * buffer that the driver may process (last buffer filled by ucode). */ |
Winkler, Tomas | 8d86422 | 2008-11-07 09:58:39 -0800 | [diff] [blame] | 1016 | r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1017 | i = rxq->read; |
| 1018 | |
| 1019 | /* Rx interrupt, but nothing sent from uCode */ |
| 1020 | if (i == r) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1021 | IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1022 | |
Mohamed Abbas | 4752c93 | 2009-05-22 11:01:51 -0700 | [diff] [blame] | 1023 | /* calculate total frames need to be restock after handling RX */ |
Zhu Yi | 7300515 | 2009-10-23 13:42:32 -0700 | [diff] [blame] | 1024 | total_empty = r - rxq->write_actual; |
Mohamed Abbas | 4752c93 | 2009-05-22 11:01:51 -0700 | [diff] [blame] | 1025 | if (total_empty < 0) |
| 1026 | total_empty += RX_QUEUE_SIZE; |
| 1027 | |
| 1028 | if (total_empty > (RX_QUEUE_SIZE / 2)) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1029 | fill_rx = 1; |
| 1030 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1031 | while (i != r) { |
Johannes Berg | f4989d9 | 2010-05-28 04:08:30 -0700 | [diff] [blame] | 1032 | int len; |
| 1033 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1034 | rxb = rxq->queue[i]; |
| 1035 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1036 | /* 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] | 1037 | * then a bug has been introduced in the queue refilling |
| 1038 | * routines -- catch it here */ |
| 1039 | BUG_ON(rxb == NULL); |
| 1040 | |
| 1041 | rxq->queue[i] = NULL; |
| 1042 | |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1043 | pci_unmap_page(priv->pci_dev, rxb->page_dma, |
| 1044 | PAGE_SIZE << priv->hw_params.rx_page_order, |
| 1045 | PCI_DMA_FROMDEVICE); |
| 1046 | pkt = rxb_addr(rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1047 | |
Johannes Berg | f4989d9 | 2010-05-28 04:08:30 -0700 | [diff] [blame] | 1048 | len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; |
| 1049 | len += sizeof(u32); /* account for status word */ |
| 1050 | trace_iwlwifi_dev_rx(priv, pkt, len); |
Johannes Berg | be1a71a | 2009-10-02 13:44:02 -0700 | [diff] [blame] | 1051 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1052 | /* Reclaim a command buffer only if this packet is a response |
| 1053 | * to a (driver-originated) command. |
| 1054 | * If the packet (e.g. Rx frame) originated from uCode, |
| 1055 | * there is no command buffer to reclaim. |
| 1056 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 1057 | * but apparently a few don't get set; catch them here. */ |
| 1058 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 1059 | (pkt->hdr.cmd != REPLY_RX_PHY_CMD) && |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1060 | (pkt->hdr.cmd != REPLY_RX) && |
Daniel Halperin | 7dddaf1 | 2008-10-23 23:48:58 -0700 | [diff] [blame] | 1061 | (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) && |
Zhu Yi | cfe0170 | 2007-09-27 11:27:31 +0800 | [diff] [blame] | 1062 | (pkt->hdr.cmd != REPLY_COMPRESSED_BA) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1063 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 1064 | (pkt->hdr.cmd != REPLY_TX); |
| 1065 | |
| 1066 | /* Based on type of command response or notification, |
| 1067 | * handle those that need handling via function in |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 1068 | * rx_handlers table. See iwl_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1069 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1070 | IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r, |
Ester Kummer | f3d6799 | 2008-05-06 11:05:12 +0800 | [diff] [blame] | 1071 | i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1072 | priv->isr_stats.rx_handlers[pkt->hdr.cmd]++; |
Zhu Yi | 29b1b26 | 2009-10-23 13:42:25 -0700 | [diff] [blame] | 1073 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1074 | } else { |
| 1075 | /* No handling needed */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1076 | IWL_DEBUG_RX(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1077 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 1078 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 1079 | pkt->hdr.cmd); |
| 1080 | } |
| 1081 | |
Zhu Yi | 29b1b26 | 2009-10-23 13:42:25 -0700 | [diff] [blame] | 1082 | /* |
| 1083 | * XXX: After here, we should always check rxb->page |
| 1084 | * against NULL before touching it or its virtual |
| 1085 | * memory (pkt). Because some rx_handler might have |
| 1086 | * already taken or freed the pages. |
| 1087 | */ |
| 1088 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1089 | if (reclaim) { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1090 | /* Invoke any callbacks, transfer the buffer to caller, |
| 1091 | * and fire off the (possibly) blocking iwl_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1092 | * as we reclaim the driver command queue */ |
Zhu Yi | 29b1b26 | 2009-10-23 13:42:25 -0700 | [diff] [blame] | 1093 | if (rxb->page) |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 1094 | iwl_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1095 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1096 | IWL_WARN(priv, "Claim null rxb?\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Zhu Yi | 7300515 | 2009-10-23 13:42:32 -0700 | [diff] [blame] | 1099 | /* Reuse the page if possible. For notification packets and |
| 1100 | * SKBs that fail to Rx correctly, add them back into the |
| 1101 | * rx_free list for reuse later. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1102 | spin_lock_irqsave(&rxq->lock, flags); |
Zhu Yi | 7300515 | 2009-10-23 13:42:32 -0700 | [diff] [blame] | 1103 | if (rxb->page != NULL) { |
| 1104 | rxb->page_dma = pci_map_page(priv->pci_dev, rxb->page, |
| 1105 | 0, PAGE_SIZE << priv->hw_params.rx_page_order, |
| 1106 | PCI_DMA_FROMDEVICE); |
| 1107 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 1108 | rxq->free_count++; |
| 1109 | } else |
| 1110 | list_add_tail(&rxb->list, &rxq->rx_used); |
| 1111 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1112 | spin_unlock_irqrestore(&rxq->lock, flags); |
Zhu Yi | 7300515 | 2009-10-23 13:42:32 -0700 | [diff] [blame] | 1113 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1114 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1115 | /* If there are a lot of unused frames, |
| 1116 | * restock the Rx queue so ucode wont assert. */ |
| 1117 | if (fill_rx) { |
| 1118 | count++; |
| 1119 | if (count >= 8) { |
Zhu Yi | 7300515 | 2009-10-23 13:42:32 -0700 | [diff] [blame] | 1120 | rxq->read = i; |
Wey-Yi Guy | 54b8155 | 2010-03-17 13:34:35 -0700 | [diff] [blame] | 1121 | iwlagn_rx_replenish_now(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1122 | count = 0; |
| 1123 | } |
| 1124 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | /* Backtrack one entry */ |
Zhu Yi | 7300515 | 2009-10-23 13:42:32 -0700 | [diff] [blame] | 1128 | rxq->read = i; |
Mohamed Abbas | 4752c93 | 2009-05-22 11:01:51 -0700 | [diff] [blame] | 1129 | if (fill_rx) |
Wey-Yi Guy | 54b8155 | 2010-03-17 13:34:35 -0700 | [diff] [blame] | 1130 | iwlagn_rx_replenish_now(priv); |
Mohamed Abbas | 4752c93 | 2009-05-22 11:01:51 -0700 | [diff] [blame] | 1131 | else |
Wey-Yi Guy | 54b8155 | 2010-03-17 13:34:35 -0700 | [diff] [blame] | 1132 | iwlagn_rx_queue_restock(priv); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1133 | } |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1134 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 1135 | /* call this function to flush any scheduled tasklet */ |
| 1136 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
| 1137 | { |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1138 | /* wait to make sure we flush pending tasklet*/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 1139 | synchronize_irq(priv->pci_dev->irq); |
| 1140 | tasklet_kill(&priv->irq_tasklet); |
| 1141 | } |
| 1142 | |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1143 | static void iwl_irq_tasklet_legacy(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1144 | { |
| 1145 | u32 inta, handled = 0; |
| 1146 | u32 inta_fh; |
| 1147 | unsigned long flags; |
Ben Cahill | c2e61da | 2009-10-30 14:36:09 -0700 | [diff] [blame] | 1148 | u32 i; |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1149 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1150 | u32 inta_mask; |
| 1151 | #endif |
| 1152 | |
| 1153 | spin_lock_irqsave(&priv->lock, flags); |
| 1154 | |
| 1155 | /* Ack/clear/reset pending uCode interrupts. |
| 1156 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 1157 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1158 | inta = iwl_read32(priv, CSR_INT); |
| 1159 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1160 | |
| 1161 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 1162 | * Any new interrupts that happen after this, either while we're |
| 1163 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1164 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 1165 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1166 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1167 | #ifdef CONFIG_IWLWIFI_DEBUG |
Reinette Chatre | 3d816c7 | 2009-08-07 15:41:37 -0700 | [diff] [blame] | 1168 | if (iwl_get_debug_level(priv) & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1169 | /* just for debug */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1170 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1171 | IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1172 | inta, inta_mask, inta_fh); |
| 1173 | } |
| 1174 | #endif |
| 1175 | |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1176 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1177 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1178 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 1179 | * atomic, make sure that inta covers all the interrupts that |
| 1180 | * we've discovered, even if FH interrupt came in just after |
| 1181 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 1182 | if (inta_fh & CSR49_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1183 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 1184 | if (inta_fh & CSR49_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1185 | inta |= CSR_INT_BIT_FH_TX; |
| 1186 | |
| 1187 | /* Now service all interrupt bits discovered above. */ |
| 1188 | if (inta & CSR_INT_BIT_HW_ERR) { |
Reinette Chatre | 58dba72 | 2009-07-17 09:30:25 -0700 | [diff] [blame] | 1189 | IWL_ERR(priv, "Hardware error detected. Restarting.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1190 | |
| 1191 | /* Tell the device to stop sending interrupts */ |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 1192 | iwl_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1193 | |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1194 | priv->isr_stats.hw++; |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 1195 | iwl_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1196 | |
| 1197 | handled |= CSR_INT_BIT_HW_ERR; |
| 1198 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1199 | return; |
| 1200 | } |
| 1201 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1202 | #ifdef CONFIG_IWLWIFI_DEBUG |
Reinette Chatre | 3d816c7 | 2009-08-07 15:41:37 -0700 | [diff] [blame] | 1203 | if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1204 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1205 | if (inta & CSR_INT_BIT_SCD) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1206 | IWL_DEBUG_ISR(priv, "Scheduler finished to transmit " |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 1207 | "the frame/frames.\n"); |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1208 | priv->isr_stats.sch++; |
| 1209 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1210 | |
| 1211 | /* Alive notification via Rx interrupt will do the real work */ |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1212 | if (inta & CSR_INT_BIT_ALIVE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1213 | IWL_DEBUG_ISR(priv, "Alive interrupt\n"); |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1214 | priv->isr_stats.alive++; |
| 1215 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1216 | } |
| 1217 | #endif |
| 1218 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 1219 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1220 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1221 | /* HW RF KILL switch toggled */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1222 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 1223 | int hw_rf_kill = 0; |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1224 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1225 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 1226 | hw_rf_kill = 1; |
| 1227 | |
Reinette Chatre | 4c423a2 | 2009-07-17 09:30:26 -0700 | [diff] [blame] | 1228 | IWL_WARN(priv, "RF_KILL bit toggled to %s.\n", |
Abhijeet Kolekar | c305606 | 2008-11-12 13:14:08 -0800 | [diff] [blame] | 1229 | hw_rf_kill ? "disable radio" : "enable radio"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1230 | |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1231 | priv->isr_stats.rfkill++; |
| 1232 | |
Emmanuel Grumbach | a9efa65 | 2008-06-30 17:23:25 +0800 | [diff] [blame] | 1233 | /* driver only loads ucode once setting the interface up. |
Helmut Schaa | 6cd0b1c | 2009-01-19 13:10:07 +0100 | [diff] [blame] | 1234 | * the driver allows loading the ucode even if the radio |
| 1235 | * is killed. Hence update the killswitch state here. The |
| 1236 | * rfkill handler will care about restarting if needed. |
Emmanuel Grumbach | a9efa65 | 2008-06-30 17:23:25 +0800 | [diff] [blame] | 1237 | */ |
Helmut Schaa | 6cd0b1c | 2009-01-19 13:10:07 +0100 | [diff] [blame] | 1238 | if (!test_bit(STATUS_ALIVE, &priv->status)) { |
| 1239 | if (hw_rf_kill) |
| 1240 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 1241 | else |
| 1242 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Johannes Berg | a60e77e | 2009-06-04 18:26:06 +0200 | [diff] [blame] | 1243 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill); |
Mohamed Abbas | edb3422 | 2008-12-11 10:33:37 -0800 | [diff] [blame] | 1244 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1245 | |
| 1246 | handled |= CSR_INT_BIT_RF_KILL; |
| 1247 | } |
| 1248 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1249 | /* Chip got too hot and stopped itself */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1250 | if (inta & CSR_INT_BIT_CT_KILL) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1251 | IWL_ERR(priv, "Microcode CT kill error detected.\n"); |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1252 | priv->isr_stats.ctkill++; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1253 | handled |= CSR_INT_BIT_CT_KILL; |
| 1254 | } |
| 1255 | |
| 1256 | /* Error detected by uCode */ |
| 1257 | if (inta & CSR_INT_BIT_SW_ERR) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1258 | IWL_ERR(priv, "Microcode SW error detected. " |
| 1259 | " Restarting 0x%X.\n", inta); |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1260 | priv->isr_stats.sw++; |
| 1261 | priv->isr_stats.sw_err = inta; |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 1262 | iwl_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1263 | handled |= CSR_INT_BIT_SW_ERR; |
| 1264 | } |
| 1265 | |
Ben Cahill | c2e61da | 2009-10-30 14:36:09 -0700 | [diff] [blame] | 1266 | /* |
| 1267 | * uCode wakes up after power-down sleep. |
| 1268 | * Tell device about any new tx or host commands enqueued, |
| 1269 | * and about any Rx buffers made available while asleep. |
| 1270 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1271 | if (inta & CSR_INT_BIT_WAKEUP) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1272 | IWL_DEBUG_ISR(priv, "Wakeup interrupt\n"); |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1273 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Ben Cahill | c2e61da | 2009-10-30 14:36:09 -0700 | [diff] [blame] | 1274 | for (i = 0; i < priv->hw_params.max_txq_num; i++) |
| 1275 | iwl_txq_update_write_ptr(priv, &priv->txq[i]); |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1276 | priv->isr_stats.wakeup++; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1277 | handled |= CSR_INT_BIT_WAKEUP; |
| 1278 | } |
| 1279 | |
| 1280 | /* All uCode command responses, including Tx command responses, |
| 1281 | * Rx "responses" (frame-received notification), and other |
| 1282 | * notifications from uCode come through here*/ |
| 1283 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 1284 | iwl_rx_handle(priv); |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1285 | priv->isr_stats.rx++; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1286 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 1287 | } |
| 1288 | |
Ben Cahill | c72cd19 | 2009-10-30 14:36:08 -0700 | [diff] [blame] | 1289 | /* This "Tx" DMA channel is used only for loading uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1290 | if (inta & CSR_INT_BIT_FH_TX) { |
Ben Cahill | c72cd19 | 2009-10-30 14:36:08 -0700 | [diff] [blame] | 1291 | IWL_DEBUG_ISR(priv, "uCode load interrupt\n"); |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1292 | priv->isr_stats.tx++; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1293 | handled |= CSR_INT_BIT_FH_TX; |
Ben Cahill | c72cd19 | 2009-10-30 14:36:08 -0700 | [diff] [blame] | 1294 | /* Wake up uCode load routine, now that load is complete */ |
Ron Rindjunsky | dbb983b | 2008-05-15 13:54:12 +0800 | [diff] [blame] | 1295 | priv->ucode_write_complete = 1; |
| 1296 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1297 | } |
| 1298 | |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1299 | if (inta & ~handled) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1300 | IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled); |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1301 | priv->isr_stats.unhandled++; |
| 1302 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1303 | |
Mohamed Abbas | 40cefda | 2009-05-22 11:01:52 -0700 | [diff] [blame] | 1304 | if (inta & ~(priv->inta_mask)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1305 | IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n", |
Mohamed Abbas | 40cefda | 2009-05-22 11:01:52 -0700 | [diff] [blame] | 1306 | inta & ~priv->inta_mask); |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1307 | IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 1311 | /* only Re-enable if diabled by irq */ |
| 1312 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 1313 | iwl_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1314 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 1315 | #ifdef CONFIG_IWLWIFI_DEBUG |
Reinette Chatre | 3d816c7 | 2009-08-07 15:41:37 -0700 | [diff] [blame] | 1316 | if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1317 | inta = iwl_read32(priv, CSR_INT); |
| 1318 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 1319 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1320 | IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1321 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 1322 | } |
| 1323 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1326 | /* tasklet for iwlagn interrupt */ |
| 1327 | static void iwl_irq_tasklet(struct iwl_priv *priv) |
| 1328 | { |
| 1329 | u32 inta = 0; |
| 1330 | u32 handled = 0; |
| 1331 | unsigned long flags; |
Ben Cahill | 8756990 | 2009-11-06 14:53:01 -0800 | [diff] [blame] | 1332 | u32 i; |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1333 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 1334 | u32 inta_mask; |
| 1335 | #endif |
| 1336 | |
| 1337 | spin_lock_irqsave(&priv->lock, flags); |
| 1338 | |
| 1339 | /* Ack/clear/reset pending uCode interrupts. |
| 1340 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 1341 | */ |
Shanyu Zhao | 48a6be6 | 2010-03-16 10:22:26 -0700 | [diff] [blame] | 1342 | /* There is a hardware bug in the interrupt mask function that some |
| 1343 | * interrupts (i.e. CSR_INT_BIT_SCD) can still be generated even if |
| 1344 | * they are disabled in the CSR_INT_MASK register. Furthermore the |
| 1345 | * ICT interrupt handling mechanism has another bug that might cause |
| 1346 | * these unmasked interrupts fail to be detected. We workaround the |
| 1347 | * hardware bugs here by ACKing all the possible interrupts so that |
| 1348 | * interrupt coalescing can still be achieved. |
| 1349 | */ |
David S. Miller | 4a35ecf | 2010-04-06 23:53:30 -0700 | [diff] [blame] | 1350 | iwl_write32(priv, CSR_INT, priv->_agn.inta | ~priv->inta_mask); |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1351 | |
Johannes Berg | a4c8b2a | 2010-01-21 06:25:54 -0800 | [diff] [blame] | 1352 | inta = priv->_agn.inta; |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1353 | |
| 1354 | #ifdef CONFIG_IWLWIFI_DEBUG |
Reinette Chatre | 3d816c7 | 2009-08-07 15:41:37 -0700 | [diff] [blame] | 1355 | if (iwl_get_debug_level(priv) & IWL_DL_ISR) { |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1356 | /* just for debug */ |
| 1357 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 1358 | IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x\n ", |
| 1359 | inta, inta_mask); |
| 1360 | } |
| 1361 | #endif |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1362 | |
| 1363 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1364 | |
Johannes Berg | a4c8b2a | 2010-01-21 06:25:54 -0800 | [diff] [blame] | 1365 | /* saved interrupt in inta variable now we can reset priv->_agn.inta */ |
| 1366 | priv->_agn.inta = 0; |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1367 | |
| 1368 | /* Now service all interrupt bits discovered above. */ |
| 1369 | if (inta & CSR_INT_BIT_HW_ERR) { |
Reinette Chatre | 58dba72 | 2009-07-17 09:30:25 -0700 | [diff] [blame] | 1370 | IWL_ERR(priv, "Hardware error detected. Restarting.\n"); |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1371 | |
| 1372 | /* Tell the device to stop sending interrupts */ |
| 1373 | iwl_disable_interrupts(priv); |
| 1374 | |
| 1375 | priv->isr_stats.hw++; |
| 1376 | iwl_irq_handle_error(priv); |
| 1377 | |
| 1378 | handled |= CSR_INT_BIT_HW_ERR; |
| 1379 | |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1380 | return; |
| 1381 | } |
| 1382 | |
| 1383 | #ifdef CONFIG_IWLWIFI_DEBUG |
Reinette Chatre | 3d816c7 | 2009-08-07 15:41:37 -0700 | [diff] [blame] | 1384 | if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) { |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1385 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
| 1386 | if (inta & CSR_INT_BIT_SCD) { |
| 1387 | IWL_DEBUG_ISR(priv, "Scheduler finished to transmit " |
| 1388 | "the frame/frames.\n"); |
| 1389 | priv->isr_stats.sch++; |
| 1390 | } |
| 1391 | |
| 1392 | /* Alive notification via Rx interrupt will do the real work */ |
| 1393 | if (inta & CSR_INT_BIT_ALIVE) { |
| 1394 | IWL_DEBUG_ISR(priv, "Alive interrupt\n"); |
| 1395 | priv->isr_stats.alive++; |
| 1396 | } |
| 1397 | } |
| 1398 | #endif |
| 1399 | /* Safely ignore these bits for debug checks below */ |
| 1400 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
| 1401 | |
| 1402 | /* HW RF KILL switch toggled */ |
| 1403 | if (inta & CSR_INT_BIT_RF_KILL) { |
| 1404 | int hw_rf_kill = 0; |
| 1405 | if (!(iwl_read32(priv, CSR_GP_CNTRL) & |
| 1406 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)) |
| 1407 | hw_rf_kill = 1; |
| 1408 | |
Reinette Chatre | 4c423a2 | 2009-07-17 09:30:26 -0700 | [diff] [blame] | 1409 | IWL_WARN(priv, "RF_KILL bit toggled to %s.\n", |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1410 | hw_rf_kill ? "disable radio" : "enable radio"); |
| 1411 | |
| 1412 | priv->isr_stats.rfkill++; |
| 1413 | |
| 1414 | /* driver only loads ucode once setting the interface up. |
| 1415 | * the driver allows loading the ucode even if the radio |
| 1416 | * is killed. Hence update the killswitch state here. The |
| 1417 | * rfkill handler will care about restarting if needed. |
| 1418 | */ |
| 1419 | if (!test_bit(STATUS_ALIVE, &priv->status)) { |
| 1420 | if (hw_rf_kill) |
| 1421 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 1422 | else |
| 1423 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Johannes Berg | a60e77e | 2009-06-04 18:26:06 +0200 | [diff] [blame] | 1424 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill); |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | handled |= CSR_INT_BIT_RF_KILL; |
| 1428 | } |
| 1429 | |
| 1430 | /* Chip got too hot and stopped itself */ |
| 1431 | if (inta & CSR_INT_BIT_CT_KILL) { |
| 1432 | IWL_ERR(priv, "Microcode CT kill error detected.\n"); |
| 1433 | priv->isr_stats.ctkill++; |
| 1434 | handled |= CSR_INT_BIT_CT_KILL; |
| 1435 | } |
| 1436 | |
| 1437 | /* Error detected by uCode */ |
| 1438 | if (inta & CSR_INT_BIT_SW_ERR) { |
| 1439 | IWL_ERR(priv, "Microcode SW error detected. " |
| 1440 | " Restarting 0x%X.\n", inta); |
| 1441 | priv->isr_stats.sw++; |
| 1442 | priv->isr_stats.sw_err = inta; |
| 1443 | iwl_irq_handle_error(priv); |
| 1444 | handled |= CSR_INT_BIT_SW_ERR; |
| 1445 | } |
| 1446 | |
| 1447 | /* uCode wakes up after power-down sleep */ |
| 1448 | if (inta & CSR_INT_BIT_WAKEUP) { |
| 1449 | IWL_DEBUG_ISR(priv, "Wakeup interrupt\n"); |
| 1450 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Ben Cahill | 8756990 | 2009-11-06 14:53:01 -0800 | [diff] [blame] | 1451 | for (i = 0; i < priv->hw_params.max_txq_num; i++) |
| 1452 | iwl_txq_update_write_ptr(priv, &priv->txq[i]); |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1453 | |
| 1454 | priv->isr_stats.wakeup++; |
| 1455 | |
| 1456 | handled |= CSR_INT_BIT_WAKEUP; |
| 1457 | } |
| 1458 | |
| 1459 | /* All uCode command responses, including Tx command responses, |
| 1460 | * Rx "responses" (frame-received notification), and other |
| 1461 | * notifications from uCode come through here*/ |
Mohamed Abbas | 40cefda | 2009-05-22 11:01:52 -0700 | [diff] [blame] | 1462 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX | |
| 1463 | CSR_INT_BIT_RX_PERIODIC)) { |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1464 | IWL_DEBUG_ISR(priv, "Rx interrupt\n"); |
Mohamed Abbas | 40cefda | 2009-05-22 11:01:52 -0700 | [diff] [blame] | 1465 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
| 1466 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 1467 | iwl_write32(priv, CSR_FH_INT_STATUS, |
| 1468 | CSR49_FH_INT_RX_MASK); |
| 1469 | } |
| 1470 | if (inta & CSR_INT_BIT_RX_PERIODIC) { |
| 1471 | handled |= CSR_INT_BIT_RX_PERIODIC; |
| 1472 | iwl_write32(priv, CSR_INT, CSR_INT_BIT_RX_PERIODIC); |
| 1473 | } |
| 1474 | /* Sending RX interrupt require many steps to be done in the |
| 1475 | * the device: |
| 1476 | * 1- write interrupt to current index in ICT table. |
| 1477 | * 2- dma RX frame. |
| 1478 | * 3- update RX shared data to indicate last write index. |
| 1479 | * 4- send interrupt. |
| 1480 | * This could lead to RX race, driver could receive RX interrupt |
Ben Cahill | 74ba67e | 2009-11-20 12:04:53 -0800 | [diff] [blame] | 1481 | * but the shared data changes does not reflect this; |
| 1482 | * periodic interrupt will detect any dangling Rx activity. |
Mohamed Abbas | 40cefda | 2009-05-22 11:01:52 -0700 | [diff] [blame] | 1483 | */ |
Ben Cahill | 74ba67e | 2009-11-20 12:04:53 -0800 | [diff] [blame] | 1484 | |
| 1485 | /* Disable periodic interrupt; we use it as just a one-shot. */ |
| 1486 | iwl_write8(priv, CSR_INT_PERIODIC_REG, |
Mohamed Abbas | 40cefda | 2009-05-22 11:01:52 -0700 | [diff] [blame] | 1487 | CSR_INT_PERIODIC_DIS); |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1488 | iwl_rx_handle(priv); |
Ben Cahill | 74ba67e | 2009-11-20 12:04:53 -0800 | [diff] [blame] | 1489 | |
| 1490 | /* |
| 1491 | * Enable periodic interrupt in 8 msec only if we received |
| 1492 | * real RX interrupt (instead of just periodic int), to catch |
| 1493 | * any dangling Rx interrupt. If it was just the periodic |
| 1494 | * interrupt, there was no dangling Rx activity, and no need |
| 1495 | * to extend the periodic interrupt; one-shot is enough. |
| 1496 | */ |
Mohamed Abbas | 40cefda | 2009-05-22 11:01:52 -0700 | [diff] [blame] | 1497 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) |
Ben Cahill | 74ba67e | 2009-11-20 12:04:53 -0800 | [diff] [blame] | 1498 | iwl_write8(priv, CSR_INT_PERIODIC_REG, |
Mohamed Abbas | 40cefda | 2009-05-22 11:01:52 -0700 | [diff] [blame] | 1499 | CSR_INT_PERIODIC_ENA); |
| 1500 | |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1501 | priv->isr_stats.rx++; |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
Ben Cahill | c72cd19 | 2009-10-30 14:36:08 -0700 | [diff] [blame] | 1504 | /* This "Tx" DMA channel is used only for loading uCode */ |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1505 | if (inta & CSR_INT_BIT_FH_TX) { |
| 1506 | iwl_write32(priv, CSR_FH_INT_STATUS, CSR49_FH_INT_TX_MASK); |
Ben Cahill | c72cd19 | 2009-10-30 14:36:08 -0700 | [diff] [blame] | 1507 | IWL_DEBUG_ISR(priv, "uCode load interrupt\n"); |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1508 | priv->isr_stats.tx++; |
| 1509 | handled |= CSR_INT_BIT_FH_TX; |
Ben Cahill | c72cd19 | 2009-10-30 14:36:08 -0700 | [diff] [blame] | 1510 | /* Wake up uCode load routine, now that load is complete */ |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1511 | priv->ucode_write_complete = 1; |
| 1512 | wake_up_interruptible(&priv->wait_command_queue); |
| 1513 | } |
| 1514 | |
| 1515 | if (inta & ~handled) { |
| 1516 | IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled); |
| 1517 | priv->isr_stats.unhandled++; |
| 1518 | } |
| 1519 | |
Mohamed Abbas | 40cefda | 2009-05-22 11:01:52 -0700 | [diff] [blame] | 1520 | if (inta & ~(priv->inta_mask)) { |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1521 | IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n", |
Mohamed Abbas | 40cefda | 2009-05-22 11:01:52 -0700 | [diff] [blame] | 1522 | inta & ~priv->inta_mask); |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1525 | /* Re-enable all interrupts */ |
| 1526 | /* only Re-enable if diabled by irq */ |
| 1527 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
| 1528 | iwl_enable_interrupts(priv); |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 1529 | } |
| 1530 | |
Wey-Yi Guy | 872c8dd | 2010-03-16 10:46:31 -0700 | [diff] [blame] | 1531 | /* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */ |
| 1532 | #define ACK_CNT_RATIO (50) |
| 1533 | #define BA_TIMEOUT_CNT (5) |
| 1534 | #define BA_TIMEOUT_MAX (16) |
| 1535 | |
| 1536 | /** |
| 1537 | * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries. |
| 1538 | * |
| 1539 | * When the ACK count ratio is 0 and aggregated BA timeout retries exceeding |
| 1540 | * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal |
| 1541 | * operation state. |
| 1542 | */ |
| 1543 | bool iwl_good_ack_health(struct iwl_priv *priv, |
| 1544 | struct iwl_rx_packet *pkt) |
| 1545 | { |
| 1546 | bool rc = true; |
| 1547 | int actual_ack_cnt_delta, expected_ack_cnt_delta; |
| 1548 | int ba_timeout_delta; |
| 1549 | |
| 1550 | actual_ack_cnt_delta = |
| 1551 | le32_to_cpu(pkt->u.stats.tx.actual_ack_cnt) - |
Wey-Yi Guy | f3aebee | 2010-06-14 17:09:54 -0700 | [diff] [blame] | 1552 | le32_to_cpu(priv->_agn.statistics.tx.actual_ack_cnt); |
Wey-Yi Guy | 872c8dd | 2010-03-16 10:46:31 -0700 | [diff] [blame] | 1553 | expected_ack_cnt_delta = |
| 1554 | le32_to_cpu(pkt->u.stats.tx.expected_ack_cnt) - |
Wey-Yi Guy | f3aebee | 2010-06-14 17:09:54 -0700 | [diff] [blame] | 1555 | le32_to_cpu(priv->_agn.statistics.tx.expected_ack_cnt); |
Wey-Yi Guy | 872c8dd | 2010-03-16 10:46:31 -0700 | [diff] [blame] | 1556 | ba_timeout_delta = |
| 1557 | le32_to_cpu(pkt->u.stats.tx.agg.ba_timeout) - |
Wey-Yi Guy | f3aebee | 2010-06-14 17:09:54 -0700 | [diff] [blame] | 1558 | le32_to_cpu(priv->_agn.statistics.tx.agg.ba_timeout); |
Wey-Yi Guy | 872c8dd | 2010-03-16 10:46:31 -0700 | [diff] [blame] | 1559 | if ((priv->_agn.agg_tids_count > 0) && |
| 1560 | (expected_ack_cnt_delta > 0) && |
| 1561 | (((actual_ack_cnt_delta * 100) / expected_ack_cnt_delta) |
| 1562 | < ACK_CNT_RATIO) && |
| 1563 | (ba_timeout_delta > BA_TIMEOUT_CNT)) { |
| 1564 | IWL_DEBUG_RADIO(priv, "actual_ack_cnt delta = %d," |
| 1565 | " expected_ack_cnt = %d\n", |
| 1566 | actual_ack_cnt_delta, expected_ack_cnt_delta); |
| 1567 | |
Johannes Berg | d73e492 | 2010-05-06 12:18:41 -0700 | [diff] [blame] | 1568 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1569 | /* |
| 1570 | * This is ifdef'ed on DEBUGFS because otherwise the |
| 1571 | * statistics aren't available. If DEBUGFS is set but |
| 1572 | * DEBUG is not, these will just compile out. |
| 1573 | */ |
Wey-Yi Guy | 872c8dd | 2010-03-16 10:46:31 -0700 | [diff] [blame] | 1574 | IWL_DEBUG_RADIO(priv, "rx_detected_cnt delta = %d\n", |
Wey-Yi Guy | f3aebee | 2010-06-14 17:09:54 -0700 | [diff] [blame] | 1575 | priv->_agn.delta_statistics.tx.rx_detected_cnt); |
Wey-Yi Guy | 872c8dd | 2010-03-16 10:46:31 -0700 | [diff] [blame] | 1576 | IWL_DEBUG_RADIO(priv, |
| 1577 | "ack_or_ba_timeout_collision delta = %d\n", |
Wey-Yi Guy | f3aebee | 2010-06-14 17:09:54 -0700 | [diff] [blame] | 1578 | priv->_agn.delta_statistics.tx. |
Wey-Yi Guy | 872c8dd | 2010-03-16 10:46:31 -0700 | [diff] [blame] | 1579 | ack_or_ba_timeout_collision); |
| 1580 | #endif |
| 1581 | IWL_DEBUG_RADIO(priv, "agg ba_timeout delta = %d\n", |
| 1582 | ba_timeout_delta); |
| 1583 | if (!actual_ack_cnt_delta && |
| 1584 | (ba_timeout_delta >= BA_TIMEOUT_MAX)) |
| 1585 | rc = false; |
| 1586 | } |
| 1587 | return rc; |
| 1588 | } |
| 1589 | |
Wey-Yi Guy | a83b914 | 2009-04-08 11:39:32 -0700 | [diff] [blame] | 1590 | |
Emmanuel Grumbach | 7d47618 | 2010-05-23 00:14:08 -0700 | [diff] [blame] | 1591 | /***************************************************************************** |
| 1592 | * |
| 1593 | * sysfs attributes |
| 1594 | * |
| 1595 | *****************************************************************************/ |
| 1596 | |
| 1597 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 1598 | |
| 1599 | /* |
| 1600 | * The following adds a new attribute to the sysfs representation |
| 1601 | * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/) |
| 1602 | * used for controlling the debug level. |
| 1603 | * |
| 1604 | * See the level definitions in iwl for details. |
| 1605 | * |
| 1606 | * The debug_level being managed using sysfs below is a per device debug |
| 1607 | * level that is used instead of the global debug level if it (the per |
| 1608 | * device debug level) is set. |
| 1609 | */ |
| 1610 | static ssize_t show_debug_level(struct device *d, |
| 1611 | struct device_attribute *attr, char *buf) |
| 1612 | { |
| 1613 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 1614 | return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv)); |
| 1615 | } |
| 1616 | static ssize_t store_debug_level(struct device *d, |
| 1617 | struct device_attribute *attr, |
| 1618 | const char *buf, size_t count) |
| 1619 | { |
| 1620 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 1621 | unsigned long val; |
| 1622 | int ret; |
| 1623 | |
| 1624 | ret = strict_strtoul(buf, 0, &val); |
| 1625 | if (ret) |
| 1626 | IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf); |
| 1627 | else { |
| 1628 | priv->debug_level = val; |
| 1629 | if (iwl_alloc_traffic_mem(priv)) |
| 1630 | IWL_ERR(priv, |
| 1631 | "Not enough memory to generate traffic log\n"); |
| 1632 | } |
| 1633 | return strnlen(buf, count); |
| 1634 | } |
| 1635 | |
| 1636 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 1637 | show_debug_level, store_debug_level); |
| 1638 | |
| 1639 | |
| 1640 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
| 1641 | |
| 1642 | |
| 1643 | static ssize_t show_temperature(struct device *d, |
| 1644 | struct device_attribute *attr, char *buf) |
| 1645 | { |
| 1646 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 1647 | |
| 1648 | if (!iwl_is_alive(priv)) |
| 1649 | return -EAGAIN; |
| 1650 | |
| 1651 | return sprintf(buf, "%d\n", priv->temperature); |
| 1652 | } |
| 1653 | |
| 1654 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 1655 | |
| 1656 | static ssize_t show_tx_power(struct device *d, |
| 1657 | struct device_attribute *attr, char *buf) |
| 1658 | { |
| 1659 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 1660 | |
| 1661 | if (!iwl_is_ready_rf(priv)) |
| 1662 | return sprintf(buf, "off\n"); |
| 1663 | else |
| 1664 | return sprintf(buf, "%d\n", priv->tx_power_user_lmt); |
| 1665 | } |
| 1666 | |
| 1667 | static ssize_t store_tx_power(struct device *d, |
| 1668 | struct device_attribute *attr, |
| 1669 | const char *buf, size_t count) |
| 1670 | { |
| 1671 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 1672 | unsigned long val; |
| 1673 | int ret; |
| 1674 | |
| 1675 | ret = strict_strtoul(buf, 10, &val); |
| 1676 | if (ret) |
| 1677 | IWL_INFO(priv, "%s is not in decimal form.\n", buf); |
| 1678 | else { |
| 1679 | ret = iwl_set_tx_power(priv, val, false); |
| 1680 | if (ret) |
| 1681 | IWL_ERR(priv, "failed setting tx power (0x%d).\n", |
| 1682 | ret); |
| 1683 | else |
| 1684 | ret = count; |
| 1685 | } |
| 1686 | return ret; |
| 1687 | } |
| 1688 | |
| 1689 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 1690 | |
Emmanuel Grumbach | 7d47618 | 2010-05-23 00:14:08 -0700 | [diff] [blame] | 1691 | static struct attribute *iwl_sysfs_entries[] = { |
| 1692 | &dev_attr_temperature.attr, |
| 1693 | &dev_attr_tx_power.attr, |
Emmanuel Grumbach | 7d47618 | 2010-05-23 00:14:08 -0700 | [diff] [blame] | 1694 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 1695 | &dev_attr_debug_level.attr, |
| 1696 | #endif |
| 1697 | NULL |
| 1698 | }; |
| 1699 | |
| 1700 | static struct attribute_group iwl_attribute_group = { |
| 1701 | .name = NULL, /* put in device directory */ |
| 1702 | .attrs = iwl_sysfs_entries, |
| 1703 | }; |
| 1704 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1705 | /****************************************************************************** |
| 1706 | * |
| 1707 | * uCode download functions |
| 1708 | * |
| 1709 | ******************************************************************************/ |
| 1710 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 1711 | static void iwl_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1712 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 1713 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 1714 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 1715 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 1716 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 1717 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 1718 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 1721 | static void iwl_nic_start(struct iwl_priv *priv) |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 1722 | { |
| 1723 | /* Remove all resets to allow NIC to operate */ |
| 1724 | iwl_write32(priv, CSR_RESET, 0); |
| 1725 | } |
| 1726 | |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 1727 | struct iwlagn_ucode_capabilities { |
| 1728 | u32 max_probe_length; |
Wey-Yi Guy | 6a822d0 | 2010-07-13 17:13:15 -0700 | [diff] [blame] | 1729 | u32 standard_phy_calibration_size; |
Johannes Berg | ece9c4e | 2010-08-23 10:46:49 +0200 | [diff] [blame] | 1730 | bool pan; |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 1731 | }; |
Ron Rindjunsky | edcdf8b | 2008-05-15 13:53:55 +0800 | [diff] [blame] | 1732 | |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 1733 | static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context); |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 1734 | static int iwl_mac_setup_register(struct iwl_priv *priv, |
| 1735 | struct iwlagn_ucode_capabilities *capa); |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 1736 | |
Jay Sternberg | 3939608 | 2010-08-12 10:24:07 -0700 | [diff] [blame] | 1737 | #define UCODE_EXPERIMENTAL_INDEX 100 |
| 1738 | #define UCODE_EXPERIMENTAL_TAG "exp" |
| 1739 | |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 1740 | static int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1741 | { |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 1742 | const char *name_pre = priv->cfg->fw_name_pre; |
Jay Sternberg | 3939608 | 2010-08-12 10:24:07 -0700 | [diff] [blame] | 1743 | char tag[8]; |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 1744 | |
Jay Sternberg | 3939608 | 2010-08-12 10:24:07 -0700 | [diff] [blame] | 1745 | if (first) { |
| 1746 | #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE |
| 1747 | priv->fw_index = UCODE_EXPERIMENTAL_INDEX; |
| 1748 | strcpy(tag, UCODE_EXPERIMENTAL_TAG); |
| 1749 | } else if (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) { |
| 1750 | #endif |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 1751 | priv->fw_index = priv->cfg->ucode_api_max; |
Jay Sternberg | 3939608 | 2010-08-12 10:24:07 -0700 | [diff] [blame] | 1752 | sprintf(tag, "%d", priv->fw_index); |
| 1753 | } else { |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 1754 | priv->fw_index--; |
Jay Sternberg | 3939608 | 2010-08-12 10:24:07 -0700 | [diff] [blame] | 1755 | sprintf(tag, "%d", priv->fw_index); |
| 1756 | } |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 1757 | |
| 1758 | if (priv->fw_index < priv->cfg->ucode_api_min) { |
| 1759 | IWL_ERR(priv, "no suitable firmware found!\n"); |
| 1760 | return -ENOENT; |
| 1761 | } |
| 1762 | |
Jay Sternberg | 3939608 | 2010-08-12 10:24:07 -0700 | [diff] [blame] | 1763 | sprintf(priv->firmware_name, "%s%s%s", name_pre, tag, ".ucode"); |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 1764 | |
Jay Sternberg | 3939608 | 2010-08-12 10:24:07 -0700 | [diff] [blame] | 1765 | IWL_DEBUG_INFO(priv, "attempting to load firmware %s'%s'\n", |
| 1766 | (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) |
| 1767 | ? "EXPERIMENTAL " : "", |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 1768 | priv->firmware_name); |
| 1769 | |
| 1770 | return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name, |
| 1771 | &priv->pci_dev->dev, GFP_KERNEL, priv, |
| 1772 | iwl_ucode_callback); |
| 1773 | } |
| 1774 | |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 1775 | struct iwlagn_firmware_pieces { |
| 1776 | const void *inst, *data, *init, *init_data, *boot; |
| 1777 | size_t inst_size, data_size, init_size, init_data_size, boot_size; |
| 1778 | |
| 1779 | u32 build; |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 1780 | |
| 1781 | u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr; |
| 1782 | u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr; |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 1783 | }; |
| 1784 | |
| 1785 | static int iwlagn_load_legacy_firmware(struct iwl_priv *priv, |
| 1786 | const struct firmware *ucode_raw, |
| 1787 | struct iwlagn_firmware_pieces *pieces) |
| 1788 | { |
| 1789 | struct iwl_ucode_header *ucode = (void *)ucode_raw->data; |
| 1790 | u32 api_ver, hdr_size; |
| 1791 | const u8 *src; |
| 1792 | |
| 1793 | priv->ucode_ver = le32_to_cpu(ucode->ver); |
| 1794 | api_ver = IWL_UCODE_API(priv->ucode_ver); |
| 1795 | |
| 1796 | switch (api_ver) { |
| 1797 | default: |
| 1798 | /* |
| 1799 | * 4965 doesn't revision the firmware file format |
| 1800 | * along with the API version, it always uses v1 |
| 1801 | * file format. |
| 1802 | */ |
| 1803 | if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != |
| 1804 | CSR_HW_REV_TYPE_4965) { |
| 1805 | hdr_size = 28; |
| 1806 | if (ucode_raw->size < hdr_size) { |
| 1807 | IWL_ERR(priv, "File size too small!\n"); |
| 1808 | return -EINVAL; |
| 1809 | } |
| 1810 | pieces->build = le32_to_cpu(ucode->u.v2.build); |
| 1811 | pieces->inst_size = le32_to_cpu(ucode->u.v2.inst_size); |
| 1812 | pieces->data_size = le32_to_cpu(ucode->u.v2.data_size); |
| 1813 | pieces->init_size = le32_to_cpu(ucode->u.v2.init_size); |
| 1814 | pieces->init_data_size = le32_to_cpu(ucode->u.v2.init_data_size); |
| 1815 | pieces->boot_size = le32_to_cpu(ucode->u.v2.boot_size); |
| 1816 | src = ucode->u.v2.data; |
| 1817 | break; |
| 1818 | } |
| 1819 | /* fall through for 4965 */ |
| 1820 | case 0: |
| 1821 | case 1: |
| 1822 | case 2: |
| 1823 | hdr_size = 24; |
| 1824 | if (ucode_raw->size < hdr_size) { |
| 1825 | IWL_ERR(priv, "File size too small!\n"); |
| 1826 | return -EINVAL; |
| 1827 | } |
| 1828 | pieces->build = 0; |
| 1829 | pieces->inst_size = le32_to_cpu(ucode->u.v1.inst_size); |
| 1830 | pieces->data_size = le32_to_cpu(ucode->u.v1.data_size); |
| 1831 | pieces->init_size = le32_to_cpu(ucode->u.v1.init_size); |
| 1832 | pieces->init_data_size = le32_to_cpu(ucode->u.v1.init_data_size); |
| 1833 | pieces->boot_size = le32_to_cpu(ucode->u.v1.boot_size); |
| 1834 | src = ucode->u.v1.data; |
| 1835 | break; |
| 1836 | } |
| 1837 | |
| 1838 | /* Verify size of file vs. image size info in file's header */ |
| 1839 | if (ucode_raw->size != hdr_size + pieces->inst_size + |
| 1840 | pieces->data_size + pieces->init_size + |
| 1841 | pieces->init_data_size + pieces->boot_size) { |
| 1842 | |
| 1843 | IWL_ERR(priv, |
| 1844 | "uCode file size %d does not match expected size\n", |
| 1845 | (int)ucode_raw->size); |
| 1846 | return -EINVAL; |
| 1847 | } |
| 1848 | |
| 1849 | pieces->inst = src; |
| 1850 | src += pieces->inst_size; |
| 1851 | pieces->data = src; |
| 1852 | src += pieces->data_size; |
| 1853 | pieces->init = src; |
| 1854 | src += pieces->init_size; |
| 1855 | pieces->init_data = src; |
| 1856 | src += pieces->init_data_size; |
| 1857 | pieces->boot = src; |
| 1858 | src += pieces->boot_size; |
| 1859 | |
| 1860 | return 0; |
| 1861 | } |
| 1862 | |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 1863 | static int iwlagn_wanted_ucode_alternative = 1; |
| 1864 | |
| 1865 | static int iwlagn_load_firmware(struct iwl_priv *priv, |
| 1866 | const struct firmware *ucode_raw, |
| 1867 | struct iwlagn_firmware_pieces *pieces, |
| 1868 | struct iwlagn_ucode_capabilities *capa) |
| 1869 | { |
| 1870 | struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data; |
| 1871 | struct iwl_ucode_tlv *tlv; |
| 1872 | size_t len = ucode_raw->size; |
| 1873 | const u8 *data; |
| 1874 | int wanted_alternative = iwlagn_wanted_ucode_alternative, tmp; |
| 1875 | u64 alternatives; |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 1876 | u32 tlv_len; |
| 1877 | enum iwl_ucode_tlv_type tlv_type; |
| 1878 | const u8 *tlv_data; |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 1879 | |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 1880 | if (len < sizeof(*ucode)) { |
| 1881 | IWL_ERR(priv, "uCode has invalid length: %zd\n", len); |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 1882 | return -EINVAL; |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 1883 | } |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 1884 | |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 1885 | if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) { |
| 1886 | IWL_ERR(priv, "invalid uCode magic: 0X%x\n", |
| 1887 | le32_to_cpu(ucode->magic)); |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 1888 | return -EINVAL; |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 1889 | } |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 1890 | |
| 1891 | /* |
| 1892 | * Check which alternatives are present, and "downgrade" |
| 1893 | * when the chosen alternative is not present, warning |
| 1894 | * the user when that happens. Some files may not have |
| 1895 | * any alternatives, so don't warn in that case. |
| 1896 | */ |
| 1897 | alternatives = le64_to_cpu(ucode->alternatives); |
| 1898 | tmp = wanted_alternative; |
| 1899 | if (wanted_alternative > 63) |
| 1900 | wanted_alternative = 63; |
| 1901 | while (wanted_alternative && !(alternatives & BIT(wanted_alternative))) |
| 1902 | wanted_alternative--; |
| 1903 | if (wanted_alternative && wanted_alternative != tmp) |
| 1904 | IWL_WARN(priv, |
| 1905 | "uCode alternative %d not available, choosing %d\n", |
| 1906 | tmp, wanted_alternative); |
| 1907 | |
| 1908 | priv->ucode_ver = le32_to_cpu(ucode->ver); |
| 1909 | pieces->build = le32_to_cpu(ucode->build); |
| 1910 | data = ucode->data; |
| 1911 | |
| 1912 | len -= sizeof(*ucode); |
| 1913 | |
Johannes Berg | 704da53 | 2010-07-14 09:34:50 -0700 | [diff] [blame] | 1914 | while (len >= sizeof(*tlv)) { |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 1915 | u16 tlv_alt; |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 1916 | |
| 1917 | len -= sizeof(*tlv); |
| 1918 | tlv = (void *)data; |
| 1919 | |
| 1920 | tlv_len = le32_to_cpu(tlv->length); |
| 1921 | tlv_type = le16_to_cpu(tlv->type); |
| 1922 | tlv_alt = le16_to_cpu(tlv->alternative); |
| 1923 | tlv_data = tlv->data; |
| 1924 | |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 1925 | if (len < tlv_len) { |
| 1926 | IWL_ERR(priv, "invalid TLV len: %zd/%u\n", |
| 1927 | len, tlv_len); |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 1928 | return -EINVAL; |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 1929 | } |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 1930 | len -= ALIGN(tlv_len, 4); |
| 1931 | data += sizeof(*tlv) + ALIGN(tlv_len, 4); |
| 1932 | |
| 1933 | /* |
| 1934 | * Alternative 0 is always valid. |
| 1935 | * |
| 1936 | * Skip alternative TLVs that are not selected. |
| 1937 | */ |
| 1938 | if (tlv_alt != 0 && tlv_alt != wanted_alternative) |
| 1939 | continue; |
| 1940 | |
| 1941 | switch (tlv_type) { |
| 1942 | case IWL_UCODE_TLV_INST: |
| 1943 | pieces->inst = tlv_data; |
| 1944 | pieces->inst_size = tlv_len; |
| 1945 | break; |
| 1946 | case IWL_UCODE_TLV_DATA: |
| 1947 | pieces->data = tlv_data; |
| 1948 | pieces->data_size = tlv_len; |
| 1949 | break; |
| 1950 | case IWL_UCODE_TLV_INIT: |
| 1951 | pieces->init = tlv_data; |
| 1952 | pieces->init_size = tlv_len; |
| 1953 | break; |
| 1954 | case IWL_UCODE_TLV_INIT_DATA: |
| 1955 | pieces->init_data = tlv_data; |
| 1956 | pieces->init_data_size = tlv_len; |
| 1957 | break; |
| 1958 | case IWL_UCODE_TLV_BOOT: |
| 1959 | pieces->boot = tlv_data; |
| 1960 | pieces->boot_size = tlv_len; |
| 1961 | break; |
| 1962 | case IWL_UCODE_TLV_PROBE_MAX_LEN: |
Johannes Berg | 704da53 | 2010-07-14 09:34:50 -0700 | [diff] [blame] | 1963 | if (tlv_len != sizeof(u32)) |
| 1964 | goto invalid_tlv_len; |
| 1965 | capa->max_probe_length = |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 1966 | le32_to_cpup((__le32 *)tlv_data); |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 1967 | break; |
Johannes Berg | ece9c4e | 2010-08-23 10:46:49 +0200 | [diff] [blame] | 1968 | case IWL_UCODE_TLV_PAN: |
| 1969 | if (tlv_len) |
| 1970 | goto invalid_tlv_len; |
| 1971 | capa->pan = true; |
| 1972 | break; |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 1973 | case IWL_UCODE_TLV_INIT_EVTLOG_PTR: |
Johannes Berg | 704da53 | 2010-07-14 09:34:50 -0700 | [diff] [blame] | 1974 | if (tlv_len != sizeof(u32)) |
| 1975 | goto invalid_tlv_len; |
| 1976 | pieces->init_evtlog_ptr = |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 1977 | le32_to_cpup((__le32 *)tlv_data); |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 1978 | break; |
| 1979 | case IWL_UCODE_TLV_INIT_EVTLOG_SIZE: |
Johannes Berg | 704da53 | 2010-07-14 09:34:50 -0700 | [diff] [blame] | 1980 | if (tlv_len != sizeof(u32)) |
| 1981 | goto invalid_tlv_len; |
| 1982 | pieces->init_evtlog_size = |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 1983 | le32_to_cpup((__le32 *)tlv_data); |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 1984 | break; |
| 1985 | case IWL_UCODE_TLV_INIT_ERRLOG_PTR: |
Johannes Berg | 704da53 | 2010-07-14 09:34:50 -0700 | [diff] [blame] | 1986 | if (tlv_len != sizeof(u32)) |
| 1987 | goto invalid_tlv_len; |
| 1988 | pieces->init_errlog_ptr = |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 1989 | le32_to_cpup((__le32 *)tlv_data); |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 1990 | break; |
| 1991 | case IWL_UCODE_TLV_RUNT_EVTLOG_PTR: |
Johannes Berg | 704da53 | 2010-07-14 09:34:50 -0700 | [diff] [blame] | 1992 | if (tlv_len != sizeof(u32)) |
| 1993 | goto invalid_tlv_len; |
| 1994 | pieces->inst_evtlog_ptr = |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 1995 | le32_to_cpup((__le32 *)tlv_data); |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 1996 | break; |
| 1997 | case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE: |
Johannes Berg | 704da53 | 2010-07-14 09:34:50 -0700 | [diff] [blame] | 1998 | if (tlv_len != sizeof(u32)) |
| 1999 | goto invalid_tlv_len; |
| 2000 | pieces->inst_evtlog_size = |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 2001 | le32_to_cpup((__le32 *)tlv_data); |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2002 | break; |
| 2003 | case IWL_UCODE_TLV_RUNT_ERRLOG_PTR: |
Johannes Berg | 704da53 | 2010-07-14 09:34:50 -0700 | [diff] [blame] | 2004 | if (tlv_len != sizeof(u32)) |
| 2005 | goto invalid_tlv_len; |
| 2006 | pieces->inst_errlog_ptr = |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 2007 | le32_to_cpup((__le32 *)tlv_data); |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2008 | break; |
Wey-Yi Guy | c8312fa | 2010-06-28 13:05:17 -0700 | [diff] [blame] | 2009 | case IWL_UCODE_TLV_ENHANCE_SENS_TBL: |
| 2010 | if (tlv_len) |
Johannes Berg | 704da53 | 2010-07-14 09:34:50 -0700 | [diff] [blame] | 2011 | goto invalid_tlv_len; |
| 2012 | priv->enhance_sensitivity_table = true; |
Wey-Yi Guy | c8312fa | 2010-06-28 13:05:17 -0700 | [diff] [blame] | 2013 | break; |
Wey-Yi Guy | 6a822d0 | 2010-07-13 17:13:15 -0700 | [diff] [blame] | 2014 | case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE: |
Johannes Berg | 704da53 | 2010-07-14 09:34:50 -0700 | [diff] [blame] | 2015 | if (tlv_len != sizeof(u32)) |
| 2016 | goto invalid_tlv_len; |
| 2017 | capa->standard_phy_calibration_size = |
Wey-Yi Guy | 6a822d0 | 2010-07-13 17:13:15 -0700 | [diff] [blame] | 2018 | le32_to_cpup((__le32 *)tlv_data); |
| 2019 | break; |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 2020 | default: |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 2021 | IWL_WARN(priv, "unknown TLV: %d\n", tlv_type); |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 2022 | break; |
| 2023 | } |
| 2024 | } |
| 2025 | |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 2026 | if (len) { |
| 2027 | IWL_ERR(priv, "invalid TLV after parsing: %zd\n", len); |
| 2028 | iwl_print_hex_dump(priv, IWL_DL_FW, (u8 *)data, len); |
Johannes Berg | 704da53 | 2010-07-14 09:34:50 -0700 | [diff] [blame] | 2029 | return -EINVAL; |
Wey-Yi Guy | ad8d833 | 2010-06-22 14:31:45 -0700 | [diff] [blame] | 2030 | } |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 2031 | |
Johannes Berg | 704da53 | 2010-07-14 09:34:50 -0700 | [diff] [blame] | 2032 | return 0; |
| 2033 | |
| 2034 | invalid_tlv_len: |
| 2035 | IWL_ERR(priv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len); |
| 2036 | iwl_print_hex_dump(priv, IWL_DL_FW, tlv_data, tlv_len); |
| 2037 | |
| 2038 | return -EINVAL; |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2041 | /** |
| 2042 | * iwl_ucode_callback - callback when firmware was loaded |
| 2043 | * |
| 2044 | * If loaded successfully, copies the firmware into buffers |
| 2045 | * for the card to fetch (via DMA). |
| 2046 | */ |
| 2047 | static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context) |
| 2048 | { |
| 2049 | struct iwl_priv *priv = context; |
| 2050 | struct iwl_ucode_header *ucode; |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2051 | int err; |
| 2052 | struct iwlagn_firmware_pieces pieces; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2053 | const unsigned int api_max = priv->cfg->ucode_api_max; |
| 2054 | const unsigned int api_min = priv->cfg->ucode_api_min; |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2055 | u32 api_ver; |
Johannes Berg | 3e4de76 | 2010-04-28 12:09:12 -0700 | [diff] [blame] | 2056 | char buildstr[25]; |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2057 | u32 build; |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 2058 | struct iwlagn_ucode_capabilities ucode_capa = { |
| 2059 | .max_probe_length = 200, |
Wey-Yi Guy | 6a822d0 | 2010-07-13 17:13:15 -0700 | [diff] [blame] | 2060 | .standard_phy_calibration_size = |
| 2061 | IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE, |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 2062 | }; |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2063 | |
| 2064 | memset(&pieces, 0, sizeof(pieces)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2065 | |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2066 | if (!ucode_raw) { |
Jay Sternberg | 3939608 | 2010-08-12 10:24:07 -0700 | [diff] [blame] | 2067 | if (priv->fw_index <= priv->cfg->ucode_api_max) |
| 2068 | IWL_ERR(priv, |
| 2069 | "request for firmware file '%s' failed.\n", |
| 2070 | priv->firmware_name); |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2071 | goto try_again; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2072 | } |
| 2073 | |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2074 | IWL_DEBUG_INFO(priv, "Loaded firmware file '%s' (%zd bytes).\n", |
| 2075 | priv->firmware_name, ucode_raw->size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2076 | |
Johannes Berg | 22adba2 | 2010-04-28 12:09:14 -0700 | [diff] [blame] | 2077 | /* Make sure that we got at least the API version number */ |
| 2078 | if (ucode_raw->size < 4) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2079 | IWL_ERR(priv, "File size way too small!\n"); |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2080 | goto try_again; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2081 | } |
| 2082 | |
| 2083 | /* Data from ucode file: header followed by uCode images */ |
Jay Sternberg | cc0f555 | 2009-07-17 09:30:16 -0700 | [diff] [blame] | 2084 | ucode = (struct iwl_ucode_header *)ucode_raw->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2085 | |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2086 | if (ucode->ver) |
| 2087 | err = iwlagn_load_legacy_firmware(priv, ucode_raw, &pieces); |
| 2088 | else |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 2089 | err = iwlagn_load_firmware(priv, ucode_raw, &pieces, |
| 2090 | &ucode_capa); |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2091 | |
| 2092 | if (err) |
| 2093 | goto try_again; |
| 2094 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2095 | api_ver = IWL_UCODE_API(priv->ucode_ver); |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2096 | build = pieces.build; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2097 | |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2098 | /* |
| 2099 | * api_ver should match the api version forming part of the |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2100 | * firmware filename ... but we don't check for that and only rely |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2101 | * on the API version read from firmware header from here on forward |
| 2102 | */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2103 | if (api_ver < api_min || api_ver > api_max) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2104 | IWL_ERR(priv, "Driver unable to support your firmware API. " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2105 | "Driver supports v%u, firmware is v%u.\n", |
| 2106 | api_max, api_ver); |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2107 | goto try_again; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2108 | } |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2109 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2110 | if (api_ver != api_max) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 2111 | IWL_ERR(priv, "Firmware has old API version. Expected v%u, " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2112 | "got v%u. New firmware can be obtained " |
| 2113 | "from http://www.intellinuxwireless.org.\n", |
| 2114 | api_max, api_ver); |
| 2115 | |
Johannes Berg | 3e4de76 | 2010-04-28 12:09:12 -0700 | [diff] [blame] | 2116 | if (build) |
Jay Sternberg | 3939608 | 2010-08-12 10:24:07 -0700 | [diff] [blame] | 2117 | sprintf(buildstr, " build %u%s", build, |
| 2118 | (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) |
| 2119 | ? " (EXP)" : ""); |
Johannes Berg | 3e4de76 | 2010-04-28 12:09:12 -0700 | [diff] [blame] | 2120 | else |
| 2121 | buildstr[0] = '\0'; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2122 | |
Johannes Berg | 3e4de76 | 2010-04-28 12:09:12 -0700 | [diff] [blame] | 2123 | IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u%s\n", |
Reinette Chatre | 5ebeb5a | 2009-10-30 14:36:04 -0700 | [diff] [blame] | 2124 | IWL_UCODE_MAJOR(priv->ucode_ver), |
| 2125 | IWL_UCODE_MINOR(priv->ucode_ver), |
| 2126 | IWL_UCODE_API(priv->ucode_ver), |
Johannes Berg | 3e4de76 | 2010-04-28 12:09:12 -0700 | [diff] [blame] | 2127 | IWL_UCODE_SERIAL(priv->ucode_ver), |
| 2128 | buildstr); |
Reinette Chatre | 5ebeb5a | 2009-10-30 14:36:04 -0700 | [diff] [blame] | 2129 | |
Johannes Berg | 3e4de76 | 2010-04-28 12:09:12 -0700 | [diff] [blame] | 2130 | snprintf(priv->hw->wiphy->fw_version, |
| 2131 | sizeof(priv->hw->wiphy->fw_version), |
| 2132 | "%u.%u.%u.%u%s", |
| 2133 | IWL_UCODE_MAJOR(priv->ucode_ver), |
| 2134 | IWL_UCODE_MINOR(priv->ucode_ver), |
| 2135 | IWL_UCODE_API(priv->ucode_ver), |
| 2136 | IWL_UCODE_SERIAL(priv->ucode_ver), |
| 2137 | buildstr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2138 | |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2139 | /* |
| 2140 | * For any of the failures below (before allocating pci memory) |
| 2141 | * we will try to load a version with a smaller API -- maybe the |
| 2142 | * user just got a corrupted version of the latest API. |
| 2143 | */ |
| 2144 | |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2145 | IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n", |
| 2146 | priv->ucode_ver); |
| 2147 | IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %Zd\n", |
| 2148 | pieces.inst_size); |
| 2149 | IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %Zd\n", |
| 2150 | pieces.data_size); |
| 2151 | IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %Zd\n", |
| 2152 | pieces.init_size); |
| 2153 | IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %Zd\n", |
| 2154 | pieces.init_data_size); |
| 2155 | IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %Zd\n", |
| 2156 | pieces.boot_size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2157 | |
| 2158 | /* Verify that uCode images will fit in card's SRAM */ |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2159 | if (pieces.inst_size > priv->hw_params.max_inst_size) { |
| 2160 | IWL_ERR(priv, "uCode instr len %Zd too large to fit in\n", |
| 2161 | pieces.inst_size); |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2162 | goto try_again; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2165 | if (pieces.data_size > priv->hw_params.max_data_size) { |
| 2166 | IWL_ERR(priv, "uCode data len %Zd too large to fit in\n", |
| 2167 | pieces.data_size); |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2168 | goto try_again; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2169 | } |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2170 | |
| 2171 | if (pieces.init_size > priv->hw_params.max_inst_size) { |
| 2172 | IWL_ERR(priv, "uCode init instr len %Zd too large to fit in\n", |
| 2173 | pieces.init_size); |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2174 | goto try_again; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2175 | } |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2176 | |
| 2177 | if (pieces.init_data_size > priv->hw_params.max_data_size) { |
| 2178 | IWL_ERR(priv, "uCode init data len %Zd too large to fit in\n", |
| 2179 | pieces.init_data_size); |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2180 | goto try_again; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2181 | } |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2182 | |
| 2183 | if (pieces.boot_size > priv->hw_params.max_bsm_size) { |
| 2184 | IWL_ERR(priv, "uCode boot instr len %Zd too large to fit in\n", |
| 2185 | pieces.boot_size); |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2186 | goto try_again; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 2190 | |
| 2191 | /* Runtime instructions and 2 copies of data: |
| 2192 | * 1) unmodified from disk |
| 2193 | * 2) backup cache for save/restore during power-downs */ |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2194 | priv->ucode_code.len = pieces.inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2195 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2196 | |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2197 | priv->ucode_data.len = pieces.data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2198 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2199 | |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2200 | priv->ucode_data_backup.len = pieces.data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2201 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2202 | |
Zhu, Yi | 1f304e4 | 2009-01-23 13:45:22 -0800 | [diff] [blame] | 2203 | if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr || |
| 2204 | !priv->ucode_data_backup.v_addr) |
| 2205 | goto err_pci_alloc; |
| 2206 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2207 | /* Initialization instructions and data */ |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2208 | if (pieces.init_size && pieces.init_data_size) { |
| 2209 | priv->ucode_init.len = pieces.init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2210 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2211 | |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2212 | priv->ucode_init_data.len = pieces.init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2213 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2214 | |
| 2215 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 2216 | goto err_pci_alloc; |
| 2217 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2218 | |
| 2219 | /* Bootstrap (instructions only, no data) */ |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2220 | if (pieces.boot_size) { |
| 2221 | priv->ucode_boot.len = pieces.boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2222 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2223 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2224 | if (!priv->ucode_boot.v_addr) |
| 2225 | goto err_pci_alloc; |
| 2226 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2227 | |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2228 | /* Now that we can no longer fail, copy information */ |
| 2229 | |
| 2230 | /* |
| 2231 | * The (size - 16) / 12 formula is based on the information recorded |
| 2232 | * for each event, which is of mode 1 (including timestamp) for all |
| 2233 | * new microcodes that include this information. |
| 2234 | */ |
| 2235 | priv->_agn.init_evtlog_ptr = pieces.init_evtlog_ptr; |
| 2236 | if (pieces.init_evtlog_size) |
| 2237 | priv->_agn.init_evtlog_size = (pieces.init_evtlog_size - 16)/12; |
| 2238 | else |
| 2239 | priv->_agn.init_evtlog_size = priv->cfg->max_event_log_size; |
| 2240 | priv->_agn.init_errlog_ptr = pieces.init_errlog_ptr; |
| 2241 | priv->_agn.inst_evtlog_ptr = pieces.inst_evtlog_ptr; |
| 2242 | if (pieces.inst_evtlog_size) |
| 2243 | priv->_agn.inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12; |
| 2244 | else |
| 2245 | priv->_agn.inst_evtlog_size = priv->cfg->max_event_log_size; |
| 2246 | priv->_agn.inst_errlog_ptr = pieces.inst_errlog_ptr; |
| 2247 | |
Johannes Berg | ece9c4e | 2010-08-23 10:46:49 +0200 | [diff] [blame] | 2248 | if (ucode_capa.pan) { |
| 2249 | priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN); |
Johannes Berg | c10afb6 | 2010-08-23 10:46:43 +0200 | [diff] [blame] | 2250 | priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN; |
Johannes Berg | ece9c4e | 2010-08-23 10:46:49 +0200 | [diff] [blame] | 2251 | } else |
| 2252 | priv->sta_key_max_num = STA_KEY_MAX_NUM; |
Johannes Berg | c10afb6 | 2010-08-23 10:46:43 +0200 | [diff] [blame] | 2253 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2254 | /* Copy images into buffers for card's bus-master reads ... */ |
| 2255 | |
| 2256 | /* Runtime instructions (first block of data in file) */ |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2257 | IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n", |
| 2258 | pieces.inst_size); |
| 2259 | memcpy(priv->ucode_code.v_addr, pieces.inst, pieces.inst_size); |
Jay Sternberg | cc0f555 | 2009-07-17 09:30:16 -0700 | [diff] [blame] | 2260 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2261 | IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2262 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 2263 | |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2264 | /* |
| 2265 | * Runtime data |
| 2266 | * NOTE: Copy into backup buffer will be done in iwl_up() |
| 2267 | */ |
| 2268 | IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n", |
| 2269 | pieces.data_size); |
| 2270 | memcpy(priv->ucode_data.v_addr, pieces.data, pieces.data_size); |
| 2271 | memcpy(priv->ucode_data_backup.v_addr, pieces.data, pieces.data_size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2272 | |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2273 | /* Initialization instructions */ |
| 2274 | if (pieces.init_size) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2275 | IWL_DEBUG_INFO(priv, "Copying (but not loading) init instr len %Zd\n", |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2276 | pieces.init_size); |
| 2277 | memcpy(priv->ucode_init.v_addr, pieces.init, pieces.init_size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2278 | } |
| 2279 | |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2280 | /* Initialization data */ |
| 2281 | if (pieces.init_data_size) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2282 | IWL_DEBUG_INFO(priv, "Copying (but not loading) init data len %Zd\n", |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2283 | pieces.init_data_size); |
| 2284 | memcpy(priv->ucode_init_data.v_addr, pieces.init_data, |
| 2285 | pieces.init_data_size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
Johannes Berg | 0e9a44d | 2010-04-28 12:09:16 -0700 | [diff] [blame] | 2288 | /* Bootstrap instructions */ |
| 2289 | IWL_DEBUG_INFO(priv, "Copying (but not loading) boot instr len %Zd\n", |
| 2290 | pieces.boot_size); |
| 2291 | memcpy(priv->ucode_boot.v_addr, pieces.boot, pieces.boot_size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2292 | |
Wey-Yi Guy | 6a822d0 | 2010-07-13 17:13:15 -0700 | [diff] [blame] | 2293 | /* |
| 2294 | * figure out the offset of chain noise reset and gain commands |
| 2295 | * base on the size of standard phy calibration commands table size |
| 2296 | */ |
| 2297 | if (ucode_capa.standard_phy_calibration_size > |
| 2298 | IWL_MAX_PHY_CALIBRATE_TBL_SIZE) |
| 2299 | ucode_capa.standard_phy_calibration_size = |
| 2300 | IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE; |
| 2301 | |
| 2302 | priv->_agn.phy_calib_chain_noise_reset_cmd = |
| 2303 | ucode_capa.standard_phy_calibration_size; |
| 2304 | priv->_agn.phy_calib_chain_noise_gain_cmd = |
| 2305 | ucode_capa.standard_phy_calibration_size + 1; |
| 2306 | |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2307 | /************************************************** |
| 2308 | * This is still part of probe() in a sense... |
| 2309 | * |
| 2310 | * 9. Setup and register with mac80211 and debugfs |
| 2311 | **************************************************/ |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 2312 | err = iwl_mac_setup_register(priv, &ucode_capa); |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2313 | if (err) |
| 2314 | goto out_unbind; |
| 2315 | |
| 2316 | err = iwl_dbgfs_register(priv, DRV_NAME); |
| 2317 | if (err) |
| 2318 | IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err); |
| 2319 | |
Emmanuel Grumbach | 7d47618 | 2010-05-23 00:14:08 -0700 | [diff] [blame] | 2320 | err = sysfs_create_group(&priv->pci_dev->dev.kobj, |
| 2321 | &iwl_attribute_group); |
| 2322 | if (err) { |
| 2323 | IWL_ERR(priv, "failed to create sysfs device attributes\n"); |
| 2324 | goto out_unbind; |
| 2325 | } |
| 2326 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2327 | /* We have our copies now, allow OS release its copies */ |
| 2328 | release_firmware(ucode_raw); |
Reinette Chatre | a15707d | 2010-05-10 15:08:11 -0700 | [diff] [blame] | 2329 | complete(&priv->_agn.firmware_loading_complete); |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2330 | return; |
| 2331 | |
| 2332 | try_again: |
| 2333 | /* try next, if any */ |
| 2334 | if (iwl_request_firmware(priv, false)) |
| 2335 | goto out_unbind; |
| 2336 | release_firmware(ucode_raw); |
| 2337 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2338 | |
| 2339 | err_pci_alloc: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2340 | IWL_ERR(priv, "failed to allocate pci memory\n"); |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 2341 | iwl_dealloc_ucode_pci(priv); |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2342 | out_unbind: |
Reinette Chatre | a15707d | 2010-05-10 15:08:11 -0700 | [diff] [blame] | 2343 | complete(&priv->_agn.firmware_loading_complete); |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 2344 | device_release_driver(&priv->pci_dev->dev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2345 | release_firmware(ucode_raw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2346 | } |
| 2347 | |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2348 | static const char *desc_lookup_text[] = { |
| 2349 | "OK", |
| 2350 | "FAIL", |
| 2351 | "BAD_PARAM", |
| 2352 | "BAD_CHECKSUM", |
| 2353 | "NMI_INTERRUPT_WDG", |
| 2354 | "SYSASSERT", |
| 2355 | "FATAL_ERROR", |
| 2356 | "BAD_COMMAND", |
| 2357 | "HW_ERROR_TUNE_LOCK", |
| 2358 | "HW_ERROR_TEMPERATURE", |
| 2359 | "ILLEGAL_CHAN_FREQ", |
| 2360 | "VCC_NOT_STABLE", |
| 2361 | "FH_ERROR", |
| 2362 | "NMI_INTERRUPT_HOST", |
| 2363 | "NMI_INTERRUPT_ACTION_PT", |
| 2364 | "NMI_INTERRUPT_UNKNOWN", |
| 2365 | "UCODE_VERSION_MISMATCH", |
| 2366 | "HW_ERROR_ABS_LOCK", |
| 2367 | "HW_ERROR_CAL_LOCK_FAIL", |
| 2368 | "NMI_INTERRUPT_INST_ACTION_PT", |
| 2369 | "NMI_INTERRUPT_DATA_ACTION_PT", |
| 2370 | "NMI_TRM_HW_ER", |
| 2371 | "NMI_INTERRUPT_TRM", |
| 2372 | "NMI_INTERRUPT_BREAK_POINT" |
| 2373 | "DEBUG_0", |
| 2374 | "DEBUG_1", |
| 2375 | "DEBUG_2", |
| 2376 | "DEBUG_3", |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2377 | }; |
| 2378 | |
Jay Sternberg | 4b58645 | 2010-07-02 15:49:10 -0700 | [diff] [blame] | 2379 | static struct { char *name; u8 num; } advanced_lookup[] = { |
| 2380 | { "NMI_INTERRUPT_WDG", 0x34 }, |
| 2381 | { "SYSASSERT", 0x35 }, |
| 2382 | { "UCODE_VERSION_MISMATCH", 0x37 }, |
| 2383 | { "BAD_COMMAND", 0x38 }, |
| 2384 | { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C }, |
| 2385 | { "FATAL_ERROR", 0x3D }, |
| 2386 | { "NMI_TRM_HW_ERR", 0x46 }, |
| 2387 | { "NMI_INTERRUPT_TRM", 0x4C }, |
| 2388 | { "NMI_INTERRUPT_BREAK_POINT", 0x54 }, |
| 2389 | { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C }, |
| 2390 | { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 }, |
| 2391 | { "NMI_INTERRUPT_HOST", 0x66 }, |
| 2392 | { "NMI_INTERRUPT_ACTION_PT", 0x7C }, |
| 2393 | { "NMI_INTERRUPT_UNKNOWN", 0x84 }, |
| 2394 | { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 }, |
| 2395 | { "ADVANCED_SYSASSERT", 0 }, |
| 2396 | }; |
| 2397 | |
| 2398 | static const char *desc_lookup(u32 num) |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2399 | { |
Jay Sternberg | 4b58645 | 2010-07-02 15:49:10 -0700 | [diff] [blame] | 2400 | int i; |
| 2401 | int max = ARRAY_SIZE(desc_lookup_text); |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2402 | |
Jay Sternberg | 4b58645 | 2010-07-02 15:49:10 -0700 | [diff] [blame] | 2403 | if (num < max) |
| 2404 | return desc_lookup_text[num]; |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2405 | |
Jay Sternberg | 4b58645 | 2010-07-02 15:49:10 -0700 | [diff] [blame] | 2406 | max = ARRAY_SIZE(advanced_lookup) - 1; |
| 2407 | for (i = 0; i < max; i++) { |
| 2408 | if (advanced_lookup[i].num == num) |
| 2409 | break;; |
| 2410 | } |
| 2411 | return advanced_lookup[i].name; |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 2415 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 2416 | |
| 2417 | void iwl_dump_nic_error_log(struct iwl_priv *priv) |
| 2418 | { |
| 2419 | u32 data2, line; |
| 2420 | u32 desc, time, count, base, data1; |
| 2421 | u32 blink1, blink2, ilink1, ilink2; |
Wey-Yi Guy | 461ef38 | 2010-03-30 17:57:53 -0700 | [diff] [blame] | 2422 | u32 pc, hcmd; |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2423 | |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2424 | if (priv->ucode_type == UCODE_INIT) { |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2425 | base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr); |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2426 | if (!base) |
| 2427 | base = priv->_agn.init_errlog_ptr; |
| 2428 | } else { |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2429 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2430 | if (!base) |
| 2431 | base = priv->_agn.inst_errlog_ptr; |
| 2432 | } |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2433 | |
| 2434 | if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) { |
Wey-Yi Guy | 212fb57 | 2009-12-02 12:53:00 -0800 | [diff] [blame] | 2435 | IWL_ERR(priv, |
| 2436 | "Not valid error log pointer 0x%08X for %s uCode\n", |
| 2437 | base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT"); |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2438 | return; |
| 2439 | } |
| 2440 | |
| 2441 | count = iwl_read_targ_mem(priv, base); |
| 2442 | |
| 2443 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
| 2444 | IWL_ERR(priv, "Start IWL Error Log Dump:\n"); |
| 2445 | IWL_ERR(priv, "Status: 0x%08lX, count: %d\n", |
| 2446 | priv->status, count); |
| 2447 | } |
| 2448 | |
| 2449 | desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32)); |
Wey-Yi Guy | 461ef38 | 2010-03-30 17:57:53 -0700 | [diff] [blame] | 2450 | pc = iwl_read_targ_mem(priv, base + 2 * sizeof(u32)); |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2451 | blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32)); |
| 2452 | blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32)); |
| 2453 | ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32)); |
| 2454 | ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32)); |
| 2455 | data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32)); |
| 2456 | data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32)); |
| 2457 | line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32)); |
| 2458 | time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32)); |
Wey-Yi Guy | 461ef38 | 2010-03-30 17:57:53 -0700 | [diff] [blame] | 2459 | hcmd = iwl_read_targ_mem(priv, base + 22 * sizeof(u32)); |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2460 | |
Johannes Berg | be1a71a | 2009-10-02 13:44:02 -0700 | [diff] [blame] | 2461 | trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, data2, line, |
| 2462 | blink1, blink2, ilink1, ilink2); |
| 2463 | |
Jay Sternberg | 8756371 | 2010-06-14 14:40:40 -0700 | [diff] [blame] | 2464 | IWL_ERR(priv, "Desc Time " |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2465 | "data1 data2 line\n"); |
Jay Sternberg | 8756371 | 2010-06-14 14:40:40 -0700 | [diff] [blame] | 2466 | IWL_ERR(priv, "%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n", |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2467 | desc_lookup(desc), desc, time, data1, data2, line); |
Wey-Yi Guy | 461ef38 | 2010-03-30 17:57:53 -0700 | [diff] [blame] | 2468 | IWL_ERR(priv, "pc blink1 blink2 ilink1 ilink2 hcmd\n"); |
| 2469 | IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n", |
| 2470 | pc, blink1, blink2, ilink1, ilink2, hcmd); |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | #define EVENT_START_OFFSET (4 * sizeof(u32)) |
| 2474 | |
| 2475 | /** |
| 2476 | * iwl_print_event_log - Dump error event log to syslog |
| 2477 | * |
| 2478 | */ |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2479 | static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx, |
| 2480 | u32 num_events, u32 mode, |
| 2481 | int pos, char **buf, size_t bufsz) |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2482 | { |
| 2483 | u32 i; |
| 2484 | u32 base; /* SRAM byte address of event log header */ |
| 2485 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 2486 | u32 ptr; /* SRAM byte address of log data */ |
| 2487 | u32 ev, time, data; /* event log data */ |
Ben Cahill | e585447 | 2009-11-06 14:52:58 -0800 | [diff] [blame] | 2488 | unsigned long reg_flags; |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2489 | |
| 2490 | if (num_events == 0) |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2491 | return pos; |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2492 | |
| 2493 | if (priv->ucode_type == UCODE_INIT) { |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2494 | base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr); |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2495 | if (!base) |
| 2496 | base = priv->_agn.init_evtlog_ptr; |
| 2497 | } else { |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2498 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2499 | if (!base) |
| 2500 | base = priv->_agn.inst_evtlog_ptr; |
| 2501 | } |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2502 | |
| 2503 | if (mode == 0) |
| 2504 | event_size = 2 * sizeof(u32); |
| 2505 | else |
| 2506 | event_size = 3 * sizeof(u32); |
| 2507 | |
| 2508 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 2509 | |
Ben Cahill | e585447 | 2009-11-06 14:52:58 -0800 | [diff] [blame] | 2510 | /* Make sure device is powered up for SRAM reads */ |
| 2511 | spin_lock_irqsave(&priv->reg_lock, reg_flags); |
| 2512 | iwl_grab_nic_access(priv); |
| 2513 | |
| 2514 | /* Set starting address; reads will auto-increment */ |
| 2515 | _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr); |
| 2516 | rmb(); |
| 2517 | |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2518 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 2519 | * place event id # at far right for easier visual parsing. */ |
| 2520 | for (i = 0; i < num_events; i++) { |
Ben Cahill | e585447 | 2009-11-06 14:52:58 -0800 | [diff] [blame] | 2521 | ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
| 2522 | time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2523 | if (mode == 0) { |
| 2524 | /* data, ev */ |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2525 | if (bufsz) { |
| 2526 | pos += scnprintf(*buf + pos, bufsz - pos, |
| 2527 | "EVT_LOG:0x%08x:%04u\n", |
| 2528 | time, ev); |
| 2529 | } else { |
| 2530 | trace_iwlwifi_dev_ucode_event(priv, 0, |
| 2531 | time, ev); |
| 2532 | IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n", |
| 2533 | time, ev); |
| 2534 | } |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2535 | } else { |
Ben Cahill | e585447 | 2009-11-06 14:52:58 -0800 | [diff] [blame] | 2536 | data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2537 | if (bufsz) { |
| 2538 | pos += scnprintf(*buf + pos, bufsz - pos, |
| 2539 | "EVT_LOGT:%010u:0x%08x:%04u\n", |
| 2540 | time, data, ev); |
| 2541 | } else { |
| 2542 | IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n", |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2543 | time, data, ev); |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2544 | trace_iwlwifi_dev_ucode_event(priv, time, |
| 2545 | data, ev); |
| 2546 | } |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2547 | } |
| 2548 | } |
Ben Cahill | e585447 | 2009-11-06 14:52:58 -0800 | [diff] [blame] | 2549 | |
| 2550 | /* Allow device to power down */ |
| 2551 | iwl_release_nic_access(priv); |
| 2552 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2553 | return pos; |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2554 | } |
| 2555 | |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2556 | /** |
| 2557 | * iwl_print_last_event_logs - Dump the newest # of event log to syslog |
| 2558 | */ |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2559 | static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity, |
| 2560 | u32 num_wraps, u32 next_entry, |
| 2561 | u32 size, u32 mode, |
| 2562 | int pos, char **buf, size_t bufsz) |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2563 | { |
| 2564 | /* |
| 2565 | * display the newest DEFAULT_LOG_ENTRIES entries |
| 2566 | * i.e the entries just before the next ont that uCode would fill. |
| 2567 | */ |
| 2568 | if (num_wraps) { |
| 2569 | if (next_entry < size) { |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2570 | pos = iwl_print_event_log(priv, |
| 2571 | capacity - (size - next_entry), |
| 2572 | size - next_entry, mode, |
| 2573 | pos, buf, bufsz); |
| 2574 | pos = iwl_print_event_log(priv, 0, |
| 2575 | next_entry, mode, |
| 2576 | pos, buf, bufsz); |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2577 | } else |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2578 | pos = iwl_print_event_log(priv, next_entry - size, |
| 2579 | size, mode, pos, buf, bufsz); |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2580 | } else { |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2581 | if (next_entry < size) { |
| 2582 | pos = iwl_print_event_log(priv, 0, next_entry, |
| 2583 | mode, pos, buf, bufsz); |
| 2584 | } else { |
| 2585 | pos = iwl_print_event_log(priv, next_entry - size, |
| 2586 | size, mode, pos, buf, bufsz); |
| 2587 | } |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2588 | } |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2589 | return pos; |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2590 | } |
| 2591 | |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2592 | #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20) |
| 2593 | |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2594 | int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log, |
| 2595 | char **buf, bool display) |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2596 | { |
| 2597 | u32 base; /* SRAM byte address of event log header */ |
| 2598 | u32 capacity; /* event log capacity in # entries */ |
| 2599 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 2600 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 2601 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 2602 | u32 size; /* # entries that we'll print */ |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2603 | u32 logsize; |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2604 | int pos = 0; |
| 2605 | size_t bufsz = 0; |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2606 | |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2607 | if (priv->ucode_type == UCODE_INIT) { |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2608 | base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr); |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2609 | logsize = priv->_agn.init_evtlog_size; |
| 2610 | if (!base) |
| 2611 | base = priv->_agn.init_evtlog_ptr; |
| 2612 | } else { |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2613 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2614 | logsize = priv->_agn.inst_evtlog_size; |
| 2615 | if (!base) |
| 2616 | base = priv->_agn.inst_evtlog_ptr; |
| 2617 | } |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2618 | |
| 2619 | if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) { |
Wey-Yi Guy | 212fb57 | 2009-12-02 12:53:00 -0800 | [diff] [blame] | 2620 | IWL_ERR(priv, |
| 2621 | "Invalid event log pointer 0x%08X for %s uCode\n", |
| 2622 | base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT"); |
Wey-Yi Guy | 937c397 | 2010-01-15 13:43:36 -0800 | [diff] [blame] | 2623 | return -EINVAL; |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | /* event log header */ |
| 2627 | capacity = iwl_read_targ_mem(priv, base); |
| 2628 | mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 2629 | num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 2630 | next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32))); |
| 2631 | |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2632 | if (capacity > logsize) { |
Ben Cahill | 84c4069 | 2009-11-06 14:52:57 -0800 | [diff] [blame] | 2633 | IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n", |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2634 | capacity, logsize); |
| 2635 | capacity = logsize; |
Ben Cahill | 84c4069 | 2009-11-06 14:52:57 -0800 | [diff] [blame] | 2636 | } |
| 2637 | |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2638 | if (next_entry > logsize) { |
Ben Cahill | 84c4069 | 2009-11-06 14:52:57 -0800 | [diff] [blame] | 2639 | IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n", |
Johannes Berg | b2e640d4 | 2010-05-05 23:24:54 -0700 | [diff] [blame] | 2640 | next_entry, logsize); |
| 2641 | next_entry = logsize; |
Ben Cahill | 84c4069 | 2009-11-06 14:52:57 -0800 | [diff] [blame] | 2642 | } |
| 2643 | |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2644 | size = num_wraps ? capacity : next_entry; |
| 2645 | |
| 2646 | /* bail out if nothing in log */ |
| 2647 | if (size == 0) { |
| 2648 | IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n"); |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2649 | return pos; |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2650 | } |
| 2651 | |
Wey-Yi Guy | f37837c | 2010-08-23 07:57:12 -0700 | [diff] [blame] | 2652 | /* enable/disable bt channel announcement */ |
| 2653 | priv->bt_ch_announce = iwlagn_bt_ch_announce; |
| 2654 | |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2655 | #ifdef CONFIG_IWLWIFI_DEBUG |
Wey-Yi Guy | 521d9bc | 2009-12-10 14:37:23 -0800 | [diff] [blame] | 2656 | if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log) |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2657 | size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES) |
| 2658 | ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size; |
| 2659 | #else |
| 2660 | size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES) |
| 2661 | ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size; |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2662 | #endif |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2663 | IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n", |
| 2664 | size); |
| 2665 | |
| 2666 | #ifdef CONFIG_IWLWIFI_DEBUG |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2667 | if (display) { |
| 2668 | if (full_log) |
| 2669 | bufsz = capacity * 48; |
| 2670 | else |
| 2671 | bufsz = size * 48; |
| 2672 | *buf = kmalloc(bufsz, GFP_KERNEL); |
| 2673 | if (!*buf) |
Wey-Yi Guy | 937c397 | 2010-01-15 13:43:36 -0800 | [diff] [blame] | 2674 | return -ENOMEM; |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2675 | } |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2676 | if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) { |
| 2677 | /* |
| 2678 | * if uCode has wrapped back to top of log, |
| 2679 | * start at the oldest entry, |
| 2680 | * i.e the next one that uCode would fill. |
| 2681 | */ |
| 2682 | if (num_wraps) |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2683 | pos = iwl_print_event_log(priv, next_entry, |
| 2684 | capacity - next_entry, mode, |
| 2685 | pos, buf, bufsz); |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2686 | /* (then/else) start at top of log */ |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2687 | pos = iwl_print_event_log(priv, 0, |
| 2688 | next_entry, mode, pos, buf, bufsz); |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2689 | } else |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2690 | pos = iwl_print_last_event_logs(priv, capacity, num_wraps, |
| 2691 | next_entry, size, mode, |
| 2692 | pos, buf, bufsz); |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2693 | #else |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2694 | pos = iwl_print_last_event_logs(priv, capacity, num_wraps, |
| 2695 | next_entry, size, mode, |
| 2696 | pos, buf, bufsz); |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2697 | #endif |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 2698 | return pos; |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 2699 | } |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 2700 | |
Wey-Yi Guy | 0975cc8 | 2010-07-31 08:34:07 -0700 | [diff] [blame] | 2701 | static void iwl_rf_kill_ct_config(struct iwl_priv *priv) |
| 2702 | { |
| 2703 | struct iwl_ct_kill_config cmd; |
| 2704 | struct iwl_ct_kill_throttling_config adv_cmd; |
| 2705 | unsigned long flags; |
| 2706 | int ret = 0; |
| 2707 | |
| 2708 | spin_lock_irqsave(&priv->lock, flags); |
| 2709 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
| 2710 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
| 2711 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2712 | priv->thermal_throttle.ct_kill_toggle = false; |
| 2713 | |
| 2714 | if (priv->cfg->support_ct_kill_exit) { |
| 2715 | adv_cmd.critical_temperature_enter = |
| 2716 | cpu_to_le32(priv->hw_params.ct_kill_threshold); |
| 2717 | adv_cmd.critical_temperature_exit = |
| 2718 | cpu_to_le32(priv->hw_params.ct_kill_exit_threshold); |
| 2719 | |
| 2720 | ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD, |
| 2721 | sizeof(adv_cmd), &adv_cmd); |
| 2722 | if (ret) |
| 2723 | IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n"); |
| 2724 | else |
| 2725 | IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD " |
| 2726 | "succeeded, " |
| 2727 | "critical temperature enter is %d," |
| 2728 | "exit is %d\n", |
| 2729 | priv->hw_params.ct_kill_threshold, |
| 2730 | priv->hw_params.ct_kill_exit_threshold); |
| 2731 | } else { |
| 2732 | cmd.critical_temperature_R = |
| 2733 | cpu_to_le32(priv->hw_params.ct_kill_threshold); |
| 2734 | |
| 2735 | ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD, |
| 2736 | sizeof(cmd), &cmd); |
| 2737 | if (ret) |
| 2738 | IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n"); |
| 2739 | else |
| 2740 | IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD " |
| 2741 | "succeeded, " |
| 2742 | "critical temperature is %d\n", |
| 2743 | priv->hw_params.ct_kill_threshold); |
| 2744 | } |
| 2745 | } |
| 2746 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2747 | /** |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2748 | * iwl_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2749 | * from protocol/runtime uCode (initialization uCode's |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2750 | * Alive gets handled by iwl_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2751 | */ |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2752 | static void iwl_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2753 | { |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 2754 | int ret = 0; |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 2755 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2756 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2757 | IWL_DEBUG_INFO(priv, "Runtime Alive received.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2758 | |
| 2759 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 2760 | /* We had an error bringing up the hardware, so take it |
| 2761 | * all the way back down so we can try again */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2762 | IWL_DEBUG_INFO(priv, "Alive failed.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2763 | goto restart; |
| 2764 | } |
| 2765 | |
| 2766 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 2767 | * This is a paranoid check, because we would not have gotten the |
| 2768 | * "runtime" alive if code weren't properly loaded. */ |
Emmanuel Grumbach | b0692f2 | 2008-04-24 11:55:18 -0700 | [diff] [blame] | 2769 | if (iwl_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2770 | /* Runtime instruction load was bad; |
| 2771 | * take it all the way back down so we can try again */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2772 | IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2773 | goto restart; |
| 2774 | } |
| 2775 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 2776 | ret = priv->cfg->ops->lib->alive_notify(priv); |
| 2777 | if (ret) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2778 | IWL_WARN(priv, |
| 2779 | "Could not complete ALIVE transition [ntf]: %d\n", ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2780 | goto restart; |
| 2781 | } |
| 2782 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 2783 | /* After the ALIVE response, we can send host commands to the uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2784 | set_bit(STATUS_ALIVE, &priv->status); |
| 2785 | |
Wey-Yi Guy | b74e31a | 2010-03-01 17:23:50 -0800 | [diff] [blame] | 2786 | if (priv->cfg->ops->lib->recover_from_tx_stall) { |
| 2787 | /* Enable timer to monitor the driver queues */ |
| 2788 | mod_timer(&priv->monitor_recover, |
| 2789 | jiffies + |
| 2790 | msecs_to_jiffies(priv->cfg->monitor_recover_period)); |
| 2791 | } |
| 2792 | |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 2793 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2794 | return; |
| 2795 | |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 2796 | ieee80211_wake_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2797 | |
Johannes Berg | 470ab2d | 2010-01-21 11:23:30 -0800 | [diff] [blame] | 2798 | priv->active_rate = IWL_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2799 | |
Wey-Yi Guy | 2f748de | 2009-09-17 10:43:51 -0700 | [diff] [blame] | 2800 | /* Configure Tx antenna selection based on H/W config */ |
| 2801 | if (priv->cfg->ops->hcmd->set_tx_ant) |
| 2802 | priv->cfg->ops->hcmd->set_tx_ant(priv, priv->cfg->valid_tx_ant); |
| 2803 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 2804 | if (iwl_is_associated_ctx(ctx)) { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 2805 | struct iwl_rxon_cmd *active_rxon = |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 2806 | (struct iwl_rxon_cmd *)&ctx->active; |
Mohamed Abbas | 019fb97 | 2009-03-17 21:59:18 -0700 | [diff] [blame] | 2807 | /* apply any changes in staging */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 2808 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2809 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 2810 | } else { |
| 2811 | /* Initialize our rx_config data */ |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 2812 | iwl_connection_init_rx_config(priv, NULL); |
Abhijeet Kolekar | 4582353 | 2009-04-08 11:26:44 -0700 | [diff] [blame] | 2813 | |
| 2814 | if (priv->cfg->ops->hcmd->set_rxon_chain) |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 2815 | priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2816 | } |
| 2817 | |
Wey-Yi Guy | aeb4a2e | 2010-08-23 07:57:05 -0700 | [diff] [blame] | 2818 | if (!priv->cfg->advanced_bt_coexist) { |
| 2819 | /* Configure Bluetooth device coexistence support */ |
| 2820 | priv->cfg->ops->hcmd->send_bt_config(priv); |
| 2821 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2822 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 2823 | iwl_reset_run_time_calib(priv); |
| 2824 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2825 | /* Configure the adapter for unassociated operation */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 2826 | iwlcore_commit_rxon(priv, ctx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2827 | |
| 2828 | /* At this point, the NIC is initialized and operational */ |
Emmanuel Grumbach | 47f4a58 | 2008-06-12 09:47:13 +0800 | [diff] [blame] | 2829 | iwl_rf_kill_ct_config(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2830 | |
Johannes Berg | e932a60 | 2009-10-02 13:44:03 -0700 | [diff] [blame] | 2831 | iwl_leds_init(priv); |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 2832 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2833 | IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 2834 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2835 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2836 | |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 2837 | iwl_power_update_mode(priv, true); |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 2838 | IWL_DEBUG_INFO(priv, "Updated power mode\n"); |
| 2839 | |
Assaf Krauss | c46fbef | 2008-06-12 09:47:05 +0800 | [diff] [blame] | 2840 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2841 | return; |
| 2842 | |
| 2843 | restart: |
| 2844 | queue_work(priv->workqueue, &priv->restart); |
| 2845 | } |
| 2846 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 2847 | static void iwl_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2848 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 2849 | static void __iwl_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2850 | { |
| 2851 | unsigned long flags; |
| 2852 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2853 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2854 | IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2855 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2856 | if (!exit_pending) |
| 2857 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 2858 | |
Stanislaw Gruszka | b62177a | 2010-08-20 15:23:47 +0200 | [diff] [blame] | 2859 | /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set |
| 2860 | * to prevent rearm timer */ |
| 2861 | if (priv->cfg->ops->lib->recover_from_tx_stall) |
| 2862 | del_timer_sync(&priv->monitor_recover); |
| 2863 | |
Johannes Berg | dcef732 | 2010-08-27 08:55:52 -0700 | [diff] [blame] | 2864 | iwl_clear_ucode_stations(priv, NULL); |
Johannes Berg | a194e32 | 2010-08-27 08:53:46 -0700 | [diff] [blame] | 2865 | iwl_dealloc_bcast_stations(priv); |
Johannes Berg | db125c7 | 2010-05-07 01:49:15 -0700 | [diff] [blame] | 2866 | iwl_clear_driver_stations(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2867 | |
Johannes Berg | a117413 | 2010-08-23 07:56:59 -0700 | [diff] [blame] | 2868 | /* reset BT coex data */ |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 2869 | priv->bt_status = 0; |
Wey-Yi Guy | a4b96cc | 2010-08-23 07:57:08 -0700 | [diff] [blame] | 2870 | priv->bt_traffic_load = priv->cfg->bt_init_traffic_load; |
Johannes Berg | a117413 | 2010-08-23 07:56:59 -0700 | [diff] [blame] | 2871 | priv->bt_sco_active = false; |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 2872 | priv->bt_full_concurrent = false; |
| 2873 | priv->bt_ci_compliance = 0; |
Johannes Berg | a117413 | 2010-08-23 07:56:59 -0700 | [diff] [blame] | 2874 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2875 | /* Unblock any waiting calls */ |
| 2876 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 2877 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2878 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 2879 | * exiting the module */ |
| 2880 | if (!exit_pending) |
| 2881 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 2882 | |
| 2883 | /* stop and reset the on-board processor */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2884 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2885 | |
| 2886 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2887 | spin_lock_irqsave(&priv->lock, flags); |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 2888 | iwl_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2889 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2890 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2891 | |
| 2892 | if (priv->mac80211_registered) |
| 2893 | ieee80211_stop_queues(priv->hw); |
| 2894 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 2895 | /* If we have not previously called iwl_init() then |
Johannes Berg | a60e77e | 2009-06-04 18:26:06 +0200 | [diff] [blame] | 2896 | * clear all bits but the RF Kill bit and return */ |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 2897 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2898 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 2899 | STATUS_RF_KILL_HW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 2900 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 2901 | STATUS_GEO_CONFIGURED | |
Mohamed Abbas | 052ec3f | 2008-06-30 17:23:15 +0800 | [diff] [blame] | 2902 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 2903 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2904 | goto exit; |
| 2905 | } |
| 2906 | |
Wey-Yi Guy | 6da3a13 | 2009-03-26 10:14:08 -0700 | [diff] [blame] | 2907 | /* ...otherwise clear out all the status bits but the RF Kill |
Johannes Berg | a60e77e | 2009-06-04 18:26:06 +0200 | [diff] [blame] | 2908 | * bit and continue taking the NIC down. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2909 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 2910 | STATUS_RF_KILL_HW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 2911 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 2912 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2913 | test_bit(STATUS_FW_ERROR, &priv->status) << |
Mohamed Abbas | 052ec3f | 2008-06-30 17:23:15 +0800 | [diff] [blame] | 2914 | STATUS_FW_ERROR | |
| 2915 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 2916 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2917 | |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 2918 | /* device going down, Stop using ICT table */ |
| 2919 | iwl_disable_ict(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2920 | |
Wey-Yi Guy | 74bcdb3 | 2010-03-17 13:34:34 -0700 | [diff] [blame] | 2921 | iwlagn_txq_ctx_stop(priv); |
Wey-Yi Guy | 54b8155 | 2010-03-17 13:34:35 -0700 | [diff] [blame] | 2922 | iwlagn_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2923 | |
Ben Cahill | 309e731 | 2009-11-06 14:53:03 -0800 | [diff] [blame] | 2924 | /* Power-down device's busmaster DMA clocks */ |
| 2925 | iwl_write_prph(priv, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2926 | udelay(5); |
| 2927 | |
Ben Cahill | 309e731 | 2009-11-06 14:53:03 -0800 | [diff] [blame] | 2928 | /* Make sure (redundant) we've released our request to stay awake */ |
| 2929 | iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
| 2930 | |
Ben Cahill | 4d2ccdb | 2009-10-09 13:20:20 -0700 | [diff] [blame] | 2931 | /* Stop the device, and put it in low power state */ |
| 2932 | priv->cfg->ops->lib->apm_ops.stop(priv); |
| 2933 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2934 | exit: |
Tomas Winkler | 885ba20 | 2008-05-29 16:34:55 +0800 | [diff] [blame] | 2935 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2936 | |
| 2937 | if (priv->ibss_beacon) |
| 2938 | dev_kfree_skb(priv->ibss_beacon); |
| 2939 | priv->ibss_beacon = NULL; |
| 2940 | |
| 2941 | /* clear out any free frames */ |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 2942 | iwl_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2943 | } |
| 2944 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 2945 | static void iwl_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2946 | { |
| 2947 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 2948 | __iwl_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2949 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 2950 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 2951 | iwl_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2952 | } |
| 2953 | |
Mohamed Abbas | 086ed11 | 2009-05-22 11:01:54 -0700 | [diff] [blame] | 2954 | #define HW_READY_TIMEOUT (50) |
| 2955 | |
| 2956 | static int iwl_set_hw_ready(struct iwl_priv *priv) |
| 2957 | { |
| 2958 | int ret = 0; |
| 2959 | |
| 2960 | iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, |
| 2961 | CSR_HW_IF_CONFIG_REG_BIT_NIC_READY); |
| 2962 | |
| 2963 | /* See if we got it */ |
| 2964 | ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG, |
| 2965 | CSR_HW_IF_CONFIG_REG_BIT_NIC_READY, |
| 2966 | CSR_HW_IF_CONFIG_REG_BIT_NIC_READY, |
| 2967 | HW_READY_TIMEOUT); |
| 2968 | if (ret != -ETIMEDOUT) |
| 2969 | priv->hw_ready = true; |
| 2970 | else |
| 2971 | priv->hw_ready = false; |
| 2972 | |
| 2973 | IWL_DEBUG_INFO(priv, "hardware %s\n", |
| 2974 | (priv->hw_ready == 1) ? "ready" : "not ready"); |
| 2975 | return ret; |
| 2976 | } |
| 2977 | |
| 2978 | static int iwl_prepare_card_hw(struct iwl_priv *priv) |
| 2979 | { |
| 2980 | int ret = 0; |
| 2981 | |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 2982 | IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter\n"); |
Mohamed Abbas | 086ed11 | 2009-05-22 11:01:54 -0700 | [diff] [blame] | 2983 | |
Mohamed Abbas | 3354a0f | 2009-06-19 13:52:41 -0700 | [diff] [blame] | 2984 | ret = iwl_set_hw_ready(priv); |
| 2985 | if (priv->hw_ready) |
| 2986 | return ret; |
| 2987 | |
| 2988 | /* If HW is not ready, prepare the conditions to check again */ |
Mohamed Abbas | 086ed11 | 2009-05-22 11:01:54 -0700 | [diff] [blame] | 2989 | iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, |
| 2990 | CSR_HW_IF_CONFIG_REG_PREPARE); |
| 2991 | |
| 2992 | ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG, |
| 2993 | ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, |
| 2994 | CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000); |
| 2995 | |
Mohamed Abbas | 3354a0f | 2009-06-19 13:52:41 -0700 | [diff] [blame] | 2996 | /* HW should be ready by now, check again. */ |
Mohamed Abbas | 086ed11 | 2009-05-22 11:01:54 -0700 | [diff] [blame] | 2997 | if (ret != -ETIMEDOUT) |
| 2998 | iwl_set_hw_ready(priv); |
| 2999 | |
| 3000 | return ret; |
| 3001 | } |
| 3002 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3003 | #define MAX_HW_RESTARTS 5 |
| 3004 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3005 | static int __iwl_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3006 | { |
Johannes Berg | a194e32 | 2010-08-27 08:53:46 -0700 | [diff] [blame] | 3007 | struct iwl_rxon_context *ctx; |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3008 | int i; |
| 3009 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3010 | |
| 3011 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3012 | IWL_WARN(priv, "Exit pending; will not bring the NIC up\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3013 | return -EIO; |
| 3014 | } |
| 3015 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 3016 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3017 | IWL_ERR(priv, "ucode not available for device bringup\n"); |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 3018 | return -EIO; |
| 3019 | } |
| 3020 | |
Johannes Berg | a194e32 | 2010-08-27 08:53:46 -0700 | [diff] [blame] | 3021 | for_each_context(priv, ctx) { |
| 3022 | ret = iwl_alloc_bcast_station(priv, ctx, true); |
| 3023 | if (ret) { |
| 3024 | iwl_dealloc_bcast_stations(priv); |
| 3025 | return ret; |
| 3026 | } |
| 3027 | } |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 3028 | |
Mohamed Abbas | 086ed11 | 2009-05-22 11:01:54 -0700 | [diff] [blame] | 3029 | iwl_prepare_card_hw(priv); |
| 3030 | |
| 3031 | if (!priv->hw_ready) { |
| 3032 | IWL_WARN(priv, "Exit HW not ready\n"); |
| 3033 | return -EIO; |
| 3034 | } |
| 3035 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3036 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Tomas Winkler | c1842d6 | 2008-08-04 16:00:43 +0800 | [diff] [blame] | 3037 | if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3038 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Emmanuel Grumbach | 3bff19c | 2008-06-30 17:23:19 +0800 | [diff] [blame] | 3039 | else |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3040 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
Emmanuel Grumbach | 3bff19c | 2008-06-30 17:23:19 +0800 | [diff] [blame] | 3041 | |
Tomas Winkler | c1842d6 | 2008-08-04 16:00:43 +0800 | [diff] [blame] | 3042 | if (iwl_is_rfkill(priv)) { |
Johannes Berg | a60e77e | 2009-06-04 18:26:06 +0200 | [diff] [blame] | 3043 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, true); |
| 3044 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3045 | iwl_enable_interrupts(priv); |
Johannes Berg | a60e77e | 2009-06-04 18:26:06 +0200 | [diff] [blame] | 3046 | IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n"); |
Tomas Winkler | c1842d6 | 2008-08-04 16:00:43 +0800 | [diff] [blame] | 3047 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3048 | } |
| 3049 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3050 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3051 | |
Johannes Berg | 13bb948 | 2010-08-23 10:46:33 +0200 | [diff] [blame] | 3052 | /* must be initialised before iwl_hw_nic_init */ |
Johannes Berg | 751ca30 | 2010-08-23 10:46:34 +0200 | [diff] [blame] | 3053 | if (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS)) |
| 3054 | priv->cmd_queue = IWL_IPAN_CMD_QUEUE_NUM; |
| 3055 | else |
| 3056 | priv->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM; |
Johannes Berg | 13bb948 | 2010-08-23 10:46:33 +0200 | [diff] [blame] | 3057 | |
Wey-Yi Guy | 74bcdb3 | 2010-03-17 13:34:34 -0700 | [diff] [blame] | 3058 | ret = iwlagn_hw_nic_init(priv); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3059 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3060 | IWL_ERR(priv, "Unable to init nic\n"); |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3061 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
| 3064 | /* make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3065 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 3066 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3067 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 3068 | |
| 3069 | /* clear (again), then enable host interrupts */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3070 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3071 | iwl_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3072 | |
| 3073 | /* really make sure rfkill handshake bits are cleared */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3074 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 3075 | 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] | 3076 | |
| 3077 | /* Copy original ucode data image from disk into backup cache. |
| 3078 | * This will be used to initialize the on-board processor's |
| 3079 | * data SRAM for a clean start when the runtime program first loads. */ |
| 3080 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3081 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3082 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3083 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 3084 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3085 | /* load bootstrap state machine, |
| 3086 | * load bootstrap program into processor's memory, |
| 3087 | * prepare to load the "initialize" uCode */ |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3088 | ret = priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3089 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3090 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3091 | IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n", |
| 3092 | ret); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3093 | continue; |
| 3094 | } |
| 3095 | |
| 3096 | /* start card; "initialize" will load runtime ucode */ |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3097 | iwl_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3098 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3099 | IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3100 | |
| 3101 | return 0; |
| 3102 | } |
| 3103 | |
| 3104 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3105 | __iwl_down(priv); |
Mohamed Abbas | 64e72c3e | 2008-06-12 09:47:03 +0800 | [diff] [blame] | 3106 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3107 | |
| 3108 | /* tried to restart and config the device for as long as our |
| 3109 | * patience could withstand */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3110 | IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3111 | return -EIO; |
| 3112 | } |
| 3113 | |
| 3114 | |
| 3115 | /***************************************************************************** |
| 3116 | * |
| 3117 | * Workqueue callbacks |
| 3118 | * |
| 3119 | *****************************************************************************/ |
| 3120 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3121 | static void iwl_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3122 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3123 | struct iwl_priv *priv = |
| 3124 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3125 | |
| 3126 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3127 | return; |
| 3128 | |
| 3129 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | f3ccc08 | 2008-05-05 10:22:45 +0800 | [diff] [blame] | 3130 | priv->cfg->ops->lib->init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3131 | mutex_unlock(&priv->mutex); |
| 3132 | } |
| 3133 | |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3134 | static void iwl_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3135 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3136 | struct iwl_priv *priv = |
| 3137 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3138 | |
| 3139 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3140 | return; |
| 3141 | |
Mohamed Abbas | 258c44a | 2009-06-03 11:44:10 -0700 | [diff] [blame] | 3142 | /* enable dram interrupt */ |
| 3143 | iwl_reset_ict(priv); |
| 3144 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3145 | mutex_lock(&priv->mutex); |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 3146 | iwl_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3147 | mutex_unlock(&priv->mutex); |
| 3148 | } |
| 3149 | |
Emmanuel Grumbach | 16e727e | 2008-06-12 09:46:52 +0800 | [diff] [blame] | 3150 | static void iwl_bg_run_time_calib_work(struct work_struct *work) |
| 3151 | { |
| 3152 | struct iwl_priv *priv = container_of(work, struct iwl_priv, |
| 3153 | run_time_calib_work); |
| 3154 | |
| 3155 | mutex_lock(&priv->mutex); |
| 3156 | |
| 3157 | if (test_bit(STATUS_EXIT_PENDING, &priv->status) || |
| 3158 | test_bit(STATUS_SCANNING, &priv->status)) { |
| 3159 | mutex_unlock(&priv->mutex); |
| 3160 | return; |
| 3161 | } |
| 3162 | |
| 3163 | if (priv->start_calib) { |
Wey-Yi Guy | 7980fba | 2010-07-14 08:08:57 -0700 | [diff] [blame] | 3164 | if (priv->cfg->bt_statistics) { |
| 3165 | iwl_chain_noise_calibration(priv, |
| 3166 | (void *)&priv->_agn.statistics_bt); |
| 3167 | iwl_sensitivity_calibration(priv, |
| 3168 | (void *)&priv->_agn.statistics_bt); |
| 3169 | } else { |
| 3170 | iwl_chain_noise_calibration(priv, |
| 3171 | (void *)&priv->_agn.statistics); |
| 3172 | iwl_sensitivity_calibration(priv, |
| 3173 | (void *)&priv->_agn.statistics); |
| 3174 | } |
Emmanuel Grumbach | 16e727e | 2008-06-12 09:46:52 +0800 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | mutex_unlock(&priv->mutex); |
Emmanuel Grumbach | 16e727e | 2008-06-12 09:46:52 +0800 | [diff] [blame] | 3178 | } |
| 3179 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3180 | static void iwl_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3181 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3182 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3183 | |
| 3184 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3185 | return; |
| 3186 | |
Johannes Berg | 19cc108 | 2009-05-08 13:44:36 -0700 | [diff] [blame] | 3187 | if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) { |
Johannes Berg | 8bd413e | 2010-08-23 10:46:40 +0200 | [diff] [blame] | 3188 | struct iwl_rxon_context *ctx; |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 3189 | bool bt_sco, bt_full_concurrent; |
| 3190 | u8 bt_ci_compliance; |
Johannes Berg | 511b082 | 2010-08-23 07:57:01 -0700 | [diff] [blame] | 3191 | u8 bt_load; |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 3192 | u8 bt_status; |
Johannes Berg | 511b082 | 2010-08-23 07:57:01 -0700 | [diff] [blame] | 3193 | |
Johannes Berg | 19cc108 | 2009-05-08 13:44:36 -0700 | [diff] [blame] | 3194 | mutex_lock(&priv->mutex); |
Johannes Berg | 8bd413e | 2010-08-23 10:46:40 +0200 | [diff] [blame] | 3195 | for_each_context(priv, ctx) |
| 3196 | ctx->vif = NULL; |
Johannes Berg | 19cc108 | 2009-05-08 13:44:36 -0700 | [diff] [blame] | 3197 | priv->is_open = 0; |
Johannes Berg | 511b082 | 2010-08-23 07:57:01 -0700 | [diff] [blame] | 3198 | |
| 3199 | /* |
| 3200 | * __iwl_down() will clear the BT status variables, |
| 3201 | * which is correct, but when we restart we really |
| 3202 | * want to keep them so restore them afterwards. |
| 3203 | * |
| 3204 | * The restart process will later pick them up and |
| 3205 | * re-configure the hw when we reconfigure the BT |
| 3206 | * command. |
| 3207 | */ |
| 3208 | bt_sco = priv->bt_sco_active; |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 3209 | bt_full_concurrent = priv->bt_full_concurrent; |
| 3210 | bt_ci_compliance = priv->bt_ci_compliance; |
Johannes Berg | 511b082 | 2010-08-23 07:57:01 -0700 | [diff] [blame] | 3211 | bt_load = priv->bt_traffic_load; |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 3212 | bt_status = priv->bt_status; |
Johannes Berg | 511b082 | 2010-08-23 07:57:01 -0700 | [diff] [blame] | 3213 | |
Johannes Berg | a117413 | 2010-08-23 07:56:59 -0700 | [diff] [blame] | 3214 | __iwl_down(priv); |
Johannes Berg | 511b082 | 2010-08-23 07:57:01 -0700 | [diff] [blame] | 3215 | |
| 3216 | priv->bt_sco_active = bt_sco; |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 3217 | priv->bt_full_concurrent = bt_full_concurrent; |
| 3218 | priv->bt_ci_compliance = bt_ci_compliance; |
Johannes Berg | 511b082 | 2010-08-23 07:57:01 -0700 | [diff] [blame] | 3219 | priv->bt_traffic_load = bt_load; |
Wey-Yi Guy | da5dbb9 | 2010-08-23 07:57:13 -0700 | [diff] [blame] | 3220 | priv->bt_status = bt_status; |
Johannes Berg | 511b082 | 2010-08-23 07:57:01 -0700 | [diff] [blame] | 3221 | |
Johannes Berg | 19cc108 | 2009-05-08 13:44:36 -0700 | [diff] [blame] | 3222 | mutex_unlock(&priv->mutex); |
Johannes Berg | a117413 | 2010-08-23 07:56:59 -0700 | [diff] [blame] | 3223 | iwl_cancel_deferred_work(priv); |
Johannes Berg | 19cc108 | 2009-05-08 13:44:36 -0700 | [diff] [blame] | 3224 | ieee80211_restart_hw(priv->hw); |
| 3225 | } else { |
| 3226 | iwl_down(priv); |
Johannes Berg | 8067651 | 2010-01-21 06:07:17 -0800 | [diff] [blame] | 3227 | |
| 3228 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3229 | return; |
| 3230 | |
| 3231 | mutex_lock(&priv->mutex); |
| 3232 | __iwl_up(priv); |
| 3233 | mutex_unlock(&priv->mutex); |
Johannes Berg | 19cc108 | 2009-05-08 13:44:36 -0700 | [diff] [blame] | 3234 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3235 | } |
| 3236 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3237 | static void iwl_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3238 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3239 | struct iwl_priv *priv = |
| 3240 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3241 | |
| 3242 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3243 | return; |
| 3244 | |
| 3245 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | 54b8155 | 2010-03-17 13:34:35 -0700 | [diff] [blame] | 3246 | iwlagn_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3247 | mutex_unlock(&priv->mutex); |
| 3248 | } |
| 3249 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3250 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 3251 | |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3252 | void iwl_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3253 | { |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3254 | struct iwl_rxon_context *ctx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3255 | struct ieee80211_conf *conf = NULL; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3256 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3257 | |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3258 | if (!vif || !priv->is_open) |
| 3259 | return; |
| 3260 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3261 | ctx = iwl_rxon_ctx_from_vif(vif); |
| 3262 | |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3263 | if (vif->type == NL80211_IFTYPE_AP) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3264 | IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3265 | return; |
| 3266 | } |
| 3267 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3268 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3269 | return; |
| 3270 | |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 3271 | iwl_scan_cancel_timeout(priv, 200); |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3272 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3273 | conf = ieee80211_get_hw_conf(priv->hw); |
| 3274 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3275 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 3276 | iwlcore_commit_rxon(priv, ctx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3277 | |
Johannes Berg | 948f5a2 | 2010-07-29 07:07:51 -0700 | [diff] [blame] | 3278 | ret = iwl_send_rxon_timing(priv, vif); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3279 | if (ret) |
Johannes Berg | 8f2d3d2 | 2010-08-23 10:46:37 +0200 | [diff] [blame] | 3280 | IWL_WARN(priv, "RXON timing - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3281 | "Attempting to continue.\n"); |
| 3282 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3283 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3284 | |
Emmanuel Grumbach | 42eb7c6 | 2008-09-17 10:10:05 +0800 | [diff] [blame] | 3285 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
Ron Rindjunsky | 4f85f5b | 2008-06-09 22:54:35 +0300 | [diff] [blame] | 3286 | |
Abhijeet Kolekar | 4582353 | 2009-04-08 11:26:44 -0700 | [diff] [blame] | 3287 | if (priv->cfg->ops->hcmd->set_rxon_chain) |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3288 | priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx); |
Abhijeet Kolekar | 4582353 | 2009-04-08 11:26:44 -0700 | [diff] [blame] | 3289 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3290 | ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3291 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3292 | IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n", |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3293 | vif->bss_conf.aid, vif->bss_conf.beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3294 | |
Johannes Berg | c213d74 | 2010-05-06 12:21:40 -0700 | [diff] [blame] | 3295 | if (vif->bss_conf.use_short_preamble) |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3296 | ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3297 | else |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3298 | ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3299 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3300 | if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) { |
Johannes Berg | c213d74 | 2010-05-06 12:21:40 -0700 | [diff] [blame] | 3301 | if (vif->bss_conf.use_short_slot) |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3302 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3303 | else |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3304 | ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3305 | } |
| 3306 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3307 | iwlcore_commit_rxon(priv, ctx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3308 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3309 | IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n", |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3310 | vif->bss_conf.aid, ctx->active.bssid_addr); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3311 | |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3312 | switch (vif->type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3313 | case NL80211_IFTYPE_STATION: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3314 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3315 | case NL80211_IFTYPE_ADHOC: |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3316 | iwl_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3317 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3318 | default: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3319 | IWL_ERR(priv, "%s Should not be called in %d mode\n", |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3320 | __func__, vif->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3321 | break; |
| 3322 | } |
| 3323 | |
Grumbach, Emmanuel | 0481644 | 2008-09-03 11:26:53 +0800 | [diff] [blame] | 3324 | /* the chain noise calibration will enabled PM upon completion |
| 3325 | * If chain noise has already been run, then we need to enable |
| 3326 | * power management here */ |
| 3327 | if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE) |
Johannes Berg | e312c24 | 2009-08-07 15:41:51 -0700 | [diff] [blame] | 3328 | iwl_power_update_mode(priv, false); |
Emmanuel Grumbach | c90a74ba | 2008-09-03 11:26:50 +0800 | [diff] [blame] | 3329 | |
| 3330 | /* Enable Rx differential gain and sensitivity calibrations */ |
| 3331 | iwl_chain_noise_reset(priv); |
| 3332 | priv->start_calib = 1; |
| 3333 | |
Reinette Chatre | 508e32e | 2008-04-14 21:16:13 -0700 | [diff] [blame] | 3334 | } |
| 3335 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3336 | /***************************************************************************** |
| 3337 | * |
| 3338 | * mac80211 entry point functions |
| 3339 | * |
| 3340 | *****************************************************************************/ |
| 3341 | |
Emmanuel Grumbach | 154b25c | 2008-06-30 17:23:24 +0800 | [diff] [blame] | 3342 | #define UCODE_READY_TIMEOUT (4 * HZ) |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3343 | |
Reinette Chatre | f0b6e2e | 2009-10-16 14:25:53 -0700 | [diff] [blame] | 3344 | /* |
| 3345 | * Not a mac80211 entry point function, but it fits in with all the |
| 3346 | * other mac80211 functions grouped here. |
| 3347 | */ |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 3348 | static int iwl_mac_setup_register(struct iwl_priv *priv, |
| 3349 | struct iwlagn_ucode_capabilities *capa) |
Reinette Chatre | f0b6e2e | 2009-10-16 14:25:53 -0700 | [diff] [blame] | 3350 | { |
| 3351 | int ret; |
| 3352 | struct ieee80211_hw *hw = priv->hw; |
| 3353 | hw->rate_control_algorithm = "iwl-agn-rs"; |
| 3354 | |
| 3355 | /* Tell mac80211 our characteristics */ |
| 3356 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
Reinette Chatre | f0b6e2e | 2009-10-16 14:25:53 -0700 | [diff] [blame] | 3357 | IEEE80211_HW_AMPDU_AGGREGATION | |
| 3358 | IEEE80211_HW_SPECTRUM_MGMT; |
| 3359 | |
| 3360 | if (!priv->cfg->broken_powersave) |
| 3361 | hw->flags |= IEEE80211_HW_SUPPORTS_PS | |
| 3362 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS; |
| 3363 | |
Johannes Berg | ba37a3d | 2009-12-10 14:37:27 -0800 | [diff] [blame] | 3364 | if (priv->cfg->sku & IWL_SKU_N) |
| 3365 | hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS | |
| 3366 | IEEE80211_HW_SUPPORTS_STATIC_SMPS; |
| 3367 | |
Reinette Chatre | 8d9698b | 2009-10-16 14:25:55 -0700 | [diff] [blame] | 3368 | hw->sta_data_size = sizeof(struct iwl_station_priv); |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 3369 | hw->vif_data_size = sizeof(struct iwl_vif_priv); |
| 3370 | |
Reinette Chatre | f0b6e2e | 2009-10-16 14:25:53 -0700 | [diff] [blame] | 3371 | hw->wiphy->interface_modes = |
| 3372 | BIT(NL80211_IFTYPE_STATION) | |
| 3373 | BIT(NL80211_IFTYPE_ADHOC); |
| 3374 | |
Reinette Chatre | f6c8f15 | 2010-03-12 11:13:26 -0800 | [diff] [blame] | 3375 | hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY | |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 3376 | WIPHY_FLAG_DISABLE_BEACON_HINTS; |
Reinette Chatre | f0b6e2e | 2009-10-16 14:25:53 -0700 | [diff] [blame] | 3377 | |
| 3378 | /* |
| 3379 | * For now, disable PS by default because it affects |
| 3380 | * RX performance significantly. |
| 3381 | */ |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 3382 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
Reinette Chatre | f0b6e2e | 2009-10-16 14:25:53 -0700 | [diff] [blame] | 3383 | |
Reinette Chatre | 1382c71 | 2010-02-25 10:02:19 -0800 | [diff] [blame] | 3384 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX; |
Reinette Chatre | f0b6e2e | 2009-10-16 14:25:53 -0700 | [diff] [blame] | 3385 | /* we create the 802.11 header and a zero-length SSID element */ |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 3386 | hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2; |
Reinette Chatre | f0b6e2e | 2009-10-16 14:25:53 -0700 | [diff] [blame] | 3387 | |
| 3388 | /* Default value; 4 EDCA QOS priorities */ |
| 3389 | hw->queues = 4; |
| 3390 | |
| 3391 | hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL; |
| 3392 | |
| 3393 | if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 3394 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 3395 | &priv->bands[IEEE80211_BAND_2GHZ]; |
| 3396 | if (priv->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 3397 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 3398 | &priv->bands[IEEE80211_BAND_5GHZ]; |
| 3399 | |
| 3400 | ret = ieee80211_register_hw(priv->hw); |
| 3401 | if (ret) { |
| 3402 | IWL_ERR(priv, "Failed to register hw (error %d)\n", ret); |
| 3403 | return ret; |
| 3404 | } |
| 3405 | priv->mac80211_registered = 1; |
| 3406 | |
| 3407 | return 0; |
| 3408 | } |
| 3409 | |
| 3410 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3411 | static int iwl_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3412 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3413 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3414 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3415 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3416 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3417 | |
| 3418 | /* we should be verifying the device is ready to be opened */ |
| 3419 | mutex_lock(&priv->mutex); |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3420 | ret = __iwl_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3421 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3422 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3423 | if (ret) |
Helmut Schaa | 6cd0b1c | 2009-01-19 13:10:07 +0100 | [diff] [blame] | 3424 | return ret; |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3425 | |
Tomas Winkler | c1842d6 | 2008-08-04 16:00:43 +0800 | [diff] [blame] | 3426 | if (iwl_is_rfkill(priv)) |
| 3427 | goto out; |
| 3428 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3429 | IWL_DEBUG_INFO(priv, "Start UP work done.\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3430 | |
Ron Rindjunsky | fe9b6b7 | 2008-05-29 16:35:06 +0800 | [diff] [blame] | 3431 | /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3432 | * mac80211 will not be run successfully. */ |
Emmanuel Grumbach | 154b25c | 2008-06-30 17:23:24 +0800 | [diff] [blame] | 3433 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 3434 | test_bit(STATUS_READY, &priv->status), |
| 3435 | UCODE_READY_TIMEOUT); |
| 3436 | if (!ret) { |
| 3437 | if (!test_bit(STATUS_READY, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3438 | IWL_ERR(priv, "START_ALIVE timeout after %dms.\n", |
Emmanuel Grumbach | 154b25c | 2008-06-30 17:23:24 +0800 | [diff] [blame] | 3439 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
Helmut Schaa | 6cd0b1c | 2009-01-19 13:10:07 +0100 | [diff] [blame] | 3440 | return -ETIMEDOUT; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3441 | } |
Ron Rindjunsky | fe9b6b7 | 2008-05-29 16:35:06 +0800 | [diff] [blame] | 3442 | } |
Tomas Winkler | 0a078ff | 2008-06-30 17:23:26 +0800 | [diff] [blame] | 3443 | |
Johannes Berg | e932a60 | 2009-10-02 13:44:03 -0700 | [diff] [blame] | 3444 | iwl_led_start(priv); |
| 3445 | |
Tomas Winkler | c1842d6 | 2008-08-04 16:00:43 +0800 | [diff] [blame] | 3446 | out: |
Tomas Winkler | 0a078ff | 2008-06-30 17:23:26 +0800 | [diff] [blame] | 3447 | priv->is_open = 1; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3448 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3449 | return 0; |
| 3450 | } |
| 3451 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3452 | static void iwl_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3453 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3454 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3455 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3456 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 3457 | |
Johannes Berg | 19cc108 | 2009-05-08 13:44:36 -0700 | [diff] [blame] | 3458 | if (!priv->is_open) |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3459 | return; |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3460 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3461 | priv->is_open = 0; |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3462 | |
Wey-Yi Guy | 5bddf54 | 2009-08-21 13:34:25 -0700 | [diff] [blame] | 3463 | if (iwl_is_ready_rf(priv) || test_bit(STATUS_SCAN_HW, &priv->status)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3464 | /* stop mac, cancel any scan request and clear |
| 3465 | * RXON_FILTER_ASSOC_MSK BIT |
| 3466 | */ |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3467 | mutex_lock(&priv->mutex); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 3468 | iwl_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 3469 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 3470 | } |
| 3471 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3472 | iwl_down(priv); |
Zhu Yi | 5a66926a | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3473 | |
| 3474 | flush_workqueue(priv->workqueue); |
Helmut Schaa | 6cd0b1c | 2009-01-19 13:10:07 +0100 | [diff] [blame] | 3475 | |
| 3476 | /* enable interrupts again in order to receive rfkill changes */ |
| 3477 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
| 3478 | iwl_enable_interrupts(priv); |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 3479 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3480 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3481 | } |
| 3482 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3483 | static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3484 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3485 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3486 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3487 | IWL_DEBUG_MACDUMP(priv, "enter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3488 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3489 | IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 3490 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3491 | |
Wey-Yi Guy | 74bcdb3 | 2010-03-17 13:34:34 -0700 | [diff] [blame] | 3492 | if (iwlagn_tx_skb(priv, skb)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3493 | dev_kfree_skb_any(skb); |
| 3494 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3495 | IWL_DEBUG_MACDUMP(priv, "leave\n"); |
Reinette Chatre | 637f883 | 2009-01-19 15:30:32 -0800 | [diff] [blame] | 3496 | return NETDEV_TX_OK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3497 | } |
| 3498 | |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3499 | void iwl_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3500 | { |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3501 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3502 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3503 | |
Johannes Berg | 76d0481 | 2010-08-23 10:46:47 +0200 | [diff] [blame] | 3504 | lockdep_assert_held(&priv->mutex); |
| 3505 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 3506 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3507 | return; |
| 3508 | |
| 3509 | /* The following should be done only at AP bring up */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3510 | if (!iwl_is_associated_ctx(ctx)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3511 | |
| 3512 | /* RXON - unassoc (to set timing command) */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3513 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 3514 | iwlcore_commit_rxon(priv, ctx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3515 | |
| 3516 | /* RXON Timing */ |
Johannes Berg | 948f5a2 | 2010-07-29 07:07:51 -0700 | [diff] [blame] | 3517 | ret = iwl_send_rxon_timing(priv, vif); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3518 | if (ret) |
Johannes Berg | 8f2d3d2 | 2010-08-23 10:46:37 +0200 | [diff] [blame] | 3519 | IWL_WARN(priv, "RXON timing failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3520 | "Attempting to continue.\n"); |
| 3521 | |
Daniel C Halperin | f513dff | 2009-11-13 11:56:34 -0800 | [diff] [blame] | 3522 | /* AP has all antennas */ |
| 3523 | priv->chain_noise_data.active_chains = |
| 3524 | priv->hw_params.valid_rx_ant; |
| 3525 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
Abhijeet Kolekar | 4582353 | 2009-04-08 11:26:44 -0700 | [diff] [blame] | 3526 | if (priv->cfg->ops->hcmd->set_rxon_chain) |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3527 | priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3528 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3529 | ctx->staging.assoc_id = 0; |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3530 | |
Johannes Berg | c213d74 | 2010-05-06 12:21:40 -0700 | [diff] [blame] | 3531 | if (vif->bss_conf.use_short_preamble) |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3532 | ctx->staging.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3533 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3534 | else |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3535 | ctx->staging.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3536 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3537 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3538 | if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) { |
Johannes Berg | c213d74 | 2010-05-06 12:21:40 -0700 | [diff] [blame] | 3539 | if (vif->bss_conf.use_short_slot) |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3540 | ctx->staging.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3541 | RXON_FLG_SHORT_SLOT_MSK; |
| 3542 | else |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3543 | ctx->staging.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3544 | ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3545 | } |
| 3546 | /* restore RXON assoc */ |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3547 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; |
| 3548 | iwlcore_commit_rxon(priv, ctx); |
Zhu Yi | e1493de | 2007-09-27 11:27:32 +0800 | [diff] [blame] | 3549 | } |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3550 | iwl_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3551 | |
| 3552 | /* FIXME - we need to add code here to detect a totally new |
| 3553 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 3554 | * clear sta table, add BCAST sta... */ |
| 3555 | } |
| 3556 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3557 | static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw, |
Johannes Berg | b3fbdcf | 2010-01-21 11:40:47 +0100 | [diff] [blame] | 3558 | struct ieee80211_vif *vif, |
| 3559 | struct ieee80211_key_conf *keyconf, |
| 3560 | struct ieee80211_sta *sta, |
| 3561 | u32 iv32, u16 *phase1key) |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 3562 | { |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 3563 | |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 3564 | struct iwl_priv *priv = hw->priv; |
Johannes Berg | a194e32 | 2010-08-27 08:53:46 -0700 | [diff] [blame] | 3565 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
| 3566 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3567 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 3568 | |
Johannes Berg | a194e32 | 2010-08-27 08:53:46 -0700 | [diff] [blame] | 3569 | iwl_update_tkip_key(priv, vif_priv->ctx, keyconf, sta, |
Johannes Berg | b3fbdcf | 2010-01-21 11:40:47 +0100 | [diff] [blame] | 3570 | iv32, phase1key); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 3571 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3572 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Emmanuel Grumbach | ab885f8 | 2008-03-20 15:06:43 +0200 | [diff] [blame] | 3573 | } |
| 3574 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3575 | static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 3576 | struct ieee80211_vif *vif, |
| 3577 | struct ieee80211_sta *sta, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3578 | struct ieee80211_key_conf *key) |
| 3579 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3580 | struct iwl_priv *priv = hw->priv; |
Johannes Berg | a194e32 | 2010-08-27 08:53:46 -0700 | [diff] [blame] | 3581 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
Johannes Berg | c10afb6 | 2010-08-23 10:46:43 +0200 | [diff] [blame] | 3582 | struct iwl_rxon_context *ctx = vif_priv->ctx; |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 3583 | int ret; |
| 3584 | u8 sta_id; |
| 3585 | bool is_default_wep_key = false; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3586 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3587 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3588 | |
Tomas Winkler | 90e8e42 | 2009-06-19 13:52:42 -0700 | [diff] [blame] | 3589 | if (priv->cfg->mod_params->sw_crypto) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3590 | IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3591 | return -EOPNOTSUPP; |
| 3592 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3593 | |
Johannes Berg | a194e32 | 2010-08-27 08:53:46 -0700 | [diff] [blame] | 3594 | sta_id = iwl_sta_id_or_broadcast(priv, vif_priv->ctx, sta); |
Johannes Berg | 0af8bca | 2010-04-30 14:08:00 -0700 | [diff] [blame] | 3595 | if (sta_id == IWL_INVALID_STATION) |
| 3596 | return -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3597 | |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3598 | mutex_lock(&priv->mutex); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 3599 | iwl_scan_cancel_timeout(priv, 100); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3600 | |
Johannes Berg | a90178fa | 2010-03-30 02:44:16 -0700 | [diff] [blame] | 3601 | /* |
| 3602 | * If we are getting WEP group key and we didn't receive any key mapping |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3603 | * so far, we are in legacy wep mode (group key only), otherwise we are |
| 3604 | * in 1X mode. |
Johannes Berg | a90178fa | 2010-03-30 02:44:16 -0700 | [diff] [blame] | 3605 | * In legacy wep mode, we use another host command to the uCode. |
| 3606 | */ |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 3607 | if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3608 | key->cipher == WLAN_CIPHER_SUITE_WEP104) && |
Johannes Berg | 54c8067 | 2010-08-18 09:35:21 -0700 | [diff] [blame] | 3609 | !sta) { |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3610 | if (cmd == SET_KEY) |
Johannes Berg | c10afb6 | 2010-08-23 10:46:43 +0200 | [diff] [blame] | 3611 | is_default_wep_key = !ctx->key_mapping_keys; |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3612 | else |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 3613 | is_default_wep_key = |
| 3614 | (key->hw_key_idx == HW_KEY_DEFAULT); |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3615 | } |
mabbas | 052c4b9 | 2007-10-25 17:15:43 +0800 | [diff] [blame] | 3616 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3617 | switch (cmd) { |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3618 | case SET_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3619 | if (is_default_wep_key) |
Johannes Berg | 2995baf | 2010-08-23 10:46:42 +0200 | [diff] [blame] | 3620 | ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3621 | else |
Johannes Berg | a194e32 | 2010-08-27 08:53:46 -0700 | [diff] [blame] | 3622 | ret = iwl_set_dynamic_key(priv, vif_priv->ctx, |
| 3623 | key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3624 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3625 | IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3626 | break; |
| 3627 | case DISABLE_KEY: |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 3628 | if (is_default_wep_key) |
Johannes Berg | c10afb6 | 2010-08-23 10:46:43 +0200 | [diff] [blame] | 3629 | ret = iwl_remove_default_wep_key(priv, ctx, key); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3630 | else |
Johannes Berg | c10afb6 | 2010-08-23 10:46:43 +0200 | [diff] [blame] | 3631 | ret = iwl_remove_dynamic_key(priv, ctx, key, sta_id); |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3632 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3633 | IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3634 | break; |
| 3635 | default: |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3636 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3637 | } |
| 3638 | |
Johannes Berg | 72e15d7 | 2010-02-19 11:42:32 -0800 | [diff] [blame] | 3639 | mutex_unlock(&priv->mutex); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3640 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3641 | |
Emmanuel Grumbach | deb09c4 | 2008-03-19 16:41:41 -0700 | [diff] [blame] | 3642 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3643 | } |
| 3644 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3645 | static int iwl_mac_ampdu_action(struct ieee80211_hw *hw, |
Johannes Berg | c951ad3 | 2009-11-16 12:00:38 +0100 | [diff] [blame] | 3646 | struct ieee80211_vif *vif, |
Johannes Berg | 832f47e | 2010-04-29 04:43:07 -0700 | [diff] [blame] | 3647 | enum ieee80211_ampdu_mlme_action action, |
| 3648 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
Tomas Winkler | d783b06 | 2008-07-18 13:53:02 +0800 | [diff] [blame] | 3649 | { |
| 3650 | struct iwl_priv *priv = hw->priv; |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 3651 | int ret = -EINVAL; |
Tomas Winkler | d783b06 | 2008-07-18 13:53:02 +0800 | [diff] [blame] | 3652 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3653 | IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3654 | sta->addr, tid); |
Tomas Winkler | d783b06 | 2008-07-18 13:53:02 +0800 | [diff] [blame] | 3655 | |
| 3656 | if (!(priv->cfg->sku & IWL_SKU_N)) |
| 3657 | return -EACCES; |
| 3658 | |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 3659 | mutex_lock(&priv->mutex); |
| 3660 | |
Tomas Winkler | d783b06 | 2008-07-18 13:53:02 +0800 | [diff] [blame] | 3661 | switch (action) { |
| 3662 | case IEEE80211_AMPDU_RX_START: |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3663 | IWL_DEBUG_HT(priv, "start Rx\n"); |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 3664 | ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn); |
| 3665 | break; |
Tomas Winkler | d783b06 | 2008-07-18 13:53:02 +0800 | [diff] [blame] | 3666 | case IEEE80211_AMPDU_RX_STOP: |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3667 | IWL_DEBUG_HT(priv, "stop Rx\n"); |
Johannes Berg | 619753f | 2010-04-30 11:30:46 -0700 | [diff] [blame] | 3668 | ret = iwl_sta_rx_agg_stop(priv, sta, tid); |
Wey-Yi Guy | 5c2207c | 2009-03-17 21:51:43 -0700 | [diff] [blame] | 3669 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 3670 | ret = 0; |
| 3671 | break; |
Tomas Winkler | d783b06 | 2008-07-18 13:53:02 +0800 | [diff] [blame] | 3672 | case IEEE80211_AMPDU_TX_START: |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3673 | IWL_DEBUG_HT(priv, "start Tx\n"); |
Johannes Berg | 619753f | 2010-04-30 11:30:46 -0700 | [diff] [blame] | 3674 | ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn); |
Wey-Yi Guy | d5a0ffa | 2010-03-04 13:38:59 -0800 | [diff] [blame] | 3675 | if (ret == 0) { |
| 3676 | priv->_agn.agg_tids_count++; |
| 3677 | IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n", |
| 3678 | priv->_agn.agg_tids_count); |
| 3679 | } |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 3680 | break; |
Tomas Winkler | d783b06 | 2008-07-18 13:53:02 +0800 | [diff] [blame] | 3681 | case IEEE80211_AMPDU_TX_STOP: |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3682 | IWL_DEBUG_HT(priv, "stop Tx\n"); |
Johannes Berg | 619753f | 2010-04-30 11:30:46 -0700 | [diff] [blame] | 3683 | ret = iwlagn_tx_agg_stop(priv, vif, sta, tid); |
Wey-Yi Guy | d5a0ffa | 2010-03-04 13:38:59 -0800 | [diff] [blame] | 3684 | if ((ret == 0) && (priv->_agn.agg_tids_count > 0)) { |
| 3685 | priv->_agn.agg_tids_count--; |
| 3686 | IWL_DEBUG_HT(priv, "priv->_agn.agg_tids_count = %u\n", |
| 3687 | priv->_agn.agg_tids_count); |
| 3688 | } |
Wey-Yi Guy | 5c2207c | 2009-03-17 21:51:43 -0700 | [diff] [blame] | 3689 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 3690 | ret = 0; |
Johannes Berg | 94597ab | 2010-08-09 10:57:02 -0700 | [diff] [blame] | 3691 | if (priv->cfg->use_rts_for_aggregation) { |
| 3692 | struct iwl_station_priv *sta_priv = |
| 3693 | (void *) sta->drv_priv; |
| 3694 | /* |
| 3695 | * switch off RTS/CTS if it was previously enabled |
| 3696 | */ |
| 3697 | |
| 3698 | sta_priv->lq_sta.lq.general_params.flags &= |
| 3699 | ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 3700 | iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif), |
| 3701 | &sta_priv->lq_sta.lq, CMD_ASYNC, false); |
Johannes Berg | 94597ab | 2010-08-09 10:57:02 -0700 | [diff] [blame] | 3702 | } |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 3703 | break; |
Wey-Yi Guy | f052797 | 2010-01-08 10:04:41 -0800 | [diff] [blame] | 3704 | case IEEE80211_AMPDU_TX_OPERATIONAL: |
Johannes Berg | 94597ab | 2010-08-09 10:57:02 -0700 | [diff] [blame] | 3705 | if (priv->cfg->use_rts_for_aggregation) { |
| 3706 | struct iwl_station_priv *sta_priv = |
| 3707 | (void *) sta->drv_priv; |
| 3708 | |
Wey-Yi Guy | cfecc6b | 2010-06-18 11:33:15 -0700 | [diff] [blame] | 3709 | /* |
| 3710 | * switch to RTS/CTS if it is the prefer protection |
| 3711 | * method for HT traffic |
| 3712 | */ |
Johannes Berg | 94597ab | 2010-08-09 10:57:02 -0700 | [diff] [blame] | 3713 | |
| 3714 | sta_priv->lq_sta.lq.general_params.flags |= |
| 3715 | LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 3716 | iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif), |
| 3717 | &sta_priv->lq_sta.lq, CMD_ASYNC, false); |
Wey-Yi Guy | cfecc6b | 2010-06-18 11:33:15 -0700 | [diff] [blame] | 3718 | } |
| 3719 | ret = 0; |
Tomas Winkler | d783b06 | 2008-07-18 13:53:02 +0800 | [diff] [blame] | 3720 | break; |
| 3721 | } |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 3722 | mutex_unlock(&priv->mutex); |
| 3723 | |
| 3724 | return ret; |
Tomas Winkler | d783b06 | 2008-07-18 13:53:02 +0800 | [diff] [blame] | 3725 | } |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 3726 | |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 3727 | static void iwl_mac_sta_notify(struct ieee80211_hw *hw, |
| 3728 | struct ieee80211_vif *vif, |
| 3729 | enum sta_notify_cmd cmd, |
| 3730 | struct ieee80211_sta *sta) |
| 3731 | { |
| 3732 | struct iwl_priv *priv = hw->priv; |
| 3733 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
| 3734 | int sta_id; |
| 3735 | |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 3736 | switch (cmd) { |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 3737 | case STA_NOTIFY_SLEEP: |
| 3738 | WARN_ON(!sta_priv->client); |
| 3739 | sta_priv->asleep = true; |
| 3740 | if (atomic_read(&sta_priv->pending_frames) > 0) |
| 3741 | ieee80211_sta_block_awake(hw, sta, true); |
| 3742 | break; |
| 3743 | case STA_NOTIFY_AWAKE: |
| 3744 | WARN_ON(!sta_priv->client); |
Daniel Halperin | 49dcc81 | 2010-01-19 10:22:19 -0800 | [diff] [blame] | 3745 | if (!sta_priv->asleep) |
| 3746 | break; |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 3747 | sta_priv->asleep = false; |
Johannes Berg | 2a87c26 | 2010-04-30 11:30:45 -0700 | [diff] [blame] | 3748 | sta_id = iwl_sta_id(sta); |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 3749 | if (sta_id != IWL_INVALID_STATION) |
| 3750 | iwl_sta_modify_ps_wake(priv, sta_id); |
| 3751 | break; |
| 3752 | default: |
| 3753 | break; |
| 3754 | } |
| 3755 | } |
| 3756 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3757 | static int iwlagn_mac_sta_add(struct ieee80211_hw *hw, |
| 3758 | struct ieee80211_vif *vif, |
| 3759 | struct ieee80211_sta *sta) |
| 3760 | { |
| 3761 | struct iwl_priv *priv = hw->priv; |
| 3762 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
Johannes Berg | a194e32 | 2010-08-27 08:53:46 -0700 | [diff] [blame] | 3763 | struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; |
Johannes Berg | eafdfbd3 | 2010-04-29 04:43:04 -0700 | [diff] [blame] | 3764 | bool is_ap = vif->type == NL80211_IFTYPE_STATION; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3765 | int ret; |
| 3766 | u8 sta_id; |
| 3767 | |
| 3768 | IWL_DEBUG_INFO(priv, "received request to add station %pM\n", |
| 3769 | sta->addr); |
Reinette Chatre | da5ae1c | 2010-05-28 09:28:39 -0700 | [diff] [blame] | 3770 | mutex_lock(&priv->mutex); |
| 3771 | IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n", |
| 3772 | sta->addr); |
| 3773 | sta_priv->common.sta_id = IWL_INVALID_STATION; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3774 | |
| 3775 | atomic_set(&sta_priv->pending_frames, 0); |
| 3776 | if (vif->type == NL80211_IFTYPE_AP) |
| 3777 | sta_priv->client = true; |
| 3778 | |
Johannes Berg | a194e32 | 2010-08-27 08:53:46 -0700 | [diff] [blame] | 3779 | ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr, |
Johannes Berg | 238d781 | 2010-08-23 10:46:45 +0200 | [diff] [blame] | 3780 | is_ap, sta, &sta_id); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3781 | if (ret) { |
| 3782 | IWL_ERR(priv, "Unable to add station %pM (%d)\n", |
| 3783 | sta->addr, ret); |
| 3784 | /* Should we return success if return code is EEXIST ? */ |
Reinette Chatre | da5ae1c | 2010-05-28 09:28:39 -0700 | [diff] [blame] | 3785 | mutex_unlock(&priv->mutex); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3786 | return ret; |
| 3787 | } |
| 3788 | |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 3789 | sta_priv->common.sta_id = sta_id; |
| 3790 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3791 | /* Initialize rate scaling */ |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 3792 | IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n", |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3793 | sta->addr); |
| 3794 | iwl_rs_rate_init(priv, sta, sta_id); |
Reinette Chatre | da5ae1c | 2010-05-28 09:28:39 -0700 | [diff] [blame] | 3795 | mutex_unlock(&priv->mutex); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3796 | |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 3797 | return 0; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3798 | } |
| 3799 | |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3800 | static void iwl_mac_channel_switch(struct ieee80211_hw *hw, |
| 3801 | struct ieee80211_channel_switch *ch_switch) |
| 3802 | { |
| 3803 | struct iwl_priv *priv = hw->priv; |
| 3804 | const struct iwl_channel_info *ch_info; |
| 3805 | struct ieee80211_conf *conf = &hw->conf; |
Shanyu Zhao | aa2dc6b | 2010-07-28 13:40:39 -0700 | [diff] [blame] | 3806 | struct ieee80211_channel *channel = ch_switch->channel; |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3807 | struct iwl_ht_config *ht_conf = &priv->current_ht_config; |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3808 | /* |
| 3809 | * MULTI-FIXME |
| 3810 | * When we add support for multiple interfaces, we need to |
| 3811 | * revisit this. The channel switch command in the device |
| 3812 | * only affects the BSS context, but what does that really |
| 3813 | * mean? And what if we get a CSA on the second interface? |
| 3814 | * This needs a lot of work. |
| 3815 | */ |
| 3816 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3817 | u16 ch; |
| 3818 | unsigned long flags = 0; |
| 3819 | |
| 3820 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
| 3821 | |
| 3822 | if (iwl_is_rfkill(priv)) |
| 3823 | goto out_exit; |
| 3824 | |
| 3825 | if (test_bit(STATUS_EXIT_PENDING, &priv->status) || |
| 3826 | test_bit(STATUS_SCANNING, &priv->status)) |
| 3827 | goto out_exit; |
| 3828 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3829 | if (!iwl_is_associated_ctx(ctx)) |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3830 | goto out_exit; |
| 3831 | |
| 3832 | /* channel switch in progress */ |
| 3833 | if (priv->switch_rxon.switch_in_progress == true) |
| 3834 | goto out_exit; |
| 3835 | |
| 3836 | mutex_lock(&priv->mutex); |
| 3837 | if (priv->cfg->ops->lib->set_channel_switch) { |
| 3838 | |
Shanyu Zhao | aa2dc6b | 2010-07-28 13:40:39 -0700 | [diff] [blame] | 3839 | ch = channel->hw_value; |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3840 | if (le16_to_cpu(ctx->active.channel) != ch) { |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3841 | ch_info = iwl_get_channel_info(priv, |
Shanyu Zhao | aa2dc6b | 2010-07-28 13:40:39 -0700 | [diff] [blame] | 3842 | channel->band, |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3843 | ch); |
| 3844 | if (!is_channel_valid(ch_info)) { |
| 3845 | IWL_DEBUG_MAC80211(priv, "invalid channel\n"); |
| 3846 | goto out; |
| 3847 | } |
| 3848 | spin_lock_irqsave(&priv->lock, flags); |
| 3849 | |
| 3850 | priv->current_ht_config.smps = conf->smps_mode; |
| 3851 | |
| 3852 | /* Configure HT40 channels */ |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 3853 | ctx->ht.enabled = conf_is_ht(conf); |
| 3854 | if (ctx->ht.enabled) { |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3855 | if (conf_is_ht40_minus(conf)) { |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 3856 | ctx->ht.extension_chan_offset = |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3857 | IEEE80211_HT_PARAM_CHA_SEC_BELOW; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 3858 | ctx->ht.is_40mhz = true; |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3859 | } else if (conf_is_ht40_plus(conf)) { |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 3860 | ctx->ht.extension_chan_offset = |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3861 | IEEE80211_HT_PARAM_CHA_SEC_ABOVE; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 3862 | ctx->ht.is_40mhz = true; |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3863 | } else { |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 3864 | ctx->ht.extension_chan_offset = |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3865 | IEEE80211_HT_PARAM_CHA_SEC_NONE; |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 3866 | ctx->ht.is_40mhz = false; |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3867 | } |
| 3868 | } else |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 3869 | ctx->ht.is_40mhz = false; |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3870 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3871 | if ((le16_to_cpu(ctx->staging.channel) != ch)) |
| 3872 | ctx->staging.flags = 0; |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3873 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3874 | iwl_set_rxon_channel(priv, channel, ctx); |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3875 | iwl_set_rxon_ht(priv, ht_conf); |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3876 | iwl_set_flags_for_band(priv, ctx, channel->band, |
Johannes Berg | 8bd413e | 2010-08-23 10:46:40 +0200 | [diff] [blame] | 3877 | ctx->vif); |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3878 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3879 | |
| 3880 | iwl_set_rate(priv); |
| 3881 | /* |
| 3882 | * at this point, staging_rxon has the |
| 3883 | * configuration for channel switch |
| 3884 | */ |
| 3885 | if (priv->cfg->ops->lib->set_channel_switch(priv, |
| 3886 | ch_switch)) |
| 3887 | priv->switch_rxon.switch_in_progress = false; |
| 3888 | } |
| 3889 | } |
| 3890 | out: |
| 3891 | mutex_unlock(&priv->mutex); |
| 3892 | out_exit: |
| 3893 | if (!priv->switch_rxon.switch_in_progress) |
Johannes Berg | 8bd413e | 2010-08-23 10:46:40 +0200 | [diff] [blame] | 3894 | ieee80211_chswitch_done(ctx->vif, false); |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 3895 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 3896 | } |
| 3897 | |
Johannes Berg | 8b8ab9d | 2010-08-17 11:24:01 +0200 | [diff] [blame] | 3898 | static void iwlagn_configure_filter(struct ieee80211_hw *hw, |
| 3899 | unsigned int changed_flags, |
| 3900 | unsigned int *total_flags, |
| 3901 | u64 multicast) |
| 3902 | { |
| 3903 | struct iwl_priv *priv = hw->priv; |
| 3904 | __le32 filter_or = 0, filter_nand = 0; |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3905 | struct iwl_rxon_context *ctx; |
Johannes Berg | 8b8ab9d | 2010-08-17 11:24:01 +0200 | [diff] [blame] | 3906 | |
| 3907 | #define CHK(test, flag) do { \ |
| 3908 | if (*total_flags & (test)) \ |
| 3909 | filter_or |= (flag); \ |
| 3910 | else \ |
| 3911 | filter_nand |= (flag); \ |
| 3912 | } while (0) |
| 3913 | |
| 3914 | IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n", |
| 3915 | changed_flags, *total_flags); |
| 3916 | |
| 3917 | CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK); |
| 3918 | CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK); |
| 3919 | CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK); |
| 3920 | |
| 3921 | #undef CHK |
| 3922 | |
| 3923 | mutex_lock(&priv->mutex); |
| 3924 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 3925 | for_each_context(priv, ctx) { |
| 3926 | ctx->staging.filter_flags &= ~filter_nand; |
| 3927 | ctx->staging.filter_flags |= filter_or; |
| 3928 | iwlcore_commit_rxon(priv, ctx); |
| 3929 | } |
Johannes Berg | 8b8ab9d | 2010-08-17 11:24:01 +0200 | [diff] [blame] | 3930 | |
| 3931 | mutex_unlock(&priv->mutex); |
| 3932 | |
| 3933 | /* |
| 3934 | * Receiving all multicast frames is always enabled by the |
| 3935 | * default flags setup in iwl_connection_init_rx_config() |
| 3936 | * since we currently do not support programming multicast |
| 3937 | * filters into the device. |
| 3938 | */ |
| 3939 | *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS | |
| 3940 | FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL; |
| 3941 | } |
| 3942 | |
Wey-Yi Guy | 716c74b | 2010-06-24 13:22:36 -0700 | [diff] [blame] | 3943 | static void iwl_mac_flush(struct ieee80211_hw *hw, bool drop) |
| 3944 | { |
| 3945 | struct iwl_priv *priv = hw->priv; |
| 3946 | |
| 3947 | mutex_lock(&priv->mutex); |
| 3948 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
| 3949 | |
| 3950 | /* do not support "flush" */ |
| 3951 | if (!priv->cfg->ops->lib->txfifo_flush) |
| 3952 | goto done; |
| 3953 | |
| 3954 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
| 3955 | IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n"); |
| 3956 | goto done; |
| 3957 | } |
| 3958 | if (iwl_is_rfkill(priv)) { |
| 3959 | IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n"); |
| 3960 | goto done; |
| 3961 | } |
| 3962 | |
| 3963 | /* |
| 3964 | * mac80211 will not push any more frames for transmit |
| 3965 | * until the flush is completed |
| 3966 | */ |
| 3967 | if (drop) { |
| 3968 | IWL_DEBUG_MAC80211(priv, "send flush command\n"); |
| 3969 | if (priv->cfg->ops->lib->txfifo_flush(priv, IWL_DROP_ALL)) { |
| 3970 | IWL_ERR(priv, "flush request fail\n"); |
| 3971 | goto done; |
| 3972 | } |
| 3973 | } |
| 3974 | IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n"); |
| 3975 | iwlagn_wait_tx_queue_empty(priv); |
| 3976 | done: |
| 3977 | mutex_unlock(&priv->mutex); |
| 3978 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
| 3979 | } |
| 3980 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3981 | /***************************************************************************** |
| 3982 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3983 | * driver setup and teardown |
| 3984 | * |
| 3985 | *****************************************************************************/ |
| 3986 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 3987 | static void iwl_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3988 | { |
Reinette Chatre | d21050c | 2009-02-13 11:51:18 -0800 | [diff] [blame] | 3989 | priv->workqueue = create_singlethread_workqueue(DRV_NAME); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3990 | |
| 3991 | init_waitqueue_head(&priv->wait_command_queue); |
| 3992 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3993 | INIT_WORK(&priv->restart, iwl_bg_restart); |
| 3994 | INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish); |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 3995 | INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update); |
Emmanuel Grumbach | 16e727e | 2008-06-12 09:46:52 +0800 | [diff] [blame] | 3996 | INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work); |
Wey-Yi Guy | 6555063 | 2010-06-24 13:18:35 -0700 | [diff] [blame] | 3997 | INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush); |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 3998 | INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency); |
Wey-Yi Guy | fbba941 | 2010-08-23 07:57:10 -0700 | [diff] [blame] | 3999 | INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config); |
Tomas Winkler | 4a4a9e8 | 2008-05-29 16:34:54 +0800 | [diff] [blame] | 4000 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start); |
| 4001 | INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 4002 | |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 4003 | iwl_setup_scan_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4004 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 4005 | if (priv->cfg->ops->lib->setup_deferred_work) |
| 4006 | priv->cfg->ops->lib->setup_deferred_work(priv); |
| 4007 | |
| 4008 | init_timer(&priv->statistics_periodic); |
| 4009 | priv->statistics_periodic.data = (unsigned long)priv; |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4010 | priv->statistics_periodic.function = iwl_bg_statistics_periodic; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4011 | |
Wey-Yi Guy | a9e1cb6 | 2009-12-10 14:37:26 -0800 | [diff] [blame] | 4012 | init_timer(&priv->ucode_trace); |
| 4013 | priv->ucode_trace.data = (unsigned long)priv; |
| 4014 | priv->ucode_trace.function = iwl_bg_ucode_trace; |
| 4015 | |
Wey-Yi Guy | b74e31a | 2010-03-01 17:23:50 -0800 | [diff] [blame] | 4016 | if (priv->cfg->ops->lib->recover_from_tx_stall) { |
| 4017 | init_timer(&priv->monitor_recover); |
| 4018 | priv->monitor_recover.data = (unsigned long)priv; |
| 4019 | priv->monitor_recover.function = |
| 4020 | priv->cfg->ops->lib->recover_from_tx_stall; |
| 4021 | } |
| 4022 | |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 4023 | if (!priv->cfg->use_isr_legacy) |
| 4024 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
| 4025 | iwl_irq_tasklet, (unsigned long)priv); |
| 4026 | else |
| 4027 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
| 4028 | iwl_irq_tasklet_legacy, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4029 | } |
| 4030 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 4031 | static void iwl_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4032 | { |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 4033 | if (priv->cfg->ops->lib->cancel_deferred_work) |
| 4034 | priv->cfg->ops->lib->cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4035 | |
Joonwoo Park | 3ae6a05 | 2007-11-29 10:43:16 +0900 | [diff] [blame] | 4036 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4037 | cancel_delayed_work(&priv->scan_check); |
Johannes Berg | 88be026 | 2010-04-07 00:21:36 -0700 | [diff] [blame] | 4038 | cancel_work_sync(&priv->start_internal_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4039 | cancel_delayed_work(&priv->alive_start); |
Wey-Yi Guy | 815e629 | 2010-06-03 10:14:01 -0700 | [diff] [blame] | 4040 | cancel_work_sync(&priv->run_time_calib_work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4041 | cancel_work_sync(&priv->beacon_update); |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 4042 | cancel_work_sync(&priv->bt_full_concurrency); |
Wey-Yi Guy | fbba941 | 2010-08-23 07:57:10 -0700 | [diff] [blame] | 4043 | cancel_work_sync(&priv->bt_runtime_config); |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 4044 | del_timer_sync(&priv->statistics_periodic); |
Wey-Yi Guy | a9e1cb6 | 2009-12-10 14:37:26 -0800 | [diff] [blame] | 4045 | del_timer_sync(&priv->ucode_trace); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4046 | } |
| 4047 | |
Reinette Chatre | 89f186a | 2009-10-30 14:36:11 -0700 | [diff] [blame] | 4048 | static void iwl_init_hw_rates(struct iwl_priv *priv, |
| 4049 | struct ieee80211_rate *rates) |
| 4050 | { |
| 4051 | int i; |
| 4052 | |
| 4053 | for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) { |
| 4054 | rates[i].bitrate = iwl_rates[i].ieee * 5; |
| 4055 | rates[i].hw_value = i; /* Rate scaling will work on indexes */ |
| 4056 | rates[i].hw_value_short = i; |
| 4057 | rates[i].flags = 0; |
| 4058 | if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) { |
| 4059 | /* |
| 4060 | * If CCK != 1M then set short preamble rate flag. |
| 4061 | */ |
| 4062 | rates[i].flags |= |
| 4063 | (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ? |
| 4064 | 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
| 4065 | } |
| 4066 | } |
| 4067 | } |
| 4068 | |
| 4069 | static int iwl_init_drv(struct iwl_priv *priv) |
| 4070 | { |
| 4071 | int ret; |
| 4072 | |
| 4073 | priv->ibss_beacon = NULL; |
| 4074 | |
Reinette Chatre | 89f186a | 2009-10-30 14:36:11 -0700 | [diff] [blame] | 4075 | spin_lock_init(&priv->sta_lock); |
| 4076 | spin_lock_init(&priv->hcmd_lock); |
| 4077 | |
| 4078 | INIT_LIST_HEAD(&priv->free_frames); |
| 4079 | |
| 4080 | mutex_init(&priv->mutex); |
Reinette Chatre | d2dfe6d | 2010-02-18 22:03:04 -0800 | [diff] [blame] | 4081 | mutex_init(&priv->sync_cmd_mutex); |
Reinette Chatre | 89f186a | 2009-10-30 14:36:11 -0700 | [diff] [blame] | 4082 | |
Reinette Chatre | 89f186a | 2009-10-30 14:36:11 -0700 | [diff] [blame] | 4083 | priv->ieee_channels = NULL; |
| 4084 | priv->ieee_rates = NULL; |
| 4085 | priv->band = IEEE80211_BAND_2GHZ; |
| 4086 | |
| 4087 | priv->iw_mode = NL80211_IFTYPE_STATION; |
Johannes Berg | ba37a3d | 2009-12-10 14:37:27 -0800 | [diff] [blame] | 4088 | priv->current_ht_config.smps = IEEE80211_SMPS_STATIC; |
Wey-Yi Guy | a13d276 | 2010-01-22 14:22:42 -0800 | [diff] [blame] | 4089 | priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF; |
Wey-Yi Guy | d5a0ffa | 2010-03-04 13:38:59 -0800 | [diff] [blame] | 4090 | priv->_agn.agg_tids_count = 0; |
Reinette Chatre | 89f186a | 2009-10-30 14:36:11 -0700 | [diff] [blame] | 4091 | |
Wey-Yi Guy | 8a472da | 2010-02-18 22:03:06 -0800 | [diff] [blame] | 4092 | /* initialize force reset */ |
| 4093 | priv->force_reset[IWL_RF_RESET].reset_duration = |
| 4094 | IWL_DELAY_NEXT_FORCE_RF_RESET; |
| 4095 | priv->force_reset[IWL_FW_RESET].reset_duration = |
| 4096 | IWL_DELAY_NEXT_FORCE_FW_RELOAD; |
Reinette Chatre | 89f186a | 2009-10-30 14:36:11 -0700 | [diff] [blame] | 4097 | |
| 4098 | /* Choose which receivers/antennas to use */ |
| 4099 | if (priv->cfg->ops->hcmd->set_rxon_chain) |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 4100 | priv->cfg->ops->hcmd->set_rxon_chain(priv, |
| 4101 | &priv->contexts[IWL_RXON_CTX_BSS]); |
Reinette Chatre | 89f186a | 2009-10-30 14:36:11 -0700 | [diff] [blame] | 4102 | |
| 4103 | iwl_init_scan_params(priv); |
| 4104 | |
Wey-Yi Guy | 22bf59a | 2010-08-23 07:57:11 -0700 | [diff] [blame] | 4105 | /* init bt coex */ |
| 4106 | if (priv->cfg->advanced_bt_coexist) { |
Wey-Yi Guy | b6e116e | 2010-08-23 07:57:14 -0700 | [diff] [blame] | 4107 | priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT; |
| 4108 | priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT; |
| 4109 | priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK; |
Wey-Yi Guy | 22bf59a | 2010-08-23 07:57:11 -0700 | [diff] [blame] | 4110 | priv->bt_on_thresh = BT_ON_THRESHOLD_DEF; |
| 4111 | priv->bt_duration = BT_DURATION_LIMIT_DEF; |
| 4112 | priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF; |
| 4113 | priv->dynamic_agg_thresh = BT_AGG_THRESHOLD_DEF; |
| 4114 | } |
| 4115 | |
Reinette Chatre | 89f186a | 2009-10-30 14:36:11 -0700 | [diff] [blame] | 4116 | /* Set the tx_power_user_lmt to the lowest power level |
| 4117 | * this value will get overwritten by channel max power avg |
| 4118 | * from eeprom */ |
Wey-Yi Guy | b744cb7 | 2010-03-23 11:37:59 -0700 | [diff] [blame] | 4119 | priv->tx_power_user_lmt = IWLAGN_TX_POWER_TARGET_POWER_MIN; |
Reinette Chatre | 89f186a | 2009-10-30 14:36:11 -0700 | [diff] [blame] | 4120 | |
| 4121 | ret = iwl_init_channel_map(priv); |
| 4122 | if (ret) { |
| 4123 | IWL_ERR(priv, "initializing regulatory failed: %d\n", ret); |
| 4124 | goto err; |
| 4125 | } |
| 4126 | |
| 4127 | ret = iwlcore_init_geos(priv); |
| 4128 | if (ret) { |
| 4129 | IWL_ERR(priv, "initializing geos failed: %d\n", ret); |
| 4130 | goto err_free_channel_map; |
| 4131 | } |
| 4132 | iwl_init_hw_rates(priv, priv->ieee_rates); |
| 4133 | |
| 4134 | return 0; |
| 4135 | |
| 4136 | err_free_channel_map: |
| 4137 | iwl_free_channel_map(priv); |
| 4138 | err: |
| 4139 | return ret; |
| 4140 | } |
| 4141 | |
| 4142 | static void iwl_uninit_drv(struct iwl_priv *priv) |
| 4143 | { |
| 4144 | iwl_calib_free_results(priv); |
| 4145 | iwlcore_free_geos(priv); |
| 4146 | iwl_free_channel_map(priv); |
Johannes Berg | 811ecc9 | 2010-04-06 04:12:41 -0700 | [diff] [blame] | 4147 | kfree(priv->scan_cmd); |
Reinette Chatre | 89f186a | 2009-10-30 14:36:11 -0700 | [diff] [blame] | 4148 | } |
| 4149 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4150 | static struct ieee80211_ops iwl_hw_ops = { |
| 4151 | .tx = iwl_mac_tx, |
| 4152 | .start = iwl_mac_start, |
| 4153 | .stop = iwl_mac_stop, |
| 4154 | .add_interface = iwl_mac_add_interface, |
| 4155 | .remove_interface = iwl_mac_remove_interface, |
| 4156 | .config = iwl_mac_config, |
Johannes Berg | 8b8ab9d | 2010-08-17 11:24:01 +0200 | [diff] [blame] | 4157 | .configure_filter = iwlagn_configure_filter, |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4158 | .set_key = iwl_mac_set_key, |
| 4159 | .update_tkip_key = iwl_mac_update_tkip_key, |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4160 | .conf_tx = iwl_mac_conf_tx, |
| 4161 | .reset_tsf = iwl_mac_reset_tsf, |
| 4162 | .bss_info_changed = iwl_bss_info_changed, |
| 4163 | .ampdu_action = iwl_mac_ampdu_action, |
Johannes Berg | 6ab10ff | 2009-11-13 11:56:37 -0800 | [diff] [blame] | 4164 | .hw_scan = iwl_mac_hw_scan, |
| 4165 | .sta_notify = iwl_mac_sta_notify, |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 4166 | .sta_add = iwlagn_mac_sta_add, |
| 4167 | .sta_remove = iwl_mac_sta_remove, |
Wey-Yi Guy | 79d0732 | 2010-05-06 08:54:11 -0700 | [diff] [blame] | 4168 | .channel_switch = iwl_mac_channel_switch, |
Wey-Yi Guy | 716c74b | 2010-06-24 13:22:36 -0700 | [diff] [blame] | 4169 | .flush = iwl_mac_flush, |
Johannes Berg | a85d7cc | 2010-07-31 08:34:10 -0700 | [diff] [blame] | 4170 | .tx_last_beacon = iwl_mac_tx_last_beacon, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4171 | }; |
| 4172 | |
Wey-Yi Guy | 3867fe0 | 2010-07-31 08:34:05 -0700 | [diff] [blame] | 4173 | static void iwl_hw_detect(struct iwl_priv *priv) |
| 4174 | { |
| 4175 | priv->hw_rev = _iwl_read32(priv, CSR_HW_REV); |
| 4176 | priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG); |
| 4177 | pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id); |
Wey-Yi Guy | 49ded76 | 2010-07-31 08:34:06 -0700 | [diff] [blame] | 4178 | IWL_DEBUG_INFO(priv, "HW Revision ID = 0x%X\n", priv->rev_id); |
Wey-Yi Guy | 3867fe0 | 2010-07-31 08:34:05 -0700 | [diff] [blame] | 4179 | } |
| 4180 | |
Wey-Yi Guy | 07d4f1a | 2010-07-31 08:34:08 -0700 | [diff] [blame] | 4181 | static int iwl_set_hw_params(struct iwl_priv *priv) |
| 4182 | { |
| 4183 | priv->hw_params.max_rxq_size = RX_QUEUE_SIZE; |
| 4184 | priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG; |
| 4185 | if (priv->cfg->mod_params->amsdu_size_8K) |
| 4186 | priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K); |
| 4187 | else |
| 4188 | priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K); |
| 4189 | |
| 4190 | priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL; |
| 4191 | |
| 4192 | if (priv->cfg->mod_params->disable_11n) |
| 4193 | priv->cfg->sku &= ~IWL_SKU_N; |
| 4194 | |
| 4195 | /* Device-specific setup */ |
| 4196 | return priv->cfg->ops->lib->set_hw_params(priv); |
| 4197 | } |
| 4198 | |
Johannes Berg | e72f368 | 2010-08-23 10:46:51 +0200 | [diff] [blame^] | 4199 | static const u8 iwlagn_bss_ac_to_fifo[] = { |
| 4200 | IWL_TX_FIFO_VO, |
| 4201 | IWL_TX_FIFO_VI, |
| 4202 | IWL_TX_FIFO_BE, |
| 4203 | IWL_TX_FIFO_BK, |
| 4204 | }; |
| 4205 | |
| 4206 | static const u8 iwlagn_bss_ac_to_queue[] = { |
| 4207 | 0, 1, 2, 3, |
| 4208 | }; |
| 4209 | |
| 4210 | static const u8 iwlagn_pan_ac_to_fifo[] = { |
| 4211 | IWL_TX_FIFO_VO_IPAN, |
| 4212 | IWL_TX_FIFO_VI_IPAN, |
| 4213 | IWL_TX_FIFO_BE_IPAN, |
| 4214 | IWL_TX_FIFO_BK_IPAN, |
| 4215 | }; |
| 4216 | |
| 4217 | static const u8 iwlagn_pan_ac_to_queue[] = { |
| 4218 | 7, 6, 5, 4, |
| 4219 | }; |
| 4220 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4221 | static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4222 | { |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 4223 | int err = 0, i; |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4224 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4225 | struct ieee80211_hw *hw; |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4226 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4227 | unsigned long flags; |
Wey-Yi Guy | c6fa17e | 2010-07-15 05:58:30 -0700 | [diff] [blame] | 4228 | u16 pci_cmd, num_mac; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4229 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4230 | /************************ |
| 4231 | * 1. Allocating HW data |
| 4232 | ************************/ |
| 4233 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4234 | /* Disabling hardware scan means that mac80211 will perform scans |
| 4235 | * "the hard way", rather than using device's scan. */ |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 4236 | if (cfg->mod_params->disable_hw_scan) { |
Reinette Chatre | a562a9d | 2009-07-17 09:30:24 -0700 | [diff] [blame] | 4237 | if (iwl_debug_level & IWL_DL_INFO) |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 4238 | dev_printk(KERN_DEBUG, &(pdev->dev), |
| 4239 | "Disabling hw_scan\n"); |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4240 | iwl_hw_ops.hw_scan = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4241 | } |
| 4242 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4243 | hw = iwl_alloc_all(cfg, &iwl_hw_ops); |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 4244 | if (!hw) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4245 | err = -ENOMEM; |
| 4246 | goto out; |
| 4247 | } |
Assaf Krauss | 1d0a082 | 2008-03-14 10:38:48 -0700 | [diff] [blame] | 4248 | priv = hw->priv; |
| 4249 | /* At this point both hw and priv are allocated. */ |
| 4250 | |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 4251 | /* |
| 4252 | * The default context is always valid, |
| 4253 | * more may be discovered when firmware |
| 4254 | * is loaded. |
| 4255 | */ |
| 4256 | priv->valid_contexts = BIT(IWL_RXON_CTX_BSS); |
| 4257 | |
| 4258 | for (i = 0; i < NUM_IWL_RXON_CTX; i++) |
| 4259 | priv->contexts[i].ctxid = i; |
| 4260 | |
Johannes Berg | 8f2d3d2 | 2010-08-23 10:46:37 +0200 | [diff] [blame] | 4261 | priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON; |
| 4262 | priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING; |
| 4263 | priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC; |
Johannes Berg | 8dfdb9d | 2010-08-23 10:46:38 +0200 | [diff] [blame] | 4264 | priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM; |
Johannes Berg | 2995baf | 2010-08-23 10:46:42 +0200 | [diff] [blame] | 4265 | priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID; |
Johannes Berg | c10afb6 | 2010-08-23 10:46:43 +0200 | [diff] [blame] | 4266 | priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY; |
Johannes Berg | e72f368 | 2010-08-23 10:46:51 +0200 | [diff] [blame^] | 4267 | priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo = iwlagn_bss_ac_to_fifo; |
| 4268 | priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue = iwlagn_bss_ac_to_queue; |
Johannes Berg | ece9c4e | 2010-08-23 10:46:49 +0200 | [diff] [blame] | 4269 | |
| 4270 | priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON; |
| 4271 | priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd = REPLY_WIPAN_RXON_TIMING; |
| 4272 | priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd = REPLY_WIPAN_RXON_ASSOC; |
| 4273 | priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM; |
| 4274 | priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN; |
| 4275 | priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY; |
| 4276 | priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID; |
| 4277 | priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION; |
Johannes Berg | e72f368 | 2010-08-23 10:46:51 +0200 | [diff] [blame^] | 4278 | priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo = iwlagn_pan_ac_to_fifo; |
| 4279 | priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue = iwlagn_pan_ac_to_queue; |
| 4280 | priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE; |
Johannes Berg | ece9c4e | 2010-08-23 10:46:49 +0200 | [diff] [blame] | 4281 | |
| 4282 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); |
Johannes Berg | 8f2d3d2 | 2010-08-23 10:46:37 +0200 | [diff] [blame] | 4283 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4284 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 4285 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4286 | IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n"); |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4287 | priv->cfg = cfg; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4288 | priv->pci_dev = pdev; |
Mohamed Abbas | 40cefda | 2009-05-22 11:01:52 -0700 | [diff] [blame] | 4289 | priv->inta_mask = CSR_INI_SET_MASK; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4290 | |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 4291 | /* is antenna coupling more than 35dB ? */ |
| 4292 | priv->bt_ant_couple_ok = |
| 4293 | (iwlagn_ant_coupling > IWL_BT_ANTENNA_COUPLING_THRESHOLD) ? |
| 4294 | true : false; |
| 4295 | |
Wey-Yi Guy | f37837c | 2010-08-23 07:57:12 -0700 | [diff] [blame] | 4296 | /* enable/disable bt channel announcement */ |
| 4297 | priv->bt_ch_announce = iwlagn_bt_ch_announce; |
| 4298 | |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 4299 | if (iwl_alloc_traffic_mem(priv)) |
| 4300 | IWL_ERR(priv, "Not enough memory to generate traffic log\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4301 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4302 | /************************** |
| 4303 | * 2. Initializing PCI bus |
| 4304 | **************************/ |
John W. Linville | 1a7123c | 2010-08-05 14:39:31 -0400 | [diff] [blame] | 4305 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | |
| 4306 | PCIE_LINK_STATE_CLKPM); |
| 4307 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4308 | if (pci_enable_device(pdev)) { |
| 4309 | err = -ENODEV; |
| 4310 | goto out_ieee80211_free_hw; |
| 4311 | } |
| 4312 | |
| 4313 | pci_set_master(pdev); |
| 4314 | |
Winkler, Tomas | 093d874c | 2008-09-26 15:09:34 +0800 | [diff] [blame] | 4315 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36)); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4316 | if (!err) |
Winkler, Tomas | 093d874c | 2008-09-26 15:09:34 +0800 | [diff] [blame] | 4317 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36)); |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 4318 | if (err) { |
Winkler, Tomas | 093d874c | 2008-09-26 15:09:34 +0800 | [diff] [blame] | 4319 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 4320 | if (!err) |
Winkler, Tomas | 093d874c | 2008-09-26 15:09:34 +0800 | [diff] [blame] | 4321 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 4322 | /* both attempts failed: */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4323 | if (err) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4324 | IWL_WARN(priv, "No suitable DMA available.\n"); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4325 | goto out_pci_disable_device; |
Ron Rindjunsky | cc2a8ea | 2008-04-21 15:41:59 -0700 | [diff] [blame] | 4326 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4327 | } |
| 4328 | |
| 4329 | err = pci_request_regions(pdev, DRV_NAME); |
| 4330 | if (err) |
| 4331 | goto out_pci_disable_device; |
| 4332 | |
| 4333 | pci_set_drvdata(pdev, priv); |
| 4334 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4335 | |
| 4336 | /*********************** |
| 4337 | * 3. Read REV register |
| 4338 | ***********************/ |
| 4339 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 4340 | if (!priv->hw_base) { |
| 4341 | err = -ENODEV; |
| 4342 | goto out_pci_release_regions; |
| 4343 | } |
| 4344 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4345 | IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n", |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4346 | (unsigned long long) pci_resource_len(pdev, 0)); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4347 | IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4348 | |
Reinette Chatre | 731a29b | 2009-12-14 14:12:11 -0800 | [diff] [blame] | 4349 | /* these spin locks will be used in apm_ops.init and EEPROM access |
Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 4350 | * we should init now |
| 4351 | */ |
| 4352 | spin_lock_init(&priv->reg_lock); |
Reinette Chatre | 731a29b | 2009-12-14 14:12:11 -0800 | [diff] [blame] | 4353 | spin_lock_init(&priv->lock); |
Reinette Chatre | 4843b5a | 2010-02-03 09:38:59 -0800 | [diff] [blame] | 4354 | |
| 4355 | /* |
| 4356 | * stop and reset the on-board processor just in case it is in a |
| 4357 | * strange state ... like being left stranded by a primary kernel |
| 4358 | * and this is now the kdump kernel trying to start up |
| 4359 | */ |
| 4360 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
| 4361 | |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 4362 | iwl_hw_detect(priv); |
Shanyu Zhao | c11362c | 2010-03-05 17:05:20 -0800 | [diff] [blame] | 4363 | IWL_INFO(priv, "Detected %s, REV=0x%X\n", |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 4364 | priv->cfg->name, priv->hw_rev); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4365 | |
Tomas Winkler | e7b6358 | 2008-09-03 11:26:49 +0800 | [diff] [blame] | 4366 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 4367 | * PCI Tx retries from interfering with C3 CPU state */ |
| 4368 | pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00); |
| 4369 | |
Mohamed Abbas | 086ed11 | 2009-05-22 11:01:54 -0700 | [diff] [blame] | 4370 | iwl_prepare_card_hw(priv); |
| 4371 | if (!priv->hw_ready) { |
| 4372 | IWL_WARN(priv, "Failed, HW not ready\n"); |
| 4373 | goto out_iounmap; |
| 4374 | } |
| 4375 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4376 | /***************** |
| 4377 | * 4. Read EEPROM |
| 4378 | *****************/ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4379 | /* Read the EEPROM */ |
| 4380 | err = iwl_eeprom_init(priv); |
| 4381 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4382 | IWL_ERR(priv, "Unable to init EEPROM\n"); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4383 | goto out_iounmap; |
| 4384 | } |
Tomas Winkler | 8614f36 | 2008-04-23 17:14:55 -0700 | [diff] [blame] | 4385 | err = iwl_eeprom_check_version(priv); |
| 4386 | if (err) |
Reinette Chatre | c8f1613 | 2009-02-27 16:21:22 -0800 | [diff] [blame] | 4387 | goto out_free_eeprom; |
Tomas Winkler | 8614f36 | 2008-04-23 17:14:55 -0700 | [diff] [blame] | 4388 | |
Ron Rindjunsky | 0288301 | 2008-05-15 13:53:53 +0800 | [diff] [blame] | 4389 | /* extract MAC Address */ |
Wey-Yi Guy | c6fa17e | 2010-07-15 05:58:30 -0700 | [diff] [blame] | 4390 | iwl_eeprom_get_mac(priv, priv->addresses[0].addr); |
| 4391 | IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr); |
| 4392 | priv->hw->wiphy->addresses = priv->addresses; |
| 4393 | priv->hw->wiphy->n_addresses = 1; |
| 4394 | num_mac = iwl_eeprom_query16(priv, EEPROM_NUM_MAC_ADDRESS); |
| 4395 | if (num_mac > 1) { |
| 4396 | memcpy(priv->addresses[1].addr, priv->addresses[0].addr, |
| 4397 | ETH_ALEN); |
| 4398 | priv->addresses[1].addr[5]++; |
| 4399 | priv->hw->wiphy->n_addresses++; |
| 4400 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4401 | |
| 4402 | /************************ |
| 4403 | * 5. Setup HW constants |
| 4404 | ************************/ |
Ron Rindjunsky | da154e30 | 2008-06-30 17:23:20 +0800 | [diff] [blame] | 4405 | if (iwl_set_hw_params(priv)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4406 | IWL_ERR(priv, "failed to set hw parameters\n"); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 4407 | goto out_free_eeprom; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4408 | } |
| 4409 | |
| 4410 | /******************* |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 4411 | * 6. Setup priv |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4412 | *******************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4413 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 4414 | err = iwl_init_drv(priv); |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4415 | if (err) |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 4416 | goto out_free_eeprom; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4417 | /* At this point both hw and priv are initialized. */ |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4418 | |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4419 | /******************** |
Abhijeet Kolekar | 09f9bf7 | 2009-04-20 14:37:03 -0700 | [diff] [blame] | 4420 | * 7. Setup services |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4421 | ********************/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4422 | spin_lock_irqsave(&priv->lock, flags); |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4423 | iwl_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4424 | spin_unlock_irqrestore(&priv->lock, flags); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4425 | |
Helmut Schaa | 6cd0b1c | 2009-01-19 13:10:07 +0100 | [diff] [blame] | 4426 | pci_enable_msi(priv->pci_dev); |
| 4427 | |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 4428 | iwl_alloc_isr_ict(priv); |
| 4429 | err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr, |
| 4430 | IRQF_SHARED, DRV_NAME, priv); |
Helmut Schaa | 6cd0b1c | 2009-01-19 13:10:07 +0100 | [diff] [blame] | 4431 | if (err) { |
| 4432 | IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 4433 | goto out_disable_msi; |
| 4434 | } |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4435 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 4436 | iwl_setup_deferred_work(priv); |
Emmanuel Grumbach | 653fa4a | 2008-06-30 17:23:11 +0800 | [diff] [blame] | 4437 | iwl_setup_rx_handlers(priv); |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4438 | |
Johannes Berg | 158bea0 | 2010-01-22 14:22:53 -0800 | [diff] [blame] | 4439 | /********************************************* |
| 4440 | * 8. Enable interrupts and read RFKILL state |
| 4441 | *********************************************/ |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 4442 | |
Helmut Schaa | 6cd0b1c | 2009-01-19 13:10:07 +0100 | [diff] [blame] | 4443 | /* enable interrupts if needed: hw bug w/a */ |
| 4444 | pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd); |
| 4445 | if (pci_cmd & PCI_COMMAND_INTX_DISABLE) { |
| 4446 | pci_cmd &= ~PCI_COMMAND_INTX_DISABLE; |
| 4447 | pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd); |
| 4448 | } |
| 4449 | |
| 4450 | iwl_enable_interrupts(priv); |
| 4451 | |
Helmut Schaa | 6cd0b1c | 2009-01-19 13:10:07 +0100 | [diff] [blame] | 4452 | /* If platform's RF_KILL switch is NOT set to KILL */ |
| 4453 | if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 4454 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 4455 | else |
| 4456 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 4457 | |
Johannes Berg | a60e77e | 2009-06-04 18:26:06 +0200 | [diff] [blame] | 4458 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, |
| 4459 | test_bit(STATUS_RF_KILL_HW, &priv->status)); |
Helmut Schaa | 6cd0b1c | 2009-01-19 13:10:07 +0100 | [diff] [blame] | 4460 | |
Emmanuel Grumbach | 58d0f36 | 2008-06-12 09:47:19 +0800 | [diff] [blame] | 4461 | iwl_power_initialize(priv); |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 4462 | iwl_tt_initialize(priv); |
Johannes Berg | 158bea0 | 2010-01-22 14:22:53 -0800 | [diff] [blame] | 4463 | |
Reinette Chatre | a15707d | 2010-05-10 15:08:11 -0700 | [diff] [blame] | 4464 | init_completion(&priv->_agn.firmware_loading_complete); |
Johannes Berg | 562db53 | 2010-04-29 07:41:53 -0700 | [diff] [blame] | 4465 | |
Johannes Berg | b08dfd0 | 2010-01-29 11:54:56 -0800 | [diff] [blame] | 4466 | err = iwl_request_firmware(priv, true); |
Johannes Berg | 158bea0 | 2010-01-22 14:22:53 -0800 | [diff] [blame] | 4467 | if (err) |
Emmanuel Grumbach | 7d47618 | 2010-05-23 00:14:08 -0700 | [diff] [blame] | 4468 | goto out_destroy_workqueue; |
Johannes Berg | 158bea0 | 2010-01-22 14:22:53 -0800 | [diff] [blame] | 4469 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4470 | return 0; |
| 4471 | |
Emmanuel Grumbach | 7d47618 | 2010-05-23 00:14:08 -0700 | [diff] [blame] | 4472 | out_destroy_workqueue: |
Reinette Chatre | c8f1613 | 2009-02-27 16:21:22 -0800 | [diff] [blame] | 4473 | destroy_workqueue(priv->workqueue); |
| 4474 | priv->workqueue = NULL; |
Helmut Schaa | 795cc0a | 2009-02-12 18:51:03 +0100 | [diff] [blame] | 4475 | free_irq(priv->pci_dev->irq, priv); |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 4476 | iwl_free_isr_ict(priv); |
Helmut Schaa | 6cd0b1c | 2009-01-19 13:10:07 +0100 | [diff] [blame] | 4477 | out_disable_msi: |
| 4478 | pci_disable_msi(priv->pci_dev); |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 4479 | iwl_uninit_drv(priv); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 4480 | out_free_eeprom: |
| 4481 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4482 | out_iounmap: |
| 4483 | pci_iounmap(pdev, priv->hw_base); |
| 4484 | out_pci_release_regions: |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 4485 | pci_set_drvdata(pdev, NULL); |
Reinette Chatre | 623d563 | 2009-03-03 11:37:04 -0800 | [diff] [blame] | 4486 | pci_release_regions(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4487 | out_pci_disable_device: |
| 4488 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4489 | out_ieee80211_free_hw: |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 4490 | iwl_free_traffic_mem(priv); |
Wey-Yi Guy | d7c76f4 | 2009-10-09 13:20:17 -0700 | [diff] [blame] | 4491 | ieee80211_free_hw(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4492 | out: |
| 4493 | return err; |
| 4494 | } |
| 4495 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4496 | static void __devexit iwl_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4497 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4498 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4499 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4500 | |
| 4501 | if (!priv) |
| 4502 | return; |
| 4503 | |
Reinette Chatre | a15707d | 2010-05-10 15:08:11 -0700 | [diff] [blame] | 4504 | wait_for_completion(&priv->_agn.firmware_loading_complete); |
Johannes Berg | 562db53 | 2010-04-29 07:41:53 -0700 | [diff] [blame] | 4505 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4506 | IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4507 | |
Emmanuel Grumbach | 6724962 | 2008-05-29 16:35:26 +0800 | [diff] [blame] | 4508 | iwl_dbgfs_unregister(priv); |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4509 | sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group); |
Emmanuel Grumbach | 6724962 | 2008-05-29 16:35:26 +0800 | [diff] [blame] | 4510 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4511 | /* ieee80211_unregister_hw call wil cause iwl_mac_stop to |
| 4512 | * to be called and iwl_down since we are removing the device |
Gregory Greenman | 0b124c3 | 2008-09-03 11:18:50 +0800 | [diff] [blame] | 4513 | * we need to set STATUS_EXIT_PENDING bit. |
| 4514 | */ |
| 4515 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Ron Rindjunsky | c4f5523 | 2008-03-28 16:21:10 -0700 | [diff] [blame] | 4516 | if (priv->mac80211_registered) { |
| 4517 | ieee80211_unregister_hw(priv->hw); |
| 4518 | priv->mac80211_registered = 0; |
Gregory Greenman | 0b124c3 | 2008-09-03 11:18:50 +0800 | [diff] [blame] | 4519 | } else { |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4520 | iwl_down(priv); |
Ron Rindjunsky | c4f5523 | 2008-03-28 16:21:10 -0700 | [diff] [blame] | 4521 | } |
| 4522 | |
Ben Cahill | c166b25 | 2009-10-23 13:42:35 -0700 | [diff] [blame] | 4523 | /* |
| 4524 | * Make sure device is reset to low power before unloading driver. |
| 4525 | * This may be redundant with iwl_down(), but there are paths to |
| 4526 | * run iwl_down() without calling apm_ops.stop(), and there are |
| 4527 | * paths to avoid running iwl_down() at all before leaving driver. |
| 4528 | * This (inexpensive) call *makes sure* device is reset. |
| 4529 | */ |
| 4530 | priv->cfg->ops->lib->apm_ops.stop(priv); |
| 4531 | |
Wey-Yi Guy | 39b73fb1 | 2009-07-24 11:13:02 -0700 | [diff] [blame] | 4532 | iwl_tt_exit(priv); |
| 4533 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4534 | /* make sure we flush any pending irq or |
| 4535 | * tasklet for the driver |
| 4536 | */ |
| 4537 | spin_lock_irqsave(&priv->lock, flags); |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4538 | iwl_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4539 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4540 | |
| 4541 | iwl_synchronize_irq(priv); |
| 4542 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4543 | iwl_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4544 | |
| 4545 | if (priv->rxq.bd) |
Wey-Yi Guy | 54b8155 | 2010-03-17 13:34:35 -0700 | [diff] [blame] | 4546 | iwlagn_rx_queue_free(priv, &priv->rxq); |
Wey-Yi Guy | 74bcdb3 | 2010-03-17 13:34:34 -0700 | [diff] [blame] | 4547 | iwlagn_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4548 | |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 4549 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4550 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4551 | |
Mohamed Abbas | 948c171 | 2007-10-25 17:15:45 +0800 | [diff] [blame] | 4552 | /*netif_stop_queue(dev); */ |
| 4553 | flush_workqueue(priv->workqueue); |
| 4554 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4555 | /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4556 | * priv->workqueue... so we can't take down the workqueue |
| 4557 | * until now... */ |
| 4558 | destroy_workqueue(priv->workqueue); |
| 4559 | priv->workqueue = NULL; |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 4560 | iwl_free_traffic_mem(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4561 | |
Helmut Schaa | 6cd0b1c | 2009-01-19 13:10:07 +0100 | [diff] [blame] | 4562 | free_irq(priv->pci_dev->irq, priv); |
| 4563 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4564 | pci_iounmap(pdev, priv->hw_base); |
| 4565 | pci_release_regions(pdev); |
| 4566 | pci_disable_device(pdev); |
| 4567 | pci_set_drvdata(pdev, NULL); |
| 4568 | |
Tomas Winkler | 6ba8795 | 2008-05-15 13:54:17 +0800 | [diff] [blame] | 4569 | iwl_uninit_drv(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4570 | |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 4571 | iwl_free_isr_ict(priv); |
| 4572 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4573 | if (priv->ibss_beacon) |
| 4574 | dev_kfree_skb(priv->ibss_beacon); |
| 4575 | |
| 4576 | ieee80211_free_hw(priv->hw); |
| 4577 | } |
| 4578 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4579 | |
| 4580 | /***************************************************************************** |
| 4581 | * |
| 4582 | * driver and module entry point |
| 4583 | * |
| 4584 | *****************************************************************************/ |
| 4585 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 4586 | /* Hardware specific file defines the PCI IDs table for that hardware module */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 4587 | static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = { |
Tomas Winkler | 4fc22b2 | 2008-07-21 18:54:42 +0300 | [diff] [blame] | 4588 | #ifdef CONFIG_IWL4965 |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 4589 | {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)}, |
| 4590 | {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)}, |
Tomas Winkler | 4fc22b2 | 2008-07-21 18:54:42 +0300 | [diff] [blame] | 4591 | #endif /* CONFIG_IWL4965 */ |
Tomas Winkler | 5a6a256 | 2008-04-24 11:55:23 -0700 | [diff] [blame] | 4592 | #ifdef CONFIG_IWL5000 |
Wey-Yi Guy | ac59257 | 2009-11-20 12:05:03 -0800 | [diff] [blame] | 4593 | /* 5100 Series WiFi */ |
| 4594 | {IWL_PCI_DEVICE(0x4232, 0x1201, iwl5100_agn_cfg)}, /* Mini Card */ |
| 4595 | {IWL_PCI_DEVICE(0x4232, 0x1301, iwl5100_agn_cfg)}, /* Half Mini Card */ |
| 4596 | {IWL_PCI_DEVICE(0x4232, 0x1204, iwl5100_agn_cfg)}, /* Mini Card */ |
| 4597 | {IWL_PCI_DEVICE(0x4232, 0x1304, iwl5100_agn_cfg)}, /* Half Mini Card */ |
| 4598 | {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bgn_cfg)}, /* Mini Card */ |
| 4599 | {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bgn_cfg)}, /* Half Mini Card */ |
| 4600 | {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)}, /* Mini Card */ |
| 4601 | {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)}, /* Half Mini Card */ |
| 4602 | {IWL_PCI_DEVICE(0x4232, 0x1221, iwl5100_agn_cfg)}, /* Mini Card */ |
| 4603 | {IWL_PCI_DEVICE(0x4232, 0x1321, iwl5100_agn_cfg)}, /* Half Mini Card */ |
| 4604 | {IWL_PCI_DEVICE(0x4232, 0x1224, iwl5100_agn_cfg)}, /* Mini Card */ |
| 4605 | {IWL_PCI_DEVICE(0x4232, 0x1324, iwl5100_agn_cfg)}, /* Half Mini Card */ |
| 4606 | {IWL_PCI_DEVICE(0x4232, 0x1225, iwl5100_bgn_cfg)}, /* Mini Card */ |
| 4607 | {IWL_PCI_DEVICE(0x4232, 0x1325, iwl5100_bgn_cfg)}, /* Half Mini Card */ |
| 4608 | {IWL_PCI_DEVICE(0x4232, 0x1226, iwl5100_abg_cfg)}, /* Mini Card */ |
| 4609 | {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)}, /* Half Mini Card */ |
| 4610 | {IWL_PCI_DEVICE(0x4237, 0x1211, iwl5100_agn_cfg)}, /* Mini Card */ |
| 4611 | {IWL_PCI_DEVICE(0x4237, 0x1311, iwl5100_agn_cfg)}, /* Half Mini Card */ |
| 4612 | {IWL_PCI_DEVICE(0x4237, 0x1214, iwl5100_agn_cfg)}, /* Mini Card */ |
| 4613 | {IWL_PCI_DEVICE(0x4237, 0x1314, iwl5100_agn_cfg)}, /* Half Mini Card */ |
| 4614 | {IWL_PCI_DEVICE(0x4237, 0x1215, iwl5100_bgn_cfg)}, /* Mini Card */ |
| 4615 | {IWL_PCI_DEVICE(0x4237, 0x1315, iwl5100_bgn_cfg)}, /* Half Mini Card */ |
| 4616 | {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)}, /* Mini Card */ |
| 4617 | {IWL_PCI_DEVICE(0x4237, 0x1316, iwl5100_abg_cfg)}, /* Half Mini Card */ |
| 4618 | |
| 4619 | /* 5300 Series WiFi */ |
| 4620 | {IWL_PCI_DEVICE(0x4235, 0x1021, iwl5300_agn_cfg)}, /* Mini Card */ |
| 4621 | {IWL_PCI_DEVICE(0x4235, 0x1121, iwl5300_agn_cfg)}, /* Half Mini Card */ |
| 4622 | {IWL_PCI_DEVICE(0x4235, 0x1024, iwl5300_agn_cfg)}, /* Mini Card */ |
| 4623 | {IWL_PCI_DEVICE(0x4235, 0x1124, iwl5300_agn_cfg)}, /* Half Mini Card */ |
| 4624 | {IWL_PCI_DEVICE(0x4235, 0x1001, iwl5300_agn_cfg)}, /* Mini Card */ |
| 4625 | {IWL_PCI_DEVICE(0x4235, 0x1101, iwl5300_agn_cfg)}, /* Half Mini Card */ |
| 4626 | {IWL_PCI_DEVICE(0x4235, 0x1004, iwl5300_agn_cfg)}, /* Mini Card */ |
| 4627 | {IWL_PCI_DEVICE(0x4235, 0x1104, iwl5300_agn_cfg)}, /* Half Mini Card */ |
| 4628 | {IWL_PCI_DEVICE(0x4236, 0x1011, iwl5300_agn_cfg)}, /* Mini Card */ |
| 4629 | {IWL_PCI_DEVICE(0x4236, 0x1111, iwl5300_agn_cfg)}, /* Half Mini Card */ |
| 4630 | {IWL_PCI_DEVICE(0x4236, 0x1014, iwl5300_agn_cfg)}, /* Mini Card */ |
| 4631 | {IWL_PCI_DEVICE(0x4236, 0x1114, iwl5300_agn_cfg)}, /* Half Mini Card */ |
| 4632 | |
| 4633 | /* 5350 Series WiFi/WiMax */ |
| 4634 | {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)}, /* Mini Card */ |
| 4635 | {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)}, /* Mini Card */ |
| 4636 | {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)}, /* Mini Card */ |
| 4637 | |
| 4638 | /* 5150 Series Wifi/WiMax */ |
| 4639 | {IWL_PCI_DEVICE(0x423C, 0x1201, iwl5150_agn_cfg)}, /* Mini Card */ |
| 4640 | {IWL_PCI_DEVICE(0x423C, 0x1301, iwl5150_agn_cfg)}, /* Half Mini Card */ |
| 4641 | {IWL_PCI_DEVICE(0x423C, 0x1206, iwl5150_abg_cfg)}, /* Mini Card */ |
| 4642 | {IWL_PCI_DEVICE(0x423C, 0x1306, iwl5150_abg_cfg)}, /* Half Mini Card */ |
| 4643 | {IWL_PCI_DEVICE(0x423C, 0x1221, iwl5150_agn_cfg)}, /* Mini Card */ |
| 4644 | {IWL_PCI_DEVICE(0x423C, 0x1321, iwl5150_agn_cfg)}, /* Half Mini Card */ |
| 4645 | |
| 4646 | {IWL_PCI_DEVICE(0x423D, 0x1211, iwl5150_agn_cfg)}, /* Mini Card */ |
| 4647 | {IWL_PCI_DEVICE(0x423D, 0x1311, iwl5150_agn_cfg)}, /* Half Mini Card */ |
| 4648 | {IWL_PCI_DEVICE(0x423D, 0x1216, iwl5150_abg_cfg)}, /* Mini Card */ |
| 4649 | {IWL_PCI_DEVICE(0x423D, 0x1316, iwl5150_abg_cfg)}, /* Half Mini Card */ |
Wey-Yi Guy | 5953a62 | 2009-09-17 10:43:53 -0700 | [diff] [blame] | 4650 | |
| 4651 | /* 6x00 Series */ |
Wey-Yi Guy | 5953a62 | 2009-09-17 10:43:53 -0700 | [diff] [blame] | 4652 | {IWL_PCI_DEVICE(0x422B, 0x1101, iwl6000_3agn_cfg)}, |
| 4653 | {IWL_PCI_DEVICE(0x422B, 0x1121, iwl6000_3agn_cfg)}, |
| 4654 | {IWL_PCI_DEVICE(0x422C, 0x1301, iwl6000i_2agn_cfg)}, |
| 4655 | {IWL_PCI_DEVICE(0x422C, 0x1306, iwl6000i_2abg_cfg)}, |
| 4656 | {IWL_PCI_DEVICE(0x422C, 0x1307, iwl6000i_2bg_cfg)}, |
| 4657 | {IWL_PCI_DEVICE(0x422C, 0x1321, iwl6000i_2agn_cfg)}, |
| 4658 | {IWL_PCI_DEVICE(0x422C, 0x1326, iwl6000i_2abg_cfg)}, |
| 4659 | {IWL_PCI_DEVICE(0x4238, 0x1111, iwl6000_3agn_cfg)}, |
| 4660 | {IWL_PCI_DEVICE(0x4239, 0x1311, iwl6000i_2agn_cfg)}, |
| 4661 | {IWL_PCI_DEVICE(0x4239, 0x1316, iwl6000i_2abg_cfg)}, |
Shanyu Zhao | 4b3e806 | 2010-04-07 18:06:36 -0700 | [diff] [blame] | 4662 | |
Shanyu Zhao | 95b1301 | 2010-04-21 11:46:33 -0700 | [diff] [blame] | 4663 | /* 6x00 Series Gen2a */ |
| 4664 | {IWL_PCI_DEVICE(0x0082, 0x1201, iwl6000g2a_2agn_cfg)}, |
| 4665 | {IWL_PCI_DEVICE(0x0085, 0x1211, iwl6000g2a_2agn_cfg)}, |
| 4666 | {IWL_PCI_DEVICE(0x0082, 0x1221, iwl6000g2a_2agn_cfg)}, |
Shanyu Zhao | 1808972 | 2010-05-06 10:15:21 -0700 | [diff] [blame] | 4667 | {IWL_PCI_DEVICE(0x0082, 0x1206, iwl6000g2a_2abg_cfg)}, |
| 4668 | {IWL_PCI_DEVICE(0x0085, 0x1216, iwl6000g2a_2abg_cfg)}, |
| 4669 | {IWL_PCI_DEVICE(0x0082, 0x1226, iwl6000g2a_2abg_cfg)}, |
| 4670 | {IWL_PCI_DEVICE(0x0082, 0x1207, iwl6000g2a_2bg_cfg)}, |
Shanyu Zhao | 9f6e1ba | 2010-05-11 15:21:54 -0700 | [diff] [blame] | 4671 | {IWL_PCI_DEVICE(0x0082, 0x1301, iwl6000g2a_2agn_cfg)}, |
| 4672 | {IWL_PCI_DEVICE(0x0082, 0x1306, iwl6000g2a_2abg_cfg)}, |
| 4673 | {IWL_PCI_DEVICE(0x0082, 0x1307, iwl6000g2a_2bg_cfg)}, |
| 4674 | {IWL_PCI_DEVICE(0x0082, 0x1321, iwl6000g2a_2agn_cfg)}, |
| 4675 | {IWL_PCI_DEVICE(0x0082, 0x1326, iwl6000g2a_2abg_cfg)}, |
| 4676 | {IWL_PCI_DEVICE(0x0085, 0x1311, iwl6000g2a_2agn_cfg)}, |
| 4677 | {IWL_PCI_DEVICE(0x0085, 0x1316, iwl6000g2a_2abg_cfg)}, |
Shanyu Zhao | 1808972 | 2010-05-06 10:15:21 -0700 | [diff] [blame] | 4678 | |
| 4679 | /* 6x00 Series Gen2b */ |
| 4680 | {IWL_PCI_DEVICE(0x008F, 0x5105, iwl6000g2b_bgn_cfg)}, |
| 4681 | {IWL_PCI_DEVICE(0x0090, 0x5115, iwl6000g2b_bgn_cfg)}, |
| 4682 | {IWL_PCI_DEVICE(0x008F, 0x5125, iwl6000g2b_bgn_cfg)}, |
| 4683 | {IWL_PCI_DEVICE(0x008F, 0x5107, iwl6000g2b_bg_cfg)}, |
| 4684 | {IWL_PCI_DEVICE(0x008F, 0x5201, iwl6000g2b_2agn_cfg)}, |
| 4685 | {IWL_PCI_DEVICE(0x0090, 0x5211, iwl6000g2b_2agn_cfg)}, |
| 4686 | {IWL_PCI_DEVICE(0x008F, 0x5221, iwl6000g2b_2agn_cfg)}, |
| 4687 | {IWL_PCI_DEVICE(0x008F, 0x5206, iwl6000g2b_2abg_cfg)}, |
| 4688 | {IWL_PCI_DEVICE(0x0090, 0x5216, iwl6000g2b_2abg_cfg)}, |
| 4689 | {IWL_PCI_DEVICE(0x008F, 0x5226, iwl6000g2b_2abg_cfg)}, |
| 4690 | {IWL_PCI_DEVICE(0x008F, 0x5207, iwl6000g2b_2bg_cfg)}, |
Shanyu Zhao | 9f6e1ba | 2010-05-11 15:21:54 -0700 | [diff] [blame] | 4691 | {IWL_PCI_DEVICE(0x008A, 0x5301, iwl6000g2b_bgn_cfg)}, |
| 4692 | {IWL_PCI_DEVICE(0x008A, 0x5305, iwl6000g2b_bgn_cfg)}, |
| 4693 | {IWL_PCI_DEVICE(0x008A, 0x5307, iwl6000g2b_bg_cfg)}, |
| 4694 | {IWL_PCI_DEVICE(0x008A, 0x5321, iwl6000g2b_bgn_cfg)}, |
| 4695 | {IWL_PCI_DEVICE(0x008A, 0x5325, iwl6000g2b_bgn_cfg)}, |
| 4696 | {IWL_PCI_DEVICE(0x008B, 0x5311, iwl6000g2b_bgn_cfg)}, |
| 4697 | {IWL_PCI_DEVICE(0x008B, 0x5315, iwl6000g2b_bgn_cfg)}, |
| 4698 | {IWL_PCI_DEVICE(0x0090, 0x5211, iwl6000g2b_2agn_cfg)}, |
| 4699 | {IWL_PCI_DEVICE(0x0090, 0x5215, iwl6000g2b_2bgn_cfg)}, |
| 4700 | {IWL_PCI_DEVICE(0x0090, 0x5216, iwl6000g2b_2abg_cfg)}, |
| 4701 | {IWL_PCI_DEVICE(0x0091, 0x5201, iwl6000g2b_2agn_cfg)}, |
| 4702 | {IWL_PCI_DEVICE(0x0091, 0x5205, iwl6000g2b_2bgn_cfg)}, |
| 4703 | {IWL_PCI_DEVICE(0x0091, 0x5206, iwl6000g2b_2abg_cfg)}, |
| 4704 | {IWL_PCI_DEVICE(0x0091, 0x5207, iwl6000g2b_2bg_cfg)}, |
| 4705 | {IWL_PCI_DEVICE(0x0091, 0x5221, iwl6000g2b_2agn_cfg)}, |
| 4706 | {IWL_PCI_DEVICE(0x0091, 0x5225, iwl6000g2b_2bgn_cfg)}, |
| 4707 | {IWL_PCI_DEVICE(0x0091, 0x5226, iwl6000g2b_2abg_cfg)}, |
Wey-Yi Guy | 5953a62 | 2009-09-17 10:43:53 -0700 | [diff] [blame] | 4708 | |
| 4709 | /* 6x50 WiFi/WiMax Series */ |
Wey-Yi Guy | 5953a62 | 2009-09-17 10:43:53 -0700 | [diff] [blame] | 4710 | {IWL_PCI_DEVICE(0x0087, 0x1301, iwl6050_2agn_cfg)}, |
| 4711 | {IWL_PCI_DEVICE(0x0087, 0x1306, iwl6050_2abg_cfg)}, |
| 4712 | {IWL_PCI_DEVICE(0x0087, 0x1321, iwl6050_2agn_cfg)}, |
| 4713 | {IWL_PCI_DEVICE(0x0087, 0x1326, iwl6050_2abg_cfg)}, |
Wey-Yi Guy | 5953a62 | 2009-09-17 10:43:53 -0700 | [diff] [blame] | 4714 | {IWL_PCI_DEVICE(0x0089, 0x1311, iwl6050_2agn_cfg)}, |
| 4715 | {IWL_PCI_DEVICE(0x0089, 0x1316, iwl6050_2abg_cfg)}, |
| 4716 | |
Shanyu Zhao | 0326433 | 2010-06-29 17:27:27 -0700 | [diff] [blame] | 4717 | /* 6x50 WiFi/WiMax Series Gen2 */ |
| 4718 | {IWL_PCI_DEVICE(0x0885, 0x1305, iwl6050g2_bgn_cfg)}, |
| 4719 | {IWL_PCI_DEVICE(0x0885, 0x1306, iwl6050g2_bgn_cfg)}, |
| 4720 | {IWL_PCI_DEVICE(0x0885, 0x1325, iwl6050g2_bgn_cfg)}, |
| 4721 | {IWL_PCI_DEVICE(0x0885, 0x1326, iwl6050g2_bgn_cfg)}, |
| 4722 | {IWL_PCI_DEVICE(0x0886, 0x1315, iwl6050g2_bgn_cfg)}, |
| 4723 | {IWL_PCI_DEVICE(0x0886, 0x1316, iwl6050g2_bgn_cfg)}, |
| 4724 | |
Jay Sternberg | 77dcb6a | 2009-03-06 13:52:55 -0800 | [diff] [blame] | 4725 | /* 1000 Series WiFi */ |
Wey-Yi Guy | 4bd0914f | 2009-09-17 10:43:52 -0700 | [diff] [blame] | 4726 | {IWL_PCI_DEVICE(0x0083, 0x1205, iwl1000_bgn_cfg)}, |
| 4727 | {IWL_PCI_DEVICE(0x0083, 0x1305, iwl1000_bgn_cfg)}, |
| 4728 | {IWL_PCI_DEVICE(0x0083, 0x1225, iwl1000_bgn_cfg)}, |
| 4729 | {IWL_PCI_DEVICE(0x0083, 0x1325, iwl1000_bgn_cfg)}, |
| 4730 | {IWL_PCI_DEVICE(0x0084, 0x1215, iwl1000_bgn_cfg)}, |
| 4731 | {IWL_PCI_DEVICE(0x0084, 0x1315, iwl1000_bgn_cfg)}, |
| 4732 | {IWL_PCI_DEVICE(0x0083, 0x1206, iwl1000_bg_cfg)}, |
| 4733 | {IWL_PCI_DEVICE(0x0083, 0x1306, iwl1000_bg_cfg)}, |
| 4734 | {IWL_PCI_DEVICE(0x0083, 0x1226, iwl1000_bg_cfg)}, |
| 4735 | {IWL_PCI_DEVICE(0x0083, 0x1326, iwl1000_bg_cfg)}, |
| 4736 | {IWL_PCI_DEVICE(0x0084, 0x1216, iwl1000_bg_cfg)}, |
| 4737 | {IWL_PCI_DEVICE(0x0084, 0x1316, iwl1000_bg_cfg)}, |
Tomas Winkler | 5a6a256 | 2008-04-24 11:55:23 -0700 | [diff] [blame] | 4738 | #endif /* CONFIG_IWL5000 */ |
Tomas Winkler | 7100e92 | 2008-12-01 16:32:18 -0800 | [diff] [blame] | 4739 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 4740 | {0} |
| 4741 | }; |
| 4742 | MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids); |
| 4743 | |
| 4744 | static struct pci_driver iwl_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4745 | .name = DRV_NAME, |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 4746 | .id_table = iwl_hw_card_ids, |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4747 | .probe = iwl_pci_probe, |
| 4748 | .remove = __devexit_p(iwl_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4749 | #ifdef CONFIG_PM |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4750 | .suspend = iwl_pci_suspend, |
| 4751 | .resume = iwl_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4752 | #endif |
| 4753 | }; |
| 4754 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4755 | static int __init iwl_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4756 | { |
| 4757 | |
| 4758 | int ret; |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 4759 | pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 4760 | pr_info(DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4761 | |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 4762 | ret = iwlagn_rate_control_register(); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4763 | if (ret) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 4764 | pr_err("Unable to register rate control algorithm: %d\n", ret); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4765 | return ret; |
| 4766 | } |
| 4767 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 4768 | ret = pci_register_driver(&iwl_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4769 | if (ret) { |
Joe Perches | c96c31e | 2010-07-26 14:39:58 -0700 | [diff] [blame] | 4770 | pr_err("Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4771 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4772 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4773 | |
| 4774 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4775 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4776 | error_register: |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 4777 | iwlagn_rate_control_unregister(); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4778 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4779 | } |
| 4780 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4781 | static void __exit iwl_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4782 | { |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 4783 | pci_unregister_driver(&iwl_driver); |
Tomas Winkler | e227cea | 2008-07-18 13:53:05 +0800 | [diff] [blame] | 4784 | iwlagn_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4785 | } |
| 4786 | |
Emmanuel Grumbach | 5b9f8cd | 2008-10-29 14:05:46 -0700 | [diff] [blame] | 4787 | module_exit(iwl_exit); |
| 4788 | module_init(iwl_init); |
Reinette Chatre | a562a9d | 2009-07-17 09:30:24 -0700 | [diff] [blame] | 4789 | |
| 4790 | #ifdef CONFIG_IWLWIFI_DEBUG |
Wey-Yi Guy | 4e30cb6 | 2009-09-17 10:43:47 -0700 | [diff] [blame] | 4791 | module_param_named(debug50, iwl_debug_level, uint, S_IRUGO); |
Reinette Chatre | a562a9d | 2009-07-17 09:30:24 -0700 | [diff] [blame] | 4792 | MODULE_PARM_DESC(debug50, "50XX debug output mask (deprecated)"); |
Wey-Yi Guy | 4e30cb6 | 2009-09-17 10:43:47 -0700 | [diff] [blame] | 4793 | module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR); |
Reinette Chatre | a562a9d | 2009-07-17 09:30:24 -0700 | [diff] [blame] | 4794 | MODULE_PARM_DESC(debug, "debug output mask"); |
| 4795 | #endif |
| 4796 | |
Wey-Yi Guy | 2b068618 | 2010-03-22 09:17:39 -0700 | [diff] [blame] | 4797 | module_param_named(swcrypto50, iwlagn_mod_params.sw_crypto, bool, S_IRUGO); |
| 4798 | MODULE_PARM_DESC(swcrypto50, |
| 4799 | "using crypto in software (default 0 [hardware]) (deprecated)"); |
| 4800 | module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO); |
| 4801 | MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])"); |
| 4802 | module_param_named(queues_num50, |
| 4803 | iwlagn_mod_params.num_of_queues, int, S_IRUGO); |
| 4804 | MODULE_PARM_DESC(queues_num50, |
| 4805 | "number of hw queues in 50xx series (deprecated)"); |
| 4806 | module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO); |
| 4807 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 4808 | module_param_named(11n_disable50, iwlagn_mod_params.disable_11n, int, S_IRUGO); |
| 4809 | MODULE_PARM_DESC(11n_disable50, "disable 50XX 11n functionality (deprecated)"); |
| 4810 | module_param_named(11n_disable, iwlagn_mod_params.disable_11n, int, S_IRUGO); |
| 4811 | MODULE_PARM_DESC(11n_disable, "disable 11n functionality"); |
| 4812 | module_param_named(amsdu_size_8K50, iwlagn_mod_params.amsdu_size_8K, |
| 4813 | int, S_IRUGO); |
| 4814 | MODULE_PARM_DESC(amsdu_size_8K50, |
| 4815 | "enable 8K amsdu size in 50XX series (deprecated)"); |
| 4816 | module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K, |
| 4817 | int, S_IRUGO); |
| 4818 | MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size"); |
| 4819 | module_param_named(fw_restart50, iwlagn_mod_params.restart_fw, int, S_IRUGO); |
| 4820 | MODULE_PARM_DESC(fw_restart50, |
| 4821 | "restart firmware in case of error (deprecated)"); |
| 4822 | module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO); |
| 4823 | MODULE_PARM_DESC(fw_restart, "restart firmware in case of error"); |
| 4824 | module_param_named( |
| 4825 | disable_hw_scan, iwlagn_mod_params.disable_hw_scan, int, S_IRUGO); |
| 4826 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 4827 | |
| 4828 | module_param_named(ucode_alternative, iwlagn_wanted_ucode_alternative, int, |
| 4829 | S_IRUGO); |
| 4830 | MODULE_PARM_DESC(ucode_alternative, |
| 4831 | "specify ucode alternative to use from ucode file"); |
Wey-Yi Guy | bee008b | 2010-08-23 07:57:04 -0700 | [diff] [blame] | 4832 | |
| 4833 | module_param_named(antenna_coupling, iwlagn_ant_coupling, int, S_IRUGO); |
| 4834 | MODULE_PARM_DESC(antenna_coupling, |
| 4835 | "specify antenna coupling in dB (defualt: 0 dB)"); |
Wey-Yi Guy | f37837c | 2010-08-23 07:57:12 -0700 | [diff] [blame] | 4836 | |
| 4837 | module_param_named(bt_ch_announce, iwlagn_bt_ch_announce, bool, S_IRUGO); |
| 4838 | MODULE_PARM_DESC(bt_ch_announce, |
| 4839 | "Enable BT channel announcement mode (default: enable)"); |