Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | 1f44780 | 2010-01-15 13:43:41 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 32 | #include <linux/init.h> |
| 33 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 35 | #include <linux/dma-mapping.h> |
| 36 | #include <linux/delay.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 37 | #include <linux/sched.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 38 | #include <linux/skbuff.h> |
| 39 | #include <linux/netdevice.h> |
| 40 | #include <linux/wireless.h> |
| 41 | #include <linux/firmware.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 42 | #include <linux/etherdevice.h> |
| 43 | #include <linux/if_arp.h> |
| 44 | |
| 45 | #include <net/ieee80211_radiotap.h> |
| 46 | #include <net/mac80211.h> |
| 47 | |
| 48 | #include <asm/div64.h> |
| 49 | |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 50 | #define DRV_NAME "iwl3945" |
| 51 | |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 52 | #include "iwl-fh.h" |
| 53 | #include "iwl-3945-fh.h" |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 54 | #include "iwl-commands.h" |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 55 | #include "iwl-sta.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 56 | #include "iwl-3945.h" |
Kolekar, Abhijeet | 5747d47 | 2008-12-19 10:37:18 +0800 | [diff] [blame] | 57 | #include "iwl-core.h" |
Reinette Chatre | 4a6547c | 2010-02-18 22:03:02 -0800 | [diff] [blame] | 58 | #include "iwl-helpers.h" |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 59 | #include "iwl-dev.h" |
Reinette Chatre | 81963d6 | 2010-01-22 14:22:57 -0800 | [diff] [blame] | 60 | #include "iwl-spectrum.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 61 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 62 | /* |
| 63 | * module name, copyright, version, etc. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 64 | */ |
| 65 | |
| 66 | #define DRV_DESCRIPTION \ |
| 67 | "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux" |
| 68 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 69 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 70 | #define VD "d" |
| 71 | #else |
| 72 | #define VD |
| 73 | #endif |
| 74 | |
Reinette Chatre | 81963d6 | 2010-01-22 14:22:57 -0800 | [diff] [blame] | 75 | /* |
| 76 | * add "s" to indicate spectrum measurement included. |
| 77 | * we add it here to be consistent with previous releases in which |
| 78 | * this was configurable. |
| 79 | */ |
| 80 | #define DRV_VERSION IWLWIFI_VERSION VD "s" |
Reinette Chatre | 1f44780 | 2010-01-15 13:43:41 -0800 | [diff] [blame] | 81 | #define DRV_COPYRIGHT "Copyright(c) 2003-2010 Intel Corporation" |
Tomas Winkler | a7b7520 | 2008-12-11 10:33:41 -0800 | [diff] [blame] | 82 | #define DRV_AUTHOR "<ilw@linux.intel.com>" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 83 | |
| 84 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 85 | MODULE_VERSION(DRV_VERSION); |
Tomas Winkler | a7b7520 | 2008-12-11 10:33:41 -0800 | [diff] [blame] | 86 | MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 87 | MODULE_LICENSE("GPL"); |
| 88 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 89 | /* module parameters */ |
| 90 | struct iwl_mod_params iwl3945_mod_params = { |
Samuel Ortiz | 9c74d9f | 2009-01-08 10:19:59 -0800 | [diff] [blame] | 91 | .sw_crypto = 1, |
Samuel Ortiz | af48d04 | 2009-01-23 13:45:19 -0800 | [diff] [blame] | 92 | .restart_fw = 1, |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 93 | /* the rest are 0 by default */ |
| 94 | }; |
| 95 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 96 | /** |
Samuel Ortiz | 7e4bca5 | 2009-01-23 13:45:18 -0800 | [diff] [blame] | 97 | * iwl3945_get_antenna_flags - Get antenna flags for RXON command |
| 98 | * @priv: eeprom and antenna fields are used to determine antenna flags |
| 99 | * |
| 100 | * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed |
| 101 | * iwl3945_mod_params.antenna specifies the antenna diversity mode: |
| 102 | * |
| 103 | * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself |
| 104 | * IWL_ANTENNA_MAIN - Force MAIN antenna |
| 105 | * IWL_ANTENNA_AUX - Force AUX antenna |
| 106 | */ |
| 107 | __le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv) |
| 108 | { |
| 109 | struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom; |
| 110 | |
| 111 | switch (iwl3945_mod_params.antenna) { |
| 112 | case IWL_ANTENNA_DIVERSITY: |
| 113 | return 0; |
| 114 | |
| 115 | case IWL_ANTENNA_MAIN: |
| 116 | if (eeprom->antenna_switch_type) |
| 117 | return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK; |
| 118 | return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK; |
| 119 | |
| 120 | case IWL_ANTENNA_AUX: |
| 121 | if (eeprom->antenna_switch_type) |
| 122 | return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK; |
| 123 | return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK; |
| 124 | } |
| 125 | |
| 126 | /* bad antenna selector value */ |
| 127 | IWL_ERR(priv, "Bad antenna selector value (0x%x)\n", |
| 128 | iwl3945_mod_params.antenna); |
| 129 | |
| 130 | return 0; /* "diversity" is default if error */ |
| 131 | } |
| 132 | |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 133 | static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 134 | struct ieee80211_key_conf *keyconf, |
| 135 | u8 sta_id) |
| 136 | { |
| 137 | unsigned long flags; |
| 138 | __le16 key_flags = 0; |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 139 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 140 | |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 141 | key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK); |
| 142 | key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 143 | |
| 144 | if (sta_id == priv->hw_params.bcast_sta_id) |
| 145 | key_flags |= STA_KEY_MULTICAST_MSK; |
| 146 | |
| 147 | keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 148 | keyconf->hw_key_idx = keyconf->keyidx; |
| 149 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 150 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 151 | spin_lock_irqsave(&priv->sta_lock, flags); |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 152 | priv->stations[sta_id].keyinfo.alg = keyconf->alg; |
| 153 | priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; |
| 154 | memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 155 | keyconf->keylen); |
| 156 | |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 157 | memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 158 | keyconf->keylen); |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 159 | |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 160 | if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 161 | == STA_KEY_FLG_NO_ENC) |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 162 | priv->stations[sta_id].sta.key.key_offset = |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 163 | iwl_get_free_ucode_key_index(priv); |
| 164 | /* else, we are overriding an existing key => no need to allocated room |
| 165 | * in uCode. */ |
| 166 | |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 167 | WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET, |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 168 | "no space for a new key"); |
| 169 | |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 170 | priv->stations[sta_id].sta.key.key_flags = key_flags; |
| 171 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 172 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 173 | |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 174 | IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n"); |
| 175 | |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 176 | ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 177 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 178 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 179 | |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 180 | return ret; |
| 181 | } |
| 182 | |
| 183 | static int iwl3945_set_tkip_dynamic_key_info(struct iwl_priv *priv, |
| 184 | struct ieee80211_key_conf *keyconf, |
| 185 | u8 sta_id) |
| 186 | { |
| 187 | return -EOPNOTSUPP; |
| 188 | } |
| 189 | |
| 190 | static int iwl3945_set_wep_dynamic_key_info(struct iwl_priv *priv, |
| 191 | struct ieee80211_key_conf *keyconf, |
| 192 | u8 sta_id) |
| 193 | { |
| 194 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 197 | static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 198 | { |
| 199 | unsigned long flags; |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 200 | struct iwl_addsta_cmd sta_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 201 | |
| 202 | spin_lock_irqsave(&priv->sta_lock, flags); |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 203 | memset(&priv->stations[sta_id].keyinfo, 0, sizeof(struct iwl_hw_key)); |
| 204 | memset(&priv->stations[sta_id].sta.key, 0, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 205 | sizeof(struct iwl4965_keyinfo)); |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 206 | priv->stations[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; |
| 207 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 208 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 209 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 210 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 211 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 212 | IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n"); |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 213 | return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 214 | } |
| 215 | |
Abhijeet Kolekar | fa11d52 | 2009-03-11 11:17:54 -0700 | [diff] [blame] | 216 | static int iwl3945_set_dynamic_key(struct iwl_priv *priv, |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 217 | struct ieee80211_key_conf *keyconf, u8 sta_id) |
| 218 | { |
| 219 | int ret = 0; |
| 220 | |
| 221 | keyconf->hw_key_idx = HW_KEY_DYNAMIC; |
| 222 | |
| 223 | switch (keyconf->alg) { |
| 224 | case ALG_CCMP: |
| 225 | ret = iwl3945_set_ccmp_dynamic_key_info(priv, keyconf, sta_id); |
| 226 | break; |
| 227 | case ALG_TKIP: |
| 228 | ret = iwl3945_set_tkip_dynamic_key_info(priv, keyconf, sta_id); |
| 229 | break; |
| 230 | case ALG_WEP: |
| 231 | ret = iwl3945_set_wep_dynamic_key_info(priv, keyconf, sta_id); |
| 232 | break; |
| 233 | default: |
Abhijeet Kolekar | 1e68023 | 2009-03-17 21:51:50 -0700 | [diff] [blame] | 234 | IWL_ERR(priv, "Unknown alg: %s alg = %d\n", __func__, keyconf->alg); |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 235 | ret = -EINVAL; |
| 236 | } |
| 237 | |
| 238 | IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n", |
| 239 | keyconf->alg, keyconf->keylen, keyconf->keyidx, |
| 240 | sta_id, ret); |
| 241 | |
| 242 | return ret; |
| 243 | } |
| 244 | |
| 245 | static int iwl3945_remove_static_key(struct iwl_priv *priv) |
| 246 | { |
| 247 | int ret = -EOPNOTSUPP; |
| 248 | |
| 249 | return ret; |
| 250 | } |
| 251 | |
| 252 | static int iwl3945_set_static_key(struct iwl_priv *priv, |
| 253 | struct ieee80211_key_conf *key) |
| 254 | { |
| 255 | if (key->alg == ALG_WEP) |
| 256 | return -EOPNOTSUPP; |
| 257 | |
| 258 | IWL_ERR(priv, "Static key invalid: alg %d\n", key->alg); |
| 259 | return -EINVAL; |
| 260 | } |
| 261 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 262 | static void iwl3945_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 263 | { |
| 264 | struct list_head *element; |
| 265 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 266 | IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 267 | priv->frames_count); |
| 268 | |
| 269 | while (!list_empty(&priv->free_frames)) { |
| 270 | element = priv->free_frames.next; |
| 271 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 272 | kfree(list_entry(element, struct iwl3945_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 273 | priv->frames_count--; |
| 274 | } |
| 275 | |
| 276 | if (priv->frames_count) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 277 | IWL_WARN(priv, "%d frames still in use. Did we lose one?\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 278 | priv->frames_count); |
| 279 | priv->frames_count = 0; |
| 280 | } |
| 281 | } |
| 282 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 283 | static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 284 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 285 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 286 | struct list_head *element; |
| 287 | if (list_empty(&priv->free_frames)) { |
| 288 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 289 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 290 | IWL_ERR(priv, "Could not allocate frame!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 291 | return NULL; |
| 292 | } |
| 293 | |
| 294 | priv->frames_count++; |
| 295 | return frame; |
| 296 | } |
| 297 | |
| 298 | element = priv->free_frames.next; |
| 299 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 300 | return list_entry(element, struct iwl3945_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 303 | static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 304 | { |
| 305 | memset(frame, 0, sizeof(*frame)); |
| 306 | list_add(&frame->list, &priv->free_frames); |
| 307 | } |
| 308 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 309 | unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 310 | struct ieee80211_hdr *hdr, |
Rami Rosen | 73ec1cc | 2008-12-16 09:37:07 +0200 | [diff] [blame] | 311 | int left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 312 | { |
| 313 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 314 | if (!iwl_is_associated(priv) || !priv->ibss_beacon || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 315 | ((priv->iw_mode != NL80211_IFTYPE_ADHOC) && |
| 316 | (priv->iw_mode != NL80211_IFTYPE_AP))) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 317 | return 0; |
| 318 | |
| 319 | if (priv->ibss_beacon->len > left) |
| 320 | return 0; |
| 321 | |
| 322 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 323 | |
| 324 | return priv->ibss_beacon->len; |
| 325 | } |
| 326 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 327 | static int iwl3945_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 328 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 329 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 330 | unsigned int frame_size; |
| 331 | int rc; |
| 332 | u8 rate; |
| 333 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 334 | frame = iwl3945_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 335 | |
| 336 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 337 | IWL_ERR(priv, "Could not obtain free frame buffer for beacon " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 338 | "command.\n"); |
| 339 | return -ENOMEM; |
| 340 | } |
| 341 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 342 | rate = iwl_rate_get_lowest_plcp(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 343 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 344 | frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 345 | |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 346 | rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 347 | &frame->u.cmd[0]); |
| 348 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 349 | iwl3945_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 350 | |
| 351 | return rc; |
| 352 | } |
| 353 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 354 | static void iwl3945_unset_hw_params(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 355 | { |
Johannes Berg | ee525d1 | 2010-01-21 06:09:28 -0800 | [diff] [blame] | 356 | if (priv->_3945.shared_virt) |
Stanislaw Gruszka | f36d04a | 2010-02-10 05:07:45 -0800 | [diff] [blame] | 357 | dma_free_coherent(&priv->pci_dev->dev, |
| 358 | sizeof(struct iwl3945_shared), |
Johannes Berg | ee525d1 | 2010-01-21 06:09:28 -0800 | [diff] [blame] | 359 | priv->_3945.shared_virt, |
| 360 | priv->_3945.shared_phys); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 363 | static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 364 | struct ieee80211_tx_info *info, |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 365 | struct iwl_device_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 366 | struct sk_buff *skb_frag, |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 367 | int sta_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 368 | { |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 369 | struct iwl3945_tx_cmd *tx_cmd = (struct iwl3945_tx_cmd *)cmd->cmd.payload; |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 370 | struct iwl_hw_key *keyinfo = &priv->stations[sta_id].keyinfo; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 371 | |
| 372 | switch (keyinfo->alg) { |
| 373 | case ALG_CCMP: |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 374 | tx_cmd->sec_ctl = TX_CMD_SEC_CCM; |
| 375 | memcpy(tx_cmd->key, keyinfo->key, keyinfo->keylen); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 376 | IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 377 | break; |
| 378 | |
| 379 | case ALG_TKIP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 380 | break; |
| 381 | |
| 382 | case ALG_WEP: |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 383 | tx_cmd->sec_ctl = TX_CMD_SEC_WEP | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 384 | (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 385 | |
| 386 | if (keyinfo->keylen == 13) |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 387 | tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 388 | |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 389 | memcpy(&tx_cmd->key[3], keyinfo->key, keyinfo->keylen); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 390 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 391 | IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption " |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 392 | "with key %d\n", info->control.hw_key->hw_key_idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 393 | break; |
| 394 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 395 | default: |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 396 | IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 397 | break; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * handle build REPLY_TX command notification. |
| 403 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 404 | static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv, |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 405 | struct iwl_device_cmd *cmd, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 406 | struct ieee80211_tx_info *info, |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 407 | struct ieee80211_hdr *hdr, u8 std_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 408 | { |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 409 | struct iwl3945_tx_cmd *tx_cmd = (struct iwl3945_tx_cmd *)cmd->cmd.payload; |
| 410 | __le32 tx_flags = tx_cmd->tx_flags; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 411 | __le16 fc = hdr->frame_control; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 412 | |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 413 | tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 414 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 415 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 416 | if (ieee80211_is_mgmt(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 417 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 418 | if (ieee80211_is_probe_resp(fc) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 419 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 420 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 421 | } else { |
| 422 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 423 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 424 | } |
| 425 | |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 426 | tx_cmd->sta_id = std_id; |
Harvey Harrison | 8b7b1e0 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 427 | if (ieee80211_has_morefrags(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 428 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 429 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 430 | if (ieee80211_is_data_qos(fc)) { |
| 431 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 432 | tx_cmd->tid_tspec = qc[0] & 0xf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 433 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 434 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 435 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 436 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 437 | |
Abhijeet Kolekar | 37dc70f | 2009-10-09 13:20:30 -0700 | [diff] [blame] | 438 | priv->cfg->ops->utils->rts_tx_cmd_flag(info, &tx_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 439 | |
| 440 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 441 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 442 | |
| 443 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 444 | if (ieee80211_is_mgmt(fc)) { |
| 445 | if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc)) |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 446 | tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 447 | else |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 448 | tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 449 | } else { |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 450 | tx_cmd->timeout.pm_frame_timeout = 0; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 451 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 452 | |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 453 | tx_cmd->driver_txop = 0; |
| 454 | tx_cmd->tx_flags = tx_flags; |
| 455 | tx_cmd->next_frame_len = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 458 | /* |
| 459 | * start REPLY_TX command process |
| 460 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 461 | static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 462 | { |
| 463 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 464 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 465 | struct iwl3945_tx_cmd *tx_cmd; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 466 | struct iwl_tx_queue *txq = NULL; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 467 | struct iwl_queue *q = NULL; |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 468 | struct iwl_device_cmd *out_cmd; |
| 469 | struct iwl_cmd_meta *out_meta; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 470 | dma_addr_t phys_addr; |
| 471 | dma_addr_t txcmd_phys; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 472 | int txq_id = skb_get_queue_mapping(skb); |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 473 | u16 len, idx, len_org, hdr_len; /* TODO: len_org is not used */ |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 474 | u8 id; |
| 475 | u8 unicast; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 476 | u8 sta_id; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 477 | u8 tid = 0; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 478 | __le16 fc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 479 | u8 wait_write_ptr = 0; |
| 480 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 481 | |
| 482 | spin_lock_irqsave(&priv->lock, flags); |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 483 | if (iwl_is_rfkill(priv)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 484 | IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 485 | goto drop_unlock; |
| 486 | } |
| 487 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 488 | if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 489 | IWL_ERR(priv, "ERROR: No TX rate available.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 490 | goto drop_unlock; |
| 491 | } |
| 492 | |
| 493 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 494 | id = 0; |
| 495 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 496 | fc = hdr->frame_control; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 497 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 498 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 499 | if (ieee80211_is_auth(fc)) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 500 | IWL_DEBUG_TX(priv, "Sending AUTH frame\n"); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 501 | else if (ieee80211_is_assoc_req(fc)) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 502 | IWL_DEBUG_TX(priv, "Sending ASSOC frame\n"); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 503 | else if (ieee80211_is_reassoc_req(fc)) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 504 | IWL_DEBUG_TX(priv, "Sending REASSOC frame\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 505 | #endif |
| 506 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 507 | spin_unlock_irqrestore(&priv->lock, flags); |
| 508 | |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 509 | hdr_len = ieee80211_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 510 | |
Johannes Berg | 2a87c26 | 2010-04-30 11:30:45 -0700 | [diff] [blame] | 511 | /* Find index into station table for destination station */ |
Johannes Berg | 0af8bca | 2010-04-30 14:08:00 -0700 | [diff] [blame] | 512 | sta_id = iwl_sta_id_or_broadcast(priv, info->control.sta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 513 | if (sta_id == IWL_INVALID_STATION) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 514 | IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 515 | hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 516 | goto drop; |
| 517 | } |
| 518 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 519 | IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 520 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 521 | if (ieee80211_is_data_qos(fc)) { |
Johannes Berg | f862a23 | 2010-05-03 01:20:52 -0700 | [diff] [blame] | 522 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 523 | tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; |
Reinette Chatre | e6a6cf4 | 2009-08-13 13:30:50 -0700 | [diff] [blame] | 524 | if (unlikely(tid >= MAX_TID_COUNT)) |
| 525 | goto drop; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 526 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 527 | |
| 528 | /* Descriptor for chosen Tx queue */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 529 | txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 530 | q = &txq->q; |
| 531 | |
Zhu Yi | dc57a30 | 2009-12-14 14:12:12 -0800 | [diff] [blame] | 532 | if ((iwl_queue_space(q) < q->high_mark)) |
| 533 | goto drop; |
| 534 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 535 | spin_lock_irqsave(&priv->lock, flags); |
| 536 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 537 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 538 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 539 | /* Set up driver data for this TFD */ |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 540 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info)); |
Johannes Berg | ff0d91c | 2010-05-17 02:37:34 -0700 | [diff] [blame] | 541 | txq->txb[q->write_ptr].skb = skb; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 542 | |
| 543 | /* Init first empty entry in queue's array of Tx/cmd buffers */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 544 | out_cmd = txq->cmd[idx]; |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 545 | out_meta = &txq->meta[idx]; |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 546 | tx_cmd = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 547 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 548 | memset(tx_cmd, 0, sizeof(*tx_cmd)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 549 | |
| 550 | /* |
| 551 | * Set up the Tx-command (not MAC!) header. |
| 552 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 553 | * after Tx, uCode's Tx response will return this value so driver can |
| 554 | * locate the frame within the tx queue and do post-tx processing. |
| 555 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 556 | out_cmd->hdr.cmd = REPLY_TX; |
| 557 | out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 558 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 559 | |
| 560 | /* Copy MAC header from skb into command buffer */ |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 561 | memcpy(tx_cmd->hdr, hdr, hdr_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 562 | |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 563 | |
| 564 | if (info->control.hw_key) |
| 565 | iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, sta_id); |
| 566 | |
| 567 | /* TODO need this for burst mode later on */ |
| 568 | iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id); |
| 569 | |
| 570 | /* set is_hcca to 0; it probably will never be implemented */ |
| 571 | iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0); |
| 572 | |
| 573 | /* Total # bytes to be transmitted */ |
| 574 | len = (u16)skb->len; |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 575 | tx_cmd->len = cpu_to_le16(len); |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 576 | |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 577 | iwl_dbg_log_tx_data_frame(priv, len, hdr); |
Wey-Yi Guy | 22fdf3c | 2009-08-07 15:41:40 -0700 | [diff] [blame] | 578 | iwl_update_stats(priv, true, fc, len); |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 579 | tx_cmd->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK; |
| 580 | tx_cmd->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK; |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 581 | |
| 582 | if (!ieee80211_has_morefrags(hdr->frame_control)) { |
| 583 | txq->need_update = 1; |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 584 | } else { |
| 585 | wait_write_ptr = 1; |
| 586 | txq->need_update = 0; |
| 587 | } |
| 588 | |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 589 | IWL_DEBUG_TX(priv, "sequence nr = 0X%x\n", |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 590 | le16_to_cpu(out_cmd->hdr.sequence)); |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 591 | IWL_DEBUG_TX(priv, "tx_flags = 0X%x\n", le32_to_cpu(tx_cmd->tx_flags)); |
Abhijeet Kolekar | 9744c91 | 2009-10-09 13:20:31 -0700 | [diff] [blame] | 592 | iwl_print_hex_dump(priv, IWL_DL_TX, tx_cmd, sizeof(*tx_cmd)); |
| 593 | iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx_cmd->hdr, |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 594 | ieee80211_hdrlen(fc)); |
| 595 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 596 | /* |
| 597 | * Use the first empty entry in this queue's command buffer array |
| 598 | * to contain the Tx command and MAC header concatenated together |
| 599 | * (payload data will be in another buffer). |
| 600 | * Size of this varies, due to varying MAC header length. |
| 601 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 602 | * of the MAC header (device reads on dword boundaries). |
| 603 | * We'll tell device about this padding later. |
| 604 | */ |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 605 | len = sizeof(struct iwl3945_tx_cmd) + |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 606 | sizeof(struct iwl_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 607 | |
| 608 | len_org = len; |
| 609 | len = (len + 3) & ~3; |
| 610 | |
| 611 | if (len_org != len) |
| 612 | len_org = 1; |
| 613 | else |
| 614 | len_org = 0; |
| 615 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 616 | /* Physical address of this Tx command's header (not MAC header!), |
| 617 | * within command buffer array. */ |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 618 | txcmd_phys = pci_map_single(priv->pci_dev, &out_cmd->hdr, |
| 619 | len, PCI_DMA_TODEVICE); |
| 620 | /* we do not map meta data ... so we can safely access address to |
| 621 | * provide to unmap command*/ |
FUJITA Tomonori | 2e72444 | 2010-06-03 14:19:20 +0900 | [diff] [blame] | 622 | dma_unmap_addr_set(out_meta, mapping, txcmd_phys); |
| 623 | dma_unmap_len_set(out_meta, len, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 624 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 625 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 626 | * first entry */ |
Samuel Ortiz | 7aaa1d7 | 2009-01-19 15:30:26 -0800 | [diff] [blame] | 627 | priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq, |
| 628 | txcmd_phys, len, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 629 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 630 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 631 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 632 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 633 | len = skb->len - hdr_len; |
| 634 | if (len) { |
| 635 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 636 | len, PCI_DMA_TODEVICE); |
Samuel Ortiz | 7aaa1d7 | 2009-01-19 15:30:26 -0800 | [diff] [blame] | 637 | priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq, |
| 638 | phys_addr, len, |
| 639 | 0, U32_PAD(len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 640 | } |
| 641 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 642 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 643 | /* Tell device the write index *just past* this latest filled TFD */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 644 | q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); |
Abhijeet Kolekar | 7bfedc5 | 2010-02-03 13:47:56 -0800 | [diff] [blame] | 645 | iwl_txq_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 646 | spin_unlock_irqrestore(&priv->lock, flags); |
| 647 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 648 | if ((iwl_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 649 | && priv->mac80211_registered) { |
| 650 | if (wait_write_ptr) { |
| 651 | spin_lock_irqsave(&priv->lock, flags); |
| 652 | txq->need_update = 1; |
Samuel Ortiz | 4f3602c | 2009-01-19 15:30:25 -0800 | [diff] [blame] | 653 | iwl_txq_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 654 | spin_unlock_irqrestore(&priv->lock, flags); |
| 655 | } |
| 656 | |
Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 657 | iwl_stop_queue(priv, skb_get_queue_mapping(skb)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | return 0; |
| 661 | |
| 662 | drop_unlock: |
| 663 | spin_unlock_irqrestore(&priv->lock, flags); |
| 664 | drop: |
| 665 | return -1; |
| 666 | } |
| 667 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 668 | static int iwl3945_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 669 | struct ieee80211_measurement_params *params, |
| 670 | u8 type) |
| 671 | { |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 672 | struct iwl_spectrum_cmd spectrum; |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 673 | struct iwl_rx_packet *pkt; |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 674 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 675 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 676 | .data = (void *)&spectrum, |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 677 | .flags = CMD_WANT_SKB, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 678 | }; |
| 679 | u32 add_time = le64_to_cpu(params->start_time); |
| 680 | int rc; |
| 681 | int spectrum_resp_status; |
| 682 | int duration = le16_to_cpu(params->duration); |
| 683 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 684 | if (iwl_is_associated(priv)) |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 685 | add_time = iwl_usecs_to_beacons(priv, |
Johannes Berg | e99f168 | 2010-01-19 10:04:28 -0800 | [diff] [blame] | 686 | le64_to_cpu(params->start_time) - priv->_3945.last_tsf, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 687 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 688 | |
| 689 | memset(&spectrum, 0, sizeof(spectrum)); |
| 690 | |
| 691 | spectrum.channel_count = cpu_to_le16(1); |
| 692 | spectrum.flags = |
| 693 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 694 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 695 | cmd.len = sizeof(spectrum); |
| 696 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 697 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 698 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 699 | spectrum.start_time = |
Wey-Yi Guy | a0ee74c | 2010-05-06 08:54:10 -0700 | [diff] [blame] | 700 | iwl_add_beacon_time(priv, |
| 701 | priv->_3945.last_beacon_time, add_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 702 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 703 | else |
| 704 | spectrum.start_time = 0; |
| 705 | |
| 706 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 707 | spectrum.channels[0].channel = params->channel; |
| 708 | spectrum.channels[0].type = type; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 709 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 710 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 711 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 712 | |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 713 | rc = iwl_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 714 | if (rc) |
| 715 | return rc; |
| 716 | |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 717 | pkt = (struct iwl_rx_packet *)cmd.reply_page; |
| 718 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 719 | IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 720 | rc = -EIO; |
| 721 | } |
| 722 | |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 723 | spectrum_resp_status = le16_to_cpu(pkt->u.spectrum.status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 724 | switch (spectrum_resp_status) { |
| 725 | case 0: /* Command will be handled */ |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 726 | if (pkt->u.spectrum.id != 0xff) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 727 | IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n", |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 728 | pkt->u.spectrum.id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 729 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 730 | } |
| 731 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 732 | rc = 0; |
| 733 | break; |
| 734 | |
| 735 | case 1: /* Command will not be handled */ |
| 736 | rc = -EAGAIN; |
| 737 | break; |
| 738 | } |
| 739 | |
Zhu Yi | 64a76b5 | 2009-12-10 14:37:21 -0800 | [diff] [blame] | 740 | iwl_free_pages(priv, cmd.reply_page); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 741 | |
| 742 | return rc; |
| 743 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 744 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 745 | static void iwl3945_rx_reply_alive(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 746 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 747 | { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 748 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 749 | struct iwl_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 750 | struct delayed_work *pwork; |
| 751 | |
| 752 | palive = &pkt->u.alive_frame; |
| 753 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 754 | IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 755 | "0x%01X 0x%01X\n", |
| 756 | palive->is_valid, palive->ver_type, |
| 757 | palive->ver_subtype); |
| 758 | |
| 759 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 760 | IWL_DEBUG_INFO(priv, "Initialization Alive received.\n"); |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 761 | memcpy(&priv->card_alive_init, &pkt->u.alive_frame, |
| 762 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 763 | pwork = &priv->init_alive_start; |
| 764 | } else { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 765 | IWL_DEBUG_INFO(priv, "Runtime Alive received.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 766 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 767 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 768 | pwork = &priv->alive_start; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 769 | iwl3945_disable_events(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /* We delay the ALIVE response by 5ms to |
| 773 | * give the HW RF Kill time to activate... */ |
| 774 | if (palive->is_valid == UCODE_VALID_OK) |
| 775 | queue_delayed_work(priv->workqueue, pwork, |
| 776 | msecs_to_jiffies(5)); |
| 777 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 778 | IWL_WARN(priv, "uCode did not respond OK.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 779 | } |
| 780 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 781 | static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 782 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 783 | { |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 784 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 785 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 786 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 787 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 788 | IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 791 | static void iwl3945_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 792 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 793 | struct iwl_priv *priv = |
| 794 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 795 | struct sk_buff *beacon; |
| 796 | |
| 797 | /* 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] | 798 | beacon = ieee80211_beacon_get(priv->hw, priv->vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 799 | |
| 800 | if (!beacon) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 801 | IWL_ERR(priv, "update beacon failed\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 802 | return; |
| 803 | } |
| 804 | |
| 805 | mutex_lock(&priv->mutex); |
| 806 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 807 | if (priv->ibss_beacon) |
| 808 | dev_kfree_skb(priv->ibss_beacon); |
| 809 | |
| 810 | priv->ibss_beacon = beacon; |
| 811 | mutex_unlock(&priv->mutex); |
| 812 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 813 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 814 | } |
| 815 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 816 | static void iwl3945_rx_beacon_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 817 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 818 | { |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 819 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 820 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 821 | struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 822 | u8 rate = beacon->beacon_notify_hdr.rate; |
| 823 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 824 | IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 825 | "tsf %d %d rate %d\n", |
| 826 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 827 | beacon->beacon_notify_hdr.failure_frame, |
| 828 | le32_to_cpu(beacon->ibss_mgr_status), |
| 829 | le32_to_cpu(beacon->high_tsf), |
| 830 | le32_to_cpu(beacon->low_tsf), rate); |
| 831 | #endif |
| 832 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 833 | if ((priv->iw_mode == NL80211_IFTYPE_AP) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 834 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 835 | queue_work(priv->workqueue, &priv->beacon_update); |
| 836 | } |
| 837 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 838 | /* Handle notification from uCode that card's power state is changing |
| 839 | * due to software, hardware, or critical temperature RFKILL */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 840 | static void iwl3945_rx_card_state_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 841 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 842 | { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 843 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 844 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 845 | unsigned long status = priv->status; |
| 846 | |
Reinette Chatre | 4c423a2 | 2009-07-17 09:30:26 -0700 | [diff] [blame] | 847 | IWL_WARN(priv, "Card state received: HW:%s SW:%s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 848 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 849 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 850 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 851 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 852 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 853 | |
| 854 | if (flags & HW_CARD_DISABLED) |
| 855 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 856 | else |
| 857 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 858 | |
| 859 | |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 860 | iwl_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 861 | |
| 862 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
Johannes Berg | a60e77e | 2009-06-04 18:26:06 +0200 | [diff] [blame] | 863 | test_bit(STATUS_RF_KILL_HW, &priv->status))) |
| 864 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, |
| 865 | test_bit(STATUS_RF_KILL_HW, &priv->status)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 866 | else |
| 867 | wake_up_interruptible(&priv->wait_command_queue); |
| 868 | } |
| 869 | |
| 870 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 871 | * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 872 | * |
| 873 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 874 | * to the host. |
| 875 | * |
| 876 | * This function chains into the hardware specific files for them to setup |
| 877 | * any hardware specific handlers as well. |
| 878 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 879 | static void iwl3945_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 880 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 881 | priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive; |
| 882 | priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta; |
Abhijeet Kolekar | 261b9c3 | 2009-02-18 15:54:29 -0800 | [diff] [blame] | 883 | priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 884 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa; |
Reinette Chatre | 81963d6 | 2010-01-22 14:22:57 -0800 | [diff] [blame] | 885 | priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] = |
| 886 | iwl_rx_spectrum_measure_notif; |
Abhijeet Kolekar | 030f05e | 2009-02-18 15:54:28 -0800 | [diff] [blame] | 887 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 888 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Abhijeet Kolekar | 030f05e | 2009-02-18 15:54:28 -0800 | [diff] [blame] | 889 | iwl_rx_pm_debug_statistics_notif; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 890 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 891 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 892 | /* |
| 893 | * The same handler is used for both the REPLY to a discrete |
| 894 | * statistics request from the host as well as for the periodic |
| 895 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 896 | */ |
Abhijeet Kolekar | 17f36fc | 2010-04-16 10:03:54 -0700 | [diff] [blame] | 897 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_reply_statistics; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 898 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 899 | |
Abhijeet Kolekar | cade0eb | 2009-02-18 15:54:26 -0800 | [diff] [blame] | 900 | iwl_setup_rx_scan_handlers(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 901 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 902 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 903 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 904 | iwl3945_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 907 | /************************** RX-FUNCTIONS ****************************/ |
| 908 | /* |
| 909 | * Rx theory of operation |
| 910 | * |
| 911 | * The host allocates 32 DMA target addresses and passes the host address |
| 912 | * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is |
| 913 | * 0 to 31 |
| 914 | * |
| 915 | * Rx Queue Indexes |
| 916 | * The host/firmware share two index registers for managing the Rx buffers. |
| 917 | * |
| 918 | * The READ index maps to the first position that the firmware may be writing |
| 919 | * to -- the driver can read up to (but not including) this position and get |
| 920 | * good data. |
| 921 | * The READ index is managed by the firmware once the card is enabled. |
| 922 | * |
| 923 | * The WRITE index maps to the last position the driver has read from -- the |
| 924 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 925 | * |
| 926 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 927 | * WRITE = READ. |
| 928 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 929 | * During initialization, the host sets up the READ queue position to the first |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 930 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 931 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 932 | * When the firmware places a packet in a buffer, it will advance the READ index |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 933 | * and fire the RX interrupt. The driver can then query the READ index and |
| 934 | * process as many packets as possible, moving the WRITE index forward as it |
| 935 | * resets the Rx queue buffers with new memory. |
| 936 | * |
| 937 | * The management in the driver is as follows: |
| 938 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 939 | * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 940 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 941 | * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 942 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 943 | * 'processed' and 'read' driver indexes as well) |
| 944 | * + A received packet is processed and handed to the kernel network stack, |
| 945 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 946 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 947 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 948 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 949 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 950 | * |
| 951 | * |
| 952 | * Driver sequence: |
| 953 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 954 | * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 955 | * iwl3945_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 956 | * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 957 | * queue, updates firmware pointers, and updates |
| 958 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 959 | * are available, schedules iwl3945_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 960 | * |
| 961 | * -- enable interrupts -- |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 962 | * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 963 | * READ INDEX, detaching the SKB from the pool. |
| 964 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 965 | * Calls iwl3945_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 966 | * slots. |
| 967 | * ... |
| 968 | * |
| 969 | */ |
| 970 | |
| 971 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 972 | * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 973 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 974 | static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 975 | dma_addr_t dma_addr) |
| 976 | { |
| 977 | return cpu_to_le32((u32)dma_addr); |
| 978 | } |
| 979 | |
| 980 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 981 | * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 982 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 983 | * If there are slots in the RX queue that need to be restocked, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 984 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 985 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 986 | * |
| 987 | * This moves the 'write' index forward to catch up with 'processed', and |
| 988 | * also updates the memory address in the firmware to reference the new |
| 989 | * target buffer. |
| 990 | */ |
Abhijeet Kolekar | 7bfedc5 | 2010-02-03 13:47:56 -0800 | [diff] [blame] | 991 | static void iwl3945_rx_queue_restock(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 992 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 993 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 994 | struct list_head *element; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 995 | struct iwl_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 996 | unsigned long flags; |
Abhijeet Kolekar | 7bfedc5 | 2010-02-03 13:47:56 -0800 | [diff] [blame] | 997 | int write; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 998 | |
| 999 | spin_lock_irqsave(&rxq->lock, flags); |
| 1000 | write = rxq->write & ~0x7; |
Winkler, Tomas | 37d6831 | 2009-01-08 10:19:54 -0800 | [diff] [blame] | 1001 | while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1002 | /* Get next free Rx buffer, remove from free list */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1003 | element = rxq->rx_free.next; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1004 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1005 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1006 | |
| 1007 | /* Point to Rx buffer via next RBD in circular buffer */ |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1008 | rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->page_dma); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1009 | rxq->queue[rxq->write] = rxb; |
| 1010 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 1011 | rxq->free_count--; |
| 1012 | } |
| 1013 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 1014 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 1015 | * refill it */ |
| 1016 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 1017 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 1018 | |
| 1019 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1020 | /* If we've added more space for the firmware to place data, tell it. |
| 1021 | * Increment device's write pointer in multiples of 8. */ |
Abhijeet Kolekar | d14d444 | 2009-06-03 11:44:08 -0700 | [diff] [blame] | 1022 | if ((rxq->write_actual != (rxq->write & ~0x7)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1023 | || (abs(rxq->write - rxq->read) > 7)) { |
| 1024 | spin_lock_irqsave(&rxq->lock, flags); |
| 1025 | rxq->need_update = 1; |
| 1026 | spin_unlock_irqrestore(&rxq->lock, flags); |
Abhijeet Kolekar | 7bfedc5 | 2010-02-03 13:47:56 -0800 | [diff] [blame] | 1027 | iwl_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1028 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1032 | * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1033 | * |
| 1034 | * When moving to rx_free an SKB is allocated for the slot. |
| 1035 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1036 | * Also restock the Rx queue via iwl3945_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1037 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1038 | */ |
Abhijeet Kolekar | d14d444 | 2009-06-03 11:44:08 -0700 | [diff] [blame] | 1039 | static void iwl3945_rx_allocate(struct iwl_priv *priv, gfp_t priority) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1040 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 1041 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1042 | struct list_head *element; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1043 | struct iwl_rx_mem_buffer *rxb; |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1044 | struct page *page; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1045 | unsigned long flags; |
Zhu Yi | 29b1b26 | 2009-10-23 13:42:25 -0700 | [diff] [blame] | 1046 | gfp_t gfp_mask = priority; |
Abhijeet Kolekar | 7224049 | 2009-04-30 13:56:26 -0700 | [diff] [blame] | 1047 | |
| 1048 | while (1) { |
| 1049 | spin_lock_irqsave(&rxq->lock, flags); |
| 1050 | |
| 1051 | if (list_empty(&rxq->rx_used)) { |
| 1052 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 1053 | return; |
| 1054 | } |
Abhijeet Kolekar | 7224049 | 2009-04-30 13:56:26 -0700 | [diff] [blame] | 1055 | spin_unlock_irqrestore(&rxq->lock, flags); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1056 | |
Reinette Chatre | f82a924 | 2009-09-17 10:43:56 -0700 | [diff] [blame] | 1057 | if (rxq->free_count > RX_LOW_WATERMARK) |
Zhu Yi | 29b1b26 | 2009-10-23 13:42:25 -0700 | [diff] [blame] | 1058 | gfp_mask |= __GFP_NOWARN; |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1059 | |
| 1060 | if (priv->hw_params.rx_page_order > 0) |
Zhu Yi | 29b1b26 | 2009-10-23 13:42:25 -0700 | [diff] [blame] | 1061 | gfp_mask |= __GFP_COMP; |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1062 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1063 | /* Alloc a new receive buffer */ |
Zhu Yi | 29b1b26 | 2009-10-23 13:42:25 -0700 | [diff] [blame] | 1064 | page = alloc_pages(gfp_mask, priv->hw_params.rx_page_order); |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1065 | if (!page) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1066 | if (net_ratelimit()) |
Reinette Chatre | f82a924 | 2009-09-17 10:43:56 -0700 | [diff] [blame] | 1067 | IWL_DEBUG_INFO(priv, "Failed to allocate SKB buffer.\n"); |
| 1068 | if ((rxq->free_count <= RX_LOW_WATERMARK) && |
| 1069 | net_ratelimit()) |
| 1070 | IWL_CRIT(priv, "Failed to allocate SKB buffer with %s. Only %u free buffers remaining.\n", |
| 1071 | priority == GFP_ATOMIC ? "GFP_ATOMIC" : "GFP_KERNEL", |
| 1072 | rxq->free_count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1073 | /* We don't reschedule replenish work here -- we will |
| 1074 | * call the restock method and if it still needs |
| 1075 | * more buffers it will schedule replenish */ |
| 1076 | break; |
| 1077 | } |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 1078 | |
Reinette Chatre | de0bd50 | 2009-09-11 10:38:12 -0700 | [diff] [blame] | 1079 | spin_lock_irqsave(&rxq->lock, flags); |
| 1080 | if (list_empty(&rxq->rx_used)) { |
| 1081 | spin_unlock_irqrestore(&rxq->lock, flags); |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1082 | __free_pages(page, priv->hw_params.rx_page_order); |
Reinette Chatre | de0bd50 | 2009-09-11 10:38:12 -0700 | [diff] [blame] | 1083 | return; |
| 1084 | } |
| 1085 | element = rxq->rx_used.next; |
| 1086 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
| 1087 | list_del(element); |
| 1088 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 1089 | |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1090 | rxb->page = page; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1091 | /* Get physical address of RB/SKB */ |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1092 | rxb->page_dma = pci_map_page(priv->pci_dev, page, 0, |
| 1093 | PAGE_SIZE << priv->hw_params.rx_page_order, |
| 1094 | PCI_DMA_FROMDEVICE); |
Abhijeet Kolekar | 7224049 | 2009-04-30 13:56:26 -0700 | [diff] [blame] | 1095 | |
| 1096 | spin_lock_irqsave(&rxq->lock, flags); |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1097 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1098 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 1099 | rxq->free_count++; |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1100 | priv->alloc_rxb_page++; |
| 1101 | |
Abhijeet Kolekar | 7224049 | 2009-04-30 13:56:26 -0700 | [diff] [blame] | 1102 | spin_unlock_irqrestore(&rxq->lock, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1103 | } |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1104 | } |
| 1105 | |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 1106 | void iwl3945_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq) |
| 1107 | { |
| 1108 | unsigned long flags; |
| 1109 | int i; |
| 1110 | spin_lock_irqsave(&rxq->lock, flags); |
| 1111 | INIT_LIST_HEAD(&rxq->rx_free); |
| 1112 | INIT_LIST_HEAD(&rxq->rx_used); |
| 1113 | /* Fill the rx_used queue with _all_ of the Rx buffers */ |
| 1114 | for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) { |
| 1115 | /* In the reset function, these buffers may have been allocated |
| 1116 | * to an SKB, so we need to unmap and free potential storage */ |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1117 | if (rxq->pool[i].page != NULL) { |
| 1118 | pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma, |
| 1119 | PAGE_SIZE << priv->hw_params.rx_page_order, |
| 1120 | PCI_DMA_FROMDEVICE); |
Zhu Yi | 64a76b5 | 2009-12-10 14:37:21 -0800 | [diff] [blame] | 1121 | __iwl_free_pages(priv, rxq->pool[i].page); |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1122 | rxq->pool[i].page = NULL; |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 1123 | } |
| 1124 | list_add_tail(&rxq->pool[i].list, &rxq->rx_used); |
| 1125 | } |
| 1126 | |
| 1127 | /* Set us so that we have processed and used all buffers, but have |
| 1128 | * not restocked the Rx queue with fresh buffers */ |
| 1129 | rxq->read = rxq->write = 0; |
Abhijeet Kolekar | d14d444 | 2009-06-03 11:44:08 -0700 | [diff] [blame] | 1130 | rxq->write_actual = 0; |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1131 | rxq->free_count = 0; |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 1132 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 1133 | } |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 1134 | |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1135 | void iwl3945_rx_replenish(void *data) |
| 1136 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1137 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1138 | unsigned long flags; |
| 1139 | |
Abhijeet Kolekar | d14d444 | 2009-06-03 11:44:08 -0700 | [diff] [blame] | 1140 | iwl3945_rx_allocate(priv, GFP_KERNEL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1141 | |
| 1142 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1143 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1144 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1145 | } |
| 1146 | |
Abhijeet Kolekar | d14d444 | 2009-06-03 11:44:08 -0700 | [diff] [blame] | 1147 | static void iwl3945_rx_replenish_now(struct iwl_priv *priv) |
| 1148 | { |
| 1149 | iwl3945_rx_allocate(priv, GFP_ATOMIC); |
| 1150 | |
| 1151 | iwl3945_rx_queue_restock(priv); |
| 1152 | } |
| 1153 | |
| 1154 | |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 1155 | /* Assumes that the skb field of the buffers in 'pool' is kept accurate. |
| 1156 | * If an SKB has been detached, the POOL needs to have its SKB set to NULL |
| 1157 | * This free routine walks the list of POOL entries and if SKB is set to |
| 1158 | * non NULL it is unmapped and freed |
| 1159 | */ |
| 1160 | static void iwl3945_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq) |
| 1161 | { |
| 1162 | int i; |
| 1163 | for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1164 | if (rxq->pool[i].page != NULL) { |
| 1165 | pci_unmap_page(priv->pci_dev, rxq->pool[i].page_dma, |
| 1166 | PAGE_SIZE << priv->hw_params.rx_page_order, |
| 1167 | PCI_DMA_FROMDEVICE); |
Zhu Yi | 64a76b5 | 2009-12-10 14:37:21 -0800 | [diff] [blame] | 1168 | __iwl_free_pages(priv, rxq->pool[i].page); |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1169 | rxq->pool[i].page = NULL; |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | |
Stanislaw Gruszka | f36d04a | 2010-02-10 05:07:45 -0800 | [diff] [blame] | 1173 | dma_free_coherent(&priv->pci_dev->dev, 4 * RX_QUEUE_SIZE, rxq->bd, |
Emmanuel Grumbach | d5b25c9 | 2010-06-07 13:21:46 -0700 | [diff] [blame] | 1174 | rxq->bd_dma); |
Stanislaw Gruszka | f36d04a | 2010-02-10 05:07:45 -0800 | [diff] [blame] | 1175 | dma_free_coherent(&priv->pci_dev->dev, sizeof(struct iwl_rb_status), |
| 1176 | rxq->rb_stts, rxq->rb_stts_dma); |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 1177 | rxq->bd = NULL; |
| 1178 | rxq->rb_stts = NULL; |
| 1179 | } |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 1180 | |
| 1181 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1182 | /* Convert linear signal-to-noise ratio into dB */ |
| 1183 | static u8 ratio2dB[100] = { |
| 1184 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 1185 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 1186 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 1187 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 1188 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 1189 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 1190 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 1191 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 1192 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 1193 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 1194 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 1195 | }; |
| 1196 | |
| 1197 | /* Calculates a relative dB value from a ratio of linear |
| 1198 | * (i.e. not dB) signal levels. |
| 1199 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1200 | int iwl3945_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1201 | { |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 1202 | /* 1000:1 or higher just report as 60 dB */ |
| 1203 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1204 | return 60; |
| 1205 | |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 1206 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1207 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 1208 | if (sig_ratio >= 100) |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 1209 | return 20 + (int)ratio2dB[sig_ratio/10]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1210 | |
| 1211 | /* We shouldn't see this */ |
| 1212 | if (sig_ratio < 1) |
| 1213 | return 0; |
| 1214 | |
| 1215 | /* Use table for ratios 1:1 - 99:1 */ |
| 1216 | return (int)ratio2dB[sig_ratio]; |
| 1217 | } |
| 1218 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1219 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1220 | * iwl3945_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1221 | * |
| 1222 | * Uses the priv->rx_handlers callback function array to invoke |
| 1223 | * the appropriate handlers, including command responses, |
| 1224 | * frame-received notifications, and other notifications. |
| 1225 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1226 | static void iwl3945_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1227 | { |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1228 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1229 | struct iwl_rx_packet *pkt; |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 1230 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1231 | u32 r, i; |
| 1232 | int reclaim; |
| 1233 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1234 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 1235 | u32 count = 8; |
Abhijeet Kolekar | d14d444 | 2009-06-03 11:44:08 -0700 | [diff] [blame] | 1236 | int total_empty = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1237 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1238 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 1239 | * buffer that the driver may process (last buffer filled by ucode). */ |
Winkler, Tomas | 8cd812b | 2008-12-19 10:37:43 +0800 | [diff] [blame] | 1240 | r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1241 | i = rxq->read; |
| 1242 | |
Abhijeet Kolekar | d14d444 | 2009-06-03 11:44:08 -0700 | [diff] [blame] | 1243 | /* calculate total frames need to be restock after handling RX */ |
Zhu Yi | 7300515 | 2009-10-23 13:42:32 -0700 | [diff] [blame] | 1244 | total_empty = r - rxq->write_actual; |
Abhijeet Kolekar | d14d444 | 2009-06-03 11:44:08 -0700 | [diff] [blame] | 1245 | if (total_empty < 0) |
| 1246 | total_empty += RX_QUEUE_SIZE; |
| 1247 | |
| 1248 | if (total_empty > (RX_QUEUE_SIZE / 2)) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1249 | fill_rx = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1250 | /* Rx interrupt, but nothing sent from uCode */ |
| 1251 | if (i == r) |
Reinette Chatre | af472a95 | 2009-08-28 09:58:50 -0700 | [diff] [blame] | 1252 | IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1253 | |
| 1254 | while (i != r) { |
Johannes Berg | f4989d9 | 2010-05-28 04:08:30 -0700 | [diff] [blame] | 1255 | int len; |
| 1256 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1257 | rxb = rxq->queue[i]; |
| 1258 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1259 | /* 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] | 1260 | * then a bug has been introduced in the queue refilling |
| 1261 | * routines -- catch it here */ |
| 1262 | BUG_ON(rxb == NULL); |
| 1263 | |
| 1264 | rxq->queue[i] = NULL; |
| 1265 | |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1266 | pci_unmap_page(priv->pci_dev, rxb->page_dma, |
| 1267 | PAGE_SIZE << priv->hw_params.rx_page_order, |
| 1268 | PCI_DMA_FROMDEVICE); |
| 1269 | pkt = rxb_addr(rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1270 | |
Johannes Berg | f4989d9 | 2010-05-28 04:08:30 -0700 | [diff] [blame] | 1271 | len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; |
| 1272 | len += sizeof(u32); /* account for status word */ |
| 1273 | trace_iwlwifi_dev_rx(priv, pkt, len); |
Johannes Berg | be1a71a | 2009-10-02 13:44:02 -0700 | [diff] [blame] | 1274 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1275 | /* Reclaim a command buffer only if this packet is a response |
| 1276 | * to a (driver-originated) command. |
| 1277 | * If the packet (e.g. Rx frame) originated from uCode, |
| 1278 | * there is no command buffer to reclaim. |
| 1279 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 1280 | * but apparently a few don't get set; catch them here. */ |
| 1281 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 1282 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 1283 | (pkt->hdr.cmd != REPLY_TX); |
| 1284 | |
| 1285 | /* Based on type of command response or notification, |
| 1286 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1287 | * rx_handlers table. See iwl3945_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1288 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Reinette Chatre | af472a95 | 2009-08-28 09:58:50 -0700 | [diff] [blame] | 1289 | IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r, i, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1290 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
Abhijeet Kolekar | 86ddbf6 | 2009-04-20 14:36:59 -0700 | [diff] [blame] | 1291 | priv->isr_stats.rx_handlers[pkt->hdr.cmd]++; |
Zhu Yi | 29b1b26 | 2009-10-23 13:42:25 -0700 | [diff] [blame] | 1292 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1293 | } else { |
| 1294 | /* No handling needed */ |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1295 | IWL_DEBUG_RX(priv, |
| 1296 | "r %d i %d No handler needed for %s, 0x%02x\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1297 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 1298 | pkt->hdr.cmd); |
| 1299 | } |
| 1300 | |
Zhu Yi | 29b1b26 | 2009-10-23 13:42:25 -0700 | [diff] [blame] | 1301 | /* |
| 1302 | * XXX: After here, we should always check rxb->page |
| 1303 | * against NULL before touching it or its virtual |
| 1304 | * memory (pkt). Because some rx_handler might have |
| 1305 | * already taken or freed the pages. |
| 1306 | */ |
| 1307 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1308 | if (reclaim) { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1309 | /* Invoke any callbacks, transfer the buffer to caller, |
| 1310 | * and fire off the (possibly) blocking iwl_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1311 | * as we reclaim the driver command queue */ |
Zhu Yi | 29b1b26 | 2009-10-23 13:42:25 -0700 | [diff] [blame] | 1312 | if (rxb->page) |
Abhijeet Kolekar | 732587a | 2009-03-11 11:17:57 -0700 | [diff] [blame] | 1313 | iwl_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1314 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1315 | IWL_WARN(priv, "Claim null rxb?\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
Zhu Yi | 7300515 | 2009-10-23 13:42:32 -0700 | [diff] [blame] | 1318 | /* Reuse the page if possible. For notification packets and |
| 1319 | * SKBs that fail to Rx correctly, add them back into the |
| 1320 | * rx_free list for reuse later. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1321 | spin_lock_irqsave(&rxq->lock, flags); |
Zhu Yi | 7300515 | 2009-10-23 13:42:32 -0700 | [diff] [blame] | 1322 | if (rxb->page != NULL) { |
| 1323 | rxb->page_dma = pci_map_page(priv->pci_dev, rxb->page, |
| 1324 | 0, PAGE_SIZE << priv->hw_params.rx_page_order, |
| 1325 | PCI_DMA_FROMDEVICE); |
| 1326 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 1327 | rxq->free_count++; |
| 1328 | } else |
| 1329 | list_add_tail(&rxb->list, &rxq->rx_used); |
| 1330 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1331 | spin_unlock_irqrestore(&rxq->lock, flags); |
Zhu Yi | 7300515 | 2009-10-23 13:42:32 -0700 | [diff] [blame] | 1332 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1333 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1334 | /* If there are a lot of unused frames, |
| 1335 | * restock the Rx queue so ucode won't assert. */ |
| 1336 | if (fill_rx) { |
| 1337 | count++; |
| 1338 | if (count >= 8) { |
Zhu Yi | 7300515 | 2009-10-23 13:42:32 -0700 | [diff] [blame] | 1339 | rxq->read = i; |
Abhijeet Kolekar | d14d444 | 2009-06-03 11:44:08 -0700 | [diff] [blame] | 1340 | iwl3945_rx_replenish_now(priv); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1341 | count = 0; |
| 1342 | } |
| 1343 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | /* Backtrack one entry */ |
Zhu Yi | 7300515 | 2009-10-23 13:42:32 -0700 | [diff] [blame] | 1347 | rxq->read = i; |
Abhijeet Kolekar | d14d444 | 2009-06-03 11:44:08 -0700 | [diff] [blame] | 1348 | if (fill_rx) |
| 1349 | iwl3945_rx_replenish_now(priv); |
| 1350 | else |
| 1351 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 1354 | /* call this function to flush any scheduled tasklet */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1355 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 1356 | { |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1357 | /* wait to make sure we flush pending tasklet*/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 1358 | synchronize_irq(priv->pci_dev->irq); |
| 1359 | tasklet_kill(&priv->irq_tasklet); |
| 1360 | } |
| 1361 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1362 | static const char *desc_lookup(int i) |
| 1363 | { |
| 1364 | switch (i) { |
| 1365 | case 1: |
| 1366 | return "FAIL"; |
| 1367 | case 2: |
| 1368 | return "BAD_PARAM"; |
| 1369 | case 3: |
| 1370 | return "BAD_CHECKSUM"; |
| 1371 | case 4: |
| 1372 | return "NMI_INTERRUPT"; |
| 1373 | case 5: |
| 1374 | return "SYSASSERT"; |
| 1375 | case 6: |
| 1376 | return "FATAL_ERROR"; |
| 1377 | } |
| 1378 | |
| 1379 | return "UNKNOWN"; |
| 1380 | } |
| 1381 | |
| 1382 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 1383 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 1384 | |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 1385 | void iwl3945_dump_nic_error_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1386 | { |
| 1387 | u32 i; |
| 1388 | u32 desc, time, count, base, data1; |
| 1389 | u32 blink1, blink2, ilink1, ilink2; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1390 | |
| 1391 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 1392 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1393 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1394 | IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1395 | return; |
| 1396 | } |
| 1397 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1398 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1399 | count = iwl_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1400 | |
| 1401 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1402 | IWL_ERR(priv, "Start IWL Error Log Dump:\n"); |
| 1403 | IWL_ERR(priv, "Status: 0x%08lX, count: %d\n", |
| 1404 | priv->status, count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1407 | IWL_ERR(priv, "Desc Time asrtPC blink2 " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1408 | "ilink1 nmiPC Line\n"); |
| 1409 | for (i = ERROR_START_OFFSET; |
| 1410 | i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET; |
| 1411 | i += ERROR_ELEM_SIZE) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1412 | desc = iwl_read_targ_mem(priv, base + i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1413 | time = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1414 | iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1415 | blink1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1416 | iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1417 | blink2 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1418 | iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1419 | ilink1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1420 | iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1421 | ilink2 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1422 | iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1423 | data1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1424 | iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1425 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1426 | IWL_ERR(priv, |
Jay Sternberg | 8756371 | 2010-06-14 14:40:40 -0700 | [diff] [blame] | 1427 | "%-13s (0x%X) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n", |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1428 | desc_lookup(desc), desc, time, blink1, blink2, |
| 1429 | ilink1, ilink2, data1); |
Johannes Berg | be1a71a | 2009-10-02 13:44:02 -0700 | [diff] [blame] | 1430 | trace_iwlwifi_dev_ucode_error(priv, desc, time, data1, 0, |
| 1431 | 0, blink1, blink2, ilink1, ilink2); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1432 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
Ben Cahill | f58177b | 2007-11-29 11:09:43 +0800 | [diff] [blame] | 1435 | #define EVENT_START_OFFSET (6 * sizeof(u32)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1436 | |
| 1437 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1438 | * iwl3945_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1439 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1440 | */ |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1441 | static int iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx, |
| 1442 | u32 num_events, u32 mode, |
| 1443 | int pos, char **buf, size_t bufsz) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1444 | { |
| 1445 | u32 i; |
| 1446 | u32 base; /* SRAM byte address of event log header */ |
| 1447 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 1448 | u32 ptr; /* SRAM byte address of log data */ |
| 1449 | u32 ev, time, data; /* event log data */ |
Ben Cahill | e585447 | 2009-11-06 14:52:58 -0800 | [diff] [blame] | 1450 | unsigned long reg_flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1451 | |
| 1452 | if (num_events == 0) |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1453 | return pos; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1454 | |
| 1455 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 1456 | |
| 1457 | if (mode == 0) |
| 1458 | event_size = 2 * sizeof(u32); |
| 1459 | else |
| 1460 | event_size = 3 * sizeof(u32); |
| 1461 | |
| 1462 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 1463 | |
Ben Cahill | e585447 | 2009-11-06 14:52:58 -0800 | [diff] [blame] | 1464 | /* Make sure device is powered up for SRAM reads */ |
| 1465 | spin_lock_irqsave(&priv->reg_lock, reg_flags); |
| 1466 | iwl_grab_nic_access(priv); |
| 1467 | |
| 1468 | /* Set starting address; reads will auto-increment */ |
| 1469 | _iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr); |
| 1470 | rmb(); |
| 1471 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1472 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 1473 | * place event id # at far right for easier visual parsing. */ |
| 1474 | for (i = 0; i < num_events; i++) { |
Ben Cahill | e585447 | 2009-11-06 14:52:58 -0800 | [diff] [blame] | 1475 | ev = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
| 1476 | time = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1477 | if (mode == 0) { |
| 1478 | /* data, ev */ |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1479 | if (bufsz) { |
| 1480 | pos += scnprintf(*buf + pos, bufsz - pos, |
| 1481 | "0x%08x:%04u\n", |
| 1482 | time, ev); |
| 1483 | } else { |
| 1484 | IWL_ERR(priv, "0x%08x\t%04u\n", time, ev); |
| 1485 | trace_iwlwifi_dev_ucode_event(priv, 0, |
| 1486 | time, ev); |
| 1487 | } |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1488 | } else { |
Ben Cahill | e585447 | 2009-11-06 14:52:58 -0800 | [diff] [blame] | 1489 | data = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1490 | if (bufsz) { |
| 1491 | pos += scnprintf(*buf + pos, bufsz - pos, |
| 1492 | "%010u:0x%08x:%04u\n", |
| 1493 | time, data, ev); |
| 1494 | } else { |
| 1495 | IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", |
| 1496 | time, data, ev); |
| 1497 | trace_iwlwifi_dev_ucode_event(priv, time, |
| 1498 | data, ev); |
| 1499 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1500 | } |
| 1501 | } |
Ben Cahill | e585447 | 2009-11-06 14:52:58 -0800 | [diff] [blame] | 1502 | |
| 1503 | /* Allow device to power down */ |
| 1504 | iwl_release_nic_access(priv); |
| 1505 | spin_unlock_irqrestore(&priv->reg_lock, reg_flags); |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1506 | return pos; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1509 | /** |
| 1510 | * iwl3945_print_last_event_logs - Dump the newest # of event log to syslog |
| 1511 | */ |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1512 | static int iwl3945_print_last_event_logs(struct iwl_priv *priv, u32 capacity, |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1513 | u32 num_wraps, u32 next_entry, |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1514 | u32 size, u32 mode, |
| 1515 | int pos, char **buf, size_t bufsz) |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1516 | { |
| 1517 | /* |
| 1518 | * display the newest DEFAULT_LOG_ENTRIES entries |
| 1519 | * i.e the entries just before the next ont that uCode would fill. |
| 1520 | */ |
| 1521 | if (num_wraps) { |
| 1522 | if (next_entry < size) { |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1523 | pos = iwl3945_print_event_log(priv, |
| 1524 | capacity - (size - next_entry), |
| 1525 | size - next_entry, mode, |
| 1526 | pos, buf, bufsz); |
| 1527 | pos = iwl3945_print_event_log(priv, 0, |
| 1528 | next_entry, mode, |
| 1529 | pos, buf, bufsz); |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1530 | } else |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1531 | pos = iwl3945_print_event_log(priv, next_entry - size, |
| 1532 | size, mode, |
| 1533 | pos, buf, bufsz); |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1534 | } else { |
| 1535 | if (next_entry < size) |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1536 | pos = iwl3945_print_event_log(priv, 0, |
| 1537 | next_entry, mode, |
| 1538 | pos, buf, bufsz); |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1539 | else |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1540 | pos = iwl3945_print_event_log(priv, next_entry - size, |
| 1541 | size, mode, |
| 1542 | pos, buf, bufsz); |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1543 | } |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1544 | return pos; |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1545 | } |
| 1546 | |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1547 | #define DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES (20) |
| 1548 | |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1549 | int iwl3945_dump_nic_event_log(struct iwl_priv *priv, bool full_log, |
| 1550 | char **buf, bool display) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1551 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1552 | u32 base; /* SRAM byte address of event log header */ |
| 1553 | u32 capacity; /* event log capacity in # entries */ |
| 1554 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 1555 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 1556 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 1557 | u32 size; /* # entries that we'll print */ |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1558 | int pos = 0; |
| 1559 | size_t bufsz = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1560 | |
| 1561 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1562 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1563 | IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base); |
Wey-Yi Guy | 937c397 | 2010-01-15 13:43:36 -0800 | [diff] [blame] | 1564 | return -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1567 | /* event log header */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1568 | capacity = iwl_read_targ_mem(priv, base); |
| 1569 | mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 1570 | num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 1571 | next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1572 | |
Wey-Yi Guy | 678b385 | 2010-03-26 12:54:37 -0700 | [diff] [blame] | 1573 | if (capacity > priv->cfg->max_event_log_size) { |
Ben Cahill | 84c4069 | 2009-11-06 14:52:57 -0800 | [diff] [blame] | 1574 | IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n", |
Wey-Yi Guy | 678b385 | 2010-03-26 12:54:37 -0700 | [diff] [blame] | 1575 | capacity, priv->cfg->max_event_log_size); |
| 1576 | capacity = priv->cfg->max_event_log_size; |
Ben Cahill | 84c4069 | 2009-11-06 14:52:57 -0800 | [diff] [blame] | 1577 | } |
| 1578 | |
Wey-Yi Guy | 678b385 | 2010-03-26 12:54:37 -0700 | [diff] [blame] | 1579 | if (next_entry > priv->cfg->max_event_log_size) { |
Ben Cahill | 84c4069 | 2009-11-06 14:52:57 -0800 | [diff] [blame] | 1580 | IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n", |
Wey-Yi Guy | 678b385 | 2010-03-26 12:54:37 -0700 | [diff] [blame] | 1581 | next_entry, priv->cfg->max_event_log_size); |
| 1582 | next_entry = priv->cfg->max_event_log_size; |
Ben Cahill | 84c4069 | 2009-11-06 14:52:57 -0800 | [diff] [blame] | 1583 | } |
| 1584 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1585 | size = num_wraps ? capacity : next_entry; |
| 1586 | |
| 1587 | /* bail out if nothing in log */ |
| 1588 | if (size == 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1589 | IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n"); |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1590 | return pos; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1591 | } |
| 1592 | |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1593 | #ifdef CONFIG_IWLWIFI_DEBUG |
Wey-Yi Guy | 521d9bc | 2009-12-10 14:37:23 -0800 | [diff] [blame] | 1594 | if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log) |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1595 | size = (size > DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES) |
| 1596 | ? DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES : size; |
| 1597 | #else |
| 1598 | size = (size > DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES) |
| 1599 | ? DEFAULT_IWL3945_DUMP_EVENT_LOG_ENTRIES : size; |
| 1600 | #endif |
| 1601 | |
| 1602 | IWL_ERR(priv, "Start IWL Event Log Dump: display last %d count\n", |
| 1603 | size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1604 | |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1605 | #ifdef CONFIG_IWLWIFI_DEBUG |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1606 | if (display) { |
| 1607 | if (full_log) |
| 1608 | bufsz = capacity * 48; |
| 1609 | else |
| 1610 | bufsz = size * 48; |
| 1611 | *buf = kmalloc(bufsz, GFP_KERNEL); |
| 1612 | if (!*buf) |
Wey-Yi Guy | 937c397 | 2010-01-15 13:43:36 -0800 | [diff] [blame] | 1613 | return -ENOMEM; |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1614 | } |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1615 | if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) { |
| 1616 | /* if uCode has wrapped back to top of log, |
| 1617 | * start at the oldest entry, |
| 1618 | * i.e the next one that uCode would fill. |
| 1619 | */ |
| 1620 | if (num_wraps) |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1621 | pos = iwl3945_print_event_log(priv, next_entry, |
| 1622 | capacity - next_entry, mode, |
| 1623 | pos, buf, bufsz); |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1624 | |
| 1625 | /* (then/else) start at top of log */ |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1626 | pos = iwl3945_print_event_log(priv, 0, next_entry, mode, |
| 1627 | pos, buf, bufsz); |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1628 | } else |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1629 | pos = iwl3945_print_last_event_logs(priv, capacity, num_wraps, |
| 1630 | next_entry, size, mode, |
| 1631 | pos, buf, bufsz); |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 1632 | #else |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1633 | pos = iwl3945_print_last_event_logs(priv, capacity, num_wraps, |
| 1634 | next_entry, size, mode, |
| 1635 | pos, buf, bufsz); |
Reinette Chatre | b7a7940 | 2009-09-25 14:24:23 -0700 | [diff] [blame] | 1636 | #endif |
Wey-Yi Guy | b03d7d0 | 2009-12-14 14:12:20 -0800 | [diff] [blame] | 1637 | return pos; |
Wey-Yi Guy | c341ddb | 2009-11-20 12:05:07 -0800 | [diff] [blame] | 1638 | } |
| 1639 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1640 | static void iwl3945_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1641 | { |
| 1642 | u32 inta, handled = 0; |
| 1643 | u32 inta_fh; |
| 1644 | unsigned long flags; |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 1645 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1646 | u32 inta_mask; |
| 1647 | #endif |
| 1648 | |
| 1649 | spin_lock_irqsave(&priv->lock, flags); |
| 1650 | |
| 1651 | /* Ack/clear/reset pending uCode interrupts. |
| 1652 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 1653 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1654 | inta = iwl_read32(priv, CSR_INT); |
| 1655 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1656 | |
| 1657 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 1658 | * Any new interrupts that happen after this, either while we're |
| 1659 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1660 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 1661 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1662 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 1663 | #ifdef CONFIG_IWLWIFI_DEBUG |
Reinette Chatre | 3d816c7 | 2009-08-07 15:41:37 -0700 | [diff] [blame] | 1664 | if (iwl_get_debug_level(priv) & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1665 | /* just for debug */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1666 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1667 | IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1668 | inta, inta_mask, inta_fh); |
| 1669 | } |
| 1670 | #endif |
| 1671 | |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 1672 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1673 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1674 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 1675 | * atomic, make sure that inta covers all the interrupts that |
| 1676 | * we've discovered, even if FH interrupt came in just after |
| 1677 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 1678 | if (inta_fh & CSR39_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1679 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 1680 | if (inta_fh & CSR39_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1681 | inta |= CSR_INT_BIT_FH_TX; |
| 1682 | |
| 1683 | /* Now service all interrupt bits discovered above. */ |
| 1684 | if (inta & CSR_INT_BIT_HW_ERR) { |
Reinette Chatre | 58dba72 | 2009-07-17 09:30:25 -0700 | [diff] [blame] | 1685 | IWL_ERR(priv, "Hardware error detected. Restarting.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1686 | |
| 1687 | /* Tell the device to stop sending interrupts */ |
Abhijeet Kolekar | ed3b932 | 2009-02-18 15:54:30 -0800 | [diff] [blame] | 1688 | iwl_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1689 | |
Abhijeet Kolekar | 86ddbf6 | 2009-04-20 14:36:59 -0700 | [diff] [blame] | 1690 | priv->isr_stats.hw++; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 1691 | iwl_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1692 | |
| 1693 | handled |= CSR_INT_BIT_HW_ERR; |
| 1694 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1695 | return; |
| 1696 | } |
| 1697 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 1698 | #ifdef CONFIG_IWLWIFI_DEBUG |
Reinette Chatre | 3d816c7 | 2009-08-07 15:41:37 -0700 | [diff] [blame] | 1699 | if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1700 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Abhijeet Kolekar | 86ddbf6 | 2009-04-20 14:36:59 -0700 | [diff] [blame] | 1701 | if (inta & CSR_INT_BIT_SCD) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1702 | IWL_DEBUG_ISR(priv, "Scheduler finished to transmit " |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 1703 | "the frame/frames.\n"); |
Abhijeet Kolekar | 86ddbf6 | 2009-04-20 14:36:59 -0700 | [diff] [blame] | 1704 | priv->isr_stats.sch++; |
| 1705 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1706 | |
| 1707 | /* Alive notification via Rx interrupt will do the real work */ |
Abhijeet Kolekar | 86ddbf6 | 2009-04-20 14:36:59 -0700 | [diff] [blame] | 1708 | if (inta & CSR_INT_BIT_ALIVE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1709 | IWL_DEBUG_ISR(priv, "Alive interrupt\n"); |
Abhijeet Kolekar | 86ddbf6 | 2009-04-20 14:36:59 -0700 | [diff] [blame] | 1710 | priv->isr_stats.alive++; |
| 1711 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1712 | } |
| 1713 | #endif |
| 1714 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 1715 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1716 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1717 | /* Error detected by uCode */ |
| 1718 | if (inta & CSR_INT_BIT_SW_ERR) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1719 | IWL_ERR(priv, "Microcode SW error detected. " |
| 1720 | "Restarting 0x%X.\n", inta); |
Abhijeet Kolekar | 86ddbf6 | 2009-04-20 14:36:59 -0700 | [diff] [blame] | 1721 | priv->isr_stats.sw++; |
| 1722 | priv->isr_stats.sw_err = inta; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 1723 | iwl_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1724 | handled |= CSR_INT_BIT_SW_ERR; |
| 1725 | } |
| 1726 | |
| 1727 | /* uCode wakes up after power-down sleep */ |
| 1728 | if (inta & CSR_INT_BIT_WAKEUP) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1729 | IWL_DEBUG_ISR(priv, "Wakeup interrupt\n"); |
Winkler, Tomas | 141c43a | 2009-01-08 10:19:53 -0800 | [diff] [blame] | 1730 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Samuel Ortiz | 4f3602c | 2009-01-19 15:30:25 -0800 | [diff] [blame] | 1731 | iwl_txq_update_write_ptr(priv, &priv->txq[0]); |
| 1732 | iwl_txq_update_write_ptr(priv, &priv->txq[1]); |
| 1733 | iwl_txq_update_write_ptr(priv, &priv->txq[2]); |
| 1734 | iwl_txq_update_write_ptr(priv, &priv->txq[3]); |
| 1735 | iwl_txq_update_write_ptr(priv, &priv->txq[4]); |
| 1736 | iwl_txq_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1737 | |
Abhijeet Kolekar | 86ddbf6 | 2009-04-20 14:36:59 -0700 | [diff] [blame] | 1738 | priv->isr_stats.wakeup++; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1739 | handled |= CSR_INT_BIT_WAKEUP; |
| 1740 | } |
| 1741 | |
| 1742 | /* All uCode command responses, including Tx command responses, |
| 1743 | * Rx "responses" (frame-received notification), and other |
| 1744 | * notifications from uCode come through here*/ |
| 1745 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1746 | iwl3945_rx_handle(priv); |
Abhijeet Kolekar | 86ddbf6 | 2009-04-20 14:36:59 -0700 | [diff] [blame] | 1747 | priv->isr_stats.rx++; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1748 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 1749 | } |
| 1750 | |
| 1751 | if (inta & CSR_INT_BIT_FH_TX) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1752 | IWL_DEBUG_ISR(priv, "Tx interrupt\n"); |
Abhijeet Kolekar | 86ddbf6 | 2009-04-20 14:36:59 -0700 | [diff] [blame] | 1753 | priv->isr_stats.tx++; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1754 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1755 | iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6)); |
Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 1756 | iwl_write_direct32(priv, FH39_TCSR_CREDIT |
| 1757 | (FH39_SRVC_CHNL), 0x0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1758 | handled |= CSR_INT_BIT_FH_TX; |
| 1759 | } |
| 1760 | |
Abhijeet Kolekar | 86ddbf6 | 2009-04-20 14:36:59 -0700 | [diff] [blame] | 1761 | if (inta & ~handled) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1762 | IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled); |
Abhijeet Kolekar | 86ddbf6 | 2009-04-20 14:36:59 -0700 | [diff] [blame] | 1763 | priv->isr_stats.unhandled++; |
| 1764 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1765 | |
Mohamed Abbas | 40cefda | 2009-05-22 11:01:52 -0700 | [diff] [blame] | 1766 | if (inta & ~priv->inta_mask) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1767 | IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n", |
Mohamed Abbas | 40cefda | 2009-05-22 11:01:52 -0700 | [diff] [blame] | 1768 | inta & ~priv->inta_mask); |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1769 | IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 1773 | /* only Re-enable if disabled by irq */ |
| 1774 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
Abhijeet Kolekar | ed3b932 | 2009-02-18 15:54:30 -0800 | [diff] [blame] | 1775 | iwl_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1776 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 1777 | #ifdef CONFIG_IWLWIFI_DEBUG |
Reinette Chatre | 3d816c7 | 2009-08-07 15:41:37 -0700 | [diff] [blame] | 1778 | if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1779 | inta = iwl_read32(priv, CSR_INT); |
| 1780 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 1781 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1782 | IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1783 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 1784 | } |
| 1785 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
Abhijeet Kolekar | 1402364 | 2010-06-02 21:15:10 -0700 | [diff] [blame] | 1788 | static int iwl3945_get_single_channel_for_scan(struct iwl_priv *priv, |
| 1789 | struct ieee80211_vif *vif, |
| 1790 | enum ieee80211_band band, |
| 1791 | struct iwl3945_scan_channel *scan_ch) |
| 1792 | { |
| 1793 | const struct ieee80211_supported_band *sband; |
| 1794 | u16 passive_dwell = 0; |
| 1795 | u16 active_dwell = 0; |
| 1796 | int added = 0; |
| 1797 | u8 channel = 0; |
| 1798 | |
| 1799 | sband = iwl_get_hw_mode(priv, band); |
| 1800 | if (!sband) { |
| 1801 | IWL_ERR(priv, "invalid band\n"); |
| 1802 | return added; |
| 1803 | } |
| 1804 | |
| 1805 | active_dwell = iwl_get_active_dwell_time(priv, band, 0); |
| 1806 | passive_dwell = iwl_get_passive_dwell_time(priv, band, vif); |
| 1807 | |
| 1808 | if (passive_dwell <= active_dwell) |
| 1809 | passive_dwell = active_dwell + 1; |
| 1810 | |
| 1811 | |
| 1812 | channel = iwl_get_single_channel_number(priv, band); |
| 1813 | |
| 1814 | if (channel) { |
| 1815 | scan_ch->channel = channel; |
| 1816 | scan_ch->type = 0; /* passive */ |
| 1817 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 1818 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 1819 | /* Set txpower levels to defaults */ |
| 1820 | scan_ch->tpc.dsp_atten = 110; |
| 1821 | if (band == IEEE80211_BAND_5GHZ) |
| 1822 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 1823 | else |
| 1824 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 1825 | added++; |
| 1826 | } else |
| 1827 | IWL_ERR(priv, "no valid channel found\n"); |
| 1828 | return added; |
| 1829 | } |
| 1830 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1831 | static int iwl3945_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1832 | enum ieee80211_band band, |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 1833 | u8 is_active, u8 n_probes, |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 1834 | struct iwl3945_scan_channel *scan_ch, |
| 1835 | struct ieee80211_vif *vif) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1836 | { |
Johannes Berg | 4e05c23 | 2009-06-19 13:52:44 -0700 | [diff] [blame] | 1837 | struct ieee80211_channel *chan; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1838 | const struct ieee80211_supported_band *sband; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 1839 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1840 | u16 passive_dwell = 0; |
| 1841 | u16 active_dwell = 0; |
| 1842 | int added, i; |
| 1843 | |
Kolekar, Abhijeet | cbba18c | 2008-12-19 10:37:42 +0800 | [diff] [blame] | 1844 | sband = iwl_get_hw_mode(priv, band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1845 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1846 | return 0; |
| 1847 | |
Samuel Ortiz | 77fecfb8 | 2009-01-23 13:45:12 -0800 | [diff] [blame] | 1848 | active_dwell = iwl_get_active_dwell_time(priv, band, n_probes); |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 1849 | passive_dwell = iwl_get_passive_dwell_time(priv, band, vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1850 | |
Abhijeet Kolekar | 8f4807a | 2008-09-03 11:26:31 +0800 | [diff] [blame] | 1851 | if (passive_dwell <= active_dwell) |
| 1852 | passive_dwell = active_dwell + 1; |
| 1853 | |
Johannes Berg | 4e05c23 | 2009-06-19 13:52:44 -0700 | [diff] [blame] | 1854 | for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) { |
| 1855 | chan = priv->scan_request->channels[i]; |
| 1856 | |
| 1857 | if (chan->band != band) |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 1858 | continue; |
| 1859 | |
Johannes Berg | 4e05c23 | 2009-06-19 13:52:44 -0700 | [diff] [blame] | 1860 | scan_ch->channel = chan->hw_value; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1861 | |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 1862 | ch_info = iwl_get_channel_info(priv, band, scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1863 | if (!is_channel_valid(ch_info)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1864 | IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1865 | scan_ch->channel); |
| 1866 | continue; |
| 1867 | } |
| 1868 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1869 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 1870 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
Abhijeet Kolekar | 011a033 | 2008-12-02 12:14:07 -0800 | [diff] [blame] | 1871 | /* If passive , set up for auto-switch |
| 1872 | * and use long active_dwell time. |
| 1873 | */ |
| 1874 | if (!is_active || is_channel_passive(ch_info) || |
Johannes Berg | 4e05c23 | 2009-06-19 13:52:44 -0700 | [diff] [blame] | 1875 | (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)) { |
Abhijeet Kolekar | 011a033 | 2008-12-02 12:14:07 -0800 | [diff] [blame] | 1876 | scan_ch->type = 0; /* passive */ |
| 1877 | if (IWL_UCODE_API(priv->ucode_ver) == 1) |
| 1878 | scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1); |
| 1879 | } else { |
| 1880 | scan_ch->type = 1; /* active */ |
| 1881 | } |
| 1882 | |
| 1883 | /* Set direct probe bits. These may be used both for active |
| 1884 | * scan channels (probes gets sent right away), |
| 1885 | * or for passive channels (probes get se sent only after |
| 1886 | * hearing clear Rx packet).*/ |
| 1887 | if (IWL_UCODE_API(priv->ucode_ver) >= 2) { |
| 1888 | if (n_probes) |
Winkler, Tomas | 0d21044 | 2009-01-23 13:45:21 -0800 | [diff] [blame] | 1889 | scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes); |
Abhijeet Kolekar | 011a033 | 2008-12-02 12:14:07 -0800 | [diff] [blame] | 1890 | } else { |
| 1891 | /* uCode v1 does not allow setting direct probe bits on |
| 1892 | * passive channel. */ |
| 1893 | if ((scan_ch->type & 1) && n_probes) |
Winkler, Tomas | 0d21044 | 2009-01-23 13:45:21 -0800 | [diff] [blame] | 1894 | scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes); |
Abhijeet Kolekar | 011a033 | 2008-12-02 12:14:07 -0800 | [diff] [blame] | 1895 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1896 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1897 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1898 | scan_ch->tpc.dsp_atten = 110; |
| 1899 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 1900 | |
| 1901 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1902 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1903 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 1904 | else { |
| 1905 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 1906 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1907 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 1908 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1909 | */ |
| 1910 | } |
| 1911 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1912 | IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1913 | scan_ch->channel, |
| 1914 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 1915 | (scan_ch->type & 1) ? |
| 1916 | active_dwell : passive_dwell); |
| 1917 | |
| 1918 | scan_ch++; |
| 1919 | added++; |
| 1920 | } |
| 1921 | |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 1922 | IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1923 | return added; |
| 1924 | } |
| 1925 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1926 | static void iwl3945_init_hw_rates(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1927 | struct ieee80211_rate *rates) |
| 1928 | { |
| 1929 | int i; |
| 1930 | |
Dan Carpenter | 8e1a53c | 2010-03-28 14:55:00 +0300 | [diff] [blame] | 1931 | for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1932 | rates[i].bitrate = iwl3945_rates[i].ieee * 5; |
| 1933 | rates[i].hw_value = i; /* Rate scaling will work on indexes */ |
| 1934 | rates[i].hw_value_short = i; |
| 1935 | rates[i].flags = 0; |
Samuel Ortiz | d9829a6 | 2008-12-19 10:37:12 +0800 | [diff] [blame] | 1936 | if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1937 | /* |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1938 | * If CCK != 1M then set short preamble rate flag. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1939 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1940 | rates[i].flags |= (iwl3945_rates[i].plcp == 10) ? |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1941 | 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1942 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1943 | } |
| 1944 | } |
| 1945 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1946 | /****************************************************************************** |
| 1947 | * |
| 1948 | * uCode download functions |
| 1949 | * |
| 1950 | ******************************************************************************/ |
| 1951 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1952 | static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1953 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 1954 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 1955 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 1956 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 1957 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 1958 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 1959 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1960 | } |
| 1961 | |
| 1962 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1963 | * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1964 | * looking at all data. |
| 1965 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1966 | static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1967 | { |
| 1968 | u32 val; |
| 1969 | u32 save_len = len; |
| 1970 | int rc = 0; |
| 1971 | u32 errcnt; |
| 1972 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1973 | IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1974 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1975 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 1976 | IWL39_RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1977 | |
| 1978 | errcnt = 0; |
| 1979 | for (; len > 0; len -= sizeof(u32), image++) { |
| 1980 | /* read data comes through single port, auto-incr addr */ |
| 1981 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 1982 | * if IWL_DL_IO is set */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1983 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1984 | if (val != le32_to_cpu(*image)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1985 | IWL_ERR(priv, "uCode INST section is invalid at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1986 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 1987 | save_len - len, val, le32_to_cpu(*image)); |
| 1988 | rc = -EIO; |
| 1989 | errcnt++; |
| 1990 | if (errcnt >= 20) |
| 1991 | break; |
| 1992 | } |
| 1993 | } |
| 1994 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1995 | |
| 1996 | if (!errcnt) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1997 | IWL_DEBUG_INFO(priv, |
| 1998 | "ucode image in INSTRUCTION memory is good\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1999 | |
| 2000 | return rc; |
| 2001 | } |
| 2002 | |
| 2003 | |
| 2004 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2005 | * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2006 | * using sample data 100 bytes apart. If these sample points are good, |
| 2007 | * it's a pretty good bet that everything between them is good, too. |
| 2008 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2009 | static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2010 | { |
| 2011 | u32 val; |
| 2012 | int rc = 0; |
| 2013 | u32 errcnt = 0; |
| 2014 | u32 i; |
| 2015 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2016 | IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2017 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2018 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 2019 | /* read data comes through single port, auto-incr addr */ |
| 2020 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 2021 | * if IWL_DL_IO is set */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2022 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 2023 | i + IWL39_RTC_INST_LOWER_BOUND); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2024 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2025 | if (val != le32_to_cpu(*image)) { |
| 2026 | #if 0 /* Enable this if you want to see details */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2027 | IWL_ERR(priv, "uCode INST section is invalid at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2028 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 2029 | i, val, *image); |
| 2030 | #endif |
| 2031 | rc = -EIO; |
| 2032 | errcnt++; |
| 2033 | if (errcnt >= 3) |
| 2034 | break; |
| 2035 | } |
| 2036 | } |
| 2037 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2038 | return rc; |
| 2039 | } |
| 2040 | |
| 2041 | |
| 2042 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2043 | * iwl3945_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2044 | * and verify its contents |
| 2045 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2046 | static int iwl3945_verify_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2047 | { |
| 2048 | __le32 *image; |
| 2049 | u32 len; |
| 2050 | int rc = 0; |
| 2051 | |
| 2052 | /* Try bootstrap */ |
| 2053 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 2054 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2055 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2056 | if (rc == 0) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2057 | IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2058 | return 0; |
| 2059 | } |
| 2060 | |
| 2061 | /* Try initialize */ |
| 2062 | image = (__le32 *)priv->ucode_init.v_addr; |
| 2063 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2064 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2065 | if (rc == 0) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2066 | IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2067 | return 0; |
| 2068 | } |
| 2069 | |
| 2070 | /* Try runtime/protocol */ |
| 2071 | image = (__le32 *)priv->ucode_code.v_addr; |
| 2072 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2073 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2074 | if (rc == 0) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2075 | IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2076 | return 0; |
| 2077 | } |
| 2078 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2079 | IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2080 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2081 | /* Since nothing seems to match, show first several data entries in |
| 2082 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 2083 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2084 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 2085 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2086 | rc = iwl3945_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2087 | |
| 2088 | return rc; |
| 2089 | } |
| 2090 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2091 | static void iwl3945_nic_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2092 | { |
| 2093 | /* Remove all resets to allow NIC to operate */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2094 | iwl_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
Johannes Berg | 93b1a2f | 2010-04-28 12:09:13 -0700 | [diff] [blame] | 2097 | #define IWL3945_UCODE_GET(item) \ |
| 2098 | static u32 iwl3945_ucode_get_##item(const struct iwl_ucode_header *ucode)\ |
| 2099 | { \ |
| 2100 | return le32_to_cpu(ucode->u.v1.item); \ |
| 2101 | } |
| 2102 | |
| 2103 | static u32 iwl3945_ucode_get_header_size(u32 api_ver) |
| 2104 | { |
Johannes Berg | 22adba2 | 2010-04-28 12:09:14 -0700 | [diff] [blame] | 2105 | return 24; |
Johannes Berg | 93b1a2f | 2010-04-28 12:09:13 -0700 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | static u8 *iwl3945_ucode_get_data(const struct iwl_ucode_header *ucode) |
| 2109 | { |
| 2110 | return (u8 *) ucode->u.v1.data; |
| 2111 | } |
| 2112 | |
| 2113 | IWL3945_UCODE_GET(inst_size); |
| 2114 | IWL3945_UCODE_GET(data_size); |
| 2115 | IWL3945_UCODE_GET(init_size); |
| 2116 | IWL3945_UCODE_GET(init_data_size); |
| 2117 | IWL3945_UCODE_GET(boot_size); |
| 2118 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2119 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2120 | * iwl3945_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2121 | * |
| 2122 | * Copy into buffers for card to fetch via bus-mastering |
| 2123 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2124 | static int iwl3945_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2125 | { |
Jay Sternberg | cc0f555 | 2009-07-17 09:30:16 -0700 | [diff] [blame] | 2126 | const struct iwl_ucode_header *ucode; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2127 | int ret = -EINVAL, index; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2128 | const struct firmware *ucode_raw; |
| 2129 | /* firmware file name contains uCode/driver compatibility version */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2130 | const char *name_pre = priv->cfg->fw_name_pre; |
| 2131 | const unsigned int api_max = priv->cfg->ucode_api_max; |
| 2132 | const unsigned int api_min = priv->cfg->ucode_api_min; |
| 2133 | char buf[25]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2134 | u8 *src; |
| 2135 | size_t len; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2136 | u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2137 | |
| 2138 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 2139 | * request_firmware() is synchronous, file is in memory on return. */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2140 | for (index = api_max; index >= api_min; index--) { |
| 2141 | sprintf(buf, "%s%u%s", name_pre, index, ".ucode"); |
| 2142 | ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev); |
| 2143 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2144 | IWL_ERR(priv, "%s firmware file req failed: %d\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2145 | buf, ret); |
| 2146 | if (ret == -ENOENT) |
| 2147 | continue; |
| 2148 | else |
| 2149 | goto error; |
| 2150 | } else { |
| 2151 | if (index < api_max) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2152 | IWL_ERR(priv, "Loaded firmware %s, " |
| 2153 | "which is deprecated. " |
| 2154 | " Please use API v%u instead.\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2155 | buf, api_max); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2156 | IWL_DEBUG_INFO(priv, "Got firmware '%s' file " |
| 2157 | "(%zd bytes) from disk\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2158 | buf, ucode_raw->size); |
| 2159 | break; |
| 2160 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2161 | } |
| 2162 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2163 | if (ret < 0) |
| 2164 | goto error; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2165 | |
| 2166 | /* Make sure that we got at least our header! */ |
Johannes Berg | 93b1a2f | 2010-04-28 12:09:13 -0700 | [diff] [blame] | 2167 | if (ucode_raw->size < iwl3945_ucode_get_header_size(1)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2168 | IWL_ERR(priv, "File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2169 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2170 | goto err_release; |
| 2171 | } |
| 2172 | |
| 2173 | /* Data from ucode file: header followed by uCode images */ |
Jay Sternberg | cc0f555 | 2009-07-17 09:30:16 -0700 | [diff] [blame] | 2174 | ucode = (struct iwl_ucode_header *)ucode_raw->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2175 | |
Chatre, Reinette | c02b3ac | 2008-12-02 12:14:05 -0800 | [diff] [blame] | 2176 | priv->ucode_ver = le32_to_cpu(ucode->ver); |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2177 | api_ver = IWL_UCODE_API(priv->ucode_ver); |
Johannes Berg | 93b1a2f | 2010-04-28 12:09:13 -0700 | [diff] [blame] | 2178 | inst_size = iwl3945_ucode_get_inst_size(ucode); |
| 2179 | data_size = iwl3945_ucode_get_data_size(ucode); |
| 2180 | init_size = iwl3945_ucode_get_init_size(ucode); |
| 2181 | init_data_size = iwl3945_ucode_get_init_data_size(ucode); |
| 2182 | boot_size = iwl3945_ucode_get_boot_size(ucode); |
| 2183 | src = iwl3945_ucode_get_data(ucode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2184 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2185 | /* api_ver should match the api version forming part of the |
| 2186 | * firmware filename ... but we don't check for that and only rely |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 2187 | * on the API version read from firmware header from here on forward */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2188 | |
| 2189 | if (api_ver < api_min || api_ver > api_max) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2190 | IWL_ERR(priv, "Driver unable to support your firmware API. " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2191 | "Driver supports v%u, firmware is v%u.\n", |
| 2192 | api_max, api_ver); |
| 2193 | priv->ucode_ver = 0; |
| 2194 | ret = -EINVAL; |
| 2195 | goto err_release; |
| 2196 | } |
| 2197 | if (api_ver != api_max) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2198 | IWL_ERR(priv, "Firmware has old API version. Expected %u, " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2199 | "got %u. New firmware can be obtained " |
| 2200 | "from http://www.intellinuxwireless.org.\n", |
| 2201 | api_max, api_ver); |
| 2202 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 2203 | IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n", |
| 2204 | IWL_UCODE_MAJOR(priv->ucode_ver), |
| 2205 | IWL_UCODE_MINOR(priv->ucode_ver), |
| 2206 | IWL_UCODE_API(priv->ucode_ver), |
| 2207 | IWL_UCODE_SERIAL(priv->ucode_ver)); |
| 2208 | |
Reinette Chatre | 5ebeb5a | 2009-10-30 14:36:04 -0700 | [diff] [blame] | 2209 | snprintf(priv->hw->wiphy->fw_version, |
| 2210 | sizeof(priv->hw->wiphy->fw_version), |
| 2211 | "%u.%u.%u.%u", |
| 2212 | IWL_UCODE_MAJOR(priv->ucode_ver), |
| 2213 | IWL_UCODE_MINOR(priv->ucode_ver), |
| 2214 | IWL_UCODE_API(priv->ucode_ver), |
| 2215 | IWL_UCODE_SERIAL(priv->ucode_ver)); |
| 2216 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2217 | IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2218 | priv->ucode_ver); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2219 | IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n", |
| 2220 | inst_size); |
| 2221 | IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n", |
| 2222 | data_size); |
| 2223 | IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n", |
| 2224 | init_size); |
| 2225 | IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n", |
| 2226 | init_data_size); |
| 2227 | IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n", |
| 2228 | boot_size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2229 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2230 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2231 | /* Verify size of file vs. image size info in file's header */ |
Johannes Berg | 93b1a2f | 2010-04-28 12:09:13 -0700 | [diff] [blame] | 2232 | if (ucode_raw->size != iwl3945_ucode_get_header_size(api_ver) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2233 | inst_size + data_size + init_size + |
| 2234 | init_data_size + boot_size) { |
| 2235 | |
Jay Sternberg | cc0f555 | 2009-07-17 09:30:16 -0700 | [diff] [blame] | 2236 | IWL_DEBUG_INFO(priv, |
| 2237 | "uCode file size %zd does not match expected size\n", |
| 2238 | ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2239 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2240 | goto err_release; |
| 2241 | } |
| 2242 | |
| 2243 | /* Verify that uCode images will fit in card's SRAM */ |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 2244 | if (inst_size > IWL39_MAX_INST_SIZE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2245 | IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n", |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2246 | inst_size); |
| 2247 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2248 | goto err_release; |
| 2249 | } |
| 2250 | |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 2251 | if (data_size > IWL39_MAX_DATA_SIZE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2252 | IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n", |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2253 | data_size); |
| 2254 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2255 | goto err_release; |
| 2256 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 2257 | if (init_size > IWL39_MAX_INST_SIZE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2258 | IWL_DEBUG_INFO(priv, |
| 2259 | "uCode init instr len %d too large to fit in\n", |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2260 | init_size); |
| 2261 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2262 | goto err_release; |
| 2263 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 2264 | if (init_data_size > IWL39_MAX_DATA_SIZE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2265 | IWL_DEBUG_INFO(priv, |
| 2266 | "uCode init data len %d too large to fit in\n", |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2267 | init_data_size); |
| 2268 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2269 | goto err_release; |
| 2270 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 2271 | if (boot_size > IWL39_MAX_BSM_SIZE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2272 | IWL_DEBUG_INFO(priv, |
| 2273 | "uCode boot instr len %d too large to fit in\n", |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2274 | boot_size); |
| 2275 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2276 | goto err_release; |
| 2277 | } |
| 2278 | |
| 2279 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 2280 | |
| 2281 | /* Runtime instructions and 2 copies of data: |
| 2282 | * 1) unmodified from disk |
| 2283 | * 2) backup cache for save/restore during power-downs */ |
| 2284 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2285 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2286 | |
| 2287 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2288 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2289 | |
| 2290 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2291 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2292 | |
| 2293 | if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr || |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2294 | !priv->ucode_data_backup.v_addr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2295 | goto err_pci_alloc; |
| 2296 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2297 | /* Initialization instructions and data */ |
| 2298 | if (init_size && init_data_size) { |
| 2299 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2300 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2301 | |
| 2302 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2303 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2304 | |
| 2305 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 2306 | goto err_pci_alloc; |
| 2307 | } |
| 2308 | |
| 2309 | /* Bootstrap (instructions only, no data) */ |
| 2310 | if (boot_size) { |
| 2311 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2312 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2313 | |
| 2314 | if (!priv->ucode_boot.v_addr) |
| 2315 | goto err_pci_alloc; |
| 2316 | } |
| 2317 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2318 | /* Copy images into buffers for card's bus-master reads ... */ |
| 2319 | |
| 2320 | /* Runtime instructions (first block of data in file) */ |
Jay Sternberg | cc0f555 | 2009-07-17 09:30:16 -0700 | [diff] [blame] | 2321 | len = inst_size; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2322 | IWL_DEBUG_INFO(priv, |
| 2323 | "Copying (but not loading) uCode instr len %zd\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2324 | memcpy(priv->ucode_code.v_addr, src, len); |
Jay Sternberg | cc0f555 | 2009-07-17 09:30:16 -0700 | [diff] [blame] | 2325 | src += len; |
| 2326 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2327 | IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2328 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 2329 | |
| 2330 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2331 | * NOTE: Copy into backup buffer will be done in iwl3945_up() */ |
Jay Sternberg | cc0f555 | 2009-07-17 09:30:16 -0700 | [diff] [blame] | 2332 | len = data_size; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2333 | IWL_DEBUG_INFO(priv, |
| 2334 | "Copying (but not loading) uCode data len %zd\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2335 | memcpy(priv->ucode_data.v_addr, src, len); |
| 2336 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
Jay Sternberg | cc0f555 | 2009-07-17 09:30:16 -0700 | [diff] [blame] | 2337 | src += len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2338 | |
| 2339 | /* Initialization instructions (3rd block) */ |
| 2340 | if (init_size) { |
Jay Sternberg | cc0f555 | 2009-07-17 09:30:16 -0700 | [diff] [blame] | 2341 | len = init_size; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2342 | IWL_DEBUG_INFO(priv, |
| 2343 | "Copying (but not loading) init instr len %zd\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2344 | memcpy(priv->ucode_init.v_addr, src, len); |
Jay Sternberg | cc0f555 | 2009-07-17 09:30:16 -0700 | [diff] [blame] | 2345 | src += len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | /* Initialization data (4th block) */ |
| 2349 | if (init_data_size) { |
Jay Sternberg | cc0f555 | 2009-07-17 09:30:16 -0700 | [diff] [blame] | 2350 | len = init_data_size; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2351 | IWL_DEBUG_INFO(priv, |
| 2352 | "Copying (but not loading) init data len %zd\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2353 | memcpy(priv->ucode_init_data.v_addr, src, len); |
Jay Sternberg | cc0f555 | 2009-07-17 09:30:16 -0700 | [diff] [blame] | 2354 | src += len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | /* Bootstrap instructions (5th block) */ |
Jay Sternberg | cc0f555 | 2009-07-17 09:30:16 -0700 | [diff] [blame] | 2358 | len = boot_size; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2359 | IWL_DEBUG_INFO(priv, |
| 2360 | "Copying (but not loading) boot instr len %zd\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2361 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 2362 | |
| 2363 | /* We have our copies now, allow OS release its copies */ |
| 2364 | release_firmware(ucode_raw); |
| 2365 | return 0; |
| 2366 | |
| 2367 | err_pci_alloc: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2368 | IWL_ERR(priv, "failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2369 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2370 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2371 | |
| 2372 | err_release: |
| 2373 | release_firmware(ucode_raw); |
| 2374 | |
| 2375 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2376 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2377 | } |
| 2378 | |
| 2379 | |
| 2380 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2381 | * iwl3945_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2382 | * |
| 2383 | * Tell initialization uCode where to find runtime uCode. |
| 2384 | * |
| 2385 | * BSM registers initially contain pointers to initialization uCode. |
| 2386 | * We need to replace them to load runtime uCode inst and data, |
| 2387 | * and to save runtime data when powering down. |
| 2388 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2389 | static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2390 | { |
| 2391 | dma_addr_t pinst; |
| 2392 | dma_addr_t pdata; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2393 | |
| 2394 | /* bits 31:0 for 3945 */ |
| 2395 | pinst = priv->ucode_code.p_addr; |
| 2396 | pdata = priv->ucode_data_backup.p_addr; |
| 2397 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2398 | /* Tell bootstrap uCode where to find image to load */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2399 | iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 2400 | iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 2401 | iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2402 | priv->ucode_data.len); |
| 2403 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 2404 | /* Inst byte count must be last to set up, bit 31 signals uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2405 | * that all new ptr/size info is in place */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2406 | iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2407 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 2408 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2409 | IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2410 | |
Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 2411 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2415 | * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2416 | * |
| 2417 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 2418 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2419 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2420 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2421 | static void iwl3945_init_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2422 | { |
| 2423 | /* Check alive response for "valid" sign from uCode */ |
| 2424 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 2425 | /* We had an error bringing up the hardware, so take it |
| 2426 | * all the way back down so we can try again */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2427 | IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2428 | goto restart; |
| 2429 | } |
| 2430 | |
| 2431 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 2432 | * This is a paranoid check, because we would not have gotten the |
| 2433 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2434 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2435 | /* Runtime instruction load was bad; |
| 2436 | * take it all the way back down so we can try again */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2437 | IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2438 | goto restart; |
| 2439 | } |
| 2440 | |
| 2441 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 2442 | * load and launch runtime uCode, which will send us another "Alive" |
| 2443 | * notification. */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2444 | IWL_DEBUG_INFO(priv, "Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2445 | if (iwl3945_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2446 | /* Runtime instruction load won't happen; |
| 2447 | * take it all the way back down so we can try again */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2448 | IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2449 | goto restart; |
| 2450 | } |
| 2451 | return; |
| 2452 | |
| 2453 | restart: |
| 2454 | queue_work(priv->workqueue, &priv->restart); |
| 2455 | } |
| 2456 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2457 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2458 | * iwl3945_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2459 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2460 | * Alive gets handled by iwl3945_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2461 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2462 | static void iwl3945_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2463 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2464 | int thermal_spin = 0; |
| 2465 | u32 rfkill; |
| 2466 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2467 | IWL_DEBUG_INFO(priv, "Runtime Alive received.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2468 | |
| 2469 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 2470 | /* We had an error bringing up the hardware, so take it |
| 2471 | * all the way back down so we can try again */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2472 | IWL_DEBUG_INFO(priv, "Alive failed.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2473 | goto restart; |
| 2474 | } |
| 2475 | |
| 2476 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 2477 | * This is a paranoid check, because we would not have gotten the |
| 2478 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2479 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2480 | /* Runtime instruction load was bad; |
| 2481 | * take it all the way back down so we can try again */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2482 | IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2483 | goto restart; |
| 2484 | } |
| 2485 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2486 | rfkill = iwl_read_prph(priv, APMG_RFKILL_REG); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2487 | IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2488 | |
| 2489 | if (rfkill & 0x1) { |
| 2490 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 2491 | /* if RFKILL is not on, then wait for thermal |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2492 | * sensor in adapter to kick in */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2493 | while (iwl3945_hw_get_temperature(priv) == 0) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2494 | thermal_spin++; |
| 2495 | udelay(10); |
| 2496 | } |
| 2497 | |
| 2498 | if (thermal_spin) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2499 | IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2500 | thermal_spin * 10); |
| 2501 | } else |
| 2502 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2503 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2504 | /* After the ALIVE response, we can send commands to 3945 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2505 | set_bit(STATUS_ALIVE, &priv->status); |
| 2506 | |
Wey-Yi Guy | b74e31a | 2010-03-01 17:23:50 -0800 | [diff] [blame] | 2507 | if (priv->cfg->ops->lib->recover_from_tx_stall) { |
| 2508 | /* Enable timer to monitor the driver queues */ |
| 2509 | mod_timer(&priv->monitor_recover, |
| 2510 | jiffies + |
| 2511 | msecs_to_jiffies(priv->cfg->monitor_recover_period)); |
| 2512 | } |
| 2513 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 2514 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2515 | return; |
| 2516 | |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 2517 | ieee80211_wake_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2518 | |
Johannes Berg | 470ab2d | 2010-01-21 11:23:30 -0800 | [diff] [blame] | 2519 | priv->active_rate = IWL_RATES_MASK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2520 | |
Ben Cahill | 4d6ccbf | 2009-11-13 11:56:29 -0800 | [diff] [blame] | 2521 | iwl_power_update_mode(priv, true); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2522 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 2523 | if (iwl_is_associated(priv)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2524 | struct iwl3945_rxon_cmd *active_rxon = |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 2525 | (struct iwl3945_rxon_cmd *)(&priv->active_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2526 | |
Abhijeet Kolekar | 8a9b992 | 2009-06-12 13:22:52 -0700 | [diff] [blame] | 2527 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2528 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 2529 | } else { |
| 2530 | /* Initialize our rx_config data */ |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 2531 | iwl_connection_init_rx_config(priv, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2532 | } |
| 2533 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2534 | /* Configure Bluetooth device coexistence support */ |
Johannes Berg | 65b52bd | 2010-04-13 01:04:31 -0700 | [diff] [blame] | 2535 | priv->cfg->ops->hcmd->send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2536 | |
| 2537 | /* Configure the adapter for unassociated operation */ |
Abhijeet Kolekar | e0158e6 | 2009-04-08 11:26:37 -0700 | [diff] [blame] | 2538 | iwlcore_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2539 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2540 | iwl3945_reg_txpower_periodic(priv); |
| 2541 | |
Johannes Berg | e932a60 | 2009-10-02 13:44:03 -0700 | [diff] [blame] | 2542 | iwl_leds_init(priv); |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 2543 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2544 | IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 2545 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2546 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2547 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2548 | return; |
| 2549 | |
| 2550 | restart: |
| 2551 | queue_work(priv->workqueue, &priv->restart); |
| 2552 | } |
| 2553 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2554 | static void iwl3945_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2555 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2556 | static void __iwl3945_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2557 | { |
| 2558 | unsigned long flags; |
| 2559 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 2560 | struct ieee80211_conf *conf = NULL; |
| 2561 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2562 | IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2563 | |
| 2564 | conf = ieee80211_get_hw_conf(priv->hw); |
| 2565 | |
| 2566 | if (!exit_pending) |
| 2567 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 2568 | |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 2569 | /* Station information will now be cleared in device */ |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 2570 | iwl_clear_ucode_stations(priv); |
| 2571 | iwl_dealloc_bcast_station(priv); |
Johannes Berg | db125c7 | 2010-05-07 01:49:15 -0700 | [diff] [blame] | 2572 | iwl_clear_driver_stations(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2573 | |
| 2574 | /* Unblock any waiting calls */ |
| 2575 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 2576 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2577 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 2578 | * exiting the module */ |
| 2579 | if (!exit_pending) |
| 2580 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 2581 | |
| 2582 | /* stop and reset the on-board processor */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2583 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2584 | |
| 2585 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2586 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | ed3b932 | 2009-02-18 15:54:30 -0800 | [diff] [blame] | 2587 | iwl_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2588 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2589 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2590 | |
| 2591 | if (priv->mac80211_registered) |
| 2592 | ieee80211_stop_queues(priv->hw); |
| 2593 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2594 | /* If we have not previously called iwl3945_init() then |
Wey-Yi Guy | 6da3a13 | 2009-03-26 10:14:08 -0700 | [diff] [blame] | 2595 | * clear all bits but the RF Kill bits and return */ |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 2596 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2597 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 2598 | STATUS_RF_KILL_HW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 2599 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 2600 | STATUS_GEO_CONFIGURED | |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 2601 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 2602 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2603 | goto exit; |
| 2604 | } |
| 2605 | |
Wey-Yi Guy | 6da3a13 | 2009-03-26 10:14:08 -0700 | [diff] [blame] | 2606 | /* ...otherwise clear out all the status bits but the RF Kill |
Johannes Berg | a60e77e | 2009-06-04 18:26:06 +0200 | [diff] [blame] | 2607 | * bit and continue taking the NIC down. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2608 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 2609 | STATUS_RF_KILL_HW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 2610 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 2611 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2612 | test_bit(STATUS_FW_ERROR, &priv->status) << |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 2613 | STATUS_FW_ERROR | |
| 2614 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 2615 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2616 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2617 | iwl3945_hw_txq_ctx_stop(priv); |
| 2618 | iwl3945_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2619 | |
Ben Cahill | 309e731 | 2009-11-06 14:53:03 -0800 | [diff] [blame] | 2620 | /* Power-down device's busmaster DMA clocks */ |
| 2621 | iwl_write_prph(priv, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2622 | udelay(5); |
| 2623 | |
Ben Cahill | 4d2ccdb | 2009-10-09 13:20:20 -0700 | [diff] [blame] | 2624 | /* Stop the device, and put it in low power state */ |
| 2625 | priv->cfg->ops->lib->apm_ops.stop(priv); |
Abbas, Mohamed | e9414b6 | 2009-01-20 21:33:55 -0800 | [diff] [blame] | 2626 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2627 | exit: |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 2628 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2629 | |
| 2630 | if (priv->ibss_beacon) |
| 2631 | dev_kfree_skb(priv->ibss_beacon); |
| 2632 | priv->ibss_beacon = NULL; |
| 2633 | |
| 2634 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2635 | iwl3945_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2636 | } |
| 2637 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2638 | static void iwl3945_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2639 | { |
| 2640 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2641 | __iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2642 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 2643 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2644 | iwl3945_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2645 | } |
| 2646 | |
| 2647 | #define MAX_HW_RESTARTS 5 |
| 2648 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2649 | static int __iwl3945_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2650 | { |
| 2651 | int rc, i; |
| 2652 | |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 2653 | rc = iwl_alloc_bcast_station(priv, false); |
| 2654 | if (rc) |
| 2655 | return rc; |
| 2656 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2657 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2658 | IWL_WARN(priv, "Exit pending; will not bring the NIC up\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2659 | return -EIO; |
| 2660 | } |
| 2661 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 2662 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2663 | IWL_ERR(priv, "ucode not available for device bring up\n"); |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 2664 | return -EIO; |
| 2665 | } |
| 2666 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 2667 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2668 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 2669 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 2670 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2671 | else { |
| 2672 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
Wey-Yi Guy | 6da3a13 | 2009-03-26 10:14:08 -0700 | [diff] [blame] | 2673 | IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n"); |
| 2674 | return -ENODEV; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2675 | } |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 2676 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2677 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2678 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2679 | rc = iwl3945_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2680 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2681 | IWL_ERR(priv, "Unable to int nic\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2682 | return rc; |
| 2683 | } |
| 2684 | |
| 2685 | /* make sure rfkill handshake bits are cleared */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2686 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 2687 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2688 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 2689 | |
| 2690 | /* clear (again), then enable host interrupts */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2691 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Abhijeet Kolekar | ed3b932 | 2009-02-18 15:54:30 -0800 | [diff] [blame] | 2692 | iwl_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2693 | |
| 2694 | /* really make sure rfkill handshake bits are cleared */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2695 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 2696 | 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] | 2697 | |
| 2698 | /* Copy original ucode data image from disk into backup cache. |
| 2699 | * This will be used to initialize the on-board processor's |
| 2700 | * data SRAM for a clean start when the runtime program first loads. */ |
| 2701 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2702 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2703 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 2704 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 2705 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 2706 | return 0; |
| 2707 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2708 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 2709 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2710 | /* load bootstrap state machine, |
| 2711 | * load bootstrap program into processor's memory, |
| 2712 | * prepare to load the "initialize" uCode */ |
Abhijeet Kolekar | 75a9a92 | 2010-02-26 15:17:01 -0800 | [diff] [blame] | 2713 | rc = priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2714 | |
| 2715 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2716 | IWL_ERR(priv, |
| 2717 | "Unable to set up bootstrap uCode: %d\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2718 | continue; |
| 2719 | } |
| 2720 | |
| 2721 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2722 | iwl3945_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2723 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2724 | IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2725 | |
| 2726 | return 0; |
| 2727 | } |
| 2728 | |
| 2729 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2730 | __iwl3945_down(priv); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 2731 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2732 | |
| 2733 | /* tried to restart and config the device for as long as our |
| 2734 | * patience could withstand */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2735 | IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2736 | return -EIO; |
| 2737 | } |
| 2738 | |
| 2739 | |
| 2740 | /***************************************************************************** |
| 2741 | * |
| 2742 | * Workqueue callbacks |
| 2743 | * |
| 2744 | *****************************************************************************/ |
| 2745 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2746 | static void iwl3945_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2747 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2748 | struct iwl_priv *priv = |
| 2749 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2750 | |
| 2751 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2752 | return; |
| 2753 | |
| 2754 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2755 | iwl3945_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2756 | mutex_unlock(&priv->mutex); |
| 2757 | } |
| 2758 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2759 | static void iwl3945_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2760 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2761 | struct iwl_priv *priv = |
| 2762 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2763 | |
| 2764 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 2765 | return; |
| 2766 | |
| 2767 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2768 | iwl3945_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2769 | mutex_unlock(&priv->mutex); |
| 2770 | } |
| 2771 | |
Ben Cahill | 743cdf1 | 2009-10-09 13:20:26 -0700 | [diff] [blame] | 2772 | /* |
| 2773 | * 3945 cannot interrupt driver when hardware rf kill switch toggles; |
| 2774 | * driver must poll CSR_GP_CNTRL_REG register for change. This register |
| 2775 | * *is* readable even when device has been SW_RESET into low power mode |
| 2776 | * (e.g. during RF KILL). |
| 2777 | */ |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 2778 | static void iwl3945_rfkill_poll(struct work_struct *data) |
| 2779 | { |
| 2780 | struct iwl_priv *priv = |
Johannes Berg | ee525d1 | 2010-01-21 06:09:28 -0800 | [diff] [blame] | 2781 | container_of(data, struct iwl_priv, _3945.rfkill_poll.work); |
Ben Cahill | 743cdf1 | 2009-10-09 13:20:26 -0700 | [diff] [blame] | 2782 | bool old_rfkill = test_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2783 | bool new_rfkill = !(iwl_read32(priv, CSR_GP_CNTRL) |
| 2784 | & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 2785 | |
Ben Cahill | 743cdf1 | 2009-10-09 13:20:26 -0700 | [diff] [blame] | 2786 | if (new_rfkill != old_rfkill) { |
| 2787 | if (new_rfkill) |
| 2788 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2789 | else |
| 2790 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 2791 | |
Ben Cahill | 743cdf1 | 2009-10-09 13:20:26 -0700 | [diff] [blame] | 2792 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, new_rfkill); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 2793 | |
Ben Cahill | 743cdf1 | 2009-10-09 13:20:26 -0700 | [diff] [blame] | 2794 | IWL_DEBUG_RF_KILL(priv, "RF_KILL bit toggled to %s.\n", |
| 2795 | new_rfkill ? "disable radio" : "enable radio"); |
| 2796 | } |
| 2797 | |
| 2798 | /* Keep this running, even if radio now enabled. This will be |
| 2799 | * cancelled in mac_start() if system decides to start again */ |
Johannes Berg | ee525d1 | 2010-01-21 06:09:28 -0800 | [diff] [blame] | 2800 | queue_delayed_work(priv->workqueue, &priv->_3945.rfkill_poll, |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 2801 | round_jiffies_relative(2 * HZ)); |
| 2802 | |
| 2803 | } |
| 2804 | |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 2805 | void iwl3945_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2806 | { |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 2807 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2808 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2809 | .len = sizeof(struct iwl3945_scan_cmd), |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 2810 | .flags = CMD_SIZE_HUGE, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2811 | }; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2812 | struct iwl3945_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2813 | struct ieee80211_conf *conf = NULL; |
Johannes Berg | 1ecf9fc | 2009-04-20 14:36:56 -0700 | [diff] [blame] | 2814 | u8 n_probes = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2815 | enum ieee80211_band band; |
Johannes Berg | 1ecf9fc | 2009-04-20 14:36:56 -0700 | [diff] [blame] | 2816 | bool is_active = false; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2817 | |
| 2818 | conf = ieee80211_get_hw_conf(priv->hw); |
| 2819 | |
Reinette Chatre | fbc9f97 | 2009-05-15 16:13:46 -0700 | [diff] [blame] | 2820 | cancel_delayed_work(&priv->scan_check); |
| 2821 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 2822 | if (!iwl_is_ready(priv)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2823 | IWL_WARN(priv, "request scan called when driver not ready.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2824 | goto done; |
| 2825 | } |
| 2826 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 2827 | /* Make sure the scan wasn't canceled before this queued work |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2828 | * was given the chance to run... */ |
| 2829 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 2830 | goto done; |
| 2831 | |
| 2832 | /* This should never be called or scheduled if there is currently |
| 2833 | * a scan active in the hardware. */ |
| 2834 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2835 | IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests " |
| 2836 | "Ignoring second request.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2837 | goto done; |
| 2838 | } |
| 2839 | |
| 2840 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2841 | IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2842 | goto done; |
| 2843 | } |
| 2844 | |
| 2845 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2846 | IWL_DEBUG_HC(priv, |
| 2847 | "Scan request while abort pending. Queuing.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2848 | goto done; |
| 2849 | } |
| 2850 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 2851 | if (iwl_is_rfkill(priv)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2852 | IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2853 | goto done; |
| 2854 | } |
| 2855 | |
| 2856 | if (!test_bit(STATUS_READY, &priv->status)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2857 | IWL_DEBUG_HC(priv, |
| 2858 | "Scan request while uninitialized. Queuing.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2859 | goto done; |
| 2860 | } |
| 2861 | |
Johannes Berg | 811ecc9 | 2010-04-06 04:12:41 -0700 | [diff] [blame] | 2862 | if (!priv->scan_cmd) { |
| 2863 | priv->scan_cmd = kmalloc(sizeof(struct iwl3945_scan_cmd) + |
| 2864 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 2865 | if (!priv->scan_cmd) { |
Wey-Yi Guy | 4f4d408 | 2010-02-24 08:28:30 -0800 | [diff] [blame] | 2866 | IWL_DEBUG_SCAN(priv, "Fail to allocate scan memory\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2867 | goto done; |
| 2868 | } |
| 2869 | } |
Johannes Berg | 811ecc9 | 2010-04-06 04:12:41 -0700 | [diff] [blame] | 2870 | scan = priv->scan_cmd; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2871 | memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2872 | |
| 2873 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 2874 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 2875 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 2876 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2877 | u16 interval = 0; |
| 2878 | u32 extra; |
| 2879 | u32 suspend_time = 100; |
| 2880 | u32 scan_suspend_time = 100; |
| 2881 | unsigned long flags; |
| 2882 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2883 | IWL_DEBUG_INFO(priv, "Scanning while associated...\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2884 | |
| 2885 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 2886 | interval = vif ? vif->bss_conf.beacon_int : 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2887 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2888 | |
| 2889 | scan->suspend_time = 0; |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 2890 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2891 | if (!interval) |
| 2892 | interval = suspend_time; |
| 2893 | /* |
| 2894 | * suspend time format: |
| 2895 | * 0-19: beacon interval in usec (time before exec.) |
| 2896 | * 20-23: 0 |
| 2897 | * 24-31: number of beacons (suspend between channels) |
| 2898 | */ |
| 2899 | |
| 2900 | extra = (suspend_time / interval) << 24; |
| 2901 | scan_suspend_time = 0xFF0FFFFF & |
| 2902 | (extra | ((suspend_time % interval) * 1024)); |
| 2903 | |
| 2904 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2905 | IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2906 | scan_suspend_time, interval); |
| 2907 | } |
| 2908 | |
Wey-Yi Guy | 4f4d408 | 2010-02-24 08:28:30 -0800 | [diff] [blame] | 2909 | if (priv->is_internal_short_scan) { |
| 2910 | IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n"); |
| 2911 | } else if (priv->scan_request->n_ssids) { |
Johannes Berg | 1ecf9fc | 2009-04-20 14:36:56 -0700 | [diff] [blame] | 2912 | int i, p = 0; |
| 2913 | IWL_DEBUG_SCAN(priv, "Kicking off active scan\n"); |
| 2914 | for (i = 0; i < priv->scan_request->n_ssids; i++) { |
| 2915 | /* always does wildcard anyway */ |
| 2916 | if (!priv->scan_request->ssids[i].ssid_len) |
| 2917 | continue; |
| 2918 | scan->direct_scan[p].id = WLAN_EID_SSID; |
| 2919 | scan->direct_scan[p].len = |
| 2920 | priv->scan_request->ssids[i].ssid_len; |
| 2921 | memcpy(scan->direct_scan[p].ssid, |
| 2922 | priv->scan_request->ssids[i].ssid, |
| 2923 | priv->scan_request->ssids[i].ssid_len); |
| 2924 | n_probes++; |
| 2925 | p++; |
| 2926 | } |
| 2927 | is_active = true; |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 2928 | } else |
Johannes Berg | 1ecf9fc | 2009-04-20 14:36:56 -0700 | [diff] [blame] | 2929 | IWL_DEBUG_SCAN(priv, "Kicking off passive scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2930 | |
| 2931 | /* We don't build a direct scan probe request; the uCode will do |
| 2932 | * that based on the direct_mask added to each channel entry */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2933 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 2934 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2935 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 2936 | |
| 2937 | /* flags + rate selection */ |
| 2938 | |
Johannes Berg | 00700ee | 2010-04-06 04:12:37 -0700 | [diff] [blame] | 2939 | switch (priv->scan_band) { |
| 2940 | case IEEE80211_BAND_2GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2941 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 2942 | scan->tx_cmd.rate = IWL_RATE_1M_PLCP; |
| 2943 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2944 | band = IEEE80211_BAND_2GHZ; |
Johannes Berg | 00700ee | 2010-04-06 04:12:37 -0700 | [diff] [blame] | 2945 | break; |
| 2946 | case IEEE80211_BAND_5GHZ: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2947 | scan->tx_cmd.rate = IWL_RATE_6M_PLCP; |
Johannes Berg | b097ad2 | 2009-04-20 14:36:57 -0700 | [diff] [blame] | 2948 | /* |
| 2949 | * If active scaning is requested but a certain channel |
| 2950 | * is marked passive, we can do active scanning if we |
| 2951 | * detect transmissions. |
| 2952 | */ |
Johannes Berg | 96ff564 | 2010-04-30 14:42:15 -0700 | [diff] [blame] | 2953 | scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT : |
| 2954 | IWL_GOOD_CRC_TH_DISABLED; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2955 | band = IEEE80211_BAND_5GHZ; |
Johannes Berg | 00700ee | 2010-04-06 04:12:37 -0700 | [diff] [blame] | 2956 | break; |
| 2957 | default: |
| 2958 | IWL_WARN(priv, "Invalid scan band\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2959 | goto done; |
| 2960 | } |
| 2961 | |
Wey-Yi Guy | 4f4d408 | 2010-02-24 08:28:30 -0800 | [diff] [blame] | 2962 | if (!priv->is_internal_short_scan) { |
| 2963 | scan->tx_cmd.len = cpu_to_le16( |
Johannes Berg | 1ecf9fc | 2009-04-20 14:36:56 -0700 | [diff] [blame] | 2964 | iwl_fill_probe_req(priv, |
| 2965 | (struct ieee80211_mgmt *)scan->data, |
Johannes Berg | 3a0b9aa | 2010-05-12 03:33:12 -0700 | [diff] [blame] | 2966 | vif->addr, |
Johannes Berg | 1ecf9fc | 2009-04-20 14:36:56 -0700 | [diff] [blame] | 2967 | priv->scan_request->ie, |
| 2968 | priv->scan_request->ie_len, |
| 2969 | IWL_MAX_SCAN_SIZE - sizeof(*scan))); |
Wey-Yi Guy | 4f4d408 | 2010-02-24 08:28:30 -0800 | [diff] [blame] | 2970 | } else { |
Johannes Berg | 3a0b9aa | 2010-05-12 03:33:12 -0700 | [diff] [blame] | 2971 | /* use bcast addr, will not be transmitted but must be valid */ |
Wey-Yi Guy | 4f4d408 | 2010-02-24 08:28:30 -0800 | [diff] [blame] | 2972 | scan->tx_cmd.len = cpu_to_le16( |
| 2973 | iwl_fill_probe_req(priv, |
| 2974 | (struct ieee80211_mgmt *)scan->data, |
Johannes Berg | 3a0b9aa | 2010-05-12 03:33:12 -0700 | [diff] [blame] | 2975 | iwl_bcast_addr, NULL, 0, |
Wey-Yi Guy | 4f4d408 | 2010-02-24 08:28:30 -0800 | [diff] [blame] | 2976 | IWL_MAX_SCAN_SIZE - sizeof(*scan))); |
| 2977 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2978 | /* select Rx antennas */ |
| 2979 | scan->flags |= iwl3945_get_antenna_flags(priv); |
| 2980 | |
Abhijeet Kolekar | 1402364 | 2010-06-02 21:15:10 -0700 | [diff] [blame] | 2981 | if (priv->is_internal_short_scan) { |
| 2982 | scan->channel_count = |
| 2983 | iwl3945_get_single_channel_for_scan(priv, vif, band, |
| 2984 | (void *)&scan->data[le16_to_cpu( |
| 2985 | scan->tx_cmd.len)]); |
| 2986 | } else { |
| 2987 | scan->channel_count = |
| 2988 | iwl3945_get_channels_for_scan(priv, band, is_active, n_probes, |
| 2989 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)], vif); |
| 2990 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2991 | |
Reinette Chatre | 14b5433 | 2008-11-04 12:21:35 -0800 | [diff] [blame] | 2992 | if (scan->channel_count == 0) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2993 | IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count); |
Reinette Chatre | 14b5433 | 2008-11-04 12:21:35 -0800 | [diff] [blame] | 2994 | goto done; |
| 2995 | } |
| 2996 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2997 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2998 | scan->channel_count * sizeof(struct iwl3945_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2999 | cmd.data = scan; |
| 3000 | scan->len = cpu_to_le16(cmd.len); |
| 3001 | |
| 3002 | set_bit(STATUS_SCAN_HW, &priv->status); |
Wey-Yi Guy | 4f4d408 | 2010-02-24 08:28:30 -0800 | [diff] [blame] | 3003 | if (iwl_send_cmd_sync(priv, &cmd)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3004 | goto done; |
| 3005 | |
| 3006 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 3007 | IWL_SCAN_CHECK_WATCHDOG); |
| 3008 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3009 | return; |
| 3010 | |
| 3011 | done: |
Mohamed Abbas | 2420ebc | 2008-11-04 12:21:34 -0800 | [diff] [blame] | 3012 | /* can not perform scan make sure we clear scanning |
| 3013 | * bits from status so next scan request can be performed. |
| 3014 | * if we dont clear scanning status bit here all next scan |
| 3015 | * will fail |
| 3016 | */ |
| 3017 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 3018 | clear_bit(STATUS_SCANNING, &priv->status); |
| 3019 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3020 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3021 | queue_work(priv->workqueue, &priv->scan_completed); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3022 | } |
| 3023 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3024 | static void iwl3945_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3025 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3026 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3027 | |
| 3028 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3029 | return; |
| 3030 | |
Johannes Berg | 19cc108 | 2009-05-08 13:44:36 -0700 | [diff] [blame] | 3031 | if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) { |
| 3032 | mutex_lock(&priv->mutex); |
| 3033 | priv->vif = NULL; |
| 3034 | priv->is_open = 0; |
| 3035 | mutex_unlock(&priv->mutex); |
| 3036 | iwl3945_down(priv); |
| 3037 | ieee80211_restart_hw(priv->hw); |
| 3038 | } else { |
| 3039 | iwl3945_down(priv); |
Johannes Berg | 8067651 | 2010-01-21 06:07:17 -0800 | [diff] [blame] | 3040 | |
| 3041 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3042 | return; |
| 3043 | |
| 3044 | mutex_lock(&priv->mutex); |
| 3045 | __iwl3945_up(priv); |
| 3046 | mutex_unlock(&priv->mutex); |
Johannes Berg | 19cc108 | 2009-05-08 13:44:36 -0700 | [diff] [blame] | 3047 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3048 | } |
| 3049 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3050 | static void iwl3945_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3051 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3052 | struct iwl_priv *priv = |
| 3053 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3054 | |
| 3055 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3056 | return; |
| 3057 | |
| 3058 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3059 | iwl3945_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3060 | mutex_unlock(&priv->mutex); |
| 3061 | } |
| 3062 | |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3063 | void iwl3945_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3064 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3065 | int rc = 0; |
| 3066 | struct ieee80211_conf *conf = NULL; |
| 3067 | |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3068 | if (!vif || !priv->is_open) |
| 3069 | return; |
| 3070 | |
| 3071 | if (vif->type == NL80211_IFTYPE_AP) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3072 | IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3073 | return; |
| 3074 | } |
| 3075 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3076 | IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n", |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3077 | vif->bss_conf.aid, priv->active_rxon.bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3078 | |
| 3079 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3080 | return; |
| 3081 | |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 3082 | iwl_scan_cancel_timeout(priv, 200); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 3083 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3084 | conf = ieee80211_get_hw_conf(priv->hw); |
| 3085 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3086 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Abhijeet Kolekar | e0158e6 | 2009-04-08 11:26:37 -0700 | [diff] [blame] | 3087 | iwlcore_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3088 | |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 3089 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3090 | iwl_setup_rxon_timing(priv, vif); |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 3091 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3092 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 3093 | if (rc) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3094 | IWL_WARN(priv, "REPLY_RXON_TIMING failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3095 | "Attempting to continue.\n"); |
| 3096 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3097 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3098 | |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3099 | priv->staging_rxon.assoc_id = cpu_to_le16(vif->bss_conf.aid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3100 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3101 | IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n", |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3102 | vif->bss_conf.aid, vif->bss_conf.beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3103 | |
Johannes Berg | c213d74 | 2010-05-06 12:21:40 -0700 | [diff] [blame] | 3104 | if (vif->bss_conf.use_short_preamble) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3105 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3106 | else |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3107 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3108 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3109 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
Johannes Berg | c213d74 | 2010-05-06 12:21:40 -0700 | [diff] [blame] | 3110 | if (vif->bss_conf.use_short_slot) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3111 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3112 | else |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3113 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3114 | } |
| 3115 | |
Abhijeet Kolekar | e0158e6 | 2009-04-08 11:26:37 -0700 | [diff] [blame] | 3116 | iwlcore_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3117 | |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3118 | switch (vif->type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3119 | case NL80211_IFTYPE_STATION: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3120 | iwl3945_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3121 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3122 | case NL80211_IFTYPE_ADHOC: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3123 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3124 | break; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3125 | default: |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3126 | IWL_ERR(priv, "%s Should not be called in %d mode\n", |
| 3127 | __func__, vif->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3128 | break; |
| 3129 | } |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 3130 | } |
| 3131 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3132 | /***************************************************************************** |
| 3133 | * |
| 3134 | * mac80211 entry point functions |
| 3135 | * |
| 3136 | *****************************************************************************/ |
| 3137 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3138 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 3139 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3140 | static int iwl3945_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3141 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3142 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3143 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3144 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3145 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3146 | |
| 3147 | /* we should be verifying the device is ready to be opened */ |
| 3148 | mutex_lock(&priv->mutex); |
| 3149 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3150 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 3151 | * ucode filename and max sizes are card-specific. */ |
| 3152 | |
| 3153 | if (!priv->ucode_code.len) { |
| 3154 | ret = iwl3945_read_ucode(priv); |
| 3155 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3156 | IWL_ERR(priv, "Could not read microcode: %d\n", ret); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3157 | mutex_unlock(&priv->mutex); |
| 3158 | goto out_release_irq; |
| 3159 | } |
| 3160 | } |
| 3161 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3162 | ret = __iwl3945_up(priv); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3163 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3164 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3165 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3166 | if (ret) |
| 3167 | goto out_release_irq; |
| 3168 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3169 | IWL_DEBUG_INFO(priv, "Start UP work.\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3170 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3171 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 3172 | * mac80211 will not be run successfully. */ |
| 3173 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 3174 | test_bit(STATUS_READY, &priv->status), |
| 3175 | UCODE_READY_TIMEOUT); |
| 3176 | if (!ret) { |
| 3177 | if (!test_bit(STATUS_READY, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3178 | IWL_ERR(priv, |
| 3179 | "Wait for START_ALIVE timeout after %dms.\n", |
| 3180 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3181 | ret = -ETIMEDOUT; |
| 3182 | goto out_release_irq; |
| 3183 | } |
| 3184 | } |
| 3185 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 3186 | /* ucode is running and will send rfkill notifications, |
| 3187 | * no need to poll the killswitch state anymore */ |
Johannes Berg | ee525d1 | 2010-01-21 06:09:28 -0800 | [diff] [blame] | 3188 | cancel_delayed_work(&priv->_3945.rfkill_poll); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 3189 | |
Johannes Berg | e932a60 | 2009-10-02 13:44:03 -0700 | [diff] [blame] | 3190 | iwl_led_start(priv); |
| 3191 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3192 | priv->is_open = 1; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3193 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3194 | return 0; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3195 | |
| 3196 | out_release_irq: |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3197 | priv->is_open = 0; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3198 | IWL_DEBUG_MAC80211(priv, "leave - failed\n"); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3199 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3200 | } |
| 3201 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3202 | static void iwl3945_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3203 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3204 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3205 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3206 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 3207 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3208 | if (!priv->is_open) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3209 | IWL_DEBUG_MAC80211(priv, "leave - skip\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3210 | return; |
| 3211 | } |
| 3212 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3213 | priv->is_open = 0; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3214 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 3215 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3216 | /* stop mac, cancel any scan request and clear |
| 3217 | * RXON_FILTER_ASSOC_MSK BIT |
| 3218 | */ |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3219 | mutex_lock(&priv->mutex); |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 3220 | iwl_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 3221 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 3222 | } |
| 3223 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3224 | iwl3945_down(priv); |
| 3225 | |
| 3226 | flush_workqueue(priv->workqueue); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 3227 | |
| 3228 | /* start polling the killswitch state again */ |
Johannes Berg | ee525d1 | 2010-01-21 06:09:28 -0800 | [diff] [blame] | 3229 | queue_delayed_work(priv->workqueue, &priv->_3945.rfkill_poll, |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 3230 | round_jiffies_relative(2 * HZ)); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 3231 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3232 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3233 | } |
| 3234 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 3235 | static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3236 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3237 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3238 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3239 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3240 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3241 | IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 3242 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3243 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 3244 | if (iwl3945_tx_skb(priv, skb)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3245 | dev_kfree_skb_any(skb); |
| 3246 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3247 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Reinette Chatre | 637f883 | 2009-01-19 15:30:32 -0800 | [diff] [blame] | 3248 | return NETDEV_TX_OK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3249 | } |
| 3250 | |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3251 | void iwl3945_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3252 | { |
| 3253 | int rc = 0; |
| 3254 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 3255 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3256 | return; |
| 3257 | |
| 3258 | /* The following should be done only at AP bring up */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3259 | if (!(iwl_is_associated(priv))) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3260 | |
| 3261 | /* RXON - unassoc (to set timing command) */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3262 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Abhijeet Kolekar | e0158e6 | 2009-04-08 11:26:37 -0700 | [diff] [blame] | 3263 | iwlcore_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3264 | |
| 3265 | /* RXON Timing */ |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 3266 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3267 | iwl_setup_rxon_timing(priv, vif); |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 3268 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
| 3269 | sizeof(priv->rxon_timing), |
| 3270 | &priv->rxon_timing); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3271 | if (rc) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3272 | IWL_WARN(priv, "REPLY_RXON_TIMING failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3273 | "Attempting to continue.\n"); |
| 3274 | |
Johannes Berg | 1dda6d2 | 2010-04-29 04:43:06 -0700 | [diff] [blame] | 3275 | priv->staging_rxon.assoc_id = 0; |
| 3276 | |
Johannes Berg | c213d74 | 2010-05-06 12:21:40 -0700 | [diff] [blame] | 3277 | if (vif->bss_conf.use_short_preamble) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3278 | priv->staging_rxon.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3279 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3280 | else |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3281 | priv->staging_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3282 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3283 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3284 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
Johannes Berg | c213d74 | 2010-05-06 12:21:40 -0700 | [diff] [blame] | 3285 | if (vif->bss_conf.use_short_slot) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3286 | priv->staging_rxon.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3287 | RXON_FLG_SHORT_SLOT_MSK; |
| 3288 | else |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3289 | priv->staging_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3290 | ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3291 | } |
| 3292 | /* restore RXON assoc */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3293 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Abhijeet Kolekar | e0158e6 | 2009-04-08 11:26:37 -0700 | [diff] [blame] | 3294 | iwlcore_commit_rxon(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 3295 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3296 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3297 | |
| 3298 | /* FIXME - we need to add code here to detect a totally new |
| 3299 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 3300 | * clear sta table, add BCAST sta... */ |
| 3301 | } |
| 3302 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3303 | static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 3304 | struct ieee80211_vif *vif, |
| 3305 | struct ieee80211_sta *sta, |
| 3306 | struct ieee80211_key_conf *key) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3307 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3308 | struct iwl_priv *priv = hw->priv; |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 3309 | int ret = 0; |
| 3310 | u8 sta_id = IWL_INVALID_STATION; |
| 3311 | u8 static_key; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3312 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3313 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3314 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 3315 | if (iwl3945_mod_params.sw_crypto) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3316 | IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3317 | return -EOPNOTSUPP; |
| 3318 | } |
| 3319 | |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 3320 | static_key = !iwl_is_associated(priv); |
| 3321 | |
| 3322 | if (!static_key) { |
Johannes Berg | 0af8bca | 2010-04-30 14:08:00 -0700 | [diff] [blame] | 3323 | sta_id = iwl_sta_id_or_broadcast(priv, sta); |
| 3324 | if (sta_id == IWL_INVALID_STATION) |
| 3325 | return -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3326 | } |
| 3327 | |
| 3328 | mutex_lock(&priv->mutex); |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 3329 | iwl_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 3330 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3331 | switch (cmd) { |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 3332 | case SET_KEY: |
| 3333 | if (static_key) |
| 3334 | ret = iwl3945_set_static_key(priv, key); |
| 3335 | else |
| 3336 | ret = iwl3945_set_dynamic_key(priv, key, sta_id); |
| 3337 | IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3338 | break; |
| 3339 | case DISABLE_KEY: |
Abhijeet Kolekar | 6e21f15 | 2009-02-27 16:21:21 -0800 | [diff] [blame] | 3340 | if (static_key) |
| 3341 | ret = iwl3945_remove_static_key(priv); |
| 3342 | else |
| 3343 | ret = iwl3945_clear_sta_key_info(priv, sta_id); |
| 3344 | IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3345 | break; |
| 3346 | default: |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 3347 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3348 | } |
| 3349 | |
Johannes Berg | 72e15d7 | 2010-02-19 11:42:32 -0800 | [diff] [blame] | 3350 | mutex_unlock(&priv->mutex); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3351 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3352 | |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 3353 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3354 | } |
| 3355 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3356 | static int iwl3945_mac_sta_add(struct ieee80211_hw *hw, |
| 3357 | struct ieee80211_vif *vif, |
| 3358 | struct ieee80211_sta *sta) |
| 3359 | { |
| 3360 | struct iwl_priv *priv = hw->priv; |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 3361 | struct iwl3945_sta_priv *sta_priv = (void *)sta->drv_priv; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3362 | int ret; |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 3363 | bool is_ap = vif->type == NL80211_IFTYPE_STATION; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3364 | u8 sta_id; |
| 3365 | |
| 3366 | IWL_DEBUG_INFO(priv, "received request to add station %pM\n", |
| 3367 | sta->addr); |
Reinette Chatre | da5ae1c | 2010-05-28 09:28:39 -0700 | [diff] [blame] | 3368 | mutex_lock(&priv->mutex); |
| 3369 | IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n", |
| 3370 | sta->addr); |
| 3371 | sta_priv->common.sta_id = IWL_INVALID_STATION; |
| 3372 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3373 | |
| 3374 | ret = iwl_add_station_common(priv, sta->addr, is_ap, &sta->ht_cap, |
| 3375 | &sta_id); |
| 3376 | if (ret) { |
| 3377 | IWL_ERR(priv, "Unable to add station %pM (%d)\n", |
| 3378 | sta->addr, ret); |
| 3379 | /* Should we return success if return code is EEXIST ? */ |
Reinette Chatre | da5ae1c | 2010-05-28 09:28:39 -0700 | [diff] [blame] | 3380 | mutex_unlock(&priv->mutex); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3381 | return ret; |
| 3382 | } |
| 3383 | |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 3384 | sta_priv->common.sta_id = sta_id; |
| 3385 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3386 | /* Initialize rate scaling */ |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 3387 | IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n", |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3388 | sta->addr); |
| 3389 | iwl3945_rs_rate_init(priv, sta, sta_id); |
Reinette Chatre | da5ae1c | 2010-05-28 09:28:39 -0700 | [diff] [blame] | 3390 | mutex_unlock(&priv->mutex); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3391 | |
| 3392 | return 0; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3393 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3394 | /***************************************************************************** |
| 3395 | * |
| 3396 | * sysfs attributes |
| 3397 | * |
| 3398 | *****************************************************************************/ |
| 3399 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 3400 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3401 | |
| 3402 | /* |
| 3403 | * The following adds a new attribute to the sysfs representation |
| 3404 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 3405 | * used for controlling the debug level. |
| 3406 | * |
| 3407 | * See the level definitions in iwl for details. |
Reinette Chatre | a562a9d | 2009-07-17 09:30:24 -0700 | [diff] [blame] | 3408 | * |
Reinette Chatre | 3d816c7 | 2009-08-07 15:41:37 -0700 | [diff] [blame] | 3409 | * The debug_level being managed using sysfs below is a per device debug |
| 3410 | * level that is used instead of the global debug level if it (the per |
| 3411 | * device debug level) is set. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3412 | */ |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3413 | static ssize_t show_debug_level(struct device *d, |
| 3414 | struct device_attribute *attr, char *buf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3415 | { |
Reinette Chatre | 3d816c7 | 2009-08-07 15:41:37 -0700 | [diff] [blame] | 3416 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 3417 | return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3418 | } |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3419 | static ssize_t store_debug_level(struct device *d, |
| 3420 | struct device_attribute *attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3421 | const char *buf, size_t count) |
| 3422 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 3423 | struct iwl_priv *priv = dev_get_drvdata(d); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3424 | unsigned long val; |
| 3425 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3426 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3427 | ret = strict_strtoul(buf, 0, &val); |
| 3428 | if (ret) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 3429 | IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf); |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 3430 | else { |
Reinette Chatre | 3d816c7 | 2009-08-07 15:41:37 -0700 | [diff] [blame] | 3431 | priv->debug_level = val; |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 3432 | if (iwl_alloc_traffic_mem(priv)) |
| 3433 | IWL_ERR(priv, |
| 3434 | "Not enough memory to generate traffic log\n"); |
| 3435 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3436 | return strnlen(buf, count); |
| 3437 | } |
| 3438 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3439 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 3440 | show_debug_level, store_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3441 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 3442 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3443 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3444 | static ssize_t show_temperature(struct device *d, |
| 3445 | struct device_attribute *attr, char *buf) |
| 3446 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 3447 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3448 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 3449 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3450 | return -EAGAIN; |
| 3451 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3452 | return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3453 | } |
| 3454 | |
| 3455 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 3456 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3457 | static ssize_t show_tx_power(struct device *d, |
| 3458 | struct device_attribute *attr, char *buf) |
| 3459 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 3460 | struct iwl_priv *priv = dev_get_drvdata(d); |
Winkler, Tomas | 62ea9c5 | 2009-01-19 15:30:29 -0800 | [diff] [blame] | 3461 | return sprintf(buf, "%d\n", priv->tx_power_user_lmt); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3462 | } |
| 3463 | |
| 3464 | static ssize_t store_tx_power(struct device *d, |
| 3465 | struct device_attribute *attr, |
| 3466 | const char *buf, size_t count) |
| 3467 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 3468 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3469 | char *p = (char *)buf; |
| 3470 | u32 val; |
| 3471 | |
| 3472 | val = simple_strtoul(p, &p, 10); |
| 3473 | if (p == buf) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 3474 | IWL_INFO(priv, ": %s is not in decimal form.\n", buf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3475 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3476 | iwl3945_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3477 | |
| 3478 | return count; |
| 3479 | } |
| 3480 | |
| 3481 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 3482 | |
| 3483 | static ssize_t show_flags(struct device *d, |
| 3484 | struct device_attribute *attr, char *buf) |
| 3485 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 3486 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3487 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3488 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3489 | } |
| 3490 | |
| 3491 | static ssize_t store_flags(struct device *d, |
| 3492 | struct device_attribute *attr, |
| 3493 | const char *buf, size_t count) |
| 3494 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 3495 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3496 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 3497 | |
| 3498 | mutex_lock(&priv->mutex); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3499 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3500 | /* Cancel any currently running scans... */ |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 3501 | if (iwl_scan_cancel_timeout(priv, 100)) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3502 | IWL_WARN(priv, "Could not cancel scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3503 | else { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3504 | IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3505 | flags); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3506 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Abhijeet Kolekar | e0158e6 | 2009-04-08 11:26:37 -0700 | [diff] [blame] | 3507 | iwlcore_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3508 | } |
| 3509 | } |
| 3510 | mutex_unlock(&priv->mutex); |
| 3511 | |
| 3512 | return count; |
| 3513 | } |
| 3514 | |
| 3515 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 3516 | |
| 3517 | static ssize_t show_filter_flags(struct device *d, |
| 3518 | struct device_attribute *attr, char *buf) |
| 3519 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 3520 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3521 | |
| 3522 | return sprintf(buf, "0x%04X\n", |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3523 | le32_to_cpu(priv->active_rxon.filter_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | static ssize_t store_filter_flags(struct device *d, |
| 3527 | struct device_attribute *attr, |
| 3528 | const char *buf, size_t count) |
| 3529 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 3530 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3531 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 3532 | |
| 3533 | mutex_lock(&priv->mutex); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3534 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3535 | /* Cancel any currently running scans... */ |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 3536 | if (iwl_scan_cancel_timeout(priv, 100)) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3537 | IWL_WARN(priv, "Could not cancel scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3538 | else { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3539 | IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3540 | "0x%04X\n", filter_flags); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3541 | priv->staging_rxon.filter_flags = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3542 | cpu_to_le32(filter_flags); |
Abhijeet Kolekar | e0158e6 | 2009-04-08 11:26:37 -0700 | [diff] [blame] | 3543 | iwlcore_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3544 | } |
| 3545 | } |
| 3546 | mutex_unlock(&priv->mutex); |
| 3547 | |
| 3548 | return count; |
| 3549 | } |
| 3550 | |
| 3551 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 3552 | store_filter_flags); |
| 3553 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3554 | static ssize_t show_measurement(struct device *d, |
| 3555 | struct device_attribute *attr, char *buf) |
| 3556 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3557 | struct iwl_priv *priv = dev_get_drvdata(d); |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 3558 | struct iwl_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3559 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 3560 | u8 *data = (u8 *)&measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3561 | unsigned long flags; |
| 3562 | |
| 3563 | spin_lock_irqsave(&priv->lock, flags); |
| 3564 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 3565 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3566 | return 0; |
| 3567 | } |
| 3568 | memcpy(&measure_report, &priv->measure_report, size); |
| 3569 | priv->measurement_status = 0; |
| 3570 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3571 | |
| 3572 | while (size && (PAGE_SIZE - len)) { |
| 3573 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 3574 | PAGE_SIZE - len, 1); |
| 3575 | len = strlen(buf); |
| 3576 | if (PAGE_SIZE - len) |
| 3577 | buf[len++] = '\n'; |
| 3578 | |
| 3579 | ofs += 16; |
| 3580 | size -= min(size, 16U); |
| 3581 | } |
| 3582 | |
| 3583 | return len; |
| 3584 | } |
| 3585 | |
| 3586 | static ssize_t store_measurement(struct device *d, |
| 3587 | struct device_attribute *attr, |
| 3588 | const char *buf, size_t count) |
| 3589 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3590 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3591 | struct ieee80211_measurement_params params = { |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3592 | .channel = le16_to_cpu(priv->active_rxon.channel), |
Johannes Berg | e99f168 | 2010-01-19 10:04:28 -0800 | [diff] [blame] | 3593 | .start_time = cpu_to_le64(priv->_3945.last_tsf), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3594 | .duration = cpu_to_le16(1), |
| 3595 | }; |
| 3596 | u8 type = IWL_MEASURE_BASIC; |
| 3597 | u8 buffer[32]; |
| 3598 | u8 channel; |
| 3599 | |
| 3600 | if (count) { |
| 3601 | char *p = buffer; |
| 3602 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 3603 | channel = simple_strtoul(p, NULL, 0); |
| 3604 | if (channel) |
| 3605 | params.channel = channel; |
| 3606 | |
| 3607 | p = buffer; |
| 3608 | while (*p && *p != ' ') |
| 3609 | p++; |
| 3610 | if (*p) |
| 3611 | type = simple_strtoul(p + 1, NULL, 0); |
| 3612 | } |
| 3613 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3614 | IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3615 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3616 | iwl3945_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3617 | |
| 3618 | return count; |
| 3619 | } |
| 3620 | |
| 3621 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 3622 | show_measurement, store_measurement); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3623 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3624 | static ssize_t store_retry_rate(struct device *d, |
| 3625 | struct device_attribute *attr, |
| 3626 | const char *buf, size_t count) |
| 3627 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3628 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3629 | |
| 3630 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 3631 | if (priv->retry_rate <= 0) |
| 3632 | priv->retry_rate = 1; |
| 3633 | |
| 3634 | return count; |
| 3635 | } |
| 3636 | |
| 3637 | static ssize_t show_retry_rate(struct device *d, |
| 3638 | struct device_attribute *attr, char *buf) |
| 3639 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3640 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3641 | return sprintf(buf, "%d", priv->retry_rate); |
| 3642 | } |
| 3643 | |
| 3644 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 3645 | store_retry_rate); |
| 3646 | |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 3647 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3648 | static ssize_t show_channels(struct device *d, |
| 3649 | struct device_attribute *attr, char *buf) |
| 3650 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3651 | /* all this shit doesn't belong into sysfs anyway */ |
| 3652 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3653 | } |
| 3654 | |
| 3655 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 3656 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3657 | static ssize_t show_antenna(struct device *d, |
| 3658 | struct device_attribute *attr, char *buf) |
| 3659 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3660 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3661 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 3662 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3663 | return -EAGAIN; |
| 3664 | |
Samuel Ortiz | 7e4bca5 | 2009-01-23 13:45:18 -0800 | [diff] [blame] | 3665 | return sprintf(buf, "%d\n", iwl3945_mod_params.antenna); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | static ssize_t store_antenna(struct device *d, |
| 3669 | struct device_attribute *attr, |
| 3670 | const char *buf, size_t count) |
| 3671 | { |
Winkler, Tomas | 7530f85 | 2009-01-27 14:27:53 -0800 | [diff] [blame] | 3672 | struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3673 | int ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3674 | |
| 3675 | if (count == 0) |
| 3676 | return 0; |
| 3677 | |
| 3678 | if (sscanf(buf, "%1i", &ant) != 1) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3679 | IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3680 | return count; |
| 3681 | } |
| 3682 | |
| 3683 | if ((ant >= 0) && (ant <= 2)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3684 | IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant); |
Samuel Ortiz | 7e4bca5 | 2009-01-23 13:45:18 -0800 | [diff] [blame] | 3685 | iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3686 | } else |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3687 | IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3688 | |
| 3689 | |
| 3690 | return count; |
| 3691 | } |
| 3692 | |
| 3693 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 3694 | |
| 3695 | static ssize_t show_status(struct device *d, |
| 3696 | struct device_attribute *attr, char *buf) |
| 3697 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 3698 | struct iwl_priv *priv = dev_get_drvdata(d); |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 3699 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3700 | return -EAGAIN; |
| 3701 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 3702 | } |
| 3703 | |
| 3704 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 3705 | |
| 3706 | static ssize_t dump_error_log(struct device *d, |
| 3707 | struct device_attribute *attr, |
| 3708 | const char *buf, size_t count) |
| 3709 | { |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 3710 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3711 | char *p = (char *)buf; |
| 3712 | |
| 3713 | if (p[0] == '1') |
Greg Kroah-Hartman | 928841b | 2009-04-30 23:02:47 -0700 | [diff] [blame] | 3714 | iwl3945_dump_nic_error_log(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3715 | |
| 3716 | return strnlen(buf, count); |
| 3717 | } |
| 3718 | |
| 3719 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 3720 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3721 | /***************************************************************************** |
| 3722 | * |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 3723 | * driver setup and tear down |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3724 | * |
| 3725 | *****************************************************************************/ |
| 3726 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3727 | static void iwl3945_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3728 | { |
Reinette Chatre | d21050c | 2009-02-13 11:51:18 -0800 | [diff] [blame] | 3729 | priv->workqueue = create_singlethread_workqueue(DRV_NAME); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3730 | |
| 3731 | init_waitqueue_head(&priv->wait_command_queue); |
| 3732 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3733 | INIT_WORK(&priv->restart, iwl3945_bg_restart); |
| 3734 | INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3735 | INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3736 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start); |
| 3737 | INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start); |
Johannes Berg | ee525d1 | 2010-01-21 06:09:28 -0800 | [diff] [blame] | 3738 | INIT_DELAYED_WORK(&priv->_3945.rfkill_poll, iwl3945_rfkill_poll); |
Samuel Ortiz | 77fecfb8 | 2009-01-23 13:45:12 -0800 | [diff] [blame] | 3739 | INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed); |
Samuel Ortiz | 77fecfb8 | 2009-01-23 13:45:12 -0800 | [diff] [blame] | 3740 | INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan); |
Abhijeet Kolekar | 1e46053 | 2010-04-23 14:14:53 -0700 | [diff] [blame] | 3741 | INIT_WORK(&priv->start_internal_scan, iwl_bg_start_internal_scan); |
Samuel Ortiz | 77fecfb8 | 2009-01-23 13:45:12 -0800 | [diff] [blame] | 3742 | INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3743 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3744 | iwl3945_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3745 | |
Wey-Yi Guy | b74e31a | 2010-03-01 17:23:50 -0800 | [diff] [blame] | 3746 | if (priv->cfg->ops->lib->recover_from_tx_stall) { |
| 3747 | init_timer(&priv->monitor_recover); |
| 3748 | priv->monitor_recover.data = (unsigned long)priv; |
| 3749 | priv->monitor_recover.function = |
| 3750 | priv->cfg->ops->lib->recover_from_tx_stall; |
| 3751 | } |
| 3752 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3753 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3754 | iwl3945_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3757 | static void iwl3945_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3758 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3759 | iwl3945_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3760 | |
Joonwoo Park | e47eb6a | 2007-11-29 10:42:49 +0900 | [diff] [blame] | 3761 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3762 | cancel_delayed_work(&priv->scan_check); |
| 3763 | cancel_delayed_work(&priv->alive_start); |
Abhijeet Kolekar | 1e46053 | 2010-04-23 14:14:53 -0700 | [diff] [blame] | 3764 | cancel_work_sync(&priv->start_internal_scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3765 | cancel_work_sync(&priv->beacon_update); |
Wey-Yi Guy | b74e31a | 2010-03-01 17:23:50 -0800 | [diff] [blame] | 3766 | if (priv->cfg->ops->lib->recover_from_tx_stall) |
| 3767 | del_timer_sync(&priv->monitor_recover); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3768 | } |
| 3769 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3770 | static struct attribute *iwl3945_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3771 | &dev_attr_antenna.attr, |
| 3772 | &dev_attr_channels.attr, |
| 3773 | &dev_attr_dump_errors.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3774 | &dev_attr_flags.attr, |
| 3775 | &dev_attr_filter_flags.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3776 | &dev_attr_measurement.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3777 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3778 | &dev_attr_status.attr, |
| 3779 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3780 | &dev_attr_tx_power.attr, |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 3781 | #ifdef CONFIG_IWLWIFI_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3782 | &dev_attr_debug_level.attr, |
| 3783 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3784 | NULL |
| 3785 | }; |
| 3786 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3787 | static struct attribute_group iwl3945_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3788 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3789 | .attrs = iwl3945_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3790 | }; |
| 3791 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3792 | static struct ieee80211_ops iwl3945_hw_ops = { |
| 3793 | .tx = iwl3945_mac_tx, |
| 3794 | .start = iwl3945_mac_start, |
| 3795 | .stop = iwl3945_mac_stop, |
Abhijeet Kolekar | cbb6ab9 | 2009-04-08 11:26:46 -0700 | [diff] [blame] | 3796 | .add_interface = iwl_mac_add_interface, |
Abhijeet Kolekar | d805231 | 2009-04-08 11:26:47 -0700 | [diff] [blame] | 3797 | .remove_interface = iwl_mac_remove_interface, |
Abhijeet Kolekar | 4808368 | 2009-04-08 11:26:48 -0700 | [diff] [blame] | 3798 | .config = iwl_mac_config, |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3799 | .configure_filter = iwl_configure_filter, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3800 | .set_key = iwl3945_mac_set_key, |
Abhijeet Kolekar | 488829f | 2009-03-26 10:14:10 -0700 | [diff] [blame] | 3801 | .conf_tx = iwl_mac_conf_tx, |
Abhijeet Kolekar | bd56426 | 2009-04-08 11:26:52 -0700 | [diff] [blame] | 3802 | .reset_tsf = iwl_mac_reset_tsf, |
Abhijeet Kolekar | 5bbe233 | 2009-04-08 11:26:35 -0700 | [diff] [blame] | 3803 | .bss_info_changed = iwl_bss_info_changed, |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 3804 | .hw_scan = iwl_mac_hw_scan, |
| 3805 | .sta_add = iwl3945_mac_sta_add, |
| 3806 | .sta_remove = iwl_mac_sta_remove, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3807 | }; |
| 3808 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 3809 | static int iwl3945_init_drv(struct iwl_priv *priv) |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3810 | { |
| 3811 | int ret; |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 3812 | struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom; |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3813 | |
| 3814 | priv->retry_rate = 1; |
| 3815 | priv->ibss_beacon = NULL; |
| 3816 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3817 | spin_lock_init(&priv->sta_lock); |
| 3818 | spin_lock_init(&priv->hcmd_lock); |
| 3819 | |
| 3820 | INIT_LIST_HEAD(&priv->free_frames); |
| 3821 | |
| 3822 | mutex_init(&priv->mutex); |
Reinette Chatre | d2dfe6d | 2010-02-18 22:03:04 -0800 | [diff] [blame] | 3823 | mutex_init(&priv->sync_cmd_mutex); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3824 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3825 | priv->ieee_channels = NULL; |
| 3826 | priv->ieee_rates = NULL; |
| 3827 | priv->band = IEEE80211_BAND_2GHZ; |
| 3828 | |
| 3829 | priv->iw_mode = NL80211_IFTYPE_STATION; |
Wey-Yi Guy | a13d276 | 2010-01-22 14:22:42 -0800 | [diff] [blame] | 3830 | priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF; |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3831 | |
Winkler, Tomas | 62ea9c5 | 2009-01-19 15:30:29 -0800 | [diff] [blame] | 3832 | priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER; |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3833 | |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 3834 | if (eeprom->version < EEPROM_3945_EEPROM_VERSION) { |
| 3835 | IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n", |
| 3836 | eeprom->version); |
| 3837 | ret = -EINVAL; |
| 3838 | goto err; |
| 3839 | } |
| 3840 | ret = iwl_init_channel_map(priv); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3841 | if (ret) { |
| 3842 | IWL_ERR(priv, "initializing regulatory failed: %d\n", ret); |
| 3843 | goto err; |
| 3844 | } |
| 3845 | |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 3846 | /* Set up txpower settings in driver for all channels */ |
| 3847 | if (iwl3945_txpower_set_from_eeprom(priv)) { |
| 3848 | ret = -EIO; |
| 3849 | goto err_free_channel_map; |
| 3850 | } |
| 3851 | |
Samuel Ortiz | 534166d | 2009-01-23 13:45:16 -0800 | [diff] [blame] | 3852 | ret = iwlcore_init_geos(priv); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3853 | if (ret) { |
| 3854 | IWL_ERR(priv, "initializing geos failed: %d\n", ret); |
| 3855 | goto err_free_channel_map; |
| 3856 | } |
Samuel Ortiz | 534166d | 2009-01-23 13:45:16 -0800 | [diff] [blame] | 3857 | iwl3945_init_hw_rates(priv, priv->ieee_rates); |
| 3858 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3859 | return 0; |
| 3860 | |
| 3861 | err_free_channel_map: |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 3862 | iwl_free_channel_map(priv); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3863 | err: |
| 3864 | return ret; |
| 3865 | } |
| 3866 | |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 3867 | #define IWL3945_MAX_PROBE_REQUEST 200 |
| 3868 | |
Abhijeet Kolekar | 2a4ddaa | 2009-02-27 16:21:23 -0800 | [diff] [blame] | 3869 | static int iwl3945_setup_mac(struct iwl_priv *priv) |
| 3870 | { |
| 3871 | int ret; |
| 3872 | struct ieee80211_hw *hw = priv->hw; |
| 3873 | |
| 3874 | hw->rate_control_algorithm = "iwl-3945-rs"; |
| 3875 | hw->sta_data_size = sizeof(struct iwl3945_sta_priv); |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 3876 | hw->vif_data_size = sizeof(struct iwl_vif_priv); |
Abhijeet Kolekar | 2a4ddaa | 2009-02-27 16:21:23 -0800 | [diff] [blame] | 3877 | |
| 3878 | /* Tell mac80211 our characteristics */ |
| 3879 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
Reinette Chatre | bc45a67 | 2009-12-14 14:12:10 -0800 | [diff] [blame] | 3880 | IEEE80211_HW_SPECTRUM_MGMT; |
| 3881 | |
| 3882 | if (!priv->cfg->broken_powersave) |
| 3883 | hw->flags |= IEEE80211_HW_SUPPORTS_PS | |
| 3884 | IEEE80211_HW_SUPPORTS_DYNAMIC_PS; |
Abhijeet Kolekar | 2a4ddaa | 2009-02-27 16:21:23 -0800 | [diff] [blame] | 3885 | |
| 3886 | hw->wiphy->interface_modes = |
| 3887 | BIT(NL80211_IFTYPE_STATION) | |
| 3888 | BIT(NL80211_IFTYPE_ADHOC); |
| 3889 | |
Reinette Chatre | f6c8f15 | 2010-03-12 11:13:26 -0800 | [diff] [blame] | 3890 | hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY | |
Johannes Berg | 5be83de | 2009-11-19 00:56:28 +0100 | [diff] [blame] | 3891 | WIPHY_FLAG_DISABLE_BEACON_HINTS; |
Luis R. Rodriguez | 3718424 | 2009-07-30 17:43:48 -0700 | [diff] [blame] | 3892 | |
Johannes Berg | 1ecf9fc | 2009-04-20 14:36:56 -0700 | [diff] [blame] | 3893 | hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX_3945; |
| 3894 | /* we create the 802.11 header and a zero-length SSID element */ |
Johannes Berg | dd7a250 | 2010-04-28 23:33:10 -0700 | [diff] [blame] | 3895 | hw->wiphy->max_scan_ie_len = IWL3945_MAX_PROBE_REQUEST - 24 - 2; |
Johannes Berg | d60cc91 | 2009-04-09 09:56:02 +0200 | [diff] [blame] | 3896 | |
Abhijeet Kolekar | 2a4ddaa | 2009-02-27 16:21:23 -0800 | [diff] [blame] | 3897 | /* Default value; 4 EDCA QOS priorities */ |
| 3898 | hw->queues = 4; |
| 3899 | |
Abhijeet Kolekar | 2a4ddaa | 2009-02-27 16:21:23 -0800 | [diff] [blame] | 3900 | if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 3901 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 3902 | &priv->bands[IEEE80211_BAND_2GHZ]; |
| 3903 | |
| 3904 | if (priv->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 3905 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 3906 | &priv->bands[IEEE80211_BAND_5GHZ]; |
| 3907 | |
| 3908 | ret = ieee80211_register_hw(priv->hw); |
| 3909 | if (ret) { |
| 3910 | IWL_ERR(priv, "Failed to register hw (error %d)\n", ret); |
| 3911 | return ret; |
| 3912 | } |
| 3913 | priv->mac80211_registered = 1; |
| 3914 | |
| 3915 | return 0; |
| 3916 | } |
| 3917 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3918 | static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3919 | { |
| 3920 | int err = 0; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3921 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3922 | struct ieee80211_hw *hw; |
Kolekar, Abhijeet | c0f20d9 | 2008-12-19 10:37:19 +0800 | [diff] [blame] | 3923 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 3924 | struct iwl3945_eeprom *eeprom; |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3925 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3926 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 3927 | /*********************** |
| 3928 | * 1. Allocating HW data |
| 3929 | * ********************/ |
| 3930 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3931 | /* mac80211 allocates memory for this device instance, including |
| 3932 | * space for this driver's private structure */ |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3933 | hw = iwl_alloc_all(cfg, &iwl3945_hw_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3934 | if (hw == NULL) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 3935 | printk(KERN_ERR DRV_NAME "Can not allocate network device\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3936 | err = -ENOMEM; |
| 3937 | goto out; |
| 3938 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3939 | priv = hw->priv; |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3940 | SET_IEEE80211_DEV(hw, &pdev->dev); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3941 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3942 | /* |
| 3943 | * Disabling hardware scan means that mac80211 will perform scans |
| 3944 | * "the hard way", rather than using device's scan. |
| 3945 | */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 3946 | if (iwl3945_mod_params.disable_hw_scan) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3947 | IWL_DEBUG_INFO(priv, "Disabling hw_scan\n"); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 3948 | iwl3945_hw_ops.hw_scan = NULL; |
| 3949 | } |
| 3950 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3951 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3952 | IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n"); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3953 | priv->cfg = cfg; |
| 3954 | priv->pci_dev = pdev; |
Mohamed Abbas | 40cefda | 2009-05-22 11:01:52 -0700 | [diff] [blame] | 3955 | priv->inta_mask = CSR_INI_SET_MASK; |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 3956 | |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 3957 | if (iwl_alloc_traffic_mem(priv)) |
| 3958 | IWL_ERR(priv, "Not enough memory to generate traffic log\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3959 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 3960 | /*************************** |
| 3961 | * 2. Initializing PCI bus |
| 3962 | * *************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3963 | if (pci_enable_device(pdev)) { |
| 3964 | err = -ENODEV; |
| 3965 | goto out_ieee80211_free_hw; |
| 3966 | } |
| 3967 | |
| 3968 | pci_set_master(pdev); |
| 3969 | |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 3970 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3971 | if (!err) |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 3972 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3973 | if (err) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 3974 | IWL_WARN(priv, "No suitable DMA available.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3975 | goto out_pci_disable_device; |
| 3976 | } |
| 3977 | |
| 3978 | pci_set_drvdata(pdev, priv); |
| 3979 | err = pci_request_regions(pdev, DRV_NAME); |
| 3980 | if (err) |
| 3981 | goto out_pci_disable_device; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 3982 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 3983 | /*********************** |
| 3984 | * 3. Read REV Register |
| 3985 | * ********************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3986 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 3987 | if (!priv->hw_base) { |
| 3988 | err = -ENODEV; |
| 3989 | goto out_pci_release_regions; |
| 3990 | } |
| 3991 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3992 | IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3993 | (unsigned long long) pci_resource_len(pdev, 0)); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3994 | IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3995 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 3996 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 3997 | * PCI Tx retries from interfering with C3 CPU state */ |
| 3998 | pci_write_config_byte(pdev, 0x41, 0x00); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3999 | |
Reinette Chatre | 731a29b | 2009-12-14 14:12:11 -0800 | [diff] [blame] | 4000 | /* these spin locks will be used in apm_ops.init and EEPROM access |
Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 4001 | * we should init now |
| 4002 | */ |
| 4003 | spin_lock_init(&priv->reg_lock); |
Reinette Chatre | 731a29b | 2009-12-14 14:12:11 -0800 | [diff] [blame] | 4004 | spin_lock_init(&priv->lock); |
Mohamed Abbas | a8b50a0 | 2009-05-22 11:01:47 -0700 | [diff] [blame] | 4005 | |
Reinette Chatre | 4843b5a | 2010-02-03 09:38:59 -0800 | [diff] [blame] | 4006 | /* |
| 4007 | * stop and reset the on-board processor just in case it is in a |
| 4008 | * strange state ... like being left stranded by a primary kernel |
| 4009 | * and this is now the kdump kernel trying to start up |
| 4010 | */ |
| 4011 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
| 4012 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4013 | /*********************** |
| 4014 | * 4. Read EEPROM |
| 4015 | * ********************/ |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4016 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4017 | /* Read the EEPROM */ |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 4018 | err = iwl_eeprom_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4019 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4020 | IWL_ERR(priv, "Unable to init EEPROM\n"); |
Reinette Chatre | c8f1613 | 2009-02-27 16:21:22 -0800 | [diff] [blame] | 4021 | goto out_iounmap; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4022 | } |
| 4023 | /* MAC Address location in EEPROM same for 3945/4965 */ |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 4024 | eeprom = (struct iwl3945_eeprom *)priv->eeprom; |
Johannes Berg | 30eabc1 | 2010-05-12 03:33:10 -0700 | [diff] [blame] | 4025 | IWL_DEBUG_INFO(priv, "MAC address: %pM\n", eeprom->mac_address); |
| 4026 | SET_IEEE80211_PERM_ADDR(priv->hw, eeprom->mac_address); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 4027 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4028 | /*********************** |
| 4029 | * 5. Setup HW Constants |
| 4030 | * ********************/ |
| 4031 | /* Device-specific setup */ |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 4032 | if (iwl3945_hw_set_hw_params(priv)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4033 | IWL_ERR(priv, "failed to set hw settings\n"); |
Reinette Chatre | c8f1613 | 2009-02-27 16:21:22 -0800 | [diff] [blame] | 4034 | goto out_eeprom_free; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4035 | } |
| 4036 | |
| 4037 | /*********************** |
| 4038 | * 6. Setup priv |
| 4039 | * ********************/ |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4040 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4041 | err = iwl3945_init_drv(priv); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4042 | if (err) { |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4043 | IWL_ERR(priv, "initializing driver failed\n"); |
Reinette Chatre | c8f1613 | 2009-02-27 16:21:22 -0800 | [diff] [blame] | 4044 | goto out_unset_hw_params; |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4045 | } |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 4046 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4047 | IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n", |
| 4048 | priv->cfg->name); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4049 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4050 | /*********************** |
Abhijeet Kolekar | 09f9bf7 | 2009-04-20 14:37:03 -0700 | [diff] [blame] | 4051 | * 7. Setup Services |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4052 | * ********************/ |
| 4053 | |
| 4054 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | ed3b932 | 2009-02-18 15:54:30 -0800 | [diff] [blame] | 4055 | iwl_disable_interrupts(priv); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4056 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4057 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 4058 | pci_enable_msi(priv->pci_dev); |
| 4059 | |
Mohamed Abbas | ef850d7 | 2009-05-22 11:01:50 -0700 | [diff] [blame] | 4060 | err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr, |
| 4061 | IRQF_SHARED, DRV_NAME, priv); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 4062 | if (err) { |
| 4063 | IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 4064 | goto out_disable_msi; |
| 4065 | } |
| 4066 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4067 | err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
| 4068 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4069 | IWL_ERR(priv, "failed to create sysfs device attributes\n"); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4070 | goto out_release_irq; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4071 | } |
| 4072 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4073 | iwl_set_rxon_channel(priv, |
| 4074 | &priv->bands[IEEE80211_BAND_2GHZ].channels[5]); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4075 | iwl3945_setup_deferred_work(priv); |
| 4076 | iwl3945_setup_rx_handlers(priv); |
Ben Cahill | 008a9e3 | 2009-10-09 13:20:27 -0700 | [diff] [blame] | 4077 | iwl_power_initialize(priv); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4078 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4079 | /********************************* |
Abhijeet Kolekar | 09f9bf7 | 2009-04-20 14:37:03 -0700 | [diff] [blame] | 4080 | * 8. Setup and Register mac80211 |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4081 | * *******************************/ |
| 4082 | |
Abhijeet Kolekar | 2a4ddaa | 2009-02-27 16:21:23 -0800 | [diff] [blame] | 4083 | iwl_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4084 | |
Abhijeet Kolekar | 2a4ddaa | 2009-02-27 16:21:23 -0800 | [diff] [blame] | 4085 | err = iwl3945_setup_mac(priv); |
| 4086 | if (err) |
| 4087 | goto out_remove_sysfs; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4088 | |
Abhijeet Kolekar | a75fbe8 | 2009-04-20 14:36:58 -0700 | [diff] [blame] | 4089 | err = iwl_dbgfs_register(priv, DRV_NAME); |
| 4090 | if (err) |
| 4091 | IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err); |
| 4092 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 4093 | /* Start monitoring the killswitch */ |
Johannes Berg | ee525d1 | 2010-01-21 06:09:28 -0800 | [diff] [blame] | 4094 | queue_delayed_work(priv->workqueue, &priv->_3945.rfkill_poll, |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 4095 | 2 * HZ); |
| 4096 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4097 | return 0; |
| 4098 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4099 | out_remove_sysfs: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4100 | destroy_workqueue(priv->workqueue); |
| 4101 | priv->workqueue = NULL; |
Reinette Chatre | c8f1613 | 2009-02-27 16:21:22 -0800 | [diff] [blame] | 4102 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
| 4103 | out_release_irq: |
| 4104 | free_irq(priv->pci_dev->irq, priv); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 4105 | out_disable_msi: |
| 4106 | pci_disable_msi(priv->pci_dev); |
Reinette Chatre | c8f1613 | 2009-02-27 16:21:22 -0800 | [diff] [blame] | 4107 | iwlcore_free_geos(priv); |
| 4108 | iwl_free_channel_map(priv); |
| 4109 | out_unset_hw_params: |
| 4110 | iwl3945_unset_hw_params(priv); |
| 4111 | out_eeprom_free: |
| 4112 | iwl_eeprom_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4113 | out_iounmap: |
| 4114 | pci_iounmap(pdev, priv->hw_base); |
| 4115 | out_pci_release_regions: |
| 4116 | pci_release_regions(pdev); |
| 4117 | out_pci_disable_device: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4118 | pci_set_drvdata(pdev, NULL); |
Reinette Chatre | 623d563 | 2009-03-03 11:37:04 -0800 | [diff] [blame] | 4119 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4120 | out_ieee80211_free_hw: |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 4121 | iwl_free_traffic_mem(priv); |
Wey-Yi Guy | d7c76f4 | 2009-10-09 13:20:17 -0700 | [diff] [blame] | 4122 | ieee80211_free_hw(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4123 | out: |
| 4124 | return err; |
| 4125 | } |
| 4126 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 4127 | static void __devexit iwl3945_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4128 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4129 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4130 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4131 | |
| 4132 | if (!priv) |
| 4133 | return; |
| 4134 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4135 | IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4136 | |
Abhijeet Kolekar | a75fbe8 | 2009-04-20 14:36:58 -0700 | [diff] [blame] | 4137 | iwl_dbgfs_unregister(priv); |
| 4138 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4139 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 4140 | |
Kolekar, Abhijeet | d552bfb | 2008-12-19 10:37:41 +0800 | [diff] [blame] | 4141 | if (priv->mac80211_registered) { |
| 4142 | ieee80211_unregister_hw(priv->hw); |
| 4143 | priv->mac80211_registered = 0; |
| 4144 | } else { |
| 4145 | iwl3945_down(priv); |
| 4146 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4147 | |
Ben Cahill | c166b25 | 2009-10-23 13:42:35 -0700 | [diff] [blame] | 4148 | /* |
| 4149 | * Make sure device is reset to low power before unloading driver. |
| 4150 | * This may be redundant with iwl_down(), but there are paths to |
| 4151 | * run iwl_down() without calling apm_ops.stop(), and there are |
| 4152 | * paths to avoid running iwl_down() at all before leaving driver. |
| 4153 | * This (inexpensive) call *makes sure* device is reset. |
| 4154 | */ |
| 4155 | priv->cfg->ops->lib->apm_ops.stop(priv); |
| 4156 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4157 | /* make sure we flush any pending irq or |
| 4158 | * tasklet for the driver |
| 4159 | */ |
| 4160 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | ed3b932 | 2009-02-18 15:54:30 -0800 | [diff] [blame] | 4161 | iwl_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4162 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4163 | |
| 4164 | iwl_synchronize_irq(priv); |
| 4165 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4166 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4167 | |
Johannes Berg | ee525d1 | 2010-01-21 06:09:28 -0800 | [diff] [blame] | 4168 | cancel_delayed_work_sync(&priv->_3945.rfkill_poll); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 4169 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4170 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4171 | |
| 4172 | if (priv->rxq.bd) |
Reinette Chatre | df833b1 | 2009-04-21 10:55:48 -0700 | [diff] [blame] | 4173 | iwl3945_rx_queue_free(priv, &priv->rxq); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4174 | iwl3945_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4175 | |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 4176 | iwl3945_unset_hw_params(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4177 | |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 4178 | /*netif_stop_queue(dev); */ |
| 4179 | flush_workqueue(priv->workqueue); |
| 4180 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4181 | /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4182 | * priv->workqueue... so we can't take down the workqueue |
| 4183 | * until now... */ |
| 4184 | destroy_workqueue(priv->workqueue); |
| 4185 | priv->workqueue = NULL; |
Wey-Yi Guy | 20594eb | 2009-08-07 15:41:39 -0700 | [diff] [blame] | 4186 | iwl_free_traffic_mem(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4187 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 4188 | free_irq(pdev->irq, priv); |
| 4189 | pci_disable_msi(pdev); |
| 4190 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4191 | pci_iounmap(pdev, priv->hw_base); |
| 4192 | pci_release_regions(pdev); |
| 4193 | pci_disable_device(pdev); |
| 4194 | pci_set_drvdata(pdev, NULL); |
| 4195 | |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 4196 | iwl_free_channel_map(priv); |
Samuel Ortiz | 534166d | 2009-01-23 13:45:16 -0800 | [diff] [blame] | 4197 | iwlcore_free_geos(priv); |
Johannes Berg | 811ecc9 | 2010-04-06 04:12:41 -0700 | [diff] [blame] | 4198 | kfree(priv->scan_cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4199 | if (priv->ibss_beacon) |
| 4200 | dev_kfree_skb(priv->ibss_beacon); |
| 4201 | |
| 4202 | ieee80211_free_hw(priv->hw); |
| 4203 | } |
| 4204 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4205 | |
| 4206 | /***************************************************************************** |
| 4207 | * |
| 4208 | * driver and module entry point |
| 4209 | * |
| 4210 | *****************************************************************************/ |
| 4211 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4212 | static struct pci_driver iwl3945_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4213 | .name = DRV_NAME, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4214 | .id_table = iwl3945_hw_card_ids, |
| 4215 | .probe = iwl3945_pci_probe, |
| 4216 | .remove = __devexit_p(iwl3945_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4217 | #ifdef CONFIG_PM |
Wey-Yi Guy | 6da3a13 | 2009-03-26 10:14:08 -0700 | [diff] [blame] | 4218 | .suspend = iwl_pci_suspend, |
| 4219 | .resume = iwl_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4220 | #endif |
| 4221 | }; |
| 4222 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4223 | static int __init iwl3945_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4224 | { |
| 4225 | |
| 4226 | int ret; |
| 4227 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 4228 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4229 | |
| 4230 | ret = iwl3945_rate_control_register(); |
| 4231 | if (ret) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 4232 | printk(KERN_ERR DRV_NAME |
| 4233 | "Unable to register rate control algorithm: %d\n", ret); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4234 | return ret; |
| 4235 | } |
| 4236 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4237 | ret = pci_register_driver(&iwl3945_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4238 | if (ret) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 4239 | printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4240 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4241 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4242 | |
| 4243 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4244 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4245 | error_register: |
| 4246 | iwl3945_rate_control_unregister(); |
| 4247 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4248 | } |
| 4249 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4250 | static void __exit iwl3945_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4251 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4252 | pci_unregister_driver(&iwl3945_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 4253 | iwl3945_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4254 | } |
| 4255 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 4256 | MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX)); |
Zhu Yi | 25cb6ca | 2008-09-11 11:45:22 +0800 | [diff] [blame] | 4257 | |
Wey-Yi Guy | 4e30cb6 | 2009-09-17 10:43:47 -0700 | [diff] [blame] | 4258 | module_param_named(antenna, iwl3945_mod_params.antenna, int, S_IRUGO); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4259 | MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); |
Wey-Yi Guy | 4e30cb6 | 2009-09-17 10:43:47 -0700 | [diff] [blame] | 4260 | module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, S_IRUGO); |
Samuel Ortiz | 9c74d9f | 2009-01-08 10:19:59 -0800 | [diff] [blame] | 4261 | MODULE_PARM_DESC(swcrypto, |
| 4262 | "using software crypto (default 1 [software])\n"); |
Reinette Chatre | a562a9d | 2009-07-17 09:30:24 -0700 | [diff] [blame] | 4263 | #ifdef CONFIG_IWLWIFI_DEBUG |
Wey-Yi Guy | 4e30cb6 | 2009-09-17 10:43:47 -0700 | [diff] [blame] | 4264 | module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4265 | MODULE_PARM_DESC(debug, "debug output mask"); |
Reinette Chatre | a562a9d | 2009-07-17 09:30:24 -0700 | [diff] [blame] | 4266 | #endif |
Wey-Yi Guy | 4e30cb6 | 2009-09-17 10:43:47 -0700 | [diff] [blame] | 4267 | module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, |
| 4268 | int, S_IRUGO); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4269 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
Wey-Yi Guy | 4e30cb6 | 2009-09-17 10:43:47 -0700 | [diff] [blame] | 4270 | module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, S_IRUGO); |
Samuel Ortiz | af48d04 | 2009-01-23 13:45:19 -0800 | [diff] [blame] | 4271 | MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error"); |
| 4272 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4273 | module_exit(iwl3945_exit); |
| 4274 | module_init(iwl3945_init); |