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