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