Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | 01f8162 | 2009-01-08 10:20:02 -0800 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 32 | #include <linux/init.h> |
| 33 | #include <linux/pci.h> |
| 34 | #include <linux/dma-mapping.h> |
| 35 | #include <linux/delay.h> |
| 36 | #include <linux/skbuff.h> |
| 37 | #include <linux/netdevice.h> |
| 38 | #include <linux/wireless.h> |
| 39 | #include <linux/firmware.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 40 | #include <linux/etherdevice.h> |
| 41 | #include <linux/if_arp.h> |
| 42 | |
| 43 | #include <net/ieee80211_radiotap.h> |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 44 | #include <net/lib80211.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 45 | #include <net/mac80211.h> |
| 46 | |
| 47 | #include <asm/div64.h> |
| 48 | |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 49 | #define DRV_NAME "iwl3945" |
| 50 | |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 51 | #include "iwl-fh.h" |
| 52 | #include "iwl-3945-fh.h" |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 53 | #include "iwl-commands.h" |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 54 | #include "iwl-sta.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 55 | #include "iwl-3945.h" |
| 56 | #include "iwl-helpers.h" |
Kolekar, Abhijeet | 5747d47 | 2008-12-19 10:37:18 +0800 | [diff] [blame] | 57 | #include "iwl-core.h" |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 58 | #include "iwl-dev.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 59 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 60 | /* |
| 61 | * module name, copyright, version, etc. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 62 | */ |
| 63 | |
| 64 | #define DRV_DESCRIPTION \ |
| 65 | "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux" |
| 66 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 67 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 68 | #define VD "d" |
| 69 | #else |
| 70 | #define VD |
| 71 | #endif |
| 72 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 73 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 74 | #define VS "s" |
| 75 | #else |
| 76 | #define VS |
| 77 | #endif |
| 78 | |
Kolekar, Abhijeet | eaa686c | 2008-12-19 10:37:17 +0800 | [diff] [blame] | 79 | #define IWL39_VERSION "1.2.26k" VD VS |
Reinette Chatre | 01f8162 | 2009-01-08 10:20:02 -0800 | [diff] [blame] | 80 | #define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation" |
Tomas Winkler | a7b7520 | 2008-12-11 10:33:41 -0800 | [diff] [blame] | 81 | #define DRV_AUTHOR "<ilw@linux.intel.com>" |
Kolekar, Abhijeet | eaa686c | 2008-12-19 10:37:17 +0800 | [diff] [blame] | 82 | #define DRV_VERSION IWL39_VERSION |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 83 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 84 | |
| 85 | MODULE_DESCRIPTION(DRV_DESCRIPTION); |
| 86 | MODULE_VERSION(DRV_VERSION); |
Tomas Winkler | a7b7520 | 2008-12-11 10:33:41 -0800 | [diff] [blame] | 87 | MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 88 | MODULE_LICENSE("GPL"); |
| 89 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 90 | /* module parameters */ |
| 91 | struct iwl_mod_params iwl3945_mod_params = { |
| 92 | .num_of_queues = IWL39_MAX_NUM_QUEUES, |
Samuel Ortiz | 9c74d9f | 2009-01-08 10:19:59 -0800 | [diff] [blame] | 93 | .sw_crypto = 1, |
Samuel Ortiz | af48d04 | 2009-01-23 13:45:19 -0800 | [diff] [blame] | 94 | .restart_fw = 1, |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 95 | /* the rest are 0 by default */ |
| 96 | }; |
| 97 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 98 | /*************** STATION TABLE MANAGEMENT **** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 99 | * mac80211 should be examined to determine if sta_info is duplicating |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 100 | * the functionality provided here |
| 101 | */ |
| 102 | |
| 103 | /**************************************************************/ |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 104 | #if 0 /* temporary disable till we add real remove station */ |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 105 | /** |
| 106 | * iwl3945_remove_station - Remove driver's knowledge of station. |
| 107 | * |
| 108 | * NOTE: This does not remove station from device's station table. |
| 109 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 110 | static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 111 | { |
| 112 | int index = IWL_INVALID_STATION; |
| 113 | int i; |
| 114 | unsigned long flags; |
| 115 | |
| 116 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 117 | |
| 118 | if (is_ap) |
| 119 | index = IWL_AP_ID; |
| 120 | else if (is_broadcast_ether_addr(addr)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 121 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 122 | else |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 123 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 124 | if (priv->stations_39[i].used && |
| 125 | !compare_ether_addr(priv->stations_39[i].sta.sta.addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 126 | addr)) { |
| 127 | index = i; |
| 128 | break; |
| 129 | } |
| 130 | |
| 131 | if (unlikely(index == IWL_INVALID_STATION)) |
| 132 | goto out; |
| 133 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 134 | if (priv->stations_39[index].used) { |
| 135 | priv->stations_39[index].used = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 136 | priv->num_stations--; |
| 137 | } |
| 138 | |
| 139 | BUG_ON(priv->num_stations < 0); |
| 140 | |
| 141 | out: |
| 142 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 143 | return 0; |
| 144 | } |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 145 | #endif |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * iwl3945_clear_stations_table - Clear the driver's station table |
| 149 | * |
| 150 | * NOTE: This does not clear or otherwise alter the device's station table. |
| 151 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 152 | static void iwl3945_clear_stations_table(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 153 | { |
| 154 | unsigned long flags; |
| 155 | |
| 156 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 157 | |
| 158 | priv->num_stations = 0; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 159 | memset(priv->stations_39, 0, sizeof(priv->stations_39)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 160 | |
| 161 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 162 | } |
| 163 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 164 | /** |
| 165 | * iwl3945_add_station - Add station to station tables in driver and device |
| 166 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 167 | u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 168 | { |
| 169 | int i; |
| 170 | int index = IWL_INVALID_STATION; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 171 | struct iwl3945_station_entry *station; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 172 | unsigned long flags_spin; |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 173 | u8 rate; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 174 | |
| 175 | spin_lock_irqsave(&priv->sta_lock, flags_spin); |
| 176 | if (is_ap) |
| 177 | index = IWL_AP_ID; |
| 178 | else if (is_broadcast_ether_addr(addr)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 179 | index = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 180 | else |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 181 | for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 182 | if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 183 | addr)) { |
| 184 | index = i; |
| 185 | break; |
| 186 | } |
| 187 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 188 | if (!priv->stations_39[i].used && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 189 | index == IWL_INVALID_STATION) |
| 190 | index = i; |
| 191 | } |
| 192 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 193 | /* These two conditions has the same outcome but keep them separate |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 194 | since they have different meaning */ |
| 195 | if (unlikely(index == IWL_INVALID_STATION)) { |
| 196 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 197 | return index; |
| 198 | } |
| 199 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 200 | if (priv->stations_39[index].used && |
| 201 | !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 202 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
| 203 | return index; |
| 204 | } |
| 205 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 206 | IWL_DEBUG_ASSOC(priv, "Add STA ID %d: %pM\n", index, addr); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 207 | station = &priv->stations_39[index]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 208 | station->used = 1; |
| 209 | priv->num_stations++; |
| 210 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 211 | /* Set up the REPLY_ADD_STA command to send to device */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 212 | memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 213 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 214 | station->sta.mode = 0; |
| 215 | station->sta.sta.sta_id = index; |
| 216 | station->sta.station_flags = 0; |
| 217 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 218 | if (priv->band == IEEE80211_BAND_5GHZ) |
Tomas Winkler | 6994633 | 2007-10-25 17:15:27 +0800 | [diff] [blame] | 219 | rate = IWL_RATE_6M_PLCP; |
| 220 | else |
| 221 | rate = IWL_RATE_1M_PLCP; |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 222 | |
| 223 | /* Turn on both antennas for the station... */ |
| 224 | station->sta.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 225 | iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK); |
Zhu Yi | c14c521 | 2007-09-27 11:27:35 +0800 | [diff] [blame] | 226 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 227 | spin_unlock_irqrestore(&priv->sta_lock, flags_spin); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 228 | |
| 229 | /* Add station to device's station table */ |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 230 | iwl_send_add_sta(priv, |
| 231 | (struct iwl_addsta_cmd *)&station->sta, flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 232 | return index; |
| 233 | |
| 234 | } |
| 235 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 236 | static int iwl3945_send_rxon_assoc(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 237 | { |
| 238 | int rc = 0; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 239 | struct iwl_rx_packet *res = NULL; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 240 | struct iwl3945_rxon_assoc_cmd rxon_assoc; |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 241 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 242 | .id = REPLY_RXON_ASSOC, |
| 243 | .len = sizeof(rxon_assoc), |
| 244 | .meta.flags = CMD_WANT_SKB, |
| 245 | .data = &rxon_assoc, |
| 246 | }; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 247 | const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon; |
| 248 | const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 249 | |
| 250 | if ((rxon1->flags == rxon2->flags) && |
| 251 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 252 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 253 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 254 | IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 255 | return 0; |
| 256 | } |
| 257 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 258 | rxon_assoc.flags = priv->staging_rxon.flags; |
| 259 | rxon_assoc.filter_flags = priv->staging_rxon.filter_flags; |
| 260 | rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates; |
| 261 | rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 262 | rxon_assoc.reserved = 0; |
| 263 | |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 264 | rc = iwl_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 265 | if (rc) |
| 266 | return rc; |
| 267 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 268 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 269 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 270 | IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 271 | rc = -EIO; |
| 272 | } |
| 273 | |
| 274 | priv->alloc_rxb_skb--; |
| 275 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 276 | |
| 277 | return rc; |
| 278 | } |
| 279 | |
| 280 | /** |
Samuel Ortiz | 7e4bca5 | 2009-01-23 13:45:18 -0800 | [diff] [blame] | 281 | * iwl3945_get_antenna_flags - Get antenna flags for RXON command |
| 282 | * @priv: eeprom and antenna fields are used to determine antenna flags |
| 283 | * |
| 284 | * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed |
| 285 | * iwl3945_mod_params.antenna specifies the antenna diversity mode: |
| 286 | * |
| 287 | * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself |
| 288 | * IWL_ANTENNA_MAIN - Force MAIN antenna |
| 289 | * IWL_ANTENNA_AUX - Force AUX antenna |
| 290 | */ |
| 291 | __le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv) |
| 292 | { |
| 293 | struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom; |
| 294 | |
| 295 | switch (iwl3945_mod_params.antenna) { |
| 296 | case IWL_ANTENNA_DIVERSITY: |
| 297 | return 0; |
| 298 | |
| 299 | case IWL_ANTENNA_MAIN: |
| 300 | if (eeprom->antenna_switch_type) |
| 301 | return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK; |
| 302 | return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK; |
| 303 | |
| 304 | case IWL_ANTENNA_AUX: |
| 305 | if (eeprom->antenna_switch_type) |
| 306 | return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK; |
| 307 | return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK; |
| 308 | } |
| 309 | |
| 310 | /* bad antenna selector value */ |
| 311 | IWL_ERR(priv, "Bad antenna selector value (0x%x)\n", |
| 312 | iwl3945_mod_params.antenna); |
| 313 | |
| 314 | return 0; /* "diversity" is default if error */ |
| 315 | } |
| 316 | |
| 317 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 318 | * iwl3945_commit_rxon - commit staging_rxon to hardware |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 319 | * |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 320 | * The RXON command in staging_rxon is committed to the hardware and |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 321 | * the active_rxon structure is updated with the new data. This |
| 322 | * function correctly transitions out of the RXON_ASSOC_MSK state if |
| 323 | * a HW tune is required based on the RXON structure changes. |
| 324 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 325 | static int iwl3945_commit_rxon(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 326 | { |
| 327 | /* cast away the const for active_rxon in this function */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 328 | struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon; |
| 329 | struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 330 | int rc = 0; |
| 331 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 332 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 333 | return -1; |
| 334 | |
| 335 | /* always get timestamp with Rx frame */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 336 | staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 337 | |
| 338 | /* select antenna */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 339 | staging_rxon->flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 340 | ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 341 | staging_rxon->flags |= iwl3945_get_antenna_flags(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 342 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 343 | rc = iwl_check_rxon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 344 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 345 | IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 346 | return -EINVAL; |
| 347 | } |
| 348 | |
| 349 | /* If we don't need to send a full RXON, we can use |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 350 | * iwl3945_rxon_assoc_cmd which is used to reconfigure filter |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 351 | * and other flags for the current radio configuration. */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 352 | if (!iwl_full_rxon_required(priv)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 353 | rc = iwl3945_send_rxon_assoc(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 354 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 355 | IWL_ERR(priv, "Error setting RXON_ASSOC " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 356 | "configuration (%d).\n", rc); |
| 357 | return rc; |
| 358 | } |
| 359 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 360 | memcpy(active_rxon, staging_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 361 | |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | /* If we are currently associated and the new config requires |
| 366 | * an RXON_ASSOC and the new config wants the associated mask enabled, |
| 367 | * we must clear the associated from the active configuration |
| 368 | * before we apply the new config */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 369 | if (iwl_is_associated(priv) && |
| 370 | (staging_rxon->filter_flags & RXON_FILTER_ASSOC_MSK)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 371 | IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 372 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 373 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 374 | /* |
| 375 | * reserved4 and 5 could have been filled by the iwlcore code. |
| 376 | * Let's clear them before pushing to the 3945. |
| 377 | */ |
| 378 | active_rxon->reserved4 = 0; |
| 379 | active_rxon->reserved5 = 0; |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 380 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 381 | sizeof(struct iwl3945_rxon_cmd), |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 382 | &priv->active_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 383 | |
| 384 | /* If the mask clearing failed then we set |
| 385 | * active_rxon back to what it was previously */ |
| 386 | if (rc) { |
| 387 | active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 388 | IWL_ERR(priv, "Error clearing ASSOC_MSK on current " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 389 | "configuration (%d).\n", rc); |
| 390 | return rc; |
| 391 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 394 | IWL_DEBUG_INFO(priv, "Sending RXON\n" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 395 | "* with%s RXON_FILTER_ASSOC_MSK\n" |
| 396 | "* channel = %d\n" |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 397 | "* bssid = %pM\n", |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 398 | ((priv->staging_rxon.filter_flags & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 399 | RXON_FILTER_ASSOC_MSK) ? "" : "out"), |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 400 | le16_to_cpu(staging_rxon->channel), |
| 401 | staging_rxon->bssid_addr); |
| 402 | |
| 403 | /* |
| 404 | * reserved4 and 5 could have been filled by the iwlcore code. |
| 405 | * Let's clear them before pushing to the 3945. |
| 406 | */ |
| 407 | staging_rxon->reserved4 = 0; |
| 408 | staging_rxon->reserved5 = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 409 | |
| 410 | /* Apply the new configuration */ |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 411 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON, |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 412 | sizeof(struct iwl3945_rxon_cmd), |
| 413 | staging_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 414 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 415 | IWL_ERR(priv, "Error setting new configuration (%d).\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 416 | return rc; |
| 417 | } |
| 418 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 419 | memcpy(active_rxon, staging_rxon, sizeof(*active_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 420 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 421 | iwl3945_clear_stations_table(priv); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 422 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 423 | /* If we issue a new RXON command which required a tune then we must |
| 424 | * send a new TXPOWER command or we won't be able to Tx any frames */ |
Samuel Ortiz | 75bcfae | 2009-01-23 13:45:11 -0800 | [diff] [blame] | 425 | rc = priv->cfg->ops->lib->send_tx_power(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 426 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 427 | IWL_ERR(priv, "Error setting Tx power (%d).\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 428 | return rc; |
| 429 | } |
| 430 | |
| 431 | /* Add the broadcast address so we can send broadcast frames */ |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 432 | if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 433 | IWL_INVALID_STATION) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 434 | IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 435 | return -EIO; |
| 436 | } |
| 437 | |
| 438 | /* If we have set the ASSOC_MSK and we are in BSS mode then |
| 439 | * add the IWL_AP_ID to the station rate table */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 440 | if (iwl_is_associated(priv) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 441 | (priv->iw_mode == NL80211_IFTYPE_STATION)) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 442 | if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr, |
| 443 | 1, 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 444 | == IWL_INVALID_STATION) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 445 | IWL_ERR(priv, "Error adding AP address for transmit\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 446 | return -EIO; |
| 447 | } |
| 448 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 449 | /* Init the hardware's rate fallback order based on the band */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 450 | rc = iwl3945_init_hw_rate_table(priv); |
| 451 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 452 | IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 453 | return -EIO; |
| 454 | } |
| 455 | |
| 456 | return 0; |
| 457 | } |
| 458 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 459 | static int iwl3945_update_sta_key_info(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 460 | struct ieee80211_key_conf *keyconf, |
| 461 | u8 sta_id) |
| 462 | { |
| 463 | unsigned long flags; |
| 464 | __le16 key_flags = 0; |
| 465 | |
| 466 | switch (keyconf->alg) { |
| 467 | case ALG_CCMP: |
| 468 | key_flags |= STA_KEY_FLG_CCMP; |
| 469 | key_flags |= cpu_to_le16( |
| 470 | keyconf->keyidx << STA_KEY_FLG_KEYID_POS); |
| 471 | key_flags &= ~STA_KEY_FLG_INVALID; |
| 472 | break; |
| 473 | case ALG_TKIP: |
| 474 | case ALG_WEP: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 475 | default: |
| 476 | return -EINVAL; |
| 477 | } |
| 478 | spin_lock_irqsave(&priv->sta_lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 479 | priv->stations_39[sta_id].keyinfo.alg = keyconf->alg; |
| 480 | priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen; |
| 481 | memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 482 | keyconf->keylen); |
| 483 | |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 484 | memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 485 | keyconf->keylen); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 486 | priv->stations_39[sta_id].sta.key.key_flags = key_flags; |
| 487 | priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 488 | priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 489 | |
| 490 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 491 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 492 | IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n"); |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 493 | iwl_send_add_sta(priv, |
| 494 | (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 495 | return 0; |
| 496 | } |
| 497 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 498 | 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] | 499 | { |
| 500 | unsigned long flags; |
| 501 | |
| 502 | spin_lock_irqsave(&priv->sta_lock, flags); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 503 | memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key)); |
| 504 | memset(&priv->stations_39[sta_id].sta.key, 0, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 505 | sizeof(struct iwl4965_keyinfo)); |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 506 | priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC; |
| 507 | priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK; |
| 508 | priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 509 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 510 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 511 | IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n"); |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 512 | iwl_send_add_sta(priv, |
| 513 | (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 514 | return 0; |
| 515 | } |
| 516 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 517 | static void iwl3945_clear_free_frames(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 518 | { |
| 519 | struct list_head *element; |
| 520 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 521 | 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] | 522 | priv->frames_count); |
| 523 | |
| 524 | while (!list_empty(&priv->free_frames)) { |
| 525 | element = priv->free_frames.next; |
| 526 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 527 | kfree(list_entry(element, struct iwl3945_frame, list)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 528 | priv->frames_count--; |
| 529 | } |
| 530 | |
| 531 | if (priv->frames_count) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 532 | 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] | 533 | priv->frames_count); |
| 534 | priv->frames_count = 0; |
| 535 | } |
| 536 | } |
| 537 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 538 | static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 539 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 540 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 541 | struct list_head *element; |
| 542 | if (list_empty(&priv->free_frames)) { |
| 543 | frame = kzalloc(sizeof(*frame), GFP_KERNEL); |
| 544 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 545 | IWL_ERR(priv, "Could not allocate frame!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 546 | return NULL; |
| 547 | } |
| 548 | |
| 549 | priv->frames_count++; |
| 550 | return frame; |
| 551 | } |
| 552 | |
| 553 | element = priv->free_frames.next; |
| 554 | list_del(element); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 555 | return list_entry(element, struct iwl3945_frame, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 558 | 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] | 559 | { |
| 560 | memset(frame, 0, sizeof(*frame)); |
| 561 | list_add(&frame->list, &priv->free_frames); |
| 562 | } |
| 563 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 564 | unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 565 | struct ieee80211_hdr *hdr, |
Rami Rosen | 73ec1cc | 2008-12-16 09:37:07 +0200 | [diff] [blame] | 566 | int left) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 567 | { |
| 568 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 569 | if (!iwl_is_associated(priv) || !priv->ibss_beacon || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 570 | ((priv->iw_mode != NL80211_IFTYPE_ADHOC) && |
| 571 | (priv->iw_mode != NL80211_IFTYPE_AP))) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 572 | return 0; |
| 573 | |
| 574 | if (priv->ibss_beacon->len > left) |
| 575 | return 0; |
| 576 | |
| 577 | memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len); |
| 578 | |
| 579 | return priv->ibss_beacon->len; |
| 580 | } |
| 581 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 582 | static int iwl3945_send_beacon_cmd(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 583 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 584 | struct iwl3945_frame *frame; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 585 | unsigned int frame_size; |
| 586 | int rc; |
| 587 | u8 rate; |
| 588 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 589 | frame = iwl3945_get_free_frame(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 590 | |
| 591 | if (!frame) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 592 | IWL_ERR(priv, "Could not obtain free frame buffer for beacon " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 593 | "command.\n"); |
| 594 | return -ENOMEM; |
| 595 | } |
| 596 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 597 | rate = iwl_rate_get_lowest_plcp(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 598 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 599 | frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 600 | |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 601 | rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 602 | &frame->u.cmd[0]); |
| 603 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 604 | iwl3945_free_frame(priv, frame); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 605 | |
| 606 | return rc; |
| 607 | } |
| 608 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 609 | static void iwl3945_unset_hw_params(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 610 | { |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 611 | if (priv->shared_virt) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 612 | pci_free_consistent(priv->pci_dev, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 613 | sizeof(struct iwl3945_shared), |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 614 | priv->shared_virt, |
| 615 | priv->shared_phys); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 616 | } |
| 617 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 618 | /* |
| 619 | * QoS support |
| 620 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 621 | static int iwl3945_send_qos_params_command(struct iwl_priv *priv, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 622 | struct iwl_qosparam_cmd *qos) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 623 | { |
| 624 | |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 625 | return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM, |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 626 | sizeof(struct iwl_qosparam_cmd), qos); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 629 | static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 630 | { |
| 631 | unsigned long flags; |
| 632 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 633 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 634 | return; |
| 635 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 636 | spin_lock_irqsave(&priv->lock, flags); |
| 637 | priv->qos_data.def_qos_parm.qos_flags = 0; |
| 638 | |
| 639 | if (priv->qos_data.qos_cap.q_AP.queue_request && |
| 640 | !priv->qos_data.qos_cap.q_AP.txop_request) |
| 641 | priv->qos_data.def_qos_parm.qos_flags |= |
| 642 | QOS_PARAM_FLG_TXOP_TYPE_MSK; |
| 643 | |
| 644 | if (priv->qos_data.qos_active) |
| 645 | priv->qos_data.def_qos_parm.qos_flags |= |
| 646 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; |
| 647 | |
| 648 | spin_unlock_irqrestore(&priv->lock, flags); |
| 649 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 650 | if (force || iwl_is_associated(priv)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 651 | IWL_DEBUG_QOS(priv, "send QoS cmd with QoS active %d \n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 652 | priv->qos_data.qos_active); |
| 653 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 654 | iwl3945_send_qos_params_command(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 655 | &(priv->qos_data.def_qos_parm)); |
| 656 | } |
| 657 | } |
| 658 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 659 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 660 | #define MAX_UCODE_BEACON_INTERVAL 1024 |
Harvey Harrison | c1b4aa3 | 2009-01-29 13:26:44 -0800 | [diff] [blame] | 661 | #define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 662 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 663 | static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 664 | { |
| 665 | u16 new_val = 0; |
| 666 | u16 beacon_factor = 0; |
| 667 | |
| 668 | beacon_factor = |
| 669 | (beacon_val + MAX_UCODE_BEACON_INTERVAL) |
| 670 | / MAX_UCODE_BEACON_INTERVAL; |
| 671 | new_val = beacon_val / beacon_factor; |
| 672 | |
| 673 | return cpu_to_le16(new_val); |
| 674 | } |
| 675 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 676 | static void iwl3945_setup_rxon_timing(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 677 | { |
| 678 | u64 interval_tm_unit; |
| 679 | u64 tsf, result; |
| 680 | unsigned long flags; |
| 681 | struct ieee80211_conf *conf = NULL; |
| 682 | u16 beacon_int = 0; |
| 683 | |
| 684 | conf = ieee80211_get_hw_conf(priv->hw); |
| 685 | |
| 686 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 687 | priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 688 | priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL; |
| 689 | |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 690 | tsf = priv->timestamp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 691 | |
| 692 | beacon_int = priv->beacon_int; |
| 693 | spin_unlock_irqrestore(&priv->lock, flags); |
| 694 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 695 | if (priv->iw_mode == NL80211_IFTYPE_STATION) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 696 | if (beacon_int == 0) { |
| 697 | priv->rxon_timing.beacon_interval = cpu_to_le16(100); |
| 698 | priv->rxon_timing.beacon_init_val = cpu_to_le32(102400); |
| 699 | } else { |
| 700 | priv->rxon_timing.beacon_interval = |
| 701 | cpu_to_le16(beacon_int); |
| 702 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 703 | iwl3945_adjust_beacon_interval( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 704 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 705 | } |
| 706 | |
| 707 | priv->rxon_timing.atim_window = 0; |
| 708 | } else { |
| 709 | priv->rxon_timing.beacon_interval = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 710 | iwl3945_adjust_beacon_interval(conf->beacon_int); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 711 | /* TODO: we need to get atim_window from upper stack |
| 712 | * for now we set to 0 */ |
| 713 | priv->rxon_timing.atim_window = 0; |
| 714 | } |
| 715 | |
| 716 | interval_tm_unit = |
| 717 | (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024); |
| 718 | result = do_div(tsf, interval_tm_unit); |
| 719 | priv->rxon_timing.beacon_init_val = |
| 720 | cpu_to_le32((u32) ((u64) interval_tm_unit - result)); |
| 721 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 722 | IWL_DEBUG_ASSOC(priv, |
| 723 | "beacon interval %d beacon timer %d beacon tim %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 724 | le16_to_cpu(priv->rxon_timing.beacon_interval), |
| 725 | le32_to_cpu(priv->rxon_timing.beacon_init_val), |
| 726 | le16_to_cpu(priv->rxon_timing.atim_window)); |
| 727 | } |
| 728 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 729 | static int iwl3945_set_mode(struct iwl_priv *priv, int mode) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 730 | { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 731 | if (mode == NL80211_IFTYPE_ADHOC) { |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 732 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 733 | |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 734 | ch_info = iwl_get_channel_info(priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 735 | priv->band, |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 736 | le16_to_cpu(priv->staging_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 737 | |
| 738 | if (!ch_info || !is_channel_ibss(ch_info)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 739 | IWL_ERR(priv, "channel %d not IBSS channel\n", |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 740 | le16_to_cpu(priv->staging_rxon.channel)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 741 | return -EINVAL; |
| 742 | } |
| 743 | } |
| 744 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 745 | iwl_connection_init_rx_config(priv, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 746 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 747 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 748 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 749 | /* don't commit rxon if rf-kill is on*/ |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 750 | if (!iwl_is_ready_rf(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 751 | return -EAGAIN; |
| 752 | |
| 753 | cancel_delayed_work(&priv->scan_check); |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 754 | if (iwl_scan_cancel_timeout(priv, 100)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 755 | IWL_WARN(priv, "Aborted scan still in progress after 100ms\n"); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 756 | IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n"); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 757 | return -EAGAIN; |
| 758 | } |
| 759 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 760 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 761 | |
| 762 | return 0; |
| 763 | } |
| 764 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 765 | static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 766 | struct ieee80211_tx_info *info, |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 767 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 768 | struct sk_buff *skb_frag, |
| 769 | int last_frag) |
| 770 | { |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 771 | struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload; |
Ivo van Doorn | 1c01442 | 2008-04-17 19:41:02 +0200 | [diff] [blame] | 772 | struct iwl3945_hw_key *keyinfo = |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 773 | &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 774 | |
| 775 | switch (keyinfo->alg) { |
| 776 | case ALG_CCMP: |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 777 | tx->sec_ctl = TX_CMD_SEC_CCM; |
| 778 | memcpy(tx->key, keyinfo->key, keyinfo->keylen); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 779 | IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 780 | break; |
| 781 | |
| 782 | case ALG_TKIP: |
| 783 | #if 0 |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 784 | tx->sec_ctl = TX_CMD_SEC_TKIP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 785 | |
| 786 | if (last_frag) |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 787 | memcpy(tx->tkip_mic.byte, skb_frag->tail - 8, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 788 | 8); |
| 789 | else |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 790 | memset(tx->tkip_mic.byte, 0, 8); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 791 | #endif |
| 792 | break; |
| 793 | |
| 794 | case ALG_WEP: |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 795 | tx->sec_ctl = TX_CMD_SEC_WEP | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 796 | (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] | 797 | |
| 798 | if (keyinfo->keylen == 13) |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 799 | tx->sec_ctl |= TX_CMD_SEC_KEY128; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 800 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 801 | memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 802 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 803 | IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption " |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 804 | "with key %d\n", info->control.hw_key->hw_key_idx); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 805 | break; |
| 806 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 807 | default: |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 808 | IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 809 | break; |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | /* |
| 814 | * handle build REPLY_TX command notification. |
| 815 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 816 | static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv, |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 817 | struct iwl_cmd *cmd, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 818 | struct ieee80211_tx_info *info, |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 819 | struct ieee80211_hdr *hdr, u8 std_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 820 | { |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 821 | struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload; |
| 822 | __le32 tx_flags = tx->tx_flags; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 823 | __le16 fc = hdr->frame_control; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 824 | u8 rc_flags = info->control.rates[0].flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 825 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 826 | tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 827 | if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 828 | tx_flags |= TX_CMD_FLG_ACK_MSK; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 829 | if (ieee80211_is_mgmt(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 830 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 831 | if (ieee80211_is_probe_resp(fc) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 832 | !(le16_to_cpu(hdr->seq_ctrl) & 0xf)) |
| 833 | tx_flags |= TX_CMD_FLG_TSF_MSK; |
| 834 | } else { |
| 835 | tx_flags &= (~TX_CMD_FLG_ACK_MSK); |
| 836 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
| 837 | } |
| 838 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 839 | tx->sta_id = std_id; |
Harvey Harrison | 8b7b1e0 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 840 | if (ieee80211_has_morefrags(fc)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 841 | tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; |
| 842 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 843 | if (ieee80211_is_data_qos(fc)) { |
| 844 | u8 *qc = ieee80211_get_qos_ctl(hdr); |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 845 | tx->tid_tspec = qc[0] & 0xf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 846 | tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 847 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 848 | tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 849 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 850 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 851 | if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 852 | tx_flags |= TX_CMD_FLG_RTS_MSK; |
| 853 | tx_flags &= ~TX_CMD_FLG_CTS_MSK; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 854 | } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 855 | tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 856 | tx_flags |= TX_CMD_FLG_CTS_MSK; |
| 857 | } |
| 858 | |
| 859 | if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK)) |
| 860 | tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK; |
| 861 | |
| 862 | tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 863 | if (ieee80211_is_mgmt(fc)) { |
| 864 | if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc)) |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 865 | tx->timeout.pm_frame_timeout = cpu_to_le16(3); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 866 | else |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 867 | tx->timeout.pm_frame_timeout = cpu_to_le16(2); |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 868 | } else { |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 869 | tx->timeout.pm_frame_timeout = 0; |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 870 | #ifdef CONFIG_IWL3945_LEDS |
| 871 | priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len); |
| 872 | #endif |
| 873 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 874 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 875 | tx->driver_txop = 0; |
| 876 | tx->tx_flags = tx_flags; |
| 877 | tx->next_frame_len = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 878 | } |
| 879 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 880 | /** |
| 881 | * iwl3945_get_sta_id - Find station's index within station table |
| 882 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 883 | static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 884 | { |
| 885 | int sta_id; |
| 886 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 887 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 888 | /* If this frame is broadcast or management, use broadcast station id */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 889 | if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) || |
| 890 | is_multicast_ether_addr(hdr->addr1)) |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 891 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 892 | |
| 893 | switch (priv->iw_mode) { |
| 894 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 895 | /* If we are a client station in a BSS network, use the special |
| 896 | * AP station entry (that's the only station we communicate with) */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 897 | case NL80211_IFTYPE_STATION: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 898 | return IWL_AP_ID; |
| 899 | |
| 900 | /* If we are an AP, then find the station, or use BCAST */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 901 | case NL80211_IFTYPE_AP: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 902 | sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 903 | if (sta_id != IWL_INVALID_STATION) |
| 904 | return sta_id; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 905 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 906 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 907 | /* If this frame is going out to an IBSS network, find the station, |
| 908 | * or create a new station table entry */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 909 | case NL80211_IFTYPE_ADHOC: { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 910 | /* Create new station table entry */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 911 | sta_id = iwl3945_hw_find_station(priv, hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 912 | if (sta_id != IWL_INVALID_STATION) |
| 913 | return sta_id; |
| 914 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 915 | sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 916 | |
| 917 | if (sta_id != IWL_INVALID_STATION) |
| 918 | return sta_id; |
| 919 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 920 | IWL_DEBUG_DROP(priv, "Station %pM not in station map. " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 921 | "Defaulting to broadcast...\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 922 | hdr->addr1); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 923 | iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr)); |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 924 | return priv->hw_params.bcast_sta_id; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 925 | } |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 926 | /* If we are in monitor mode, use BCAST. This is required for |
| 927 | * packet injection. */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 928 | case NL80211_IFTYPE_MONITOR: |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 929 | return priv->hw_params.bcast_sta_id; |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 930 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 931 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 932 | IWL_WARN(priv, "Unknown mode of operation: %d\n", |
| 933 | priv->iw_mode); |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 934 | return priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | |
| 938 | /* |
| 939 | * start REPLY_TX command process |
| 940 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 941 | 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] | 942 | { |
| 943 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 944 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 945 | struct iwl3945_tx_cmd *tx; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 946 | struct iwl_tx_queue *txq = NULL; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 947 | struct iwl_queue *q = NULL; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 948 | struct iwl_cmd *out_cmd = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 949 | dma_addr_t phys_addr; |
| 950 | dma_addr_t txcmd_phys; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 951 | int txq_id = skb_get_queue_mapping(skb); |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 952 | u16 len, idx, len_org, hdr_len; |
| 953 | u8 id; |
| 954 | u8 unicast; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 955 | u8 sta_id; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 956 | u8 tid = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 957 | u16 seq_number = 0; |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 958 | __le16 fc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 959 | u8 wait_write_ptr = 0; |
Tomas Winkler | 54dbb52 | 2008-05-15 13:54:06 +0800 | [diff] [blame] | 960 | u8 *qc = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 961 | unsigned long flags; |
| 962 | int rc; |
| 963 | |
| 964 | spin_lock_irqsave(&priv->lock, flags); |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 965 | if (iwl_is_rfkill(priv)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 966 | IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 967 | goto drop_unlock; |
| 968 | } |
| 969 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 970 | 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] | 971 | IWL_ERR(priv, "ERROR: No TX rate available.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 972 | goto drop_unlock; |
| 973 | } |
| 974 | |
| 975 | unicast = !is_multicast_ether_addr(hdr->addr1); |
| 976 | id = 0; |
| 977 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 978 | fc = hdr->frame_control; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 979 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 980 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 981 | if (ieee80211_is_auth(fc)) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 982 | IWL_DEBUG_TX(priv, "Sending AUTH frame\n"); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 983 | else if (ieee80211_is_assoc_req(fc)) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 984 | IWL_DEBUG_TX(priv, "Sending ASSOC frame\n"); |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 985 | else if (ieee80211_is_reassoc_req(fc)) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 986 | IWL_DEBUG_TX(priv, "Sending REASSOC frame\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 987 | #endif |
| 988 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 989 | /* drop all data frame if we are not associated */ |
Stefanik Gábor | 914233d | 2008-06-30 17:23:30 +0800 | [diff] [blame] | 990 | if (ieee80211_is_data(fc) && |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 991 | (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 992 | (!iwl_is_associated(priv) || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 993 | ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 994 | IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 995 | goto drop_unlock; |
| 996 | } |
| 997 | |
| 998 | spin_unlock_irqrestore(&priv->lock, flags); |
| 999 | |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 1000 | hdr_len = ieee80211_hdrlen(fc); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1001 | |
| 1002 | /* Find (or create) index into station table for destination station */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1003 | sta_id = iwl3945_get_sta_id(priv, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1004 | if (sta_id == IWL_INVALID_STATION) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1005 | IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 1006 | hdr->addr1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1007 | goto drop; |
| 1008 | } |
| 1009 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1010 | IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1011 | |
Harvey Harrison | fd7c8a4 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 1012 | if (ieee80211_is_data_qos(fc)) { |
| 1013 | qc = ieee80211_get_qos_ctl(hdr); |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 1014 | tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1015 | seq_number = priv->stations_39[sta_id].tid[tid].seq_number & |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1016 | IEEE80211_SCTL_SEQ; |
| 1017 | hdr->seq_ctrl = cpu_to_le16(seq_number) | |
| 1018 | (hdr->seq_ctrl & |
Harvey Harrison | c1b4aa3 | 2009-01-29 13:26:44 -0800 | [diff] [blame] | 1019 | cpu_to_le16(IEEE80211_SCTL_FRAG)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1020 | seq_number += 0x10; |
| 1021 | } |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1022 | |
| 1023 | /* Descriptor for chosen Tx queue */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 1024 | txq = &priv->txq[txq_id]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1025 | q = &txq->q; |
| 1026 | |
| 1027 | spin_lock_irqsave(&priv->lock, flags); |
| 1028 | |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1029 | idx = get_cmd_index(q, q->write_ptr, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1030 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1031 | /* Set up driver data for this TFD */ |
Winkler, Tomas | dbb6654 | 2008-12-22 11:31:14 +0800 | [diff] [blame] | 1032 | memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info)); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1033 | txq->txb[q->write_ptr].skb[0] = skb; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1034 | |
| 1035 | /* Init first empty entry in queue's array of Tx/cmd buffers */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 1036 | out_cmd = txq->cmd[idx]; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 1037 | tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1038 | memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr)); |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 1039 | memset(tx, 0, sizeof(*tx)); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1040 | |
| 1041 | /* |
| 1042 | * Set up the Tx-command (not MAC!) header. |
| 1043 | * Store the chosen Tx queue and TFD index within the sequence field; |
| 1044 | * after Tx, uCode's Tx response will return this value so driver can |
| 1045 | * locate the frame within the tx queue and do post-tx processing. |
| 1046 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1047 | out_cmd->hdr.cmd = REPLY_TX; |
| 1048 | 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] | 1049 | INDEX_TO_SEQ(q->write_ptr))); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1050 | |
| 1051 | /* Copy MAC header from skb into command buffer */ |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 1052 | memcpy(tx->hdr, hdr, hdr_len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1053 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1054 | /* |
| 1055 | * Use the first empty entry in this queue's command buffer array |
| 1056 | * to contain the Tx command and MAC header concatenated together |
| 1057 | * (payload data will be in another buffer). |
| 1058 | * Size of this varies, due to varying MAC header length. |
| 1059 | * If end is not dword aligned, we'll have 2 extra bytes at the end |
| 1060 | * of the MAC header (device reads on dword boundaries). |
| 1061 | * We'll tell device about this padding later. |
| 1062 | */ |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 1063 | len = sizeof(struct iwl3945_tx_cmd) + |
Tomas Winkler | 4c89725 | 2008-12-19 10:37:05 +0800 | [diff] [blame] | 1064 | sizeof(struct iwl_cmd_header) + hdr_len; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1065 | |
| 1066 | len_org = len; |
| 1067 | len = (len + 3) & ~3; |
| 1068 | |
| 1069 | if (len_org != len) |
| 1070 | len_org = 1; |
| 1071 | else |
| 1072 | len_org = 0; |
| 1073 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1074 | /* Physical address of this Tx command's header (not MAC header!), |
| 1075 | * within command buffer array. */ |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 1076 | txcmd_phys = pci_map_single(priv->pci_dev, |
| 1077 | out_cmd, sizeof(struct iwl_cmd), |
| 1078 | PCI_DMA_TODEVICE); |
| 1079 | pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys); |
| 1080 | pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd)); |
| 1081 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 1082 | * first entry */ |
| 1083 | txcmd_phys += offsetof(struct iwl_cmd, hdr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1084 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1085 | /* Add buffer containing Tx command and MAC(!) header to TFD's |
| 1086 | * first entry */ |
Samuel Ortiz | 7aaa1d7 | 2009-01-19 15:30:26 -0800 | [diff] [blame] | 1087 | priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq, |
| 1088 | txcmd_phys, len, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1089 | |
Johannes Berg | d0f0980 | 2008-07-29 11:32:07 +0200 | [diff] [blame] | 1090 | if (info->control.hw_key) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1091 | iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1092 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1093 | /* Set up TFD's 2nd entry to point directly to remainder of skb, |
| 1094 | * if any (802.11 null frames have no payload). */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1095 | len = skb->len - hdr_len; |
| 1096 | if (len) { |
| 1097 | phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len, |
| 1098 | len, PCI_DMA_TODEVICE); |
Samuel Ortiz | 7aaa1d7 | 2009-01-19 15:30:26 -0800 | [diff] [blame] | 1099 | priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq, |
| 1100 | phys_addr, len, |
| 1101 | 0, U32_PAD(len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1104 | /* Total # bytes to be transmitted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1105 | len = (u16)skb->len; |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 1106 | tx->len = cpu_to_le16(len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1107 | |
| 1108 | /* TODO need this for burst mode later on */ |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 1109 | iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1110 | |
| 1111 | /* set is_hcca to 0; it probably will never be implemented */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1112 | iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1113 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 1114 | tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK; |
| 1115 | tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1116 | |
Harvey Harrison | 8b7b1e0 | 2008-06-11 14:21:56 -0700 | [diff] [blame] | 1117 | if (!ieee80211_has_morefrags(hdr->frame_control)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1118 | txq->need_update = 1; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 1119 | if (qc) |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 1120 | priv->stations_39[sta_id].tid[tid].seq_number = seq_number; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1121 | } else { |
| 1122 | wait_write_ptr = 1; |
| 1123 | txq->need_update = 0; |
| 1124 | } |
| 1125 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 1126 | iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1127 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 1128 | iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr, |
Harvey Harrison | 7294ec9 | 2008-07-15 18:43:59 -0700 | [diff] [blame] | 1129 | ieee80211_hdrlen(fc)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1130 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1131 | /* Tell device the write index *just past* this latest filled TFD */ |
Tomas Winkler | c54b679 | 2008-03-06 17:36:53 -0800 | [diff] [blame] | 1132 | q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd); |
Samuel Ortiz | 4f3602c | 2009-01-19 15:30:25 -0800 | [diff] [blame] | 1133 | rc = iwl_txq_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1134 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1135 | |
| 1136 | if (rc) |
| 1137 | return rc; |
| 1138 | |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 1139 | if ((iwl_queue_space(q) < q->high_mark) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1140 | && priv->mac80211_registered) { |
| 1141 | if (wait_write_ptr) { |
| 1142 | spin_lock_irqsave(&priv->lock, flags); |
| 1143 | txq->need_update = 1; |
Samuel Ortiz | 4f3602c | 2009-01-19 15:30:25 -0800 | [diff] [blame] | 1144 | iwl_txq_update_write_ptr(priv, txq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1145 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1146 | } |
| 1147 | |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 1148 | ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | return 0; |
| 1152 | |
| 1153 | drop_unlock: |
| 1154 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1155 | drop: |
| 1156 | return -1; |
| 1157 | } |
| 1158 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 1159 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1160 | |
| 1161 | #include "iwl-spectrum.h" |
| 1162 | |
| 1163 | #define BEACON_TIME_MASK_LOW 0x00FFFFFF |
| 1164 | #define BEACON_TIME_MASK_HIGH 0xFF000000 |
| 1165 | #define TIME_UNIT 1024 |
| 1166 | |
| 1167 | /* |
| 1168 | * extended beacon time format |
| 1169 | * time in usec will be changed into a 32-bit value in 8:24 format |
| 1170 | * the high 1 byte is the beacon counts |
| 1171 | * the lower 3 bytes is the time in usec within one beacon interval |
| 1172 | */ |
| 1173 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1174 | static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1175 | { |
| 1176 | u32 quot; |
| 1177 | u32 rem; |
| 1178 | u32 interval = beacon_interval * 1024; |
| 1179 | |
| 1180 | if (!interval || !usec) |
| 1181 | return 0; |
| 1182 | |
| 1183 | quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24); |
| 1184 | rem = (usec % interval) & BEACON_TIME_MASK_LOW; |
| 1185 | |
| 1186 | return (quot << 24) + rem; |
| 1187 | } |
| 1188 | |
| 1189 | /* base is usually what we get from ucode with each received frame, |
| 1190 | * the same as HW timer counter counting down |
| 1191 | */ |
| 1192 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1193 | static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1194 | { |
| 1195 | u32 base_low = base & BEACON_TIME_MASK_LOW; |
| 1196 | u32 addon_low = addon & BEACON_TIME_MASK_LOW; |
| 1197 | u32 interval = beacon_interval * TIME_UNIT; |
| 1198 | u32 res = (base & BEACON_TIME_MASK_HIGH) + |
| 1199 | (addon & BEACON_TIME_MASK_HIGH); |
| 1200 | |
| 1201 | if (base_low > addon_low) |
| 1202 | res += base_low - addon_low; |
| 1203 | else if (base_low < addon_low) { |
| 1204 | res += interval + base_low - addon_low; |
| 1205 | res += (1 << 24); |
| 1206 | } else |
| 1207 | res += (1 << 24); |
| 1208 | |
| 1209 | return cpu_to_le32(res); |
| 1210 | } |
| 1211 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1212 | static int iwl3945_get_measurement(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1213 | struct ieee80211_measurement_params *params, |
| 1214 | u8 type) |
| 1215 | { |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1216 | struct iwl_spectrum_cmd spectrum; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1217 | struct iwl_rx_packet *res; |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1218 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1219 | .id = REPLY_SPECTRUM_MEASUREMENT_CMD, |
| 1220 | .data = (void *)&spectrum, |
| 1221 | .meta.flags = CMD_WANT_SKB, |
| 1222 | }; |
| 1223 | u32 add_time = le64_to_cpu(params->start_time); |
| 1224 | int rc; |
| 1225 | int spectrum_resp_status; |
| 1226 | int duration = le16_to_cpu(params->duration); |
| 1227 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 1228 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1229 | add_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1230 | iwl3945_usecs_to_beacons( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1231 | le64_to_cpu(params->start_time) - priv->last_tsf, |
| 1232 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1233 | |
| 1234 | memset(&spectrum, 0, sizeof(spectrum)); |
| 1235 | |
| 1236 | spectrum.channel_count = cpu_to_le16(1); |
| 1237 | spectrum.flags = |
| 1238 | RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK; |
| 1239 | spectrum.filter_flags = MEASUREMENT_FILTER_FLAG; |
| 1240 | cmd.len = sizeof(spectrum); |
| 1241 | spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); |
| 1242 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 1243 | if (iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1244 | spectrum.start_time = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1245 | iwl3945_add_beacon_time(priv->last_beacon_time, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1246 | add_time, |
| 1247 | le16_to_cpu(priv->rxon_timing.beacon_interval)); |
| 1248 | else |
| 1249 | spectrum.start_time = 0; |
| 1250 | |
| 1251 | spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); |
| 1252 | spectrum.channels[0].channel = params->channel; |
| 1253 | spectrum.channels[0].type = type; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 1254 | if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1255 | spectrum.flags |= RXON_FLG_BAND_24G_MSK | |
| 1256 | RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; |
| 1257 | |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 1258 | rc = iwl_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1259 | if (rc) |
| 1260 | return rc; |
| 1261 | |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1262 | res = (struct iwl_rx_packet *)cmd.meta.u.skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1263 | if (res->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1264 | IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1265 | rc = -EIO; |
| 1266 | } |
| 1267 | |
| 1268 | spectrum_resp_status = le16_to_cpu(res->u.spectrum.status); |
| 1269 | switch (spectrum_resp_status) { |
| 1270 | case 0: /* Command will be handled */ |
| 1271 | if (res->u.spectrum.id != 0xff) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1272 | IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n", |
Ian Schram | bc434dd | 2007-10-25 17:15:29 +0800 | [diff] [blame] | 1273 | res->u.spectrum.id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1274 | priv->measurement_status &= ~MEASUREMENT_READY; |
| 1275 | } |
| 1276 | priv->measurement_status |= MEASUREMENT_ACTIVE; |
| 1277 | rc = 0; |
| 1278 | break; |
| 1279 | |
| 1280 | case 1: /* Command will not be handled */ |
| 1281 | rc = -EAGAIN; |
| 1282 | break; |
| 1283 | } |
| 1284 | |
| 1285 | dev_kfree_skb_any(cmd.meta.u.skb); |
| 1286 | |
| 1287 | return rc; |
| 1288 | } |
| 1289 | #endif |
| 1290 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1291 | static void iwl3945_rx_reply_alive(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1292 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1293 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1294 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
| 1295 | struct iwl_alive_resp *palive; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1296 | struct delayed_work *pwork; |
| 1297 | |
| 1298 | palive = &pkt->u.alive_frame; |
| 1299 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1300 | IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1301 | "0x%01X 0x%01X\n", |
| 1302 | palive->is_valid, palive->ver_type, |
| 1303 | palive->ver_subtype); |
| 1304 | |
| 1305 | if (palive->ver_subtype == INITIALIZE_SUBTYPE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1306 | IWL_DEBUG_INFO(priv, "Initialization Alive received.\n"); |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1307 | memcpy(&priv->card_alive_init, &pkt->u.alive_frame, |
| 1308 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1309 | pwork = &priv->init_alive_start; |
| 1310 | } else { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1311 | IWL_DEBUG_INFO(priv, "Runtime Alive received.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1312 | memcpy(&priv->card_alive, &pkt->u.alive_frame, |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1313 | sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1314 | pwork = &priv->alive_start; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1315 | iwl3945_disable_events(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | /* We delay the ALIVE response by 5ms to |
| 1319 | * give the HW RF Kill time to activate... */ |
| 1320 | if (palive->is_valid == UCODE_VALID_OK) |
| 1321 | queue_delayed_work(priv->workqueue, pwork, |
| 1322 | msecs_to_jiffies(5)); |
| 1323 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1324 | IWL_WARN(priv, "uCode did not respond OK.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1327 | static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1328 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1329 | { |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 1330 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1331 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Helmut Schaa | c7e035a | 2009-01-19 13:02:15 +0100 | [diff] [blame] | 1332 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1333 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1334 | 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] | 1335 | return; |
| 1336 | } |
| 1337 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1338 | static void iwl3945_bg_beacon_update(struct work_struct *work) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1339 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1340 | struct iwl_priv *priv = |
| 1341 | container_of(work, struct iwl_priv, beacon_update); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1342 | struct sk_buff *beacon; |
| 1343 | |
| 1344 | /* 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] | 1345 | beacon = ieee80211_beacon_get(priv->hw, priv->vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1346 | |
| 1347 | if (!beacon) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1348 | IWL_ERR(priv, "update beacon failed\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1349 | return; |
| 1350 | } |
| 1351 | |
| 1352 | mutex_lock(&priv->mutex); |
| 1353 | /* new beacon skb is allocated every time; dispose previous.*/ |
| 1354 | if (priv->ibss_beacon) |
| 1355 | dev_kfree_skb(priv->ibss_beacon); |
| 1356 | |
| 1357 | priv->ibss_beacon = beacon; |
| 1358 | mutex_unlock(&priv->mutex); |
| 1359 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1360 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1363 | static void iwl3945_rx_beacon_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1364 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1365 | { |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 1366 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1367 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1368 | struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1369 | u8 rate = beacon->beacon_notify_hdr.rate; |
| 1370 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1371 | IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1372 | "tsf %d %d rate %d\n", |
| 1373 | le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK, |
| 1374 | beacon->beacon_notify_hdr.failure_frame, |
| 1375 | le32_to_cpu(beacon->ibss_mgr_status), |
| 1376 | le32_to_cpu(beacon->high_tsf), |
| 1377 | le32_to_cpu(beacon->low_tsf), rate); |
| 1378 | #endif |
| 1379 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1380 | if ((priv->iw_mode == NL80211_IFTYPE_AP) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1381 | (!test_bit(STATUS_EXIT_PENDING, &priv->status))) |
| 1382 | queue_work(priv->workqueue, &priv->beacon_update); |
| 1383 | } |
| 1384 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1385 | /* Handle notification from uCode that card's power state is changing |
| 1386 | * due to software, hardware, or critical temperature RFKILL */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1387 | static void iwl3945_rx_card_state_notif(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1388 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1389 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1390 | struct iwl_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1391 | u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags); |
| 1392 | unsigned long status = priv->status; |
| 1393 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1394 | IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1395 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 1396 | (flags & SW_CARD_DISABLED) ? "Kill" : "On"); |
| 1397 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1398 | iwl_write32(priv, CSR_UCODE_DRV_GP1_SET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1399 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 1400 | |
| 1401 | if (flags & HW_CARD_DISABLED) |
| 1402 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 1403 | else |
| 1404 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 1405 | |
| 1406 | |
| 1407 | if (flags & SW_CARD_DISABLED) |
| 1408 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
| 1409 | else |
| 1410 | clear_bit(STATUS_RF_KILL_SW, &priv->status); |
| 1411 | |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 1412 | iwl_scan_cancel(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1413 | |
| 1414 | if ((test_bit(STATUS_RF_KILL_HW, &status) != |
| 1415 | test_bit(STATUS_RF_KILL_HW, &priv->status)) || |
| 1416 | (test_bit(STATUS_RF_KILL_SW, &status) != |
| 1417 | test_bit(STATUS_RF_KILL_SW, &priv->status))) |
| 1418 | queue_work(priv->workqueue, &priv->rf_kill); |
| 1419 | else |
| 1420 | wake_up_interruptible(&priv->wait_command_queue); |
| 1421 | } |
| 1422 | |
| 1423 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1424 | * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1425 | * |
| 1426 | * Setup the RX handlers for each of the reply types sent from the uCode |
| 1427 | * to the host. |
| 1428 | * |
| 1429 | * This function chains into the hardware specific files for them to setup |
| 1430 | * any hardware specific handlers as well. |
| 1431 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1432 | static void iwl3945_setup_rx_handlers(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1433 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1434 | priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive; |
| 1435 | priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta; |
Abhijeet Kolekar | 261b9c3 | 2009-02-18 15:54:29 -0800 | [diff] [blame] | 1436 | priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error; |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 1437 | priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa; |
Abhijeet Kolekar | 030f05e | 2009-02-18 15:54:28 -0800 | [diff] [blame] | 1438 | priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1439 | priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] = |
Abhijeet Kolekar | 030f05e | 2009-02-18 15:54:28 -0800 | [diff] [blame] | 1440 | iwl_rx_pm_debug_statistics_notif; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1441 | priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1442 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1443 | /* |
| 1444 | * The same handler is used for both the REPLY to a discrete |
| 1445 | * statistics request from the host as well as for the periodic |
| 1446 | * statistics notifications (after received beacons) from the uCode. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1447 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1448 | priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics; |
| 1449 | priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1450 | |
Abhijeet Kolekar | 261b9c3 | 2009-02-18 15:54:29 -0800 | [diff] [blame] | 1451 | iwl_setup_spectrum_handlers(priv); |
Abhijeet Kolekar | cade0eb | 2009-02-18 15:54:26 -0800 | [diff] [blame] | 1452 | iwl_setup_rx_scan_handlers(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1453 | priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1454 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1455 | /* Set up hardware specific Rx handlers */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1456 | iwl3945_hw_rx_handler_setup(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | /** |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 1460 | * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries |
| 1461 | * When FW advances 'R' index, all entries between old and new 'R' index |
| 1462 | * need to be reclaimed. |
| 1463 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1464 | static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv, |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 1465 | int txq_id, int index) |
| 1466 | { |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 1467 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 1468 | struct iwl_queue *q = &txq->q; |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 1469 | int nfreed = 0; |
| 1470 | |
Winkler, Tomas | 625a381 | 2009-01-08 10:19:55 -0800 | [diff] [blame] | 1471 | if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1472 | IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, " |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 1473 | "is out of range [0-%d] %d %d.\n", txq_id, |
| 1474 | index, q->n_bd, q->write_ptr, q->read_ptr); |
| 1475 | return; |
| 1476 | } |
| 1477 | |
| 1478 | for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index; |
| 1479 | q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { |
| 1480 | if (nfreed > 1) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1481 | IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index, |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 1482 | q->write_ptr, q->read_ptr); |
| 1483 | queue_work(priv->workqueue, &priv->restart); |
| 1484 | break; |
| 1485 | } |
| 1486 | nfreed++; |
| 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | |
| 1491 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1492 | * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1493 | * @rxb: Rx buffer to reclaim |
| 1494 | * |
| 1495 | * If an Rx buffer has an async callback associated with it the callback |
| 1496 | * will be executed. The attached skb (if present) will only be freed |
| 1497 | * if the callback returns 1 |
| 1498 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1499 | static void iwl3945_tx_cmd_complete(struct iwl_priv *priv, |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1500 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1501 | { |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1502 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1503 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 1504 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 1505 | int index = SEQ_TO_INDEX(sequence); |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 1506 | int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1507 | int cmd_index; |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 1508 | struct iwl_cmd *cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1509 | |
Chatre, Reinette | 638d0eb | 2009-01-19 15:30:24 -0800 | [diff] [blame] | 1510 | if (WARN(txq_id != IWL_CMD_QUEUE_NUM, |
| 1511 | "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n", |
| 1512 | txq_id, sequence, |
| 1513 | priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr, |
| 1514 | priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) { |
| 1515 | iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32); |
| 1516 | return; |
| 1517 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1518 | |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 1519 | cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge); |
| 1520 | cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1521 | |
| 1522 | /* Input error checking is done when commands are added to queue. */ |
| 1523 | if (cmd->meta.flags & CMD_WANT_SKB) { |
| 1524 | cmd->meta.source->u.skb = rxb->skb; |
| 1525 | rxb->skb = NULL; |
| 1526 | } else if (cmd->meta.u.callback && |
| 1527 | !cmd->meta.u.callback(priv, cmd, rxb->skb)) |
| 1528 | rxb->skb = NULL; |
| 1529 | |
Tomas Winkler | 91c066f | 2008-03-06 17:36:55 -0800 | [diff] [blame] | 1530 | iwl3945_cmd_queue_reclaim(priv, txq_id, index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1531 | |
| 1532 | if (!(cmd->meta.flags & CMD_ASYNC)) { |
| 1533 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 1534 | wake_up_interruptible(&priv->wait_command_queue); |
| 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | /************************** RX-FUNCTIONS ****************************/ |
| 1539 | /* |
| 1540 | * Rx theory of operation |
| 1541 | * |
| 1542 | * The host allocates 32 DMA target addresses and passes the host address |
| 1543 | * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is |
| 1544 | * 0 to 31 |
| 1545 | * |
| 1546 | * Rx Queue Indexes |
| 1547 | * The host/firmware share two index registers for managing the Rx buffers. |
| 1548 | * |
| 1549 | * The READ index maps to the first position that the firmware may be writing |
| 1550 | * to -- the driver can read up to (but not including) this position and get |
| 1551 | * good data. |
| 1552 | * The READ index is managed by the firmware once the card is enabled. |
| 1553 | * |
| 1554 | * The WRITE index maps to the last position the driver has read from -- the |
| 1555 | * position preceding WRITE is the last slot the firmware can place a packet. |
| 1556 | * |
| 1557 | * The queue is empty (no good data) if WRITE = READ - 1, and is full if |
| 1558 | * WRITE = READ. |
| 1559 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1560 | * 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] | 1561 | * INDEX position, and WRITE to the last (READ - 1 wrapped) |
| 1562 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1563 | * 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] | 1564 | * and fire the RX interrupt. The driver can then query the READ index and |
| 1565 | * process as many packets as possible, moving the WRITE index forward as it |
| 1566 | * resets the Rx queue buffers with new memory. |
| 1567 | * |
| 1568 | * The management in the driver is as follows: |
| 1569 | * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When |
| 1570 | * 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] | 1571 | * to replenish the iwl->rxq->rx_free. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1572 | * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1573 | * iwl->rxq is replenished and the READ INDEX is updated (updating the |
| 1574 | * 'processed' and 'read' driver indexes as well) |
| 1575 | * + A received packet is processed and handed to the kernel network stack, |
| 1576 | * detached from the iwl->rxq. The driver 'processed' index is updated. |
| 1577 | * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free |
| 1578 | * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ |
| 1579 | * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there |
| 1580 | * were enough free buffers and RX_STALLED is set it is cleared. |
| 1581 | * |
| 1582 | * |
| 1583 | * Driver sequence: |
| 1584 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1585 | * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1586 | * iwl3945_rx_queue_restock |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1587 | * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1588 | * queue, updates firmware pointers, and updates |
| 1589 | * the WRITE index. If insufficient rx_free buffers |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1590 | * are available, schedules iwl3945_rx_replenish |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1591 | * |
| 1592 | * -- enable interrupts -- |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1593 | * 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] | 1594 | * READ INDEX, detaching the SKB from the pool. |
| 1595 | * Moves the packet buffer from queue to rx_used. |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1596 | * Calls iwl3945_rx_queue_restock to refill any empty |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1597 | * slots. |
| 1598 | * ... |
| 1599 | * |
| 1600 | */ |
| 1601 | |
| 1602 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1603 | * 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] | 1604 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1605 | static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1606 | dma_addr_t dma_addr) |
| 1607 | { |
| 1608 | return cpu_to_le32((u32)dma_addr); |
| 1609 | } |
| 1610 | |
| 1611 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1612 | * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1613 | * |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1614 | * 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] | 1615 | * and we have free pre-allocated buffers, fill the ranks as much |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1616 | * as we can, pulling from rx_free. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1617 | * |
| 1618 | * This moves the 'write' index forward to catch up with 'processed', and |
| 1619 | * also updates the memory address in the firmware to reference the new |
| 1620 | * target buffer. |
| 1621 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1622 | static int iwl3945_rx_queue_restock(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1623 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 1624 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1625 | struct list_head *element; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1626 | struct iwl_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1627 | unsigned long flags; |
| 1628 | int write, rc; |
| 1629 | |
| 1630 | spin_lock_irqsave(&rxq->lock, flags); |
| 1631 | write = rxq->write & ~0x7; |
Winkler, Tomas | 37d6831 | 2009-01-08 10:19:54 -0800 | [diff] [blame] | 1632 | while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) { |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1633 | /* Get next free Rx buffer, remove from free list */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1634 | element = rxq->rx_free.next; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1635 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1636 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1637 | |
| 1638 | /* Point to Rx buffer via next RBD in circular buffer */ |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1639 | rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1640 | rxq->queue[rxq->write] = rxb; |
| 1641 | rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; |
| 1642 | rxq->free_count--; |
| 1643 | } |
| 1644 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 1645 | /* If the pre-allocated buffer pool is dropping low, schedule to |
| 1646 | * refill it */ |
| 1647 | if (rxq->free_count <= RX_LOW_WATERMARK) |
| 1648 | queue_work(priv->workqueue, &priv->rx_replenish); |
| 1649 | |
| 1650 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1651 | /* If we've added more space for the firmware to place data, tell it. |
| 1652 | * Increment device's write pointer in multiples of 8. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1653 | if ((write != (rxq->write & ~0x7)) |
| 1654 | || (abs(rxq->write - rxq->read) > 7)) { |
| 1655 | spin_lock_irqsave(&rxq->lock, flags); |
| 1656 | rxq->need_update = 1; |
| 1657 | spin_unlock_irqrestore(&rxq->lock, flags); |
Winkler, Tomas | 141c43a | 2009-01-08 10:19:53 -0800 | [diff] [blame] | 1658 | rc = iwl_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1659 | if (rc) |
| 1660 | return rc; |
| 1661 | } |
| 1662 | |
| 1663 | return 0; |
| 1664 | } |
| 1665 | |
| 1666 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1667 | * 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] | 1668 | * |
| 1669 | * When moving to rx_free an SKB is allocated for the slot. |
| 1670 | * |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1671 | * Also restock the Rx queue via iwl3945_rx_queue_restock. |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 1672 | * This is called as a scheduled work item (except for during initialization) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1673 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1674 | static void iwl3945_rx_allocate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1675 | { |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 1676 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1677 | struct list_head *element; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1678 | struct iwl_rx_mem_buffer *rxb; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1679 | unsigned long flags; |
| 1680 | spin_lock_irqsave(&rxq->lock, flags); |
| 1681 | while (!list_empty(&rxq->rx_used)) { |
| 1682 | element = rxq->rx_used.next; |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1683 | rxb = list_entry(element, struct iwl_rx_mem_buffer, list); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1684 | |
| 1685 | /* Alloc a new receive buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1686 | rxb->skb = |
Winkler, Tomas | 1e33dc6 | 2009-01-08 10:19:57 -0800 | [diff] [blame] | 1687 | alloc_skb(priv->hw_params.rx_buf_size, |
| 1688 | __GFP_NOWARN | GFP_ATOMIC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1689 | if (!rxb->skb) { |
| 1690 | if (net_ratelimit()) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 1691 | IWL_CRIT(priv, ": Can not allocate SKB buffers\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1692 | /* We don't reschedule replenish work here -- we will |
| 1693 | * call the restock method and if it still needs |
| 1694 | * more buffers it will schedule replenish */ |
| 1695 | break; |
| 1696 | } |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 1697 | |
| 1698 | /* If radiotap head is required, reserve some headroom here. |
| 1699 | * The physical head count is a variable rx_stats->phy_count. |
| 1700 | * We reserve 4 bytes here. Plus these extra bytes, the |
| 1701 | * headroom of the physical head should be enough for the |
| 1702 | * radiotap head that iwl3945 supported. See iwl3945_rt. |
| 1703 | */ |
| 1704 | skb_reserve(rxb->skb, 4); |
| 1705 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1706 | priv->alloc_rxb_skb++; |
| 1707 | list_del(element); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1708 | |
| 1709 | /* Get physical address of RB/SKB */ |
Winkler, Tomas | 1e33dc6 | 2009-01-08 10:19:57 -0800 | [diff] [blame] | 1710 | rxb->real_dma_addr = pci_map_single(priv->pci_dev, |
| 1711 | rxb->skb->data, |
| 1712 | priv->hw_params.rx_buf_size, |
| 1713 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1714 | list_add_tail(&rxb->list, &rxq->rx_free); |
| 1715 | rxq->free_count++; |
| 1716 | } |
| 1717 | spin_unlock_irqrestore(&rxq->lock, flags); |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1718 | } |
| 1719 | |
| 1720 | /* |
| 1721 | * this should be called while priv->lock is locked |
| 1722 | */ |
Tomas Winkler | 4fd1f84 | 2007-12-05 20:59:58 +0200 | [diff] [blame] | 1723 | static void __iwl3945_rx_replenish(void *data) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1724 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1725 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1726 | |
| 1727 | iwl3945_rx_allocate(priv); |
| 1728 | iwl3945_rx_queue_restock(priv); |
| 1729 | } |
| 1730 | |
| 1731 | |
| 1732 | void iwl3945_rx_replenish(void *data) |
| 1733 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1734 | struct iwl_priv *priv = data; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1735 | unsigned long flags; |
| 1736 | |
| 1737 | iwl3945_rx_allocate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1738 | |
| 1739 | spin_lock_irqsave(&priv->lock, flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1740 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1741 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1742 | } |
| 1743 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1744 | /* Convert linear signal-to-noise ratio into dB */ |
| 1745 | static u8 ratio2dB[100] = { |
| 1746 | /* 0 1 2 3 4 5 6 7 8 9 */ |
| 1747 | 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */ |
| 1748 | 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */ |
| 1749 | 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */ |
| 1750 | 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */ |
| 1751 | 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */ |
| 1752 | 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */ |
| 1753 | 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */ |
| 1754 | 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */ |
| 1755 | 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */ |
| 1756 | 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */ |
| 1757 | }; |
| 1758 | |
| 1759 | /* Calculates a relative dB value from a ratio of linear |
| 1760 | * (i.e. not dB) signal levels. |
| 1761 | * Conversion assumes that levels are voltages (20*log), not powers (10*log). */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1762 | int iwl3945_calc_db_from_ratio(int sig_ratio) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1763 | { |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 1764 | /* 1000:1 or higher just report as 60 dB */ |
| 1765 | if (sig_ratio >= 1000) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1766 | return 60; |
| 1767 | |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 1768 | /* 100:1 or higher, divide by 10 and use table, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1769 | * add 20 dB to make up for divide by 10 */ |
Adrian Bunk | 221c80c | 2008-02-02 23:19:01 +0200 | [diff] [blame] | 1770 | if (sig_ratio >= 100) |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 1771 | return 20 + (int)ratio2dB[sig_ratio/10]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1772 | |
| 1773 | /* We shouldn't see this */ |
| 1774 | if (sig_ratio < 1) |
| 1775 | return 0; |
| 1776 | |
| 1777 | /* Use table for ratios 1:1 - 99:1 */ |
| 1778 | return (int)ratio2dB[sig_ratio]; |
| 1779 | } |
| 1780 | |
| 1781 | #define PERFECT_RSSI (-20) /* dBm */ |
| 1782 | #define WORST_RSSI (-95) /* dBm */ |
| 1783 | #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI) |
| 1784 | |
| 1785 | /* Calculate an indication of rx signal quality (a percentage, not dBm!). |
| 1786 | * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info |
| 1787 | * about formulas used below. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1788 | int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1789 | { |
| 1790 | int sig_qual; |
| 1791 | int degradation = PERFECT_RSSI - rssi_dbm; |
| 1792 | |
| 1793 | /* If we get a noise measurement, use signal-to-noise ratio (SNR) |
| 1794 | * as indicator; formula is (signal dbm - noise dbm). |
| 1795 | * SNR at or above 40 is a great signal (100%). |
| 1796 | * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator. |
| 1797 | * Weakest usable signal is usually 10 - 15 dB SNR. */ |
| 1798 | if (noise_dbm) { |
| 1799 | if (rssi_dbm - noise_dbm >= 40) |
| 1800 | return 100; |
| 1801 | else if (rssi_dbm < noise_dbm) |
| 1802 | return 0; |
| 1803 | sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2; |
| 1804 | |
| 1805 | /* Else use just the signal level. |
| 1806 | * This formula is a least squares fit of data points collected and |
| 1807 | * compared with a reference system that had a percentage (%) display |
| 1808 | * for signal quality. */ |
| 1809 | } else |
| 1810 | sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation * |
| 1811 | (15 * RSSI_RANGE + 62 * degradation)) / |
| 1812 | (RSSI_RANGE * RSSI_RANGE); |
| 1813 | |
| 1814 | if (sig_qual > 100) |
| 1815 | sig_qual = 100; |
| 1816 | else if (sig_qual < 1) |
| 1817 | sig_qual = 0; |
| 1818 | |
| 1819 | return sig_qual; |
| 1820 | } |
| 1821 | |
| 1822 | /** |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1823 | * iwl3945_rx_handle - Main entry function for receiving responses from uCode |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1824 | * |
| 1825 | * Uses the priv->rx_handlers callback function array to invoke |
| 1826 | * the appropriate handlers, including command responses, |
| 1827 | * frame-received notifications, and other notifications. |
| 1828 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1829 | static void iwl3945_rx_handle(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1830 | { |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1831 | struct iwl_rx_mem_buffer *rxb; |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1832 | struct iwl_rx_packet *pkt; |
Abhijeet Kolekar | cc2f362 | 2008-12-19 10:37:25 +0800 | [diff] [blame] | 1833 | struct iwl_rx_queue *rxq = &priv->rxq; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1834 | u32 r, i; |
| 1835 | int reclaim; |
| 1836 | unsigned long flags; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1837 | u8 fill_rx = 0; |
Mohamed Abbas | d68ab68 | 2008-02-07 13:16:33 -0800 | [diff] [blame] | 1838 | u32 count = 8; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1839 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 1840 | /* uCode's read index (stored in shared DRAM) indicates the last Rx |
| 1841 | * buffer that the driver may process (last buffer filled by ucode). */ |
Winkler, Tomas | 8cd812b | 2008-12-19 10:37:43 +0800 | [diff] [blame] | 1842 | r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1843 | i = rxq->read; |
| 1844 | |
Winkler, Tomas | 37d6831 | 2009-01-08 10:19:54 -0800 | [diff] [blame] | 1845 | if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2)) |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1846 | fill_rx = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1847 | /* Rx interrupt, but nothing sent from uCode */ |
| 1848 | if (i == r) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1849 | IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1850 | |
| 1851 | while (i != r) { |
| 1852 | rxb = rxq->queue[i]; |
| 1853 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1854 | /* 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] | 1855 | * then a bug has been introduced in the queue refilling |
| 1856 | * routines -- catch it here */ |
| 1857 | BUG_ON(rxb == NULL); |
| 1858 | |
| 1859 | rxq->queue[i] = NULL; |
| 1860 | |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1861 | pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr, |
Winkler, Tomas | 1e33dc6 | 2009-01-08 10:19:57 -0800 | [diff] [blame] | 1862 | priv->hw_params.rx_buf_size, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1863 | PCI_DMA_FROMDEVICE); |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 1864 | pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1865 | |
| 1866 | /* Reclaim a command buffer only if this packet is a response |
| 1867 | * to a (driver-originated) command. |
| 1868 | * If the packet (e.g. Rx frame) originated from uCode, |
| 1869 | * there is no command buffer to reclaim. |
| 1870 | * Ucode should set SEQ_RX_FRAME bit if ucode-originated, |
| 1871 | * but apparently a few don't get set; catch them here. */ |
| 1872 | reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) && |
| 1873 | (pkt->hdr.cmd != STATISTICS_NOTIFICATION) && |
| 1874 | (pkt->hdr.cmd != REPLY_TX); |
| 1875 | |
| 1876 | /* Based on type of command response or notification, |
| 1877 | * handle those that need handling via function in |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1878 | * rx_handlers table. See iwl3945_setup_rx_handlers() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1879 | if (priv->rx_handlers[pkt->hdr.cmd]) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1880 | IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1881 | "r = %d, i = %d, %s, 0x%02x\n", r, i, |
| 1882 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); |
| 1883 | priv->rx_handlers[pkt->hdr.cmd] (priv, rxb); |
| 1884 | } else { |
| 1885 | /* No handling needed */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 1886 | IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1887 | "r %d i %d No handler needed for %s, 0x%02x\n", |
| 1888 | r, i, get_cmd_string(pkt->hdr.cmd), |
| 1889 | pkt->hdr.cmd); |
| 1890 | } |
| 1891 | |
| 1892 | if (reclaim) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 1893 | /* Invoke any callbacks, transfer the skb to caller, and |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 1894 | * fire off the (possibly) blocking iwl_send_cmd() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1895 | * as we reclaim the driver command queue */ |
| 1896 | if (rxb && rxb->skb) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1897 | iwl3945_tx_cmd_complete(priv, rxb); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1898 | else |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1899 | IWL_WARN(priv, "Claim null rxb?\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | /* For now we just don't re-use anything. We can tweak this |
| 1903 | * later to try and re-use notification packets and SKBs that |
| 1904 | * fail to Rx correctly */ |
| 1905 | if (rxb->skb != NULL) { |
| 1906 | priv->alloc_rxb_skb--; |
| 1907 | dev_kfree_skb_any(rxb->skb); |
| 1908 | rxb->skb = NULL; |
| 1909 | } |
| 1910 | |
Abhijeet Kolekar | 6100b58 | 2008-12-19 10:37:24 +0800 | [diff] [blame] | 1911 | pci_unmap_single(priv->pci_dev, rxb->real_dma_addr, |
Winkler, Tomas | 1e33dc6 | 2009-01-08 10:19:57 -0800 | [diff] [blame] | 1912 | priv->hw_params.rx_buf_size, |
| 1913 | PCI_DMA_FROMDEVICE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1914 | spin_lock_irqsave(&rxq->lock, flags); |
| 1915 | list_add_tail(&rxb->list, &priv->rxq.rx_used); |
| 1916 | spin_unlock_irqrestore(&rxq->lock, flags); |
| 1917 | i = (i + 1) & RX_QUEUE_MASK; |
Mohamed Abbas | 5c0eef9 | 2007-11-29 11:10:14 +0800 | [diff] [blame] | 1918 | /* If there are a lot of unused frames, |
| 1919 | * restock the Rx queue so ucode won't assert. */ |
| 1920 | if (fill_rx) { |
| 1921 | count++; |
| 1922 | if (count >= 8) { |
| 1923 | priv->rxq.read = i; |
| 1924 | __iwl3945_rx_replenish(priv); |
| 1925 | count = 0; |
| 1926 | } |
| 1927 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | /* Backtrack one entry */ |
| 1931 | priv->rxq.read = i; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1932 | iwl3945_rx_queue_restock(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1933 | } |
| 1934 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 1935 | /* call this function to flush any scheduled tasklet */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1936 | static inline void iwl_synchronize_irq(struct iwl_priv *priv) |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 1937 | { |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 1938 | /* wait to make sure we flush pending tasklet*/ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 1939 | synchronize_irq(priv->pci_dev->irq); |
| 1940 | tasklet_kill(&priv->irq_tasklet); |
| 1941 | } |
| 1942 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1943 | static const char *desc_lookup(int i) |
| 1944 | { |
| 1945 | switch (i) { |
| 1946 | case 1: |
| 1947 | return "FAIL"; |
| 1948 | case 2: |
| 1949 | return "BAD_PARAM"; |
| 1950 | case 3: |
| 1951 | return "BAD_CHECKSUM"; |
| 1952 | case 4: |
| 1953 | return "NMI_INTERRUPT"; |
| 1954 | case 5: |
| 1955 | return "SYSASSERT"; |
| 1956 | case 6: |
| 1957 | return "FATAL_ERROR"; |
| 1958 | } |
| 1959 | |
| 1960 | return "UNKNOWN"; |
| 1961 | } |
| 1962 | |
| 1963 | #define ERROR_START_OFFSET (1 * sizeof(u32)) |
| 1964 | #define ERROR_ELEM_SIZE (7 * sizeof(u32)) |
| 1965 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 1966 | static void iwl3945_dump_nic_error_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1967 | { |
| 1968 | u32 i; |
| 1969 | u32 desc, time, count, base, data1; |
| 1970 | u32 blink1, blink2, ilink1, ilink2; |
| 1971 | int rc; |
| 1972 | |
| 1973 | base = le32_to_cpu(priv->card_alive.error_event_table_ptr); |
| 1974 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1975 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1976 | IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1977 | return; |
| 1978 | } |
| 1979 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1980 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1981 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 1982 | IWL_WARN(priv, "Can not read from adapter at this time.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1983 | return; |
| 1984 | } |
| 1985 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1986 | count = iwl_read_targ_mem(priv, base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1987 | |
| 1988 | if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1989 | IWL_ERR(priv, "Start IWL Error Log Dump:\n"); |
| 1990 | IWL_ERR(priv, "Status: 0x%08lX, count: %d\n", |
| 1991 | priv->status, count); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1992 | } |
| 1993 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 1994 | IWL_ERR(priv, "Desc Time asrtPC blink2 " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1995 | "ilink1 nmiPC Line\n"); |
| 1996 | for (i = ERROR_START_OFFSET; |
| 1997 | i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET; |
| 1998 | i += ERROR_ELEM_SIZE) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 1999 | desc = iwl_read_targ_mem(priv, base + i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2000 | time = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2001 | iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2002 | blink1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2003 | iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2004 | blink2 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2005 | iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2006 | ilink1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2007 | iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2008 | ilink2 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2009 | iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2010 | data1 = |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2011 | iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2012 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2013 | IWL_ERR(priv, |
| 2014 | "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n", |
| 2015 | desc_lookup(desc), desc, time, blink1, blink2, |
| 2016 | ilink1, ilink2, data1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2017 | } |
| 2018 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2019 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2020 | |
| 2021 | } |
| 2022 | |
Ben Cahill | f58177b | 2007-11-29 11:09:43 +0800 | [diff] [blame] | 2023 | #define EVENT_START_OFFSET (6 * sizeof(u32)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2024 | |
| 2025 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2026 | * iwl3945_print_event_log - Dump error event log to syslog |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2027 | * |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2028 | * NOTE: Must be called with iwl_grab_nic_access() already obtained! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2029 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2030 | static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2031 | u32 num_events, u32 mode) |
| 2032 | { |
| 2033 | u32 i; |
| 2034 | u32 base; /* SRAM byte address of event log header */ |
| 2035 | u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */ |
| 2036 | u32 ptr; /* SRAM byte address of log data */ |
| 2037 | u32 ev, time, data; /* event log data */ |
| 2038 | |
| 2039 | if (num_events == 0) |
| 2040 | return; |
| 2041 | |
| 2042 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
| 2043 | |
| 2044 | if (mode == 0) |
| 2045 | event_size = 2 * sizeof(u32); |
| 2046 | else |
| 2047 | event_size = 3 * sizeof(u32); |
| 2048 | |
| 2049 | ptr = base + EVENT_START_OFFSET + (start_idx * event_size); |
| 2050 | |
| 2051 | /* "time" is actually "data" for mode 0 (no timestamp). |
| 2052 | * place event id # at far right for easier visual parsing. */ |
| 2053 | for (i = 0; i < num_events; i++) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2054 | ev = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2055 | ptr += sizeof(u32); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2056 | time = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2057 | ptr += sizeof(u32); |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2058 | if (mode == 0) { |
| 2059 | /* data, ev */ |
| 2060 | IWL_ERR(priv, "0x%08x\t%04u\n", time, ev); |
| 2061 | } else { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2062 | data = iwl_read_targ_mem(priv, ptr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2063 | ptr += sizeof(u32); |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2064 | IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2065 | } |
| 2066 | } |
| 2067 | } |
| 2068 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2069 | static void iwl3945_dump_nic_event_log(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2070 | { |
| 2071 | int rc; |
| 2072 | u32 base; /* SRAM byte address of event log header */ |
| 2073 | u32 capacity; /* event log capacity in # entries */ |
| 2074 | u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */ |
| 2075 | u32 num_wraps; /* # times uCode wrapped to top of log */ |
| 2076 | u32 next_entry; /* index of next entry to be written by uCode */ |
| 2077 | u32 size; /* # entries that we'll print */ |
| 2078 | |
| 2079 | base = le32_to_cpu(priv->card_alive.log_event_table_ptr); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2080 | if (!iwl3945_hw_valid_rtc_data_addr(base)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2081 | IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2082 | return; |
| 2083 | } |
| 2084 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2085 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2086 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2087 | IWL_WARN(priv, "Can not read from adapter at this time.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2088 | return; |
| 2089 | } |
| 2090 | |
| 2091 | /* event log header */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2092 | capacity = iwl_read_targ_mem(priv, base); |
| 2093 | mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32))); |
| 2094 | num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32))); |
| 2095 | next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32))); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2096 | |
| 2097 | size = num_wraps ? capacity : next_entry; |
| 2098 | |
| 2099 | /* bail out if nothing in log */ |
| 2100 | if (size == 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2101 | IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n"); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2102 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2103 | return; |
| 2104 | } |
| 2105 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2106 | IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2107 | size, num_wraps); |
| 2108 | |
| 2109 | /* if uCode has wrapped back to top of log, start at the oldest entry, |
| 2110 | * i.e the next one that uCode would fill. */ |
| 2111 | if (num_wraps) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2112 | iwl3945_print_event_log(priv, next_entry, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2113 | capacity - next_entry, mode); |
| 2114 | |
| 2115 | /* (then/else) start at top of log */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2116 | iwl3945_print_event_log(priv, 0, next_entry, mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2117 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2118 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2119 | } |
| 2120 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2121 | static void iwl3945_error_recovery(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2122 | { |
| 2123 | unsigned long flags; |
| 2124 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 2125 | memcpy(&priv->staging_rxon, &priv->recovery_rxon, |
| 2126 | sizeof(priv->staging_rxon)); |
| 2127 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2128 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2129 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2130 | iwl3945_add_station(priv, priv->bssid, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2131 | |
| 2132 | spin_lock_irqsave(&priv->lock, flags); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 2133 | priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2134 | priv->error_recovering = 0; |
| 2135 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2136 | } |
| 2137 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2138 | static void iwl3945_irq_tasklet(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2139 | { |
| 2140 | u32 inta, handled = 0; |
| 2141 | u32 inta_fh; |
| 2142 | unsigned long flags; |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 2143 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2144 | u32 inta_mask; |
| 2145 | #endif |
| 2146 | |
| 2147 | spin_lock_irqsave(&priv->lock, flags); |
| 2148 | |
| 2149 | /* Ack/clear/reset pending uCode interrupts. |
| 2150 | * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS, |
| 2151 | * and will clear only when CSR_FH_INT_STATUS gets cleared. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2152 | inta = iwl_read32(priv, CSR_INT); |
| 2153 | iwl_write32(priv, CSR_INT, inta); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2154 | |
| 2155 | /* Ack/clear/reset pending flow-handler (DMA) interrupts. |
| 2156 | * Any new interrupts that happen after this, either while we're |
| 2157 | * in this tasklet, or later, will show up in next ISR/tasklet. */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2158 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
| 2159 | iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2160 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 2161 | #ifdef CONFIG_IWLWIFI_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2162 | if (priv->debug_level & IWL_DL_ISR) { |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2163 | /* just for debug */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2164 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2165 | 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] | 2166 | inta, inta_mask, inta_fh); |
| 2167 | } |
| 2168 | #endif |
| 2169 | |
| 2170 | /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not |
| 2171 | * atomic, make sure that inta covers all the interrupts that |
| 2172 | * we've discovered, even if FH interrupt came in just after |
| 2173 | * reading CSR_INT. */ |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 2174 | if (inta_fh & CSR39_FH_INT_RX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2175 | inta |= CSR_INT_BIT_FH_RX; |
Tomas Winkler | 6f83eaa | 2008-03-04 18:09:28 -0800 | [diff] [blame] | 2176 | if (inta_fh & CSR39_FH_INT_TX_MASK) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2177 | inta |= CSR_INT_BIT_FH_TX; |
| 2178 | |
| 2179 | /* Now service all interrupt bits discovered above. */ |
| 2180 | if (inta & CSR_INT_BIT_HW_ERR) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2181 | IWL_ERR(priv, "Microcode HW error detected. Restarting.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2182 | |
| 2183 | /* Tell the device to stop sending interrupts */ |
Abhijeet Kolekar | ed3b932 | 2009-02-18 15:54:30 -0800 | [diff] [blame] | 2184 | iwl_disable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2185 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 2186 | iwl_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2187 | |
| 2188 | handled |= CSR_INT_BIT_HW_ERR; |
| 2189 | |
| 2190 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2191 | |
| 2192 | return; |
| 2193 | } |
| 2194 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 2195 | #ifdef CONFIG_IWLWIFI_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2196 | if (priv->debug_level & (IWL_DL_ISR)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2197 | /* NIC fires this, but we don't use it, redundant with WAKEUP */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2198 | if (inta & CSR_INT_BIT_SCD) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2199 | IWL_DEBUG_ISR(priv, "Scheduler finished to transmit " |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2200 | "the frame/frames.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2201 | |
| 2202 | /* Alive notification via Rx interrupt will do the real work */ |
| 2203 | if (inta & CSR_INT_BIT_ALIVE) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2204 | IWL_DEBUG_ISR(priv, "Alive interrupt\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2205 | } |
| 2206 | #endif |
| 2207 | /* Safely ignore these bits for debug checks below */ |
Joonwoo Park | 25c03d8 | 2008-01-23 10:15:20 -0800 | [diff] [blame] | 2208 | inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2209 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2210 | /* Error detected by uCode */ |
| 2211 | if (inta & CSR_INT_BIT_SW_ERR) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2212 | IWL_ERR(priv, "Microcode SW error detected. " |
| 2213 | "Restarting 0x%X.\n", inta); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 2214 | iwl_irq_handle_error(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2215 | handled |= CSR_INT_BIT_SW_ERR; |
| 2216 | } |
| 2217 | |
| 2218 | /* uCode wakes up after power-down sleep */ |
| 2219 | if (inta & CSR_INT_BIT_WAKEUP) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2220 | IWL_DEBUG_ISR(priv, "Wakeup interrupt\n"); |
Winkler, Tomas | 141c43a | 2009-01-08 10:19:53 -0800 | [diff] [blame] | 2221 | iwl_rx_queue_update_write_ptr(priv, &priv->rxq); |
Samuel Ortiz | 4f3602c | 2009-01-19 15:30:25 -0800 | [diff] [blame] | 2222 | iwl_txq_update_write_ptr(priv, &priv->txq[0]); |
| 2223 | iwl_txq_update_write_ptr(priv, &priv->txq[1]); |
| 2224 | iwl_txq_update_write_ptr(priv, &priv->txq[2]); |
| 2225 | iwl_txq_update_write_ptr(priv, &priv->txq[3]); |
| 2226 | iwl_txq_update_write_ptr(priv, &priv->txq[4]); |
| 2227 | iwl_txq_update_write_ptr(priv, &priv->txq[5]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2228 | |
| 2229 | handled |= CSR_INT_BIT_WAKEUP; |
| 2230 | } |
| 2231 | |
| 2232 | /* All uCode command responses, including Tx command responses, |
| 2233 | * Rx "responses" (frame-received notification), and other |
| 2234 | * notifications from uCode come through here*/ |
| 2235 | if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2236 | iwl3945_rx_handle(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2237 | handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX); |
| 2238 | } |
| 2239 | |
| 2240 | if (inta & CSR_INT_BIT_FH_TX) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2241 | IWL_DEBUG_ISR(priv, "Tx interrupt\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2242 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2243 | iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6)); |
| 2244 | if (!iwl_grab_nic_access(priv)) { |
| 2245 | iwl_write_direct32(priv, FH39_TCSR_CREDIT |
Tomas Winkler | bddadf8 | 2008-12-19 10:37:01 +0800 | [diff] [blame] | 2246 | (FH39_SRVC_CHNL), 0x0); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2247 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2248 | } |
| 2249 | handled |= CSR_INT_BIT_FH_TX; |
| 2250 | } |
| 2251 | |
| 2252 | if (inta & ~handled) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2253 | IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2254 | |
| 2255 | if (inta & ~CSR_INI_SET_MASK) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2256 | IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2257 | inta & ~CSR_INI_SET_MASK); |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2258 | IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | /* Re-enable all interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 2262 | /* only Re-enable if disabled by irq */ |
| 2263 | if (test_bit(STATUS_INT_ENABLED, &priv->status)) |
Abhijeet Kolekar | ed3b932 | 2009-02-18 15:54:30 -0800 | [diff] [blame] | 2264 | iwl_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2265 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 2266 | #ifdef CONFIG_IWLWIFI_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 2267 | if (priv->debug_level & (IWL_DL_ISR)) { |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2268 | inta = iwl_read32(priv, CSR_INT); |
| 2269 | inta_mask = iwl_read32(priv, CSR_INT_MASK); |
| 2270 | inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2271 | 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] | 2272 | "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags); |
| 2273 | } |
| 2274 | #endif |
| 2275 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2276 | } |
| 2277 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2278 | static int iwl3945_get_channels_for_scan(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2279 | enum ieee80211_band band, |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 2280 | u8 is_active, u8 n_probes, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2281 | struct iwl3945_scan_channel *scan_ch) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2282 | { |
| 2283 | const struct ieee80211_channel *channels = NULL; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2284 | const struct ieee80211_supported_band *sband; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 2285 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2286 | u16 passive_dwell = 0; |
| 2287 | u16 active_dwell = 0; |
| 2288 | int added, i; |
| 2289 | |
Kolekar, Abhijeet | cbba18c | 2008-12-19 10:37:42 +0800 | [diff] [blame] | 2290 | sband = iwl_get_hw_mode(priv, band); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2291 | if (!sband) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2292 | return 0; |
| 2293 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2294 | channels = sband->channels; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2295 | |
Samuel Ortiz | 77fecfb8 | 2009-01-23 13:45:12 -0800 | [diff] [blame] | 2296 | active_dwell = iwl_get_active_dwell_time(priv, band, n_probes); |
| 2297 | passive_dwell = iwl_get_passive_dwell_time(priv, band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2298 | |
Abhijeet Kolekar | 8f4807a | 2008-09-03 11:26:31 +0800 | [diff] [blame] | 2299 | if (passive_dwell <= active_dwell) |
| 2300 | passive_dwell = active_dwell + 1; |
| 2301 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2302 | for (i = 0, added = 0; i < sband->n_channels; i++) { |
Johannes Berg | 182e2e6 | 2008-04-04 10:41:56 +0200 | [diff] [blame] | 2303 | if (channels[i].flags & IEEE80211_CHAN_DISABLED) |
| 2304 | continue; |
| 2305 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2306 | scan_ch->channel = channels[i].hw_value; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2307 | |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 2308 | ch_info = iwl_get_channel_info(priv, band, scan_ch->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2309 | if (!is_channel_valid(ch_info)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2310 | IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2311 | scan_ch->channel); |
| 2312 | continue; |
| 2313 | } |
| 2314 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2315 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 2316 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
Abhijeet Kolekar | 011a033 | 2008-12-02 12:14:07 -0800 | [diff] [blame] | 2317 | /* If passive , set up for auto-switch |
| 2318 | * and use long active_dwell time. |
| 2319 | */ |
| 2320 | if (!is_active || is_channel_passive(ch_info) || |
| 2321 | (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) { |
| 2322 | scan_ch->type = 0; /* passive */ |
| 2323 | if (IWL_UCODE_API(priv->ucode_ver) == 1) |
| 2324 | scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1); |
| 2325 | } else { |
| 2326 | scan_ch->type = 1; /* active */ |
| 2327 | } |
| 2328 | |
| 2329 | /* Set direct probe bits. These may be used both for active |
| 2330 | * scan channels (probes gets sent right away), |
| 2331 | * or for passive channels (probes get se sent only after |
| 2332 | * hearing clear Rx packet).*/ |
| 2333 | if (IWL_UCODE_API(priv->ucode_ver) >= 2) { |
| 2334 | if (n_probes) |
Winkler, Tomas | 0d21044 | 2009-01-23 13:45:21 -0800 | [diff] [blame] | 2335 | scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes); |
Abhijeet Kolekar | 011a033 | 2008-12-02 12:14:07 -0800 | [diff] [blame] | 2336 | } else { |
| 2337 | /* uCode v1 does not allow setting direct probe bits on |
| 2338 | * passive channel. */ |
| 2339 | if ((scan_ch->type & 1) && n_probes) |
Winkler, Tomas | 0d21044 | 2009-01-23 13:45:21 -0800 | [diff] [blame] | 2340 | scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes); |
Abhijeet Kolekar | 011a033 | 2008-12-02 12:14:07 -0800 | [diff] [blame] | 2341 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2342 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2343 | /* Set txpower levels to defaults */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2344 | scan_ch->tpc.dsp_atten = 110; |
| 2345 | /* scan_pwr_info->tpc.dsp_atten; */ |
| 2346 | |
| 2347 | /*scan_pwr_info->tpc.tx_gain; */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2348 | if (band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2349 | scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 2350 | else { |
| 2351 | scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3)); |
| 2352 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2353 | * power level: |
Reinette Chatre | 8a1b024 | 2008-01-14 17:46:25 -0800 | [diff] [blame] | 2354 | * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2355 | */ |
| 2356 | } |
| 2357 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2358 | IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2359 | scan_ch->channel, |
| 2360 | (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE", |
| 2361 | (scan_ch->type & 1) ? |
| 2362 | active_dwell : passive_dwell); |
| 2363 | |
| 2364 | scan_ch++; |
| 2365 | added++; |
| 2366 | } |
| 2367 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2368 | IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2369 | return added; |
| 2370 | } |
| 2371 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2372 | static void iwl3945_init_hw_rates(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2373 | struct ieee80211_rate *rates) |
| 2374 | { |
| 2375 | int i; |
| 2376 | |
| 2377 | for (i = 0; i < IWL_RATE_COUNT; i++) { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2378 | rates[i].bitrate = iwl3945_rates[i].ieee * 5; |
| 2379 | rates[i].hw_value = i; /* Rate scaling will work on indexes */ |
| 2380 | rates[i].hw_value_short = i; |
| 2381 | rates[i].flags = 0; |
Samuel Ortiz | d9829a6 | 2008-12-19 10:37:12 +0800 | [diff] [blame] | 2382 | if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2383 | /* |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2384 | * If CCK != 1M then set short preamble rate flag. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2385 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2386 | rates[i].flags |= (iwl3945_rates[i].plcp == 10) ? |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2387 | 0 : IEEE80211_RATE_SHORT_PREAMBLE; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2388 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2389 | } |
| 2390 | } |
| 2391 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2392 | /****************************************************************************** |
| 2393 | * |
| 2394 | * uCode download functions |
| 2395 | * |
| 2396 | ******************************************************************************/ |
| 2397 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2398 | static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2399 | { |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2400 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code); |
| 2401 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data); |
| 2402 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
| 2403 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init); |
| 2404 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
| 2405 | iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2409 | * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2410 | * looking at all data. |
| 2411 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2412 | 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] | 2413 | { |
| 2414 | u32 val; |
| 2415 | u32 save_len = len; |
| 2416 | int rc = 0; |
| 2417 | u32 errcnt; |
| 2418 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2419 | IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2420 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2421 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2422 | if (rc) |
| 2423 | return rc; |
| 2424 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2425 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 2426 | IWL39_RTC_INST_LOWER_BOUND); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2427 | |
| 2428 | errcnt = 0; |
| 2429 | for (; len > 0; len -= sizeof(u32), image++) { |
| 2430 | /* read data comes through single port, auto-incr addr */ |
| 2431 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 2432 | * if IWL_DL_IO is set */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2433 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2434 | if (val != le32_to_cpu(*image)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2435 | IWL_ERR(priv, "uCode INST section is invalid at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2436 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 2437 | save_len - len, val, le32_to_cpu(*image)); |
| 2438 | rc = -EIO; |
| 2439 | errcnt++; |
| 2440 | if (errcnt >= 20) |
| 2441 | break; |
| 2442 | } |
| 2443 | } |
| 2444 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2445 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2446 | |
| 2447 | if (!errcnt) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2448 | IWL_DEBUG_INFO(priv, |
| 2449 | "ucode image in INSTRUCTION memory is good\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2450 | |
| 2451 | return rc; |
| 2452 | } |
| 2453 | |
| 2454 | |
| 2455 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2456 | * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2457 | * using sample data 100 bytes apart. If these sample points are good, |
| 2458 | * it's a pretty good bet that everything between them is good, too. |
| 2459 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2460 | 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] | 2461 | { |
| 2462 | u32 val; |
| 2463 | int rc = 0; |
| 2464 | u32 errcnt = 0; |
| 2465 | u32 i; |
| 2466 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2467 | IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2468 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2469 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2470 | if (rc) |
| 2471 | return rc; |
| 2472 | |
| 2473 | for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) { |
| 2474 | /* read data comes through single port, auto-incr addr */ |
| 2475 | /* NOTE: Use the debugless read so we don't flood kernel log |
| 2476 | * if IWL_DL_IO is set */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2477 | iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 2478 | i + IWL39_RTC_INST_LOWER_BOUND); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2479 | val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2480 | if (val != le32_to_cpu(*image)) { |
| 2481 | #if 0 /* Enable this if you want to see details */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2482 | IWL_ERR(priv, "uCode INST section is invalid at " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2483 | "offset 0x%x, is 0x%x, s/b 0x%x\n", |
| 2484 | i, val, *image); |
| 2485 | #endif |
| 2486 | rc = -EIO; |
| 2487 | errcnt++; |
| 2488 | if (errcnt >= 3) |
| 2489 | break; |
| 2490 | } |
| 2491 | } |
| 2492 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2493 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2494 | |
| 2495 | return rc; |
| 2496 | } |
| 2497 | |
| 2498 | |
| 2499 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2500 | * iwl3945_verify_ucode - determine which instruction image is in SRAM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2501 | * and verify its contents |
| 2502 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2503 | static int iwl3945_verify_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2504 | { |
| 2505 | __le32 *image; |
| 2506 | u32 len; |
| 2507 | int rc = 0; |
| 2508 | |
| 2509 | /* Try bootstrap */ |
| 2510 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 2511 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2512 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2513 | if (rc == 0) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2514 | IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2515 | return 0; |
| 2516 | } |
| 2517 | |
| 2518 | /* Try initialize */ |
| 2519 | image = (__le32 *)priv->ucode_init.v_addr; |
| 2520 | len = priv->ucode_init.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2521 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2522 | if (rc == 0) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2523 | IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2524 | return 0; |
| 2525 | } |
| 2526 | |
| 2527 | /* Try runtime/protocol */ |
| 2528 | image = (__le32 *)priv->ucode_code.v_addr; |
| 2529 | len = priv->ucode_code.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2530 | rc = iwl3945_verify_inst_sparse(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2531 | if (rc == 0) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2532 | IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2533 | return 0; |
| 2534 | } |
| 2535 | |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2536 | IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2537 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2538 | /* Since nothing seems to match, show first several data entries in |
| 2539 | * instruction SRAM, so maybe visual inspection will give a clue. |
| 2540 | * Selection of bootstrap image (vs. other images) is arbitrary. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2541 | image = (__le32 *)priv->ucode_boot.v_addr; |
| 2542 | len = priv->ucode_boot.len; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2543 | rc = iwl3945_verify_inst_full(priv, image, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2544 | |
| 2545 | return rc; |
| 2546 | } |
| 2547 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2548 | static void iwl3945_nic_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2549 | { |
| 2550 | /* Remove all resets to allow NIC to operate */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2551 | iwl_write32(priv, CSR_RESET, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2555 | * iwl3945_read_ucode - Read uCode images from disk file. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2556 | * |
| 2557 | * Copy into buffers for card to fetch via bus-mastering |
| 2558 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2559 | static int iwl3945_read_ucode(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2560 | { |
Kolekar, Abhijeet | a78fe75 | 2008-12-19 10:37:21 +0800 | [diff] [blame] | 2561 | struct iwl_ucode *ucode; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2562 | int ret = -EINVAL, index; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2563 | const struct firmware *ucode_raw; |
| 2564 | /* firmware file name contains uCode/driver compatibility version */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2565 | const char *name_pre = priv->cfg->fw_name_pre; |
| 2566 | const unsigned int api_max = priv->cfg->ucode_api_max; |
| 2567 | const unsigned int api_min = priv->cfg->ucode_api_min; |
| 2568 | char buf[25]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2569 | u8 *src; |
| 2570 | size_t len; |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2571 | 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] | 2572 | |
| 2573 | /* Ask kernel firmware_class module to get the boot firmware off disk. |
| 2574 | * request_firmware() is synchronous, file is in memory on return. */ |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2575 | for (index = api_max; index >= api_min; index--) { |
| 2576 | sprintf(buf, "%s%u%s", name_pre, index, ".ucode"); |
| 2577 | ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev); |
| 2578 | if (ret < 0) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2579 | IWL_ERR(priv, "%s firmware file req failed: %d\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2580 | buf, ret); |
| 2581 | if (ret == -ENOENT) |
| 2582 | continue; |
| 2583 | else |
| 2584 | goto error; |
| 2585 | } else { |
| 2586 | if (index < api_max) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2587 | IWL_ERR(priv, "Loaded firmware %s, " |
| 2588 | "which is deprecated. " |
| 2589 | " Please use API v%u instead.\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2590 | buf, api_max); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2591 | IWL_DEBUG_INFO(priv, "Got firmware '%s' file " |
| 2592 | "(%zd bytes) from disk\n", |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2593 | buf, ucode_raw->size); |
| 2594 | break; |
| 2595 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2596 | } |
| 2597 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2598 | if (ret < 0) |
| 2599 | goto error; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2600 | |
| 2601 | /* Make sure that we got at least our header! */ |
| 2602 | if (ucode_raw->size < sizeof(*ucode)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2603 | IWL_ERR(priv, "File size way too small!\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2604 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2605 | goto err_release; |
| 2606 | } |
| 2607 | |
| 2608 | /* Data from ucode file: header followed by uCode images */ |
| 2609 | ucode = (void *)ucode_raw->data; |
| 2610 | |
Chatre, Reinette | c02b3ac | 2008-12-02 12:14:05 -0800 | [diff] [blame] | 2611 | priv->ucode_ver = le32_to_cpu(ucode->ver); |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2612 | api_ver = IWL_UCODE_API(priv->ucode_ver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2613 | inst_size = le32_to_cpu(ucode->inst_size); |
| 2614 | data_size = le32_to_cpu(ucode->data_size); |
| 2615 | init_size = le32_to_cpu(ucode->init_size); |
| 2616 | init_data_size = le32_to_cpu(ucode->init_data_size); |
| 2617 | boot_size = le32_to_cpu(ucode->boot_size); |
| 2618 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2619 | /* api_ver should match the api version forming part of the |
| 2620 | * firmware filename ... but we don't check for that and only rely |
| 2621 | * on the API version read from firware header from here on forward */ |
| 2622 | |
| 2623 | if (api_ver < api_min || api_ver > api_max) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2624 | IWL_ERR(priv, "Driver unable to support your firmware API. " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2625 | "Driver supports v%u, firmware is v%u.\n", |
| 2626 | api_max, api_ver); |
| 2627 | priv->ucode_ver = 0; |
| 2628 | ret = -EINVAL; |
| 2629 | goto err_release; |
| 2630 | } |
| 2631 | if (api_ver != api_max) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2632 | IWL_ERR(priv, "Firmware has old API version. Expected %u, " |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2633 | "got %u. New firmware can be obtained " |
| 2634 | "from http://www.intellinuxwireless.org.\n", |
| 2635 | api_max, api_ver); |
| 2636 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 2637 | IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n", |
| 2638 | IWL_UCODE_MAJOR(priv->ucode_ver), |
| 2639 | IWL_UCODE_MINOR(priv->ucode_ver), |
| 2640 | IWL_UCODE_API(priv->ucode_ver), |
| 2641 | IWL_UCODE_SERIAL(priv->ucode_ver)); |
| 2642 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2643 | 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] | 2644 | priv->ucode_ver); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2645 | IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n", |
| 2646 | inst_size); |
| 2647 | IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n", |
| 2648 | data_size); |
| 2649 | IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n", |
| 2650 | init_size); |
| 2651 | IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n", |
| 2652 | init_data_size); |
| 2653 | IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n", |
| 2654 | boot_size); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2655 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 2656 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2657 | /* Verify size of file vs. image size info in file's header */ |
| 2658 | if (ucode_raw->size < sizeof(*ucode) + |
| 2659 | inst_size + data_size + init_size + |
| 2660 | init_data_size + boot_size) { |
| 2661 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2662 | IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n", |
| 2663 | ucode_raw->size); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2664 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2665 | goto err_release; |
| 2666 | } |
| 2667 | |
| 2668 | /* Verify that uCode images will fit in card's SRAM */ |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 2669 | if (inst_size > IWL39_MAX_INST_SIZE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2670 | 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] | 2671 | inst_size); |
| 2672 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2673 | goto err_release; |
| 2674 | } |
| 2675 | |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 2676 | if (data_size > IWL39_MAX_DATA_SIZE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2677 | 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] | 2678 | data_size); |
| 2679 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2680 | goto err_release; |
| 2681 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 2682 | if (init_size > IWL39_MAX_INST_SIZE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2683 | IWL_DEBUG_INFO(priv, |
| 2684 | "uCode init instr len %d too large to fit in\n", |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2685 | init_size); |
| 2686 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2687 | goto err_release; |
| 2688 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 2689 | if (init_data_size > IWL39_MAX_DATA_SIZE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2690 | IWL_DEBUG_INFO(priv, |
| 2691 | "uCode init data len %d too large to fit in\n", |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2692 | init_data_size); |
| 2693 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2694 | goto err_release; |
| 2695 | } |
Samuel Ortiz | 250bdd2 | 2008-12-19 10:37:11 +0800 | [diff] [blame] | 2696 | if (boot_size > IWL39_MAX_BSM_SIZE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2697 | IWL_DEBUG_INFO(priv, |
| 2698 | "uCode boot instr len %d too large to fit in\n", |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2699 | boot_size); |
| 2700 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2701 | goto err_release; |
| 2702 | } |
| 2703 | |
| 2704 | /* Allocate ucode buffers for card's bus-master loading ... */ |
| 2705 | |
| 2706 | /* Runtime instructions and 2 copies of data: |
| 2707 | * 1) unmodified from disk |
| 2708 | * 2) backup cache for save/restore during power-downs */ |
| 2709 | priv->ucode_code.len = inst_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2710 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2711 | |
| 2712 | priv->ucode_data.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2713 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2714 | |
| 2715 | priv->ucode_data_backup.len = data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2716 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2717 | |
| 2718 | if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr || |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2719 | !priv->ucode_data_backup.v_addr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2720 | goto err_pci_alloc; |
| 2721 | |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2722 | /* Initialization instructions and data */ |
| 2723 | if (init_size && init_data_size) { |
| 2724 | priv->ucode_init.len = init_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2725 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2726 | |
| 2727 | priv->ucode_init_data.len = init_data_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2728 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2729 | |
| 2730 | if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr) |
| 2731 | goto err_pci_alloc; |
| 2732 | } |
| 2733 | |
| 2734 | /* Bootstrap (instructions only, no data) */ |
| 2735 | if (boot_size) { |
| 2736 | priv->ucode_boot.len = boot_size; |
Tomas Winkler | 98c9221 | 2008-01-14 17:46:20 -0800 | [diff] [blame] | 2737 | iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2738 | |
| 2739 | if (!priv->ucode_boot.v_addr) |
| 2740 | goto err_pci_alloc; |
| 2741 | } |
| 2742 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2743 | /* Copy images into buffers for card's bus-master reads ... */ |
| 2744 | |
| 2745 | /* Runtime instructions (first block of data in file) */ |
| 2746 | src = &ucode->data[0]; |
| 2747 | len = priv->ucode_code.len; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2748 | IWL_DEBUG_INFO(priv, |
| 2749 | "Copying (but not loading) uCode instr len %zd\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2750 | memcpy(priv->ucode_code.v_addr, src, len); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2751 | 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] | 2752 | priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr); |
| 2753 | |
| 2754 | /* Runtime data (2nd block) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2755 | * NOTE: Copy into backup buffer will be done in iwl3945_up() */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2756 | src = &ucode->data[inst_size]; |
| 2757 | len = priv->ucode_data.len; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2758 | IWL_DEBUG_INFO(priv, |
| 2759 | "Copying (but not loading) uCode data len %zd\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2760 | memcpy(priv->ucode_data.v_addr, src, len); |
| 2761 | memcpy(priv->ucode_data_backup.v_addr, src, len); |
| 2762 | |
| 2763 | /* Initialization instructions (3rd block) */ |
| 2764 | if (init_size) { |
| 2765 | src = &ucode->data[inst_size + data_size]; |
| 2766 | len = priv->ucode_init.len; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2767 | IWL_DEBUG_INFO(priv, |
| 2768 | "Copying (but not loading) init instr len %zd\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2769 | memcpy(priv->ucode_init.v_addr, src, len); |
| 2770 | } |
| 2771 | |
| 2772 | /* Initialization data (4th block) */ |
| 2773 | if (init_data_size) { |
| 2774 | src = &ucode->data[inst_size + data_size + init_size]; |
| 2775 | len = priv->ucode_init_data.len; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2776 | IWL_DEBUG_INFO(priv, |
| 2777 | "Copying (but not loading) init data len %zd\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2778 | memcpy(priv->ucode_init_data.v_addr, src, len); |
| 2779 | } |
| 2780 | |
| 2781 | /* Bootstrap instructions (5th block) */ |
| 2782 | src = &ucode->data[inst_size + data_size + init_size + init_data_size]; |
| 2783 | len = priv->ucode_boot.len; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2784 | IWL_DEBUG_INFO(priv, |
| 2785 | "Copying (but not loading) boot instr len %zd\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2786 | memcpy(priv->ucode_boot.v_addr, src, len); |
| 2787 | |
| 2788 | /* We have our copies now, allow OS release its copies */ |
| 2789 | release_firmware(ucode_raw); |
| 2790 | return 0; |
| 2791 | |
| 2792 | err_pci_alloc: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 2793 | IWL_ERR(priv, "failed to allocate pci memory\n"); |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2794 | ret = -ENOMEM; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2795 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2796 | |
| 2797 | err_release: |
| 2798 | release_firmware(ucode_raw); |
| 2799 | |
| 2800 | error: |
Tomas Winkler | 90e759d | 2007-11-29 11:09:41 +0800 | [diff] [blame] | 2801 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | |
| 2805 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2806 | * iwl3945_set_ucode_ptrs - Set uCode address location |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2807 | * |
| 2808 | * Tell initialization uCode where to find runtime uCode. |
| 2809 | * |
| 2810 | * BSM registers initially contain pointers to initialization uCode. |
| 2811 | * We need to replace them to load runtime uCode inst and data, |
| 2812 | * and to save runtime data when powering down. |
| 2813 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2814 | static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2815 | { |
| 2816 | dma_addr_t pinst; |
| 2817 | dma_addr_t pdata; |
| 2818 | int rc = 0; |
| 2819 | unsigned long flags; |
| 2820 | |
| 2821 | /* bits 31:0 for 3945 */ |
| 2822 | pinst = priv->ucode_code.p_addr; |
| 2823 | pdata = priv->ucode_data_backup.p_addr; |
| 2824 | |
| 2825 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2826 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2827 | if (rc) { |
| 2828 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2829 | return rc; |
| 2830 | } |
| 2831 | |
| 2832 | /* Tell bootstrap uCode where to find image to load */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2833 | iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 2834 | iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 2835 | iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2836 | priv->ucode_data.len); |
| 2837 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 2838 | /* 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] | 2839 | * that all new ptr/size info is in place */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2840 | iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2841 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 2842 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2843 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2844 | |
| 2845 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2846 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2847 | IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2848 | |
| 2849 | return rc; |
| 2850 | } |
| 2851 | |
| 2852 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2853 | * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2854 | * |
| 2855 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 2856 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2857 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2858 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2859 | static void iwl3945_init_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2860 | { |
| 2861 | /* Check alive response for "valid" sign from uCode */ |
| 2862 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 2863 | /* We had an error bringing up the hardware, so take it |
| 2864 | * all the way back down so we can try again */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2865 | IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2866 | goto restart; |
| 2867 | } |
| 2868 | |
| 2869 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 2870 | * This is a paranoid check, because we would not have gotten the |
| 2871 | * "initialize" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2872 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2873 | /* Runtime instruction load was bad; |
| 2874 | * take it all the way back down so we can try again */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2875 | IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2876 | goto restart; |
| 2877 | } |
| 2878 | |
| 2879 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 2880 | * load and launch runtime uCode, which will send us another "Alive" |
| 2881 | * notification. */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2882 | IWL_DEBUG_INFO(priv, "Initialization Alive received.\n"); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2883 | if (iwl3945_set_ucode_ptrs(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2884 | /* Runtime instruction load won't happen; |
| 2885 | * take it all the way back down so we can try again */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2886 | IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2887 | goto restart; |
| 2888 | } |
| 2889 | return; |
| 2890 | |
| 2891 | restart: |
| 2892 | queue_work(priv->workqueue, &priv->restart); |
| 2893 | } |
| 2894 | |
| 2895 | |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 2896 | /* temporary */ |
| 2897 | static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, |
| 2898 | struct sk_buff *skb); |
| 2899 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2900 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2901 | * iwl3945_alive_start - called after REPLY_ALIVE notification received |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2902 | * from protocol/runtime uCode (initialization uCode's |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2903 | * Alive gets handled by iwl3945_init_alive_start()). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2904 | */ |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 2905 | static void iwl3945_alive_start(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2906 | { |
| 2907 | int rc = 0; |
| 2908 | int thermal_spin = 0; |
| 2909 | u32 rfkill; |
| 2910 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2911 | IWL_DEBUG_INFO(priv, "Runtime Alive received.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2912 | |
| 2913 | if (priv->card_alive.is_valid != UCODE_VALID_OK) { |
| 2914 | /* We had an error bringing up the hardware, so take it |
| 2915 | * all the way back down so we can try again */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2916 | IWL_DEBUG_INFO(priv, "Alive failed.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2917 | goto restart; |
| 2918 | } |
| 2919 | |
| 2920 | /* Initialize uCode has loaded Runtime uCode ... verify inst image. |
| 2921 | * This is a paranoid check, because we would not have gotten the |
| 2922 | * "runtime" alive if code weren't properly loaded. */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2923 | if (iwl3945_verify_ucode(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2924 | /* Runtime instruction load was bad; |
| 2925 | * take it all the way back down so we can try again */ |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2926 | IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2927 | goto restart; |
| 2928 | } |
| 2929 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2930 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2931 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2932 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2933 | if (rc) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 2934 | IWL_WARN(priv, "Can not read RFKILL status from adapter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2935 | return; |
| 2936 | } |
| 2937 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2938 | rfkill = iwl_read_prph(priv, APMG_RFKILL_REG); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2939 | IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 2940 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2941 | |
| 2942 | if (rfkill & 0x1) { |
| 2943 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 2944 | /* if RFKILL is not on, then wait for thermal |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2945 | * sensor in adapter to kick in */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2946 | while (iwl3945_hw_get_temperature(priv) == 0) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2947 | thermal_spin++; |
| 2948 | udelay(10); |
| 2949 | } |
| 2950 | |
| 2951 | if (thermal_spin) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2952 | IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2953 | thermal_spin * 10); |
| 2954 | } else |
| 2955 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 2956 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2957 | /* After the ALIVE response, we can send commands to 3945 uCode */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2958 | set_bit(STATUS_ALIVE, &priv->status); |
| 2959 | |
| 2960 | /* Clear out the uCode error bit if it is set */ |
| 2961 | clear_bit(STATUS_FW_ERROR, &priv->status); |
| 2962 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 2963 | if (iwl_is_rfkill(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2964 | return; |
| 2965 | |
Johannes Berg | 36d6825 | 2008-05-15 12:55:26 +0200 | [diff] [blame] | 2966 | ieee80211_wake_queues(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2967 | |
| 2968 | priv->active_rate = priv->rates_mask; |
| 2969 | priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK; |
| 2970 | |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 2971 | iwl_power_update_mode(priv, false); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2972 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 2973 | if (iwl_is_associated(priv)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2974 | struct iwl3945_rxon_cmd *active_rxon = |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 2975 | (struct iwl3945_rxon_cmd *)(&priv->active_rxon); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2976 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 2977 | memcpy(&priv->staging_rxon, &priv->active_rxon, |
| 2978 | sizeof(priv->staging_rxon)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2979 | active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
| 2980 | } else { |
| 2981 | /* Initialize our rx_config data */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 2982 | iwl_connection_init_rx_config(priv, priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2983 | } |
| 2984 | |
Ben Cahill | 9fbab51 | 2007-11-29 11:09:47 +0800 | [diff] [blame] | 2985 | /* Configure Bluetooth device coexistence support */ |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 2986 | iwl_send_bt_config(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2987 | |
| 2988 | /* Configure the adapter for unassociated operation */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2989 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2990 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2991 | iwl3945_reg_txpower_periodic(priv); |
| 2992 | |
Reinette Chatre | fe00b5a | 2008-04-03 16:05:23 -0700 | [diff] [blame] | 2993 | iwl3945_led_register(priv); |
| 2994 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 2995 | IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n"); |
Rick Farrington | a9f4678 | 2008-03-18 14:57:49 -0700 | [diff] [blame] | 2996 | set_bit(STATUS_READY, &priv->status); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 2997 | wake_up_interruptible(&priv->wait_command_queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2998 | |
| 2999 | if (priv->error_recovering) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3000 | iwl3945_error_recovery(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3001 | |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 3002 | /* reassociate for ADHOC mode */ |
| 3003 | if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) { |
| 3004 | struct sk_buff *beacon = ieee80211_beacon_get(priv->hw, |
| 3005 | priv->vif); |
| 3006 | if (beacon) |
| 3007 | iwl3945_mac_beacon_update(priv->hw, beacon); |
| 3008 | } |
| 3009 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3010 | return; |
| 3011 | |
| 3012 | restart: |
| 3013 | queue_work(priv->workqueue, &priv->restart); |
| 3014 | } |
| 3015 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3016 | static void iwl3945_cancel_deferred_work(struct iwl_priv *priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3017 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3018 | static void __iwl3945_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3019 | { |
| 3020 | unsigned long flags; |
| 3021 | int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status); |
| 3022 | struct ieee80211_conf *conf = NULL; |
| 3023 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3024 | IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3025 | |
| 3026 | conf = ieee80211_get_hw_conf(priv->hw); |
| 3027 | |
| 3028 | if (!exit_pending) |
| 3029 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
| 3030 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 3031 | iwl3945_led_unregister(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3032 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3033 | |
| 3034 | /* Unblock any waiting calls */ |
| 3035 | wake_up_interruptible_all(&priv->wait_command_queue); |
| 3036 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3037 | /* Wipe out the EXIT_PENDING status bit if we are not actually |
| 3038 | * exiting the module */ |
| 3039 | if (!exit_pending) |
| 3040 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
| 3041 | |
| 3042 | /* stop and reset the on-board processor */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3043 | iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3044 | |
| 3045 | /* tell the device to stop sending interrupts */ |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3046 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | ed3b932 | 2009-02-18 15:54:30 -0800 | [diff] [blame] | 3047 | iwl_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 3048 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3049 | iwl_synchronize_irq(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3050 | |
| 3051 | if (priv->mac80211_registered) |
| 3052 | ieee80211_stop_queues(priv->hw); |
| 3053 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3054 | /* If we have not previously called iwl3945_init() then |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3055 | * clear all bits but the RF Kill and SUSPEND bits and return */ |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 3056 | if (!iwl_is_init(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3057 | priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 3058 | STATUS_RF_KILL_HW | |
| 3059 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 3060 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 3061 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 3062 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3063 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 3064 | STATUS_IN_SUSPEND | |
| 3065 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 3066 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3067 | goto exit; |
| 3068 | } |
| 3069 | |
| 3070 | /* ...otherwise clear out all the status bits but the RF Kill and |
| 3071 | * SUSPEND bits and continue taking the NIC down. */ |
| 3072 | priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) << |
| 3073 | STATUS_RF_KILL_HW | |
| 3074 | test_bit(STATUS_RF_KILL_SW, &priv->status) << |
| 3075 | STATUS_RF_KILL_SW | |
Reinette Chatre | 9788864 | 2008-02-06 11:20:38 -0800 | [diff] [blame] | 3076 | test_bit(STATUS_GEO_CONFIGURED, &priv->status) << |
| 3077 | STATUS_GEO_CONFIGURED | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3078 | test_bit(STATUS_IN_SUSPEND, &priv->status) << |
| 3079 | STATUS_IN_SUSPEND | |
| 3080 | test_bit(STATUS_FW_ERROR, &priv->status) << |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 3081 | STATUS_FW_ERROR | |
| 3082 | test_bit(STATUS_EXIT_PENDING, &priv->status) << |
| 3083 | STATUS_EXIT_PENDING; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3084 | |
Abbas, Mohamed | e9414b6 | 2009-01-20 21:33:55 -0800 | [diff] [blame] | 3085 | priv->cfg->ops->lib->apm_ops.reset(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3086 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3087 | iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3088 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3089 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3090 | iwl3945_hw_txq_ctx_stop(priv); |
| 3091 | iwl3945_hw_rxq_stop(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3092 | |
| 3093 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3094 | if (!iwl_grab_nic_access(priv)) { |
| 3095 | iwl_write_prph(priv, APMG_CLK_DIS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3096 | APMG_CLK_VAL_DMA_CLK_RQT); |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3097 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3098 | } |
| 3099 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3100 | |
| 3101 | udelay(5); |
| 3102 | |
Abbas, Mohamed | e9414b6 | 2009-01-20 21:33:55 -0800 | [diff] [blame] | 3103 | if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 3104 | priv->cfg->ops->lib->apm_ops.stop(priv); |
| 3105 | else |
| 3106 | priv->cfg->ops->lib->apm_ops.reset(priv); |
| 3107 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3108 | exit: |
Tomas Winkler | 3d24a9f | 2008-12-19 10:37:07 +0800 | [diff] [blame] | 3109 | memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3110 | |
| 3111 | if (priv->ibss_beacon) |
| 3112 | dev_kfree_skb(priv->ibss_beacon); |
| 3113 | priv->ibss_beacon = NULL; |
| 3114 | |
| 3115 | /* clear out any free frames */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3116 | iwl3945_clear_free_frames(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3117 | } |
| 3118 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3119 | static void iwl3945_down(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3120 | { |
| 3121 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3122 | __iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3123 | mutex_unlock(&priv->mutex); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 3124 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3125 | iwl3945_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | #define MAX_HW_RESTARTS 5 |
| 3129 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3130 | static int __iwl3945_up(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3131 | { |
| 3132 | int rc, i; |
| 3133 | |
| 3134 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3135 | IWL_WARN(priv, "Exit pending; will not bring the NIC up\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3136 | return -EIO; |
| 3137 | } |
| 3138 | |
| 3139 | if (test_bit(STATUS_RF_KILL_SW, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3140 | IWL_WARN(priv, "Radio disabled by SW RF kill (module " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3141 | "parameter)\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3142 | return -ENODEV; |
| 3143 | } |
| 3144 | |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 3145 | if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3146 | IWL_ERR(priv, "ucode not available for device bring up\n"); |
Reinette Chatre | e903fbd | 2008-01-30 22:05:15 -0800 | [diff] [blame] | 3147 | return -EIO; |
| 3148 | } |
| 3149 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3150 | /* If platform's RF_KILL switch is NOT set to KILL */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3151 | if (iwl_read32(priv, CSR_GP_CNTRL) & |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3152 | CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 3153 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3154 | else { |
| 3155 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3156 | if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3157 | IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3158 | return -ENODEV; |
| 3159 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3160 | } |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 3161 | |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3162 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3163 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3164 | rc = iwl3945_hw_nic_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3165 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3166 | IWL_ERR(priv, "Unable to int nic\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3167 | return rc; |
| 3168 | } |
| 3169 | |
| 3170 | /* make sure rfkill handshake bits are cleared */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3171 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 3172 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3173 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
| 3174 | |
| 3175 | /* clear (again), then enable host interrupts */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3176 | iwl_write32(priv, CSR_INT, 0xFFFFFFFF); |
Abhijeet Kolekar | ed3b932 | 2009-02-18 15:54:30 -0800 | [diff] [blame] | 3177 | iwl_enable_interrupts(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3178 | |
| 3179 | /* really make sure rfkill handshake bits are cleared */ |
Abhijeet Kolekar | 5d49f49 | 2008-12-19 10:37:29 +0800 | [diff] [blame] | 3180 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL); |
| 3181 | 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] | 3182 | |
| 3183 | /* Copy original ucode data image from disk into backup cache. |
| 3184 | * This will be used to initialize the on-board processor's |
| 3185 | * data SRAM for a clean start when the runtime program first loads. */ |
| 3186 | memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr, |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3187 | priv->ucode_data.len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3188 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3189 | /* We return success when we resume from suspend and rf_kill is on. */ |
| 3190 | if (test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 3191 | return 0; |
| 3192 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3193 | for (i = 0; i < MAX_HW_RESTARTS; i++) { |
| 3194 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3195 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3196 | |
| 3197 | /* load bootstrap state machine, |
| 3198 | * load bootstrap program into processor's memory, |
| 3199 | * prepare to load the "initialize" uCode */ |
Kolekar, Abhijeet | 0164b9b | 2008-12-19 10:37:37 +0800 | [diff] [blame] | 3200 | priv->cfg->ops->lib->load_ucode(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3201 | |
| 3202 | if (rc) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3203 | IWL_ERR(priv, |
| 3204 | "Unable to set up bootstrap uCode: %d\n", rc); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3205 | continue; |
| 3206 | } |
| 3207 | |
| 3208 | /* start card; "initialize" will load runtime ucode */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3209 | iwl3945_nic_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3210 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3211 | IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3212 | |
| 3213 | return 0; |
| 3214 | } |
| 3215 | |
| 3216 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3217 | __iwl3945_down(priv); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 3218 | clear_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3219 | |
| 3220 | /* tried to restart and config the device for as long as our |
| 3221 | * patience could withstand */ |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3222 | IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3223 | return -EIO; |
| 3224 | } |
| 3225 | |
| 3226 | |
| 3227 | /***************************************************************************** |
| 3228 | * |
| 3229 | * Workqueue callbacks |
| 3230 | * |
| 3231 | *****************************************************************************/ |
| 3232 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3233 | static void iwl3945_bg_init_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3234 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3235 | struct iwl_priv *priv = |
| 3236 | container_of(data, struct iwl_priv, init_alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3237 | |
| 3238 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3239 | return; |
| 3240 | |
| 3241 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3242 | iwl3945_init_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3243 | mutex_unlock(&priv->mutex); |
| 3244 | } |
| 3245 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3246 | static void iwl3945_bg_alive_start(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3247 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3248 | struct iwl_priv *priv = |
| 3249 | container_of(data, struct iwl_priv, alive_start.work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3250 | |
| 3251 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3252 | return; |
| 3253 | |
| 3254 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3255 | iwl3945_alive_start(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3256 | mutex_unlock(&priv->mutex); |
| 3257 | } |
| 3258 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 3259 | static void iwl3945_rfkill_poll(struct work_struct *data) |
| 3260 | { |
| 3261 | struct iwl_priv *priv = |
| 3262 | container_of(data, struct iwl_priv, rfkill_poll.work); |
| 3263 | unsigned long status = priv->status; |
| 3264 | |
| 3265 | if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW) |
| 3266 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3267 | else |
| 3268 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
| 3269 | |
| 3270 | if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status)) |
| 3271 | queue_work(priv->workqueue, &priv->rf_kill); |
| 3272 | |
| 3273 | queue_delayed_work(priv->workqueue, &priv->rfkill_poll, |
| 3274 | round_jiffies_relative(2 * HZ)); |
| 3275 | |
| 3276 | } |
| 3277 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3278 | #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3279 | static void iwl3945_bg_request_scan(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3280 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3281 | struct iwl_priv *priv = |
| 3282 | container_of(data, struct iwl_priv, request_scan); |
Winkler, Tomas | c2d79b4 | 2008-12-19 10:37:34 +0800 | [diff] [blame] | 3283 | struct iwl_host_cmd cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3284 | .id = REPLY_SCAN_CMD, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3285 | .len = sizeof(struct iwl3945_scan_cmd), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3286 | .meta.flags = CMD_SIZE_HUGE, |
| 3287 | }; |
| 3288 | int rc = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3289 | struct iwl3945_scan_cmd *scan; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3290 | struct ieee80211_conf *conf = NULL; |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 3291 | u8 n_probes = 2; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3292 | enum ieee80211_band band; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 3293 | DECLARE_SSID_BUF(ssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3294 | |
| 3295 | conf = ieee80211_get_hw_conf(priv->hw); |
| 3296 | |
| 3297 | mutex_lock(&priv->mutex); |
| 3298 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 3299 | if (!iwl_is_ready(priv)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3300 | IWL_WARN(priv, "request scan called when driver not ready.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3301 | goto done; |
| 3302 | } |
| 3303 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 3304 | /* Make sure the scan wasn't canceled before this queued work |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3305 | * was given the chance to run... */ |
| 3306 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 3307 | goto done; |
| 3308 | |
| 3309 | /* This should never be called or scheduled if there is currently |
| 3310 | * a scan active in the hardware. */ |
| 3311 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3312 | IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests " |
| 3313 | "Ignoring second request.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3314 | rc = -EIO; |
| 3315 | goto done; |
| 3316 | } |
| 3317 | |
| 3318 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3319 | IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3320 | goto done; |
| 3321 | } |
| 3322 | |
| 3323 | if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3324 | IWL_DEBUG_HC(priv, |
| 3325 | "Scan request while abort pending. Queuing.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3326 | goto done; |
| 3327 | } |
| 3328 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 3329 | if (iwl_is_rfkill(priv)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3330 | IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3331 | goto done; |
| 3332 | } |
| 3333 | |
| 3334 | if (!test_bit(STATUS_READY, &priv->status)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3335 | IWL_DEBUG_HC(priv, |
| 3336 | "Scan request while uninitialized. Queuing.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3337 | goto done; |
| 3338 | } |
| 3339 | |
| 3340 | if (!priv->scan_bands) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3341 | IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3342 | goto done; |
| 3343 | } |
| 3344 | |
Winkler, Tomas | 805cee5 | 2009-01-19 15:30:28 -0800 | [diff] [blame] | 3345 | if (!priv->scan) { |
| 3346 | priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3347 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
Winkler, Tomas | 805cee5 | 2009-01-19 15:30:28 -0800 | [diff] [blame] | 3348 | if (!priv->scan) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3349 | rc = -ENOMEM; |
| 3350 | goto done; |
| 3351 | } |
| 3352 | } |
Winkler, Tomas | 805cee5 | 2009-01-19 15:30:28 -0800 | [diff] [blame] | 3353 | scan = priv->scan; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3354 | memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3355 | |
| 3356 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 3357 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 3358 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3359 | if (iwl_is_associated(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3360 | u16 interval = 0; |
| 3361 | u32 extra; |
| 3362 | u32 suspend_time = 100; |
| 3363 | u32 scan_suspend_time = 100; |
| 3364 | unsigned long flags; |
| 3365 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3366 | IWL_DEBUG_INFO(priv, "Scanning while associated...\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3367 | |
| 3368 | spin_lock_irqsave(&priv->lock, flags); |
| 3369 | interval = priv->beacon_int; |
| 3370 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3371 | |
| 3372 | scan->suspend_time = 0; |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 3373 | scan->max_out_time = cpu_to_le32(200 * 1024); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3374 | if (!interval) |
| 3375 | interval = suspend_time; |
| 3376 | /* |
| 3377 | * suspend time format: |
| 3378 | * 0-19: beacon interval in usec (time before exec.) |
| 3379 | * 20-23: 0 |
| 3380 | * 24-31: number of beacons (suspend between channels) |
| 3381 | */ |
| 3382 | |
| 3383 | extra = (suspend_time / interval) << 24; |
| 3384 | scan_suspend_time = 0xFF0FFFFF & |
| 3385 | (extra | ((suspend_time % interval) * 1024)); |
| 3386 | |
| 3387 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3388 | IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3389 | scan_suspend_time, interval); |
| 3390 | } |
| 3391 | |
| 3392 | /* We should add the ability for user to lock to PASSIVE ONLY */ |
| 3393 | if (priv->one_direct_scan) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3394 | IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n", |
| 3395 | print_ssid(ssid, priv->direct_ssid, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 3396 | priv->direct_ssid_len)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3397 | scan->direct_scan[0].id = WLAN_EID_SSID; |
| 3398 | scan->direct_scan[0].len = priv->direct_ssid_len; |
| 3399 | memcpy(scan->direct_scan[0].ssid, |
| 3400 | priv->direct_ssid, priv->direct_ssid_len); |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 3401 | n_probes++; |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 3402 | } else |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3403 | IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3404 | |
| 3405 | /* We don't build a direct scan probe request; the uCode will do |
| 3406 | * that based on the direct_mask added to each channel entry */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3407 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 3408 | scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3409 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 3410 | |
| 3411 | /* flags + rate selection */ |
| 3412 | |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 3413 | if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3414 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 3415 | scan->tx_cmd.rate = IWL_RATE_1M_PLCP; |
| 3416 | scan->good_CRC_th = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3417 | band = IEEE80211_BAND_2GHZ; |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 3418 | } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3419 | scan->tx_cmd.rate = IWL_RATE_6M_PLCP; |
| 3420 | scan->good_CRC_th = IWL_GOOD_CRC_TH; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3421 | band = IEEE80211_BAND_5GHZ; |
Ron Rindjunsky | 66b5004 | 2008-06-25 16:46:31 +0800 | [diff] [blame] | 3422 | } else { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3423 | IWL_WARN(priv, "Invalid scan band count\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3424 | goto done; |
| 3425 | } |
| 3426 | |
Samuel Ortiz | 77fecfb8 | 2009-01-23 13:45:12 -0800 | [diff] [blame] | 3427 | scan->tx_cmd.len = cpu_to_le16( |
| 3428 | iwl_fill_probe_req(priv, band, |
| 3429 | (struct ieee80211_mgmt *)scan->data, |
| 3430 | IWL_MAX_SCAN_SIZE - sizeof(*scan))); |
| 3431 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3432 | /* select Rx antennas */ |
| 3433 | scan->flags |= iwl3945_get_antenna_flags(priv); |
| 3434 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3435 | if (priv->iw_mode == NL80211_IFTYPE_MONITOR) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3436 | scan->filter_flags = RXON_FILTER_PROMISC_MSK; |
| 3437 | |
Abhijeet Kolekar | f934052 | 2008-09-03 11:26:58 +0800 | [diff] [blame] | 3438 | scan->channel_count = |
| 3439 | iwl3945_get_channels_for_scan(priv, band, 1, /* active */ |
| 3440 | n_probes, |
| 3441 | (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3442 | |
Reinette Chatre | 14b5433 | 2008-11-04 12:21:35 -0800 | [diff] [blame] | 3443 | if (scan->channel_count == 0) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3444 | IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count); |
Reinette Chatre | 14b5433 | 2008-11-04 12:21:35 -0800 | [diff] [blame] | 3445 | goto done; |
| 3446 | } |
| 3447 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3448 | cmd.len += le16_to_cpu(scan->tx_cmd.len) + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3449 | scan->channel_count * sizeof(struct iwl3945_scan_channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3450 | cmd.data = scan; |
| 3451 | scan->len = cpu_to_le16(cmd.len); |
| 3452 | |
| 3453 | set_bit(STATUS_SCAN_HW, &priv->status); |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 3454 | rc = iwl_send_cmd_sync(priv, &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3455 | if (rc) |
| 3456 | goto done; |
| 3457 | |
| 3458 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
| 3459 | IWL_SCAN_CHECK_WATCHDOG); |
| 3460 | |
| 3461 | mutex_unlock(&priv->mutex); |
| 3462 | return; |
| 3463 | |
| 3464 | done: |
Mohamed Abbas | 2420ebc | 2008-11-04 12:21:34 -0800 | [diff] [blame] | 3465 | /* can not perform scan make sure we clear scanning |
| 3466 | * bits from status so next scan request can be performed. |
| 3467 | * if we dont clear scanning status bit here all next scan |
| 3468 | * will fail |
| 3469 | */ |
| 3470 | clear_bit(STATUS_SCAN_HW, &priv->status); |
| 3471 | clear_bit(STATUS_SCANNING, &priv->status); |
| 3472 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3473 | /* inform mac80211 scan aborted */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3474 | queue_work(priv->workqueue, &priv->scan_completed); |
| 3475 | mutex_unlock(&priv->mutex); |
| 3476 | } |
| 3477 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3478 | static void iwl3945_bg_up(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3479 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3480 | struct iwl_priv *priv = container_of(data, struct iwl_priv, up); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3481 | |
| 3482 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3483 | return; |
| 3484 | |
| 3485 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3486 | __iwl3945_up(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3487 | mutex_unlock(&priv->mutex); |
Samuel Ortiz | c0af96a | 2009-01-21 18:27:54 +0100 | [diff] [blame] | 3488 | iwl_rfkill_set_hw_state(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3489 | } |
| 3490 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3491 | static void iwl3945_bg_restart(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3492 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3493 | struct iwl_priv *priv = container_of(data, struct iwl_priv, restart); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3494 | |
| 3495 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3496 | return; |
| 3497 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3498 | iwl3945_down(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3499 | queue_work(priv->workqueue, &priv->up); |
| 3500 | } |
| 3501 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3502 | static void iwl3945_bg_rx_replenish(struct work_struct *data) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3503 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3504 | struct iwl_priv *priv = |
| 3505 | container_of(data, struct iwl_priv, rx_replenish); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3506 | |
| 3507 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3508 | return; |
| 3509 | |
| 3510 | mutex_lock(&priv->mutex); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3511 | iwl3945_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3512 | mutex_unlock(&priv->mutex); |
| 3513 | } |
| 3514 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3515 | #define IWL_DELAY_NEXT_SCAN (HZ*2) |
| 3516 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3517 | static void iwl3945_post_associate(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3518 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3519 | int rc = 0; |
| 3520 | struct ieee80211_conf *conf = NULL; |
| 3521 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3522 | if (priv->iw_mode == NL80211_IFTYPE_AP) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3523 | 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] | 3524 | return; |
| 3525 | } |
| 3526 | |
| 3527 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3528 | IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n", |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3529 | priv->assoc_id, priv->active_rxon.bssid_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3530 | |
| 3531 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 3532 | return; |
| 3533 | |
Abhijeet Kolekar | 322a981 | 2008-09-03 11:26:27 +0800 | [diff] [blame] | 3534 | if (!priv->vif || !priv->is_open) |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 3535 | return; |
Abhijeet Kolekar | 322a981 | 2008-09-03 11:26:27 +0800 | [diff] [blame] | 3536 | |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 3537 | iwl_scan_cancel_timeout(priv, 200); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 3538 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3539 | conf = ieee80211_get_hw_conf(priv->hw); |
| 3540 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3541 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3542 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3543 | |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 3544 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3545 | iwl3945_setup_rxon_timing(priv); |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 3546 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3547 | sizeof(priv->rxon_timing), &priv->rxon_timing); |
| 3548 | if (rc) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3549 | IWL_WARN(priv, "REPLY_RXON_TIMING failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3550 | "Attempting to continue.\n"); |
| 3551 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3552 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3553 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3554 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3555 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3556 | IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3557 | priv->assoc_id, priv->beacon_int); |
| 3558 | |
| 3559 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3560 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3561 | else |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3562 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3563 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3564 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3565 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3566 | priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3567 | else |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3568 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3569 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3570 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3571 | priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3572 | |
| 3573 | } |
| 3574 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3575 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3576 | |
| 3577 | switch (priv->iw_mode) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3578 | case NL80211_IFTYPE_STATION: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3579 | iwl3945_rate_scale_init(priv->hw, IWL_AP_ID); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3580 | break; |
| 3581 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3582 | case NL80211_IFTYPE_ADHOC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3583 | |
Abhijeet Kolekar | ce546fd | 2008-11-19 15:32:22 -0800 | [diff] [blame] | 3584 | priv->assoc_id = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3585 | iwl3945_add_station(priv, priv->bssid, 0, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3586 | iwl3945_sync_sta(priv, IWL_STA_ID, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3587 | (priv->band == IEEE80211_BAND_5GHZ) ? |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3588 | IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP, |
| 3589 | CMD_ASYNC); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3590 | iwl3945_rate_scale_init(priv->hw, IWL_STA_ID); |
| 3591 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3592 | |
| 3593 | break; |
| 3594 | |
| 3595 | default: |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3596 | IWL_ERR(priv, "%s Should not be called in %d mode\n", |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 3597 | __func__, priv->iw_mode); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3598 | break; |
| 3599 | } |
| 3600 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3601 | iwl3945_activate_qos(priv, 0); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 3602 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3603 | /* we have just associated, don't start scan too early */ |
| 3604 | priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 3605 | } |
| 3606 | |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 3607 | static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3608 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3609 | /***************************************************************************** |
| 3610 | * |
| 3611 | * mac80211 entry point functions |
| 3612 | * |
| 3613 | *****************************************************************************/ |
| 3614 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3615 | #define UCODE_READY_TIMEOUT (2 * HZ) |
| 3616 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3617 | static int iwl3945_mac_start(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3618 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3619 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3620 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3621 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3622 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3623 | |
| 3624 | /* we should be verifying the device is ready to be opened */ |
| 3625 | mutex_lock(&priv->mutex); |
| 3626 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3627 | memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3628 | /* fetch ucode file from disk, alloc and copy to bus-master buffers ... |
| 3629 | * ucode filename and max sizes are card-specific. */ |
| 3630 | |
| 3631 | if (!priv->ucode_code.len) { |
| 3632 | ret = iwl3945_read_ucode(priv); |
| 3633 | if (ret) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3634 | IWL_ERR(priv, "Could not read microcode: %d\n", ret); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3635 | mutex_unlock(&priv->mutex); |
| 3636 | goto out_release_irq; |
| 3637 | } |
| 3638 | } |
| 3639 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3640 | ret = __iwl3945_up(priv); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3641 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3642 | mutex_unlock(&priv->mutex); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3643 | |
Samuel Ortiz | c0af96a | 2009-01-21 18:27:54 +0100 | [diff] [blame] | 3644 | iwl_rfkill_set_hw_state(priv); |
Adel Gadllah | 80fcc9e | 2008-07-01 17:49:50 +0200 | [diff] [blame] | 3645 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3646 | if (ret) |
| 3647 | goto out_release_irq; |
| 3648 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3649 | IWL_DEBUG_INFO(priv, "Start UP work.\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3650 | |
| 3651 | if (test_bit(STATUS_IN_SUSPEND, &priv->status)) |
| 3652 | return 0; |
| 3653 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3654 | /* Wait for START_ALIVE from ucode. Otherwise callbacks from |
| 3655 | * mac80211 will not be run successfully. */ |
| 3656 | ret = wait_event_interruptible_timeout(priv->wait_command_queue, |
| 3657 | test_bit(STATUS_READY, &priv->status), |
| 3658 | UCODE_READY_TIMEOUT); |
| 3659 | if (!ret) { |
| 3660 | if (!test_bit(STATUS_READY, &priv->status)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 3661 | IWL_ERR(priv, |
| 3662 | "Wait for START_ALIVE timeout after %dms.\n", |
| 3663 | jiffies_to_msecs(UCODE_READY_TIMEOUT)); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3664 | ret = -ETIMEDOUT; |
| 3665 | goto out_release_irq; |
| 3666 | } |
| 3667 | } |
| 3668 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 3669 | /* ucode is running and will send rfkill notifications, |
| 3670 | * no need to poll the killswitch state anymore */ |
| 3671 | cancel_delayed_work(&priv->rfkill_poll); |
| 3672 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3673 | priv->is_open = 1; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3674 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3675 | return 0; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3676 | |
| 3677 | out_release_irq: |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3678 | priv->is_open = 0; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3679 | IWL_DEBUG_MAC80211(priv, "leave - failed\n"); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3680 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3681 | } |
| 3682 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3683 | static void iwl3945_mac_stop(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3684 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3685 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3686 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3687 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 3688 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3689 | if (!priv->is_open) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3690 | IWL_DEBUG_MAC80211(priv, "leave - skip\n"); |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3691 | return; |
| 3692 | } |
| 3693 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3694 | priv->is_open = 0; |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3695 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 3696 | if (iwl_is_ready_rf(priv)) { |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 3697 | /* stop mac, cancel any scan request and clear |
| 3698 | * RXON_FILTER_ASSOC_MSK BIT |
| 3699 | */ |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3700 | mutex_lock(&priv->mutex); |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 3701 | iwl_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 3702 | mutex_unlock(&priv->mutex); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 3703 | } |
| 3704 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3705 | iwl3945_down(priv); |
| 3706 | |
| 3707 | flush_workqueue(priv->workqueue); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 3708 | |
| 3709 | /* start polling the killswitch state again */ |
| 3710 | queue_delayed_work(priv->workqueue, &priv->rfkill_poll, |
| 3711 | round_jiffies_relative(2 * HZ)); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 3712 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3713 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3714 | } |
| 3715 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 3716 | 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] | 3717 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3718 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3719 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3720 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3721 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3722 | 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] | 3723 | ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3724 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 3725 | if (iwl3945_tx_skb(priv, skb)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3726 | dev_kfree_skb_any(skb); |
| 3727 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3728 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Reinette Chatre | 637f883 | 2009-01-19 15:30:32 -0800 | [diff] [blame] | 3729 | return NETDEV_TX_OK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3730 | } |
| 3731 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3732 | static int iwl3945_mac_add_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3733 | struct ieee80211_if_init_conf *conf) |
| 3734 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3735 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3736 | unsigned long flags; |
| 3737 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3738 | IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3739 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3740 | if (priv->vif) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3741 | IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n"); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 3742 | return -EOPNOTSUPP; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | spin_lock_irqsave(&priv->lock, flags); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3746 | priv->vif = conf->vif; |
Zhu, Yi | 60294de | 2008-10-29 14:05:45 -0700 | [diff] [blame] | 3747 | priv->iw_mode = conf->type; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3748 | |
| 3749 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3750 | |
| 3751 | mutex_lock(&priv->mutex); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 3752 | |
| 3753 | if (conf->mac_addr) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3754 | IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr); |
Tomas Winkler | 864792e | 2007-11-27 21:00:52 +0200 | [diff] [blame] | 3755 | memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN); |
| 3756 | } |
| 3757 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 3758 | if (iwl_is_ready(priv)) |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3759 | iwl3945_set_mode(priv, conf->type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3760 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3761 | mutex_unlock(&priv->mutex); |
| 3762 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3763 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3764 | return 0; |
| 3765 | } |
| 3766 | |
| 3767 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3768 | * iwl3945_mac_config - mac80211 config callback |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3769 | * |
| 3770 | * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to |
| 3771 | * be set inappropriately and the driver currently sets the hardware up to |
| 3772 | * use it whenever needed. |
| 3773 | */ |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 3774 | static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3775 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3776 | struct iwl_priv *priv = hw->priv; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 3777 | const struct iwl_channel_info *ch_info; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 3778 | struct ieee80211_conf *conf = &hw->conf; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3779 | unsigned long flags; |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3780 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3781 | |
| 3782 | mutex_lock(&priv->mutex); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3783 | IWL_DEBUG_MAC80211(priv, "enter to channel %d\n", |
| 3784 | conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3785 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 3786 | if (!iwl_is_ready(priv)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3787 | IWL_DEBUG_MAC80211(priv, "leave - not ready\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3788 | ret = -EIO; |
| 3789 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3790 | } |
| 3791 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 3792 | if (unlikely(!iwl3945_mod_params.disable_hw_scan && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3793 | test_bit(STATUS_SCANNING, &priv->status))) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3794 | IWL_DEBUG_MAC80211(priv, "leave - scanning\n"); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 3795 | set_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3796 | mutex_unlock(&priv->mutex); |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 3797 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | spin_lock_irqsave(&priv->lock, flags); |
| 3801 | |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 3802 | ch_info = iwl_get_channel_info(priv, conf->channel->band, |
| 3803 | conf->channel->hw_value); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3804 | if (!is_channel_valid(ch_info)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3805 | IWL_DEBUG_SCAN(priv, |
| 3806 | "Channel %d [%d] is INVALID for this band.\n", |
| 3807 | conf->channel->hw_value, conf->channel->band); |
| 3808 | IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3809 | spin_unlock_irqrestore(&priv->lock, flags); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3810 | ret = -EINVAL; |
| 3811 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3812 | } |
| 3813 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3814 | iwl_set_rxon_channel(priv, conf->channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3815 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3816 | iwl_set_flags_for_band(priv, conf->channel->band); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3817 | |
| 3818 | /* The list of supported rates and rate mask can be different |
| 3819 | * for each phymode; since the phymode may have changed, reset |
| 3820 | * the rate mask to what mac80211 lists */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3821 | iwl_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3822 | |
| 3823 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3824 | |
| 3825 | #ifdef IEEE80211_CONF_CHANNEL_SWITCH |
| 3826 | if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3827 | iwl3945_hw_channel_switch(priv, conf->channel); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3828 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3829 | } |
| 3830 | #endif |
| 3831 | |
Abhijeet Kolekar | 7dc45f2 | 2009-02-18 15:54:32 -0800 | [diff] [blame^] | 3832 | if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) { |
| 3833 | IWL_DEBUG_MAC80211(priv, "leave - RF-KILL - waiting for uCode\n"); |
| 3834 | goto out; |
| 3835 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3836 | |
| 3837 | if (!conf->radio_enabled) { |
Abhijeet Kolekar | 7dc45f2 | 2009-02-18 15:54:32 -0800 | [diff] [blame^] | 3838 | iwl_radio_kill_sw_disable_radio(priv); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3839 | IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3840 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3841 | } |
| 3842 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 3843 | if (iwl_is_rfkill(priv)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3844 | IWL_DEBUG_MAC80211(priv, "leave - RF kill\n"); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3845 | ret = -EIO; |
| 3846 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3847 | } |
| 3848 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3849 | iwl_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3850 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3851 | if (memcmp(&priv->active_rxon, |
| 3852 | &priv->staging_rxon, sizeof(priv->staging_rxon))) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3853 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3854 | else |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3855 | IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3856 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3857 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3858 | |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3859 | out: |
Zhu Yi | a064647 | 2007-12-20 14:10:01 +0800 | [diff] [blame] | 3860 | clear_bit(STATUS_CONF_PENDING, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3861 | mutex_unlock(&priv->mutex); |
Zhu Yi | 76bb77e | 2007-11-22 10:53:22 +0800 | [diff] [blame] | 3862 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3863 | } |
| 3864 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3865 | static void iwl3945_config_ap(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3866 | { |
| 3867 | int rc = 0; |
| 3868 | |
Maarten Lankhorst | d986bcd | 2008-01-23 10:15:16 -0800 | [diff] [blame] | 3869 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3870 | return; |
| 3871 | |
| 3872 | /* The following should be done only at AP bring up */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3873 | if (!(iwl_is_associated(priv))) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3874 | |
| 3875 | /* RXON - unassoc (to set timing command) */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3876 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3877 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3878 | |
| 3879 | /* RXON Timing */ |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 3880 | memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3881 | iwl3945_setup_rxon_timing(priv); |
Samuel Ortiz | 518099a | 2009-01-19 15:30:27 -0800 | [diff] [blame] | 3882 | rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, |
| 3883 | sizeof(priv->rxon_timing), |
| 3884 | &priv->rxon_timing); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3885 | if (rc) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3886 | IWL_WARN(priv, "REPLY_RXON_TIMING failed - " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3887 | "Attempting to continue.\n"); |
| 3888 | |
| 3889 | /* FIXME: what should be the assoc_id for AP? */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3890 | priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3891 | if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3892 | priv->staging_rxon.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3893 | RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3894 | else |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3895 | priv->staging_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3896 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
| 3897 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3898 | if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3899 | if (priv->assoc_capability & |
| 3900 | WLAN_CAPABILITY_SHORT_SLOT_TIME) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3901 | priv->staging_rxon.flags |= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3902 | RXON_FLG_SHORT_SLOT_MSK; |
| 3903 | else |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3904 | priv->staging_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3905 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 3906 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3907 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3908 | priv->staging_rxon.flags &= |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3909 | ~RXON_FLG_SHORT_SLOT_MSK; |
| 3910 | } |
| 3911 | /* restore RXON assoc */ |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3912 | priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3913 | iwl3945_commit_rxon(priv); |
Kolekar, Abhijeet | b5323d3 | 2008-12-19 10:37:22 +0800 | [diff] [blame] | 3914 | iwl3945_add_station(priv, iwl_bcast_addr, 0, 0); |
Zhu Yi | 556f8db | 2007-09-27 11:27:33 +0800 | [diff] [blame] | 3915 | } |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3916 | iwl3945_send_beacon_cmd(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3917 | |
| 3918 | /* FIXME - we need to add code here to detect a totally new |
| 3919 | * configuration, reset the AP, unassoc, rxon timing, assoc, |
| 3920 | * clear sta table, add BCAST sta... */ |
| 3921 | } |
| 3922 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 3923 | static int iwl3945_mac_config_interface(struct ieee80211_hw *hw, |
| 3924 | struct ieee80211_vif *vif, |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3925 | struct ieee80211_if_conf *conf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3926 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 3927 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3928 | int rc; |
| 3929 | |
| 3930 | if (conf == NULL) |
| 3931 | return -EIO; |
| 3932 | |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 3933 | if (priv->vif != vif) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3934 | IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n"); |
Emmanuel Grumbach | b716bb9 | 2008-03-04 18:09:32 -0800 | [diff] [blame] | 3935 | return 0; |
| 3936 | } |
| 3937 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 3938 | /* handle this temporarily here */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3939 | if (priv->iw_mode == NL80211_IFTYPE_ADHOC && |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 3940 | conf->changed & IEEE80211_IFCC_BEACON) { |
| 3941 | struct sk_buff *beacon = ieee80211_beacon_get(hw, vif); |
| 3942 | if (!beacon) |
| 3943 | return -ENOMEM; |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 3944 | mutex_lock(&priv->mutex); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 3945 | rc = iwl3945_mac_beacon_update(hw, beacon); |
Mohamed Abbas | 9bdf5ec | 2008-11-07 09:58:35 -0800 | [diff] [blame] | 3946 | mutex_unlock(&priv->mutex); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 3947 | if (rc) |
| 3948 | return rc; |
| 3949 | } |
| 3950 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 3951 | if (!iwl_is_alive(priv)) |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 3952 | return -EAGAIN; |
| 3953 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3954 | mutex_lock(&priv->mutex); |
| 3955 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3956 | if (conf->bssid) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3957 | IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3958 | |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 3959 | /* |
| 3960 | * very dubious code was here; the probe filtering flag is never set: |
| 3961 | * |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3962 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) && |
| 3963 | !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) { |
Johannes Berg | 4150c57 | 2007-09-17 01:29:23 -0400 | [diff] [blame] | 3964 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3965 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 3966 | if (priv->iw_mode == NL80211_IFTYPE_AP) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3967 | if (!conf->bssid) { |
| 3968 | conf->bssid = priv->mac_addr; |
| 3969 | memcpy(priv->bssid, priv->mac_addr, ETH_ALEN); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3970 | IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 3971 | conf->bssid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3972 | } |
| 3973 | if (priv->ibss_beacon) |
| 3974 | dev_kfree_skb(priv->ibss_beacon); |
| 3975 | |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 3976 | priv->ibss_beacon = ieee80211_beacon_get(hw, vif); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3977 | } |
| 3978 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 3979 | if (iwl_is_rfkill(priv)) |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 3980 | goto done; |
| 3981 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3982 | if (conf->bssid && !is_zero_ether_addr(conf->bssid) && |
| 3983 | !is_multicast_ether_addr(conf->bssid)) { |
| 3984 | /* If there is currently a HW scan going on in the background |
| 3985 | * then we need to cancel it else the RXON below will fail. */ |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 3986 | if (iwl_scan_cancel_timeout(priv, 100)) { |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 3987 | IWL_WARN(priv, "Aborted scan still in progress " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3988 | "after 100ms\n"); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 3989 | IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3990 | mutex_unlock(&priv->mutex); |
| 3991 | return -EAGAIN; |
| 3992 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 3993 | memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3994 | |
| 3995 | /* TODO: Audit driver for usage of these members and see |
| 3996 | * if mac80211 deprecates them (priv->bssid looks like it |
| 3997 | * shouldn't be there, but I haven't scanned the IBSS code |
| 3998 | * to verify) - jpk */ |
| 3999 | memcpy(priv->bssid, conf->bssid, ETH_ALEN); |
| 4000 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 4001 | if (priv->iw_mode == NL80211_IFTYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4002 | iwl3945_config_ap(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4003 | else { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4004 | rc = iwl3945_commit_rxon(priv); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 4005 | if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4006 | iwl3945_add_station(priv, |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4007 | priv->active_rxon.bssid_addr, 1, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4008 | } |
| 4009 | |
| 4010 | } else { |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 4011 | iwl_scan_cancel_timeout(priv, 100); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4012 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4013 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4014 | } |
| 4015 | |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4016 | done: |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4017 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4018 | mutex_unlock(&priv->mutex); |
| 4019 | |
| 4020 | return 0; |
| 4021 | } |
| 4022 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4023 | static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4024 | struct ieee80211_if_init_conf *conf) |
| 4025 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4026 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4027 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4028 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4029 | |
| 4030 | mutex_lock(&priv->mutex); |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 4031 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 4032 | if (iwl_is_ready_rf(priv)) { |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 4033 | iwl_scan_cancel_timeout(priv, 100); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4034 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4035 | iwl3945_commit_rxon(priv); |
| 4036 | } |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 4037 | if (priv->vif == conf->vif) { |
| 4038 | priv->vif = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4039 | memset(priv->bssid, 0, ETH_ALEN); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4040 | } |
| 4041 | mutex_unlock(&priv->mutex); |
| 4042 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4043 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4044 | } |
| 4045 | |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4046 | #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6) |
| 4047 | |
| 4048 | static void iwl3945_bss_info_changed(struct ieee80211_hw *hw, |
| 4049 | struct ieee80211_vif *vif, |
| 4050 | struct ieee80211_bss_conf *bss_conf, |
| 4051 | u32 changes) |
| 4052 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4053 | struct iwl_priv *priv = hw->priv; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4054 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4055 | IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes); |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4056 | |
| 4057 | if (changes & BSS_CHANGED_ERP_PREAMBLE) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4058 | IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n", |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4059 | bss_conf->use_short_preamble); |
| 4060 | if (bss_conf->use_short_preamble) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4061 | priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4062 | else |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4063 | priv->staging_rxon.flags &= |
| 4064 | ~RXON_FLG_SHORT_PREAMBLE_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | if (changes & BSS_CHANGED_ERP_CTS_PROT) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4068 | IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", |
| 4069 | bss_conf->use_cts_prot); |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4070 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4071 | priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4072 | else |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4073 | priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4074 | } |
| 4075 | |
| 4076 | if (changes & BSS_CHANGED_ASSOC) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4077 | IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc); |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4078 | /* This should never happen as this function should |
| 4079 | * never be called from interrupt context. */ |
| 4080 | if (WARN_ON_ONCE(in_interrupt())) |
| 4081 | return; |
| 4082 | if (bss_conf->assoc) { |
| 4083 | priv->assoc_id = bss_conf->aid; |
| 4084 | priv->beacon_int = bss_conf->beacon_int; |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 4085 | priv->timestamp = bss_conf->timestamp; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4086 | priv->assoc_capability = bss_conf->assoc_capability; |
Winkler, Tomas | 3dae0c4 | 2009-01-19 15:30:30 -0800 | [diff] [blame] | 4087 | priv->power_data.dtim_period = bss_conf->dtim_period; |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4088 | priv->next_scan_jiffies = jiffies + |
| 4089 | IWL_DELAY_NEXT_SCAN_AFTER_ASSOC; |
| 4090 | mutex_lock(&priv->mutex); |
| 4091 | iwl3945_post_associate(priv); |
| 4092 | mutex_unlock(&priv->mutex); |
| 4093 | } else { |
| 4094 | priv->assoc_id = 0; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4095 | IWL_DEBUG_MAC80211(priv, |
| 4096 | "DISASSOC %d\n", bss_conf->assoc); |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4097 | } |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4098 | } else if (changes && iwl_is_associated(priv) && priv->assoc_id) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4099 | IWL_DEBUG_MAC80211(priv, |
| 4100 | "Associated Changes %d\n", changes); |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4101 | iwl3945_send_rxon_assoc(priv); |
| 4102 | } |
| 4103 | |
| 4104 | } |
| 4105 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4106 | 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] | 4107 | struct ieee80211_vif *vif, |
| 4108 | struct ieee80211_sta *sta, |
| 4109 | struct ieee80211_key_conf *key) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4110 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4111 | struct iwl_priv *priv = hw->priv; |
Johannes Berg | dc822b5 | 2008-12-29 12:55:09 +0100 | [diff] [blame] | 4112 | const u8 *addr; |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 4113 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4114 | u8 sta_id; |
| 4115 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4116 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4117 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 4118 | if (iwl3945_mod_params.sw_crypto) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4119 | IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4120 | return -EOPNOTSUPP; |
| 4121 | } |
| 4122 | |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 4123 | addr = sta ? sta->addr : iwl_bcast_addr; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4124 | sta_id = iwl3945_hw_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4125 | if (sta_id == IWL_INVALID_STATION) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4126 | IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 4127 | addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4128 | return -EINVAL; |
| 4129 | } |
| 4130 | |
| 4131 | mutex_lock(&priv->mutex); |
| 4132 | |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 4133 | iwl_scan_cancel_timeout(priv, 100); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 4134 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4135 | switch (cmd) { |
| 4136 | case SET_KEY: |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 4137 | ret = iwl3945_update_sta_key_info(priv, key, sta_id); |
| 4138 | if (!ret) { |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4139 | iwl_set_rxon_hwcrypto(priv, 1); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4140 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4141 | key->hw_key_idx = sta_id; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4142 | IWL_DEBUG_MAC80211(priv, |
| 4143 | "set_key success, using hwcrypto\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4144 | key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; |
| 4145 | } |
| 4146 | break; |
| 4147 | case DISABLE_KEY: |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 4148 | ret = iwl3945_clear_sta_key_info(priv, sta_id); |
| 4149 | if (!ret) { |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4150 | iwl_set_rxon_hwcrypto(priv, 0); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4151 | iwl3945_commit_rxon(priv); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4152 | IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4153 | } |
| 4154 | break; |
| 4155 | default: |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 4156 | ret = -EINVAL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4157 | } |
| 4158 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4159 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4160 | mutex_unlock(&priv->mutex); |
| 4161 | |
Winkler, Tomas | 4298679 | 2009-01-19 15:30:22 -0800 | [diff] [blame] | 4162 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4163 | } |
| 4164 | |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 4165 | static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4166 | const struct ieee80211_tx_queue_params *params) |
| 4167 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4168 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4169 | unsigned long flags; |
| 4170 | int q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4171 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4172 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4173 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 4174 | if (!iwl_is_ready_rf(priv)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4175 | IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4176 | return -EIO; |
| 4177 | } |
| 4178 | |
| 4179 | if (queue >= AC_NUM) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4180 | IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4181 | return 0; |
| 4182 | } |
| 4183 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4184 | q = AC_NUM - 1 - queue; |
| 4185 | |
| 4186 | spin_lock_irqsave(&priv->lock, flags); |
| 4187 | |
| 4188 | priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); |
| 4189 | priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); |
| 4190 | priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; |
| 4191 | priv->qos_data.def_qos_parm.ac[q].edca_txop = |
Johannes Berg | 3330d7be | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 4192 | cpu_to_le16((params->txop * 32)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4193 | |
| 4194 | priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; |
| 4195 | priv->qos_data.qos_active = 1; |
| 4196 | |
| 4197 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4198 | |
| 4199 | mutex_lock(&priv->mutex); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 4200 | if (priv->iw_mode == NL80211_IFTYPE_AP) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4201 | iwl3945_activate_qos(priv, 1); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4202 | else if (priv->assoc_id && iwl_is_associated(priv)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4203 | iwl3945_activate_qos(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4204 | |
| 4205 | mutex_unlock(&priv->mutex); |
| 4206 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4207 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4208 | return 0; |
| 4209 | } |
| 4210 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4211 | static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4212 | struct ieee80211_tx_queue_stats *stats) |
| 4213 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4214 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4215 | int i, avail; |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 4216 | struct iwl_tx_queue *txq; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4217 | struct iwl_queue *q; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4218 | unsigned long flags; |
| 4219 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4220 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4221 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 4222 | if (!iwl_is_ready_rf(priv)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4223 | IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4224 | return -EIO; |
| 4225 | } |
| 4226 | |
| 4227 | spin_lock_irqsave(&priv->lock, flags); |
| 4228 | |
| 4229 | for (i = 0; i < AC_NUM; i++) { |
Samuel Ortiz | 188cf6c | 2008-12-22 11:31:16 +0800 | [diff] [blame] | 4230 | txq = &priv->txq[i]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4231 | q = &txq->q; |
Samuel Ortiz | d20b3c6 | 2008-12-19 10:37:15 +0800 | [diff] [blame] | 4232 | avail = iwl_queue_space(q); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4233 | |
Johannes Berg | 57ffc58 | 2008-04-29 17:18:59 +0200 | [diff] [blame] | 4234 | stats[i].len = q->n_window - avail; |
| 4235 | stats[i].limit = q->n_window - q->high_mark; |
| 4236 | stats[i].count = q->n_window; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4237 | |
| 4238 | } |
| 4239 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4240 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4241 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4242 | |
| 4243 | return 0; |
| 4244 | } |
| 4245 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4246 | static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4247 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4248 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4249 | unsigned long flags; |
| 4250 | |
| 4251 | mutex_lock(&priv->mutex); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4252 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4253 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 4254 | iwl_reset_qos(priv); |
Ron Rindjunsky | 292ae17 | 2008-02-06 11:20:39 -0800 | [diff] [blame] | 4255 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4256 | spin_lock_irqsave(&priv->lock, flags); |
| 4257 | priv->assoc_id = 0; |
| 4258 | priv->assoc_capability = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4259 | |
| 4260 | /* new association get rid of ibss beacon skb */ |
| 4261 | if (priv->ibss_beacon) |
| 4262 | dev_kfree_skb(priv->ibss_beacon); |
| 4263 | |
| 4264 | priv->ibss_beacon = NULL; |
| 4265 | |
| 4266 | priv->beacon_int = priv->hw->conf.beacon_int; |
Tomas Winkler | 28afaf9 | 2008-12-19 10:37:06 +0800 | [diff] [blame] | 4267 | priv->timestamp = 0; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 4268 | if ((priv->iw_mode == NL80211_IFTYPE_STATION)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4269 | priv->beacon_int = 0; |
| 4270 | |
| 4271 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4272 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 4273 | if (!iwl_is_ready_rf(priv)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4274 | IWL_DEBUG_MAC80211(priv, "leave - not ready\n"); |
Mohamed Abbas | fde3571 | 2007-11-29 11:10:15 +0800 | [diff] [blame] | 4275 | mutex_unlock(&priv->mutex); |
| 4276 | return; |
| 4277 | } |
| 4278 | |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 4279 | /* we are restarting association process |
| 4280 | * clear RXON_FILTER_ASSOC_MSK bit |
| 4281 | */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 4282 | if (priv->iw_mode != NL80211_IFTYPE_AP) { |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 4283 | iwl_scan_cancel_timeout(priv, 100); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4284 | priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4285 | iwl3945_commit_rxon(priv); |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 4286 | } |
| 4287 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4288 | /* Per mac80211.h: This is only used in IBSS mode... */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 4289 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { |
Mohamed Abbas | 15e869d | 2007-10-25 17:15:46 +0800 | [diff] [blame] | 4290 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4291 | IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4292 | mutex_unlock(&priv->mutex); |
| 4293 | return; |
| 4294 | } |
| 4295 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4296 | iwl_set_rate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4297 | |
| 4298 | mutex_unlock(&priv->mutex); |
| 4299 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4300 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4301 | |
| 4302 | } |
| 4303 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 4304 | static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4305 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4306 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4307 | unsigned long flags; |
| 4308 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4309 | IWL_DEBUG_MAC80211(priv, "enter\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4310 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 4311 | if (!iwl_is_ready_rf(priv)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4312 | IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4313 | return -EIO; |
| 4314 | } |
| 4315 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 4316 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4317 | IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4318 | return -EIO; |
| 4319 | } |
| 4320 | |
| 4321 | spin_lock_irqsave(&priv->lock, flags); |
| 4322 | |
| 4323 | if (priv->ibss_beacon) |
| 4324 | dev_kfree_skb(priv->ibss_beacon); |
| 4325 | |
| 4326 | priv->ibss_beacon = skb; |
| 4327 | |
| 4328 | priv->assoc_id = 0; |
| 4329 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4330 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4331 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4332 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 4333 | iwl_reset_qos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4334 | |
Abhijeet Kolekar | dc4b1e7 | 2008-09-03 11:26:30 +0800 | [diff] [blame] | 4335 | iwl3945_post_associate(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4336 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4337 | |
| 4338 | return 0; |
| 4339 | } |
| 4340 | |
| 4341 | /***************************************************************************** |
| 4342 | * |
| 4343 | * sysfs attributes |
| 4344 | * |
| 4345 | *****************************************************************************/ |
| 4346 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 4347 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4348 | |
| 4349 | /* |
| 4350 | * The following adds a new attribute to the sysfs representation |
| 4351 | * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/) |
| 4352 | * used for controlling the debug level. |
| 4353 | * |
| 4354 | * See the level definitions in iwl for details. |
| 4355 | */ |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4356 | static ssize_t show_debug_level(struct device *d, |
| 4357 | struct device_attribute *attr, char *buf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4358 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4359 | struct iwl_priv *priv = d->driver_data; |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4360 | |
| 4361 | return sprintf(buf, "0x%08X\n", priv->debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4362 | } |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4363 | static ssize_t store_debug_level(struct device *d, |
| 4364 | struct device_attribute *attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4365 | const char *buf, size_t count) |
| 4366 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4367 | struct iwl_priv *priv = d->driver_data; |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4368 | unsigned long val; |
| 4369 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4370 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4371 | ret = strict_strtoul(buf, 0, &val); |
| 4372 | if (ret) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4373 | IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4374 | else |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4375 | priv->debug_level = val; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4376 | |
| 4377 | return strnlen(buf, count); |
| 4378 | } |
| 4379 | |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4380 | static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 4381 | show_debug_level, store_debug_level); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4382 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 4383 | #endif /* CONFIG_IWLWIFI_DEBUG */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4384 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4385 | static ssize_t show_temperature(struct device *d, |
| 4386 | struct device_attribute *attr, char *buf) |
| 4387 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4388 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4389 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 4390 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4391 | return -EAGAIN; |
| 4392 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4393 | return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4394 | } |
| 4395 | |
| 4396 | static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL); |
| 4397 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4398 | static ssize_t show_tx_power(struct device *d, |
| 4399 | struct device_attribute *attr, char *buf) |
| 4400 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4401 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Winkler, Tomas | 62ea9c5 | 2009-01-19 15:30:29 -0800 | [diff] [blame] | 4402 | return sprintf(buf, "%d\n", priv->tx_power_user_lmt); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4403 | } |
| 4404 | |
| 4405 | static ssize_t store_tx_power(struct device *d, |
| 4406 | struct device_attribute *attr, |
| 4407 | const char *buf, size_t count) |
| 4408 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4409 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4410 | char *p = (char *)buf; |
| 4411 | u32 val; |
| 4412 | |
| 4413 | val = simple_strtoul(p, &p, 10); |
| 4414 | if (p == buf) |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 4415 | IWL_INFO(priv, ": %s is not in decimal form.\n", buf); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4416 | else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4417 | iwl3945_hw_reg_set_txpower(priv, val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4418 | |
| 4419 | return count; |
| 4420 | } |
| 4421 | |
| 4422 | static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power); |
| 4423 | |
| 4424 | static ssize_t show_flags(struct device *d, |
| 4425 | struct device_attribute *attr, char *buf) |
| 4426 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4427 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4428 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4429 | return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4430 | } |
| 4431 | |
| 4432 | static ssize_t store_flags(struct device *d, |
| 4433 | struct device_attribute *attr, |
| 4434 | const char *buf, size_t count) |
| 4435 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4436 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4437 | u32 flags = simple_strtoul(buf, NULL, 0); |
| 4438 | |
| 4439 | mutex_lock(&priv->mutex); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4440 | if (le32_to_cpu(priv->staging_rxon.flags) != flags) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4441 | /* Cancel any currently running scans... */ |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 4442 | if (iwl_scan_cancel_timeout(priv, 100)) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4443 | IWL_WARN(priv, "Could not cancel scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4444 | else { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4445 | IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4446 | flags); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4447 | priv->staging_rxon.flags = cpu_to_le32(flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4448 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4449 | } |
| 4450 | } |
| 4451 | mutex_unlock(&priv->mutex); |
| 4452 | |
| 4453 | return count; |
| 4454 | } |
| 4455 | |
| 4456 | static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags); |
| 4457 | |
| 4458 | static ssize_t show_filter_flags(struct device *d, |
| 4459 | struct device_attribute *attr, char *buf) |
| 4460 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4461 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4462 | |
| 4463 | return sprintf(buf, "0x%04X\n", |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4464 | le32_to_cpu(priv->active_rxon.filter_flags)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4465 | } |
| 4466 | |
| 4467 | static ssize_t store_filter_flags(struct device *d, |
| 4468 | struct device_attribute *attr, |
| 4469 | const char *buf, size_t count) |
| 4470 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4471 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4472 | u32 filter_flags = simple_strtoul(buf, NULL, 0); |
| 4473 | |
| 4474 | mutex_lock(&priv->mutex); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4475 | if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4476 | /* Cancel any currently running scans... */ |
Winkler, Tomas | af0053d | 2009-01-19 15:30:23 -0800 | [diff] [blame] | 4477 | if (iwl_scan_cancel_timeout(priv, 100)) |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 4478 | IWL_WARN(priv, "Could not cancel scan.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4479 | else { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4480 | IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4481 | "0x%04X\n", filter_flags); |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4482 | priv->staging_rxon.filter_flags = |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4483 | cpu_to_le32(filter_flags); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4484 | iwl3945_commit_rxon(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4485 | } |
| 4486 | } |
| 4487 | mutex_unlock(&priv->mutex); |
| 4488 | |
| 4489 | return count; |
| 4490 | } |
| 4491 | |
| 4492 | static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, |
| 4493 | store_filter_flags); |
| 4494 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4495 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4496 | |
| 4497 | static ssize_t show_measurement(struct device *d, |
| 4498 | struct device_attribute *attr, char *buf) |
| 4499 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4500 | struct iwl_priv *priv = dev_get_drvdata(d); |
Tomas Winkler | 600c0e1 | 2008-12-19 10:37:04 +0800 | [diff] [blame] | 4501 | struct iwl_spectrum_notification measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4502 | u32 size = sizeof(measure_report), len = 0, ofs = 0; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 4503 | u8 *data = (u8 *)&measure_report; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4504 | unsigned long flags; |
| 4505 | |
| 4506 | spin_lock_irqsave(&priv->lock, flags); |
| 4507 | if (!(priv->measurement_status & MEASUREMENT_READY)) { |
| 4508 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4509 | return 0; |
| 4510 | } |
| 4511 | memcpy(&measure_report, &priv->measure_report, size); |
| 4512 | priv->measurement_status = 0; |
| 4513 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4514 | |
| 4515 | while (size && (PAGE_SIZE - len)) { |
| 4516 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 4517 | PAGE_SIZE - len, 1); |
| 4518 | len = strlen(buf); |
| 4519 | if (PAGE_SIZE - len) |
| 4520 | buf[len++] = '\n'; |
| 4521 | |
| 4522 | ofs += 16; |
| 4523 | size -= min(size, 16U); |
| 4524 | } |
| 4525 | |
| 4526 | return len; |
| 4527 | } |
| 4528 | |
| 4529 | static ssize_t store_measurement(struct device *d, |
| 4530 | struct device_attribute *attr, |
| 4531 | const char *buf, size_t count) |
| 4532 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4533 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4534 | struct ieee80211_measurement_params params = { |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4535 | .channel = le16_to_cpu(priv->active_rxon.channel), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4536 | .start_time = cpu_to_le64(priv->last_tsf), |
| 4537 | .duration = cpu_to_le16(1), |
| 4538 | }; |
| 4539 | u8 type = IWL_MEASURE_BASIC; |
| 4540 | u8 buffer[32]; |
| 4541 | u8 channel; |
| 4542 | |
| 4543 | if (count) { |
| 4544 | char *p = buffer; |
| 4545 | strncpy(buffer, buf, min(sizeof(buffer), count)); |
| 4546 | channel = simple_strtoul(p, NULL, 0); |
| 4547 | if (channel) |
| 4548 | params.channel = channel; |
| 4549 | |
| 4550 | p = buffer; |
| 4551 | while (*p && *p != ' ') |
| 4552 | p++; |
| 4553 | if (*p) |
| 4554 | type = simple_strtoul(p + 1, NULL, 0); |
| 4555 | } |
| 4556 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4557 | IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4558 | "channel %d (for '%s')\n", type, params.channel, buf); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4559 | iwl3945_get_measurement(priv, ¶ms, type); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4560 | |
| 4561 | return count; |
| 4562 | } |
| 4563 | |
| 4564 | static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR, |
| 4565 | show_measurement, store_measurement); |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4566 | #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4567 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4568 | static ssize_t store_retry_rate(struct device *d, |
| 4569 | struct device_attribute *attr, |
| 4570 | const char *buf, size_t count) |
| 4571 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4572 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4573 | |
| 4574 | priv->retry_rate = simple_strtoul(buf, NULL, 0); |
| 4575 | if (priv->retry_rate <= 0) |
| 4576 | priv->retry_rate = 1; |
| 4577 | |
| 4578 | return count; |
| 4579 | } |
| 4580 | |
| 4581 | static ssize_t show_retry_rate(struct device *d, |
| 4582 | struct device_attribute *attr, char *buf) |
| 4583 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4584 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4585 | return sprintf(buf, "%d", priv->retry_rate); |
| 4586 | } |
| 4587 | |
| 4588 | static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate, |
| 4589 | store_retry_rate); |
| 4590 | |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 4591 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4592 | static ssize_t store_power_level(struct device *d, |
| 4593 | struct device_attribute *attr, |
| 4594 | const char *buf, size_t count) |
| 4595 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4596 | struct iwl_priv *priv = dev_get_drvdata(d); |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 4597 | int ret; |
| 4598 | unsigned long mode; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4599 | |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 4600 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4601 | mutex_lock(&priv->mutex); |
| 4602 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 4603 | if (!iwl_is_ready(priv)) { |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 4604 | ret = -EAGAIN; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4605 | goto out; |
| 4606 | } |
| 4607 | |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 4608 | ret = strict_strtoul(buf, 10, &mode); |
| 4609 | if (ret) |
| 4610 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4611 | |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 4612 | ret = iwl_power_set_user_mode(priv, mode); |
| 4613 | if (ret) { |
| 4614 | IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n"); |
| 4615 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4616 | } |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 4617 | ret = count; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4618 | |
| 4619 | out: |
| 4620 | mutex_unlock(&priv->mutex); |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 4621 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4622 | } |
| 4623 | |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 4624 | static ssize_t show_power_level(struct device *d, |
| 4625 | struct device_attribute *attr, char *buf) |
| 4626 | { |
| 4627 | struct iwl_priv *priv = dev_get_drvdata(d); |
| 4628 | int mode = priv->power_data.user_power_setting; |
| 4629 | int system = priv->power_data.system_power_setting; |
| 4630 | int level = priv->power_data.power_mode; |
| 4631 | char *p = buf; |
| 4632 | |
| 4633 | switch (system) { |
| 4634 | case IWL_POWER_SYS_AUTO: |
| 4635 | p += sprintf(p, "SYSTEM:auto"); |
| 4636 | break; |
| 4637 | case IWL_POWER_SYS_AC: |
| 4638 | p += sprintf(p, "SYSTEM:ac"); |
| 4639 | break; |
| 4640 | case IWL_POWER_SYS_BATTERY: |
| 4641 | p += sprintf(p, "SYSTEM:battery"); |
| 4642 | break; |
| 4643 | } |
| 4644 | |
| 4645 | p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ? |
| 4646 | "fixed" : "auto"); |
| 4647 | p += sprintf(p, "\tINDEX:%d", level); |
| 4648 | p += sprintf(p, "\n"); |
| 4649 | return p - buf + 1; |
| 4650 | } |
| 4651 | |
| 4652 | static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, |
| 4653 | show_power_level, store_power_level); |
| 4654 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4655 | #define MAX_WX_STRING 80 |
| 4656 | |
| 4657 | /* Values are in microsecond */ |
| 4658 | static const s32 timeout_duration[] = { |
| 4659 | 350000, |
| 4660 | 250000, |
| 4661 | 75000, |
| 4662 | 37000, |
| 4663 | 25000, |
| 4664 | }; |
| 4665 | static const s32 period_duration[] = { |
| 4666 | 400000, |
| 4667 | 700000, |
| 4668 | 1000000, |
| 4669 | 1000000, |
| 4670 | 1000000 |
| 4671 | }; |
| 4672 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4673 | static ssize_t show_channels(struct device *d, |
| 4674 | struct device_attribute *attr, char *buf) |
| 4675 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4676 | /* all this shit doesn't belong into sysfs anyway */ |
| 4677 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4678 | } |
| 4679 | |
| 4680 | static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL); |
| 4681 | |
| 4682 | static ssize_t show_statistics(struct device *d, |
| 4683 | struct device_attribute *attr, char *buf) |
| 4684 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4685 | struct iwl_priv *priv = dev_get_drvdata(d); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4686 | u32 size = sizeof(struct iwl3945_notif_statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4687 | u32 len = 0, ofs = 0; |
Abhijeet Kolekar | f2c7e52 | 2008-12-19 10:37:27 +0800 | [diff] [blame] | 4688 | u8 *data = (u8 *)&priv->statistics_39; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4689 | int rc = 0; |
| 4690 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 4691 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4692 | return -EAGAIN; |
| 4693 | |
| 4694 | mutex_lock(&priv->mutex); |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 4695 | rc = iwl_send_statistics_request(priv, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4696 | mutex_unlock(&priv->mutex); |
| 4697 | |
| 4698 | if (rc) { |
| 4699 | len = sprintf(buf, |
| 4700 | "Error sending statistics request: 0x%08X\n", rc); |
| 4701 | return len; |
| 4702 | } |
| 4703 | |
| 4704 | while (size && (PAGE_SIZE - len)) { |
| 4705 | hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len, |
| 4706 | PAGE_SIZE - len, 1); |
| 4707 | len = strlen(buf); |
| 4708 | if (PAGE_SIZE - len) |
| 4709 | buf[len++] = '\n'; |
| 4710 | |
| 4711 | ofs += 16; |
| 4712 | size -= min(size, 16U); |
| 4713 | } |
| 4714 | |
| 4715 | return len; |
| 4716 | } |
| 4717 | |
| 4718 | static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); |
| 4719 | |
| 4720 | static ssize_t show_antenna(struct device *d, |
| 4721 | struct device_attribute *attr, char *buf) |
| 4722 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4723 | struct iwl_priv *priv = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4724 | |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 4725 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4726 | return -EAGAIN; |
| 4727 | |
Samuel Ortiz | 7e4bca5 | 2009-01-23 13:45:18 -0800 | [diff] [blame] | 4728 | return sprintf(buf, "%d\n", iwl3945_mod_params.antenna); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | static ssize_t store_antenna(struct device *d, |
| 4732 | struct device_attribute *attr, |
| 4733 | const char *buf, size_t count) |
| 4734 | { |
Winkler, Tomas | 7530f85 | 2009-01-27 14:27:53 -0800 | [diff] [blame] | 4735 | struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4736 | int ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4737 | |
| 4738 | if (count == 0) |
| 4739 | return 0; |
| 4740 | |
| 4741 | if (sscanf(buf, "%1i", &ant) != 1) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4742 | IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4743 | return count; |
| 4744 | } |
| 4745 | |
| 4746 | if ((ant >= 0) && (ant <= 2)) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4747 | IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant); |
Samuel Ortiz | 7e4bca5 | 2009-01-23 13:45:18 -0800 | [diff] [blame] | 4748 | iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4749 | } else |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4750 | IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4751 | |
| 4752 | |
| 4753 | return count; |
| 4754 | } |
| 4755 | |
| 4756 | static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna); |
| 4757 | |
| 4758 | static ssize_t show_status(struct device *d, |
| 4759 | struct device_attribute *attr, char *buf) |
| 4760 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4761 | struct iwl_priv *priv = (struct iwl_priv *)d->driver_data; |
Kolekar, Abhijeet | 775a6e2 | 2008-12-19 10:37:36 +0800 | [diff] [blame] | 4762 | if (!iwl_is_alive(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4763 | return -EAGAIN; |
| 4764 | return sprintf(buf, "0x%08x\n", (int)priv->status); |
| 4765 | } |
| 4766 | |
| 4767 | static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); |
| 4768 | |
| 4769 | static ssize_t dump_error_log(struct device *d, |
| 4770 | struct device_attribute *attr, |
| 4771 | const char *buf, size_t count) |
| 4772 | { |
| 4773 | char *p = (char *)buf; |
| 4774 | |
| 4775 | if (p[0] == '1') |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4776 | iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4777 | |
| 4778 | return strnlen(buf, count); |
| 4779 | } |
| 4780 | |
| 4781 | static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log); |
| 4782 | |
| 4783 | static ssize_t dump_event_log(struct device *d, |
| 4784 | struct device_attribute *attr, |
| 4785 | const char *buf, size_t count) |
| 4786 | { |
| 4787 | char *p = (char *)buf; |
| 4788 | |
| 4789 | if (p[0] == '1') |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4790 | iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4791 | |
| 4792 | return strnlen(buf, count); |
| 4793 | } |
| 4794 | |
| 4795 | static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log); |
| 4796 | |
| 4797 | /***************************************************************************** |
| 4798 | * |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 4799 | * driver setup and tear down |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4800 | * |
| 4801 | *****************************************************************************/ |
| 4802 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4803 | static void iwl3945_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4804 | { |
Reinette Chatre | d21050c | 2009-02-13 11:51:18 -0800 | [diff] [blame] | 4805 | priv->workqueue = create_singlethread_workqueue(DRV_NAME); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4806 | |
| 4807 | init_waitqueue_head(&priv->wait_command_queue); |
| 4808 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4809 | INIT_WORK(&priv->up, iwl3945_bg_up); |
| 4810 | INIT_WORK(&priv->restart, iwl3945_bg_restart); |
| 4811 | INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish); |
Samuel Ortiz | c0af96a | 2009-01-21 18:27:54 +0100 | [diff] [blame] | 4812 | INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4813 | INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4814 | INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start); |
| 4815 | INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 4816 | INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll); |
Samuel Ortiz | 77fecfb8 | 2009-01-23 13:45:12 -0800 | [diff] [blame] | 4817 | INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed); |
| 4818 | INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan); |
| 4819 | INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan); |
| 4820 | INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4821 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4822 | iwl3945_hw_setup_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4823 | |
| 4824 | tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4825 | iwl3945_irq_tasklet, (unsigned long)priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4826 | } |
| 4827 | |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4828 | static void iwl3945_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4829 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4830 | iwl3945_hw_cancel_deferred_work(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4831 | |
Joonwoo Park | e47eb6a | 2007-11-29 10:42:49 +0900 | [diff] [blame] | 4832 | cancel_delayed_work_sync(&priv->init_alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4833 | cancel_delayed_work(&priv->scan_check); |
| 4834 | cancel_delayed_work(&priv->alive_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4835 | cancel_work_sync(&priv->beacon_update); |
| 4836 | } |
| 4837 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4838 | static struct attribute *iwl3945_sysfs_entries[] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4839 | &dev_attr_antenna.attr, |
| 4840 | &dev_attr_channels.attr, |
| 4841 | &dev_attr_dump_errors.attr, |
| 4842 | &dev_attr_dump_events.attr, |
| 4843 | &dev_attr_flags.attr, |
| 4844 | &dev_attr_filter_flags.attr, |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4845 | #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4846 | &dev_attr_measurement.attr, |
| 4847 | #endif |
| 4848 | &dev_attr_power_level.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4849 | &dev_attr_retry_rate.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4850 | &dev_attr_statistics.attr, |
| 4851 | &dev_attr_status.attr, |
| 4852 | &dev_attr_temperature.attr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4853 | &dev_attr_tx_power.attr, |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 4854 | #ifdef CONFIG_IWLWIFI_DEBUG |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4855 | &dev_attr_debug_level.attr, |
| 4856 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4857 | NULL |
| 4858 | }; |
| 4859 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4860 | static struct attribute_group iwl3945_attribute_group = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4861 | .name = NULL, /* put in device directory */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4862 | .attrs = iwl3945_sysfs_entries, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4863 | }; |
| 4864 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4865 | static struct ieee80211_ops iwl3945_hw_ops = { |
| 4866 | .tx = iwl3945_mac_tx, |
| 4867 | .start = iwl3945_mac_start, |
| 4868 | .stop = iwl3945_mac_stop, |
| 4869 | .add_interface = iwl3945_mac_add_interface, |
| 4870 | .remove_interface = iwl3945_mac_remove_interface, |
| 4871 | .config = iwl3945_mac_config, |
| 4872 | .config_interface = iwl3945_mac_config_interface, |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 4873 | .configure_filter = iwl_configure_filter, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4874 | .set_key = iwl3945_mac_set_key, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4875 | .get_tx_stats = iwl3945_mac_get_tx_stats, |
| 4876 | .conf_tx = iwl3945_mac_conf_tx, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4877 | .reset_tsf = iwl3945_mac_reset_tsf, |
Abhijeet Kolekar | cd56d33 | 2008-09-03 11:26:21 +0800 | [diff] [blame] | 4878 | .bss_info_changed = iwl3945_bss_info_changed, |
Abhijeet Kolekar | e9dde6f6 | 2009-02-18 15:54:27 -0800 | [diff] [blame] | 4879 | .hw_scan = iwl_mac_hw_scan |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4880 | }; |
| 4881 | |
Winkler, Tomas | e52119c | 2008-12-22 11:31:19 +0800 | [diff] [blame] | 4882 | static int iwl3945_init_drv(struct iwl_priv *priv) |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4883 | { |
| 4884 | int ret; |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 4885 | struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom; |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4886 | |
| 4887 | priv->retry_rate = 1; |
| 4888 | priv->ibss_beacon = NULL; |
| 4889 | |
| 4890 | spin_lock_init(&priv->lock); |
Winkler, Tomas | 3dae0c4 | 2009-01-19 15:30:30 -0800 | [diff] [blame] | 4891 | spin_lock_init(&priv->power_data.lock); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4892 | spin_lock_init(&priv->sta_lock); |
| 4893 | spin_lock_init(&priv->hcmd_lock); |
| 4894 | |
| 4895 | INIT_LIST_HEAD(&priv->free_frames); |
| 4896 | |
| 4897 | mutex_init(&priv->mutex); |
| 4898 | |
| 4899 | /* Clear the driver's (not device's) station table */ |
| 4900 | iwl3945_clear_stations_table(priv); |
| 4901 | |
| 4902 | priv->data_retry_limit = -1; |
| 4903 | priv->ieee_channels = NULL; |
| 4904 | priv->ieee_rates = NULL; |
| 4905 | priv->band = IEEE80211_BAND_2GHZ; |
| 4906 | |
| 4907 | priv->iw_mode = NL80211_IFTYPE_STATION; |
| 4908 | |
| 4909 | iwl_reset_qos(priv); |
| 4910 | |
| 4911 | priv->qos_data.qos_active = 0; |
| 4912 | priv->qos_data.qos_cap.val = 0; |
| 4913 | |
| 4914 | priv->rates_mask = IWL_RATES_MASK; |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 4915 | /* If power management is turned on, default to CAM mode */ |
| 4916 | priv->power_mode = IWL_POWER_MODE_CAM; |
Winkler, Tomas | 62ea9c5 | 2009-01-19 15:30:29 -0800 | [diff] [blame] | 4917 | priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER; |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4918 | |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 4919 | if (eeprom->version < EEPROM_3945_EEPROM_VERSION) { |
| 4920 | IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n", |
| 4921 | eeprom->version); |
| 4922 | ret = -EINVAL; |
| 4923 | goto err; |
| 4924 | } |
| 4925 | ret = iwl_init_channel_map(priv); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4926 | if (ret) { |
| 4927 | IWL_ERR(priv, "initializing regulatory failed: %d\n", ret); |
| 4928 | goto err; |
| 4929 | } |
| 4930 | |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 4931 | /* Set up txpower settings in driver for all channels */ |
| 4932 | if (iwl3945_txpower_set_from_eeprom(priv)) { |
| 4933 | ret = -EIO; |
| 4934 | goto err_free_channel_map; |
| 4935 | } |
| 4936 | |
Samuel Ortiz | 534166d | 2009-01-23 13:45:16 -0800 | [diff] [blame] | 4937 | ret = iwlcore_init_geos(priv); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4938 | if (ret) { |
| 4939 | IWL_ERR(priv, "initializing geos failed: %d\n", ret); |
| 4940 | goto err_free_channel_map; |
| 4941 | } |
Samuel Ortiz | 534166d | 2009-01-23 13:45:16 -0800 | [diff] [blame] | 4942 | iwl3945_init_hw_rates(priv, priv->ieee_rates); |
| 4943 | |
| 4944 | if (priv->bands[IEEE80211_BAND_2GHZ].n_channels) |
| 4945 | priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] = |
| 4946 | &priv->bands[IEEE80211_BAND_2GHZ]; |
| 4947 | if (priv->bands[IEEE80211_BAND_5GHZ].n_channels) |
| 4948 | priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] = |
| 4949 | &priv->bands[IEEE80211_BAND_5GHZ]; |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4950 | |
| 4951 | return 0; |
| 4952 | |
| 4953 | err_free_channel_map: |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 4954 | iwl_free_channel_map(priv); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4955 | err: |
| 4956 | return ret; |
| 4957 | } |
| 4958 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4959 | 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] | 4960 | { |
| 4961 | int err = 0; |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 4962 | struct iwl_priv *priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4963 | struct ieee80211_hw *hw; |
Kolekar, Abhijeet | c0f20d9 | 2008-12-19 10:37:19 +0800 | [diff] [blame] | 4964 | struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 4965 | struct iwl3945_eeprom *eeprom; |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 4966 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4967 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 4968 | /*********************** |
| 4969 | * 1. Allocating HW data |
| 4970 | * ********************/ |
| 4971 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4972 | /* mac80211 allocates memory for this device instance, including |
| 4973 | * space for this driver's private structure */ |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4974 | hw = iwl_alloc_all(cfg, &iwl3945_hw_ops); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4975 | if (hw == NULL) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 4976 | printk(KERN_ERR DRV_NAME "Can not allocate network device\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4977 | err = -ENOMEM; |
| 4978 | goto out; |
| 4979 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4980 | priv = hw->priv; |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4981 | SET_IEEE80211_DEV(hw, &pdev->dev); |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 4982 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 4983 | if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) || |
| 4984 | (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 4985 | IWL_ERR(priv, |
| 4986 | "invalid queues_num, should be between %d and %d\n", |
| 4987 | IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES); |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 4988 | err = -EINVAL; |
| 4989 | goto out; |
| 4990 | } |
| 4991 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 4992 | /* |
| 4993 | * Disabling hardware scan means that mac80211 will perform scans |
| 4994 | * "the hard way", rather than using device's scan. |
| 4995 | */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 4996 | if (iwl3945_mod_params.disable_hw_scan) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 4997 | IWL_DEBUG_INFO(priv, "Disabling hw_scan\n"); |
Samuel Ortiz | 40b8ec0 | 2008-12-19 10:37:08 +0800 | [diff] [blame] | 4998 | iwl3945_hw_ops.hw_scan = NULL; |
| 4999 | } |
| 5000 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 5001 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 5002 | IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n"); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 5003 | priv->cfg = cfg; |
| 5004 | priv->pci_dev = pdev; |
| 5005 | |
Samuel Ortiz | d08853a | 2009-01-23 13:45:17 -0800 | [diff] [blame] | 5006 | #ifdef CONFIG_IWLWIFI_DEBUG |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 5007 | priv->debug_level = iwl3945_mod_params.debug; |
| 5008 | atomic_set(&priv->restrict_refcnt, 0); |
| 5009 | #endif |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5010 | hw->rate_control_algorithm = "iwl-3945-rs"; |
| 5011 | hw->sta_data_size = sizeof(struct iwl3945_sta_priv); |
| 5012 | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 5013 | /* Tell mac80211 our characteristics */ |
Johannes Berg | 605a0bd | 2008-07-15 10:10:01 +0200 | [diff] [blame] | 5014 | hw->flags = IEEE80211_HW_SIGNAL_DBM | |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 5015 | IEEE80211_HW_NOISE_DBM; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5016 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 5017 | hw->wiphy->interface_modes = |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 5018 | BIT(NL80211_IFTYPE_STATION) | |
| 5019 | BIT(NL80211_IFTYPE_ADHOC); |
| 5020 | |
Luis R. Rodriguez | 2a44f91 | 2009-01-22 15:05:49 -0800 | [diff] [blame] | 5021 | hw->wiphy->custom_regulatory = true; |
Luis R. Rodriguez | ea4a82dc | 2008-11-12 14:22:04 -0800 | [diff] [blame] | 5022 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 5023 | hw->wiphy->max_scan_ssids = 1; |
| 5024 | |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5025 | /* 4 EDCA QOS priorities */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5026 | hw->queues = 4; |
| 5027 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5028 | /*************************** |
| 5029 | * 2. Initializing PCI bus |
| 5030 | * *************************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5031 | if (pci_enable_device(pdev)) { |
| 5032 | err = -ENODEV; |
| 5033 | goto out_ieee80211_free_hw; |
| 5034 | } |
| 5035 | |
| 5036 | pci_set_master(pdev); |
| 5037 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5038 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 5039 | if (!err) |
| 5040 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 5041 | if (err) { |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 5042 | IWL_WARN(priv, "No suitable DMA available.\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5043 | goto out_pci_disable_device; |
| 5044 | } |
| 5045 | |
| 5046 | pci_set_drvdata(pdev, priv); |
| 5047 | err = pci_request_regions(pdev, DRV_NAME); |
| 5048 | if (err) |
| 5049 | goto out_pci_disable_device; |
Cahill, Ben M | 6440adb | 2007-11-29 11:09:55 +0800 | [diff] [blame] | 5050 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5051 | /*********************** |
| 5052 | * 3. Read REV Register |
| 5053 | * ********************/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5054 | priv->hw_base = pci_iomap(pdev, 0, 0); |
| 5055 | if (!priv->hw_base) { |
| 5056 | err = -ENODEV; |
| 5057 | goto out_pci_release_regions; |
| 5058 | } |
| 5059 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 5060 | IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5061 | (unsigned long long) pci_resource_len(pdev, 0)); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 5062 | IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5063 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5064 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 5065 | * PCI Tx retries from interfering with C3 CPU state */ |
| 5066 | pci_write_config_byte(pdev, 0x41, 0x00); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5067 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 5068 | /* amp init */ |
| 5069 | err = priv->cfg->ops->lib->apm_ops.init(priv); |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 5070 | if (err < 0) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 5071 | IWL_DEBUG_INFO(priv, "Failed to init APMG\n"); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 5072 | goto out_iounmap; |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 5073 | } |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5074 | |
| 5075 | /*********************** |
| 5076 | * 4. Read EEPROM |
| 5077 | * ********************/ |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 5078 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5079 | /* Read the EEPROM */ |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 5080 | err = iwl_eeprom_init(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5081 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5082 | IWL_ERR(priv, "Unable to init EEPROM\n"); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5083 | goto out_remove_sysfs; |
| 5084 | } |
| 5085 | /* MAC Address location in EEPROM same for 3945/4965 */ |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 5086 | eeprom = (struct iwl3945_eeprom *)priv->eeprom; |
| 5087 | memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 5088 | IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr); |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5089 | SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr); |
| 5090 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5091 | /*********************** |
| 5092 | * 5. Setup HW Constants |
| 5093 | * ********************/ |
| 5094 | /* Device-specific setup */ |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 5095 | if (iwl3945_hw_set_hw_params(priv)) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5096 | IWL_ERR(priv, "failed to set hw settings\n"); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5097 | goto out_iounmap; |
| 5098 | } |
| 5099 | |
| 5100 | /*********************** |
| 5101 | * 6. Setup priv |
| 5102 | * ********************/ |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5103 | |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 5104 | err = iwl3945_init_drv(priv); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5105 | if (err) { |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 5106 | IWL_ERR(priv, "initializing driver failed\n"); |
| 5107 | goto out_free_geos; |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5108 | } |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5109 | |
Tomas Winkler | 978785a | 2008-12-19 10:37:31 +0800 | [diff] [blame] | 5110 | IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n", |
| 5111 | priv->cfg->name); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5112 | |
| 5113 | /*********************************** |
| 5114 | * 7. Initialize Module Parameters |
| 5115 | * **********************************/ |
| 5116 | |
| 5117 | /* Initialize module parameter values here */ |
| 5118 | /* Disable radio (SW RF KILL) via parameter when loading driver */ |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 5119 | if (iwl3945_mod_params.disable) { |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5120 | set_bit(STATUS_RF_KILL_SW, &priv->status); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 5121 | IWL_DEBUG_INFO(priv, "Radio disabled.\n"); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5122 | } |
| 5123 | |
| 5124 | |
| 5125 | /*********************** |
| 5126 | * 8. Setup Services |
| 5127 | * ********************/ |
| 5128 | |
| 5129 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | ed3b932 | 2009-02-18 15:54:30 -0800 | [diff] [blame] | 5130 | iwl_disable_interrupts(priv); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5131 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5132 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5133 | pci_enable_msi(priv->pci_dev); |
| 5134 | |
Abhijeet Kolekar | f17d08a | 2009-02-18 15:54:31 -0800 | [diff] [blame] | 5135 | err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED, |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5136 | DRV_NAME, priv); |
| 5137 | if (err) { |
| 5138 | IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq); |
| 5139 | goto out_disable_msi; |
| 5140 | } |
| 5141 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5142 | err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
| 5143 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5144 | IWL_ERR(priv, "failed to create sysfs device attributes\n"); |
Kolekar, Abhijeet | 90a30a0 | 2008-12-19 10:37:40 +0800 | [diff] [blame] | 5145 | goto out_release_irq; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5146 | } |
| 5147 | |
Samuel Ortiz | 8ccde88 | 2009-01-27 14:27:52 -0800 | [diff] [blame] | 5148 | iwl_set_rxon_channel(priv, |
| 5149 | &priv->bands[IEEE80211_BAND_2GHZ].channels[5]); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5150 | iwl3945_setup_deferred_work(priv); |
| 5151 | iwl3945_setup_rx_handlers(priv); |
| 5152 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5153 | /********************************* |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5154 | * 9. Setup and Register mac80211 |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5155 | * *******************************/ |
| 5156 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5157 | err = ieee80211_register_hw(priv->hw); |
| 5158 | if (err) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5159 | IWL_ERR(priv, "Failed to register network device: %d\n", err); |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5160 | goto out_remove_sysfs; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5161 | } |
| 5162 | |
Zhu Yi | 5a66926 | 2008-01-14 17:46:18 -0800 | [diff] [blame] | 5163 | priv->hw->conf.beacon_int = 100; |
| 5164 | priv->mac80211_registered = 1; |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5165 | |
Samuel Ortiz | c0af96a | 2009-01-21 18:27:54 +0100 | [diff] [blame] | 5166 | err = iwl_rfkill_init(priv); |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5167 | if (err) |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 5168 | IWL_ERR(priv, "Unable to initialize RFKILL system. " |
Abhijeet Kolekar | ebef200 | 2008-06-30 17:23:18 +0800 | [diff] [blame] | 5169 | "Ignoring error: %d\n", err); |
| 5170 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5171 | /* Start monitoring the killswitch */ |
| 5172 | queue_delayed_work(priv->workqueue, &priv->rfkill_poll, |
| 5173 | 2 * HZ); |
| 5174 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5175 | return 0; |
| 5176 | |
Kolekar, Abhijeet | cee53dd | 2008-11-12 13:14:04 -0800 | [diff] [blame] | 5177 | out_remove_sysfs: |
| 5178 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Reinette Chatre | 849e0dc | 2008-01-23 10:15:18 -0800 | [diff] [blame] | 5179 | out_free_geos: |
Samuel Ortiz | 534166d | 2009-01-23 13:45:16 -0800 | [diff] [blame] | 5180 | iwlcore_free_geos(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5181 | |
| 5182 | out_release_irq: |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5183 | free_irq(priv->pci_dev->irq, priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5184 | destroy_workqueue(priv->workqueue); |
| 5185 | priv->workqueue = NULL; |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 5186 | iwl3945_unset_hw_params(priv); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5187 | out_disable_msi: |
| 5188 | pci_disable_msi(priv->pci_dev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5189 | out_iounmap: |
| 5190 | pci_iounmap(pdev, priv->hw_base); |
| 5191 | out_pci_release_regions: |
| 5192 | pci_release_regions(pdev); |
| 5193 | out_pci_disable_device: |
| 5194 | pci_disable_device(pdev); |
| 5195 | pci_set_drvdata(pdev, NULL); |
| 5196 | out_ieee80211_free_hw: |
| 5197 | ieee80211_free_hw(priv->hw); |
| 5198 | out: |
| 5199 | return err; |
| 5200 | } |
| 5201 | |
Reinette Chatre | c83dbf6 | 2008-03-21 13:53:41 -0700 | [diff] [blame] | 5202 | static void __devexit iwl3945_pci_remove(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5203 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5204 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5205 | unsigned long flags; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5206 | |
| 5207 | if (!priv) |
| 5208 | return; |
| 5209 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 5210 | IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5211 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5212 | set_bit(STATUS_EXIT_PENDING, &priv->status); |
Zhu Yi | b24d22b | 2007-12-19 13:59:52 +0800 | [diff] [blame] | 5213 | |
Kolekar, Abhijeet | d552bfb | 2008-12-19 10:37:41 +0800 | [diff] [blame] | 5214 | if (priv->mac80211_registered) { |
| 5215 | ieee80211_unregister_hw(priv->hw); |
| 5216 | priv->mac80211_registered = 0; |
| 5217 | } else { |
| 5218 | iwl3945_down(priv); |
| 5219 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5220 | |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5221 | /* make sure we flush any pending irq or |
| 5222 | * tasklet for the driver |
| 5223 | */ |
| 5224 | spin_lock_irqsave(&priv->lock, flags); |
Abhijeet Kolekar | ed3b932 | 2009-02-18 15:54:30 -0800 | [diff] [blame] | 5225 | iwl_disable_interrupts(priv); |
Mohamed Abbas | 0359fac | 2008-03-28 16:21:08 -0700 | [diff] [blame] | 5226 | spin_unlock_irqrestore(&priv->lock, flags); |
| 5227 | |
| 5228 | iwl_synchronize_irq(priv); |
| 5229 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5230 | sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5231 | |
Samuel Ortiz | c0af96a | 2009-01-21 18:27:54 +0100 | [diff] [blame] | 5232 | iwl_rfkill_unregister(priv); |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5233 | cancel_delayed_work(&priv->rfkill_poll); |
| 5234 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5235 | iwl3945_dealloc_ucode_pci(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5236 | |
| 5237 | if (priv->rxq.bd) |
Winkler, Tomas | 51af3d3 | 2008-12-22 11:31:23 +0800 | [diff] [blame] | 5238 | iwl_rx_queue_free(priv, &priv->rxq); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5239 | iwl3945_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5240 | |
Abhijeet Kolekar | 3832ec9 | 2008-12-19 10:37:26 +0800 | [diff] [blame] | 5241 | iwl3945_unset_hw_params(priv); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5242 | iwl3945_clear_stations_table(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5243 | |
Mohamed Abbas | 6ef89d0 | 2007-10-25 17:15:47 +0800 | [diff] [blame] | 5244 | /*netif_stop_queue(dev); */ |
| 5245 | flush_workqueue(priv->workqueue); |
| 5246 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5247 | /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5248 | * priv->workqueue... so we can't take down the workqueue |
| 5249 | * until now... */ |
| 5250 | destroy_workqueue(priv->workqueue); |
| 5251 | priv->workqueue = NULL; |
| 5252 | |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5253 | free_irq(pdev->irq, priv); |
| 5254 | pci_disable_msi(pdev); |
| 5255 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5256 | pci_iounmap(pdev, priv->hw_base); |
| 5257 | pci_release_regions(pdev); |
| 5258 | pci_disable_device(pdev); |
| 5259 | pci_set_drvdata(pdev, NULL); |
| 5260 | |
Samuel Ortiz | e614891 | 2009-01-23 13:45:15 -0800 | [diff] [blame] | 5261 | iwl_free_channel_map(priv); |
Samuel Ortiz | 534166d | 2009-01-23 13:45:16 -0800 | [diff] [blame] | 5262 | iwlcore_free_geos(priv); |
Winkler, Tomas | 805cee5 | 2009-01-19 15:30:28 -0800 | [diff] [blame] | 5263 | kfree(priv->scan); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5264 | if (priv->ibss_beacon) |
| 5265 | dev_kfree_skb(priv->ibss_beacon); |
| 5266 | |
| 5267 | ieee80211_free_hw(priv->hw); |
| 5268 | } |
| 5269 | |
| 5270 | #ifdef CONFIG_PM |
| 5271 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5272 | static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5273 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5274 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5275 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5276 | if (priv->is_open) { |
| 5277 | set_bit(STATUS_IN_SUSPEND, &priv->status); |
| 5278 | iwl3945_mac_stop(priv->hw); |
| 5279 | priv->is_open = 1; |
| 5280 | } |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5281 | pci_save_state(pdev); |
| 5282 | pci_disable_device(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5283 | pci_set_power_state(pdev, PCI_D3hot); |
| 5284 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5285 | return 0; |
| 5286 | } |
| 5287 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5288 | static int iwl3945_pci_resume(struct pci_dev *pdev) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5289 | { |
Abhijeet Kolekar | 4a8a432 | 2008-12-19 10:37:28 +0800 | [diff] [blame] | 5290 | struct iwl_priv *priv = pci_get_drvdata(pdev); |
Winkler, Tomas | 450154e | 2009-01-27 14:27:55 -0800 | [diff] [blame] | 5291 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5292 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5293 | pci_set_power_state(pdev, PCI_D0); |
Winkler, Tomas | 450154e | 2009-01-27 14:27:55 -0800 | [diff] [blame] | 5294 | ret = pci_enable_device(pdev); |
| 5295 | if (ret) |
| 5296 | return ret; |
Helmut Schaa | 2663516 | 2009-01-15 09:38:44 +0100 | [diff] [blame] | 5297 | pci_restore_state(pdev); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5298 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5299 | if (priv->is_open) |
| 5300 | iwl3945_mac_start(priv->hw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5301 | |
Zhu Yi | e655b9f | 2008-01-24 02:19:38 -0800 | [diff] [blame] | 5302 | clear_bit(STATUS_IN_SUSPEND, &priv->status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5303 | return 0; |
| 5304 | } |
| 5305 | |
| 5306 | #endif /* CONFIG_PM */ |
| 5307 | |
| 5308 | /***************************************************************************** |
| 5309 | * |
| 5310 | * driver and module entry point |
| 5311 | * |
| 5312 | *****************************************************************************/ |
| 5313 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5314 | static struct pci_driver iwl3945_driver = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5315 | .name = DRV_NAME, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5316 | .id_table = iwl3945_hw_card_ids, |
| 5317 | .probe = iwl3945_pci_probe, |
| 5318 | .remove = __devexit_p(iwl3945_pci_remove), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5319 | #ifdef CONFIG_PM |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5320 | .suspend = iwl3945_pci_suspend, |
| 5321 | .resume = iwl3945_pci_resume, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5322 | #endif |
| 5323 | }; |
| 5324 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5325 | static int __init iwl3945_init(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5326 | { |
| 5327 | |
| 5328 | int ret; |
| 5329 | printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n"); |
| 5330 | printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5331 | |
| 5332 | ret = iwl3945_rate_control_register(); |
| 5333 | if (ret) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 5334 | printk(KERN_ERR DRV_NAME |
| 5335 | "Unable to register rate control algorithm: %d\n", ret); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5336 | return ret; |
| 5337 | } |
| 5338 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5339 | ret = pci_register_driver(&iwl3945_driver); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5340 | if (ret) { |
Samuel Ortiz | a3139c5 | 2008-12-19 10:37:09 +0800 | [diff] [blame] | 5341 | printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n"); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5342 | goto error_register; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5343 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5344 | |
| 5345 | return ret; |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5346 | |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5347 | error_register: |
| 5348 | iwl3945_rate_control_unregister(); |
| 5349 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5350 | } |
| 5351 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5352 | static void __exit iwl3945_exit(void) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5353 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5354 | pci_unregister_driver(&iwl3945_driver); |
Reinette Chatre | 897e1cf | 2008-03-28 16:21:09 -0700 | [diff] [blame] | 5355 | iwl3945_rate_control_unregister(); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5356 | } |
| 5357 | |
Reinette Chatre | a0987a8 | 2008-12-02 12:14:06 -0800 | [diff] [blame] | 5358 | MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX)); |
Zhu Yi | 25cb6ca | 2008-09-11 11:45:22 +0800 | [diff] [blame] | 5359 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 5360 | module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5361 | MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 5362 | module_param_named(disable, iwl3945_mod_params.disable, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5363 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Samuel Ortiz | 9c74d9f | 2009-01-08 10:19:59 -0800 | [diff] [blame] | 5364 | module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444); |
| 5365 | MODULE_PARM_DESC(swcrypto, |
| 5366 | "using software crypto (default 1 [software])\n"); |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 5367 | module_param_named(debug, iwl3945_mod_params.debug, uint, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5368 | MODULE_PARM_DESC(debug, "debug output mask"); |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 5369 | module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5370 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 5371 | |
Kolekar, Abhijeet | df878d8 | 2008-12-19 10:37:35 +0800 | [diff] [blame] | 5372 | module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 5373 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 5374 | |
Samuel Ortiz | af48d04 | 2009-01-23 13:45:19 -0800 | [diff] [blame] | 5375 | module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444); |
| 5376 | MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error"); |
| 5377 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 5378 | module_exit(iwl3945_exit); |
| 5379 | module_init(iwl3945_init); |