Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | eb7ae89 | 2008-03-11 16:17:17 -0700 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * James P. Ketrenos <ipw2100-admin@linux.intel.com> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | *****************************************************************************/ |
| 26 | |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/version.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/pci.h> |
| 32 | #include <linux/dma-mapping.h> |
| 33 | #include <linux/delay.h> |
| 34 | #include <linux/skbuff.h> |
| 35 | #include <linux/netdevice.h> |
| 36 | #include <linux/wireless.h> |
| 37 | #include <net/mac80211.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 38 | #include <linux/etherdevice.h> |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 39 | #include <asm/unaligned.h> |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 40 | |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 41 | #include "iwl-eeprom.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 42 | #include "iwl-4965.h" |
Tomas Winkler | fee1247 | 2008-04-03 16:05:21 -0700 | [diff] [blame] | 43 | #include "iwl-core.h" |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 44 | #include "iwl-io.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 45 | #include "iwl-helpers.h" |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 46 | #include "iwl-calib.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 47 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 48 | /* module parameters */ |
| 49 | static struct iwl_mod_params iwl4965_mod_params = { |
Ron Rindjunsky | dfe7d45 | 2008-04-15 16:01:45 -0700 | [diff] [blame] | 50 | .num_of_queues = IWL4965_MAX_NUM_QUEUES, |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 51 | .enable_qos = 1, |
| 52 | .amsdu_size_8K = 1, |
| 53 | /* the rest are 0 by default */ |
| 54 | }; |
| 55 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 56 | static void iwl4965_hw_card_show_info(struct iwl_priv *priv); |
Christoph Hellwig | 416e143 | 2007-10-25 17:15:49 +0800 | [diff] [blame] | 57 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 58 | #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \ |
| 59 | [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \ |
| 60 | IWL_RATE_SISO_##s##M_PLCP, \ |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 61 | IWL_RATE_MIMO2_##s##M_PLCP,\ |
| 62 | IWL_RATE_MIMO3_##s##M_PLCP,\ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 63 | IWL_RATE_##r##M_IEEE, \ |
| 64 | IWL_RATE_##ip##M_INDEX, \ |
| 65 | IWL_RATE_##in##M_INDEX, \ |
| 66 | IWL_RATE_##rp##M_INDEX, \ |
| 67 | IWL_RATE_##rn##M_INDEX, \ |
| 68 | IWL_RATE_##pp##M_INDEX, \ |
| 69 | IWL_RATE_##np##M_INDEX } |
| 70 | |
| 71 | /* |
| 72 | * Parameter order: |
| 73 | * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate |
| 74 | * |
| 75 | * If there isn't a valid next or previous rate then INV is used which |
| 76 | * maps to IWL_RATE_INVALID |
| 77 | * |
| 78 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 79 | const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT] = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 80 | IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */ |
| 81 | IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */ |
| 82 | IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */ |
| 83 | IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */ |
| 84 | IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */ |
| 85 | IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */ |
| 86 | IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */ |
| 87 | IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */ |
| 88 | IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */ |
| 89 | IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */ |
| 90 | IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */ |
| 91 | IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */ |
| 92 | IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */ |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 93 | /* FIXME:RS: ^^ should be INV (legacy) */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 96 | #ifdef CONFIG_IWL4965_HT |
| 97 | |
| 98 | static const u16 default_tid_to_tx_fifo[] = { |
| 99 | IWL_TX_FIFO_AC1, |
| 100 | IWL_TX_FIFO_AC0, |
| 101 | IWL_TX_FIFO_AC0, |
| 102 | IWL_TX_FIFO_AC1, |
| 103 | IWL_TX_FIFO_AC2, |
| 104 | IWL_TX_FIFO_AC2, |
| 105 | IWL_TX_FIFO_AC3, |
| 106 | IWL_TX_FIFO_AC3, |
| 107 | IWL_TX_FIFO_NONE, |
| 108 | IWL_TX_FIFO_NONE, |
| 109 | IWL_TX_FIFO_NONE, |
| 110 | IWL_TX_FIFO_NONE, |
| 111 | IWL_TX_FIFO_NONE, |
| 112 | IWL_TX_FIFO_NONE, |
| 113 | IWL_TX_FIFO_NONE, |
| 114 | IWL_TX_FIFO_NONE, |
| 115 | IWL_TX_FIFO_AC3 |
| 116 | }; |
| 117 | |
| 118 | #endif /*CONFIG_IWL4965_HT */ |
| 119 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 120 | /* check contents of special bootstrap uCode SRAM */ |
| 121 | static int iwl4965_verify_bsm(struct iwl_priv *priv) |
| 122 | { |
| 123 | __le32 *image = priv->ucode_boot.v_addr; |
| 124 | u32 len = priv->ucode_boot.len; |
| 125 | u32 reg; |
| 126 | u32 val; |
| 127 | |
| 128 | IWL_DEBUG_INFO("Begin verify bsm\n"); |
| 129 | |
| 130 | /* verify BSM SRAM contents */ |
| 131 | val = iwl_read_prph(priv, BSM_WR_DWCOUNT_REG); |
| 132 | for (reg = BSM_SRAM_LOWER_BOUND; |
| 133 | reg < BSM_SRAM_LOWER_BOUND + len; |
| 134 | reg += sizeof(u32), image++) { |
| 135 | val = iwl_read_prph(priv, reg); |
| 136 | if (val != le32_to_cpu(*image)) { |
| 137 | IWL_ERROR("BSM uCode verification failed at " |
| 138 | "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", |
| 139 | BSM_SRAM_LOWER_BOUND, |
| 140 | reg - BSM_SRAM_LOWER_BOUND, len, |
| 141 | val, le32_to_cpu(*image)); |
| 142 | return -EIO; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n"); |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * iwl4965_load_bsm - Load bootstrap instructions |
| 153 | * |
| 154 | * BSM operation: |
| 155 | * |
| 156 | * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program |
| 157 | * in special SRAM that does not power down during RFKILL. When powering back |
| 158 | * up after power-saving sleeps (or during initial uCode load), the BSM loads |
| 159 | * the bootstrap program into the on-board processor, and starts it. |
| 160 | * |
| 161 | * The bootstrap program loads (via DMA) instructions and data for a new |
| 162 | * program from host DRAM locations indicated by the host driver in the |
| 163 | * BSM_DRAM_* registers. Once the new program is loaded, it starts |
| 164 | * automatically. |
| 165 | * |
| 166 | * When initializing the NIC, the host driver points the BSM to the |
| 167 | * "initialize" uCode image. This uCode sets up some internal data, then |
| 168 | * notifies host via "initialize alive" that it is complete. |
| 169 | * |
| 170 | * The host then replaces the BSM_DRAM_* pointer values to point to the |
| 171 | * normal runtime uCode instructions and a backup uCode data cache buffer |
| 172 | * (filled initially with starting data values for the on-board processor), |
| 173 | * then triggers the "initialize" uCode to load and launch the runtime uCode, |
| 174 | * which begins normal operation. |
| 175 | * |
| 176 | * When doing a power-save shutdown, runtime uCode saves data SRAM into |
| 177 | * the backup data cache in DRAM before SRAM is powered down. |
| 178 | * |
| 179 | * When powering back up, the BSM loads the bootstrap program. This reloads |
| 180 | * the runtime uCode instructions and the backup data cache into SRAM, |
| 181 | * and re-launches the runtime uCode from where it left off. |
| 182 | */ |
| 183 | static int iwl4965_load_bsm(struct iwl_priv *priv) |
| 184 | { |
| 185 | __le32 *image = priv->ucode_boot.v_addr; |
| 186 | u32 len = priv->ucode_boot.len; |
| 187 | dma_addr_t pinst; |
| 188 | dma_addr_t pdata; |
| 189 | u32 inst_len; |
| 190 | u32 data_len; |
| 191 | int i; |
| 192 | u32 done; |
| 193 | u32 reg_offset; |
| 194 | int ret; |
| 195 | |
| 196 | IWL_DEBUG_INFO("Begin load bsm\n"); |
| 197 | |
| 198 | /* make sure bootstrap program is no larger than BSM's SRAM size */ |
| 199 | if (len > IWL_MAX_BSM_SIZE) |
| 200 | return -EINVAL; |
| 201 | |
| 202 | /* Tell bootstrap uCode where to find the "Initialize" uCode |
| 203 | * in host DRAM ... host DRAM physical address bits 35:4 for 4965. |
| 204 | * NOTE: iwl4965_initialize_alive_start() will replace these values, |
| 205 | * after the "initialize" uCode has run, to point to |
| 206 | * runtime/protocol instructions and backup data cache. */ |
| 207 | pinst = priv->ucode_init.p_addr >> 4; |
| 208 | pdata = priv->ucode_init_data.p_addr >> 4; |
| 209 | inst_len = priv->ucode_init.len; |
| 210 | data_len = priv->ucode_init_data.len; |
| 211 | |
| 212 | ret = iwl_grab_nic_access(priv); |
| 213 | if (ret) |
| 214 | return ret; |
| 215 | |
| 216 | iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 217 | iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 218 | iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); |
| 219 | iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); |
| 220 | |
| 221 | /* Fill BSM memory with bootstrap instructions */ |
| 222 | for (reg_offset = BSM_SRAM_LOWER_BOUND; |
| 223 | reg_offset < BSM_SRAM_LOWER_BOUND + len; |
| 224 | reg_offset += sizeof(u32), image++) |
| 225 | _iwl_write_prph(priv, reg_offset, le32_to_cpu(*image)); |
| 226 | |
| 227 | ret = iwl4965_verify_bsm(priv); |
| 228 | if (ret) { |
| 229 | iwl_release_nic_access(priv); |
| 230 | return ret; |
| 231 | } |
| 232 | |
| 233 | /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ |
| 234 | iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0); |
| 235 | iwl_write_prph(priv, BSM_WR_MEM_DST_REG, RTC_INST_LOWER_BOUND); |
| 236 | iwl_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); |
| 237 | |
| 238 | /* Load bootstrap code into instruction SRAM now, |
| 239 | * to prepare to load "initialize" uCode */ |
| 240 | iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START); |
| 241 | |
| 242 | /* Wait for load of bootstrap uCode to finish */ |
| 243 | for (i = 0; i < 100; i++) { |
| 244 | done = iwl_read_prph(priv, BSM_WR_CTRL_REG); |
| 245 | if (!(done & BSM_WR_CTRL_REG_BIT_START)) |
| 246 | break; |
| 247 | udelay(10); |
| 248 | } |
| 249 | if (i < 100) |
| 250 | IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i); |
| 251 | else { |
| 252 | IWL_ERROR("BSM write did not complete!\n"); |
| 253 | return -EIO; |
| 254 | } |
| 255 | |
| 256 | /* Enable future boot loads whenever power management unit triggers it |
| 257 | * (e.g. when powering back up after power-save shutdown) */ |
| 258 | iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN); |
| 259 | |
| 260 | iwl_release_nic_access(priv); |
| 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 265 | static int iwl4965_init_drv(struct iwl_priv *priv) |
| 266 | { |
| 267 | int ret; |
| 268 | int i; |
| 269 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 270 | priv->retry_rate = 1; |
| 271 | priv->ibss_beacon = NULL; |
| 272 | |
| 273 | spin_lock_init(&priv->lock); |
| 274 | spin_lock_init(&priv->power_data.lock); |
| 275 | spin_lock_init(&priv->sta_lock); |
| 276 | spin_lock_init(&priv->hcmd_lock); |
| 277 | spin_lock_init(&priv->lq_mngr.lock); |
| 278 | |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 279 | priv->shared_virt = pci_alloc_consistent(priv->pci_dev, |
| 280 | sizeof(struct iwl4965_shared), |
| 281 | &priv->shared_phys); |
| 282 | |
| 283 | if (!priv->shared_virt) { |
| 284 | ret = -ENOMEM; |
| 285 | goto err; |
| 286 | } |
| 287 | |
| 288 | memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared)); |
| 289 | |
| 290 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 291 | for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++) |
| 292 | INIT_LIST_HEAD(&priv->ibss_mac_hash[i]); |
| 293 | |
| 294 | INIT_LIST_HEAD(&priv->free_frames); |
| 295 | |
| 296 | mutex_init(&priv->mutex); |
| 297 | |
| 298 | /* Clear the driver's (not device's) station table */ |
| 299 | iwlcore_clear_stations_table(priv); |
| 300 | |
| 301 | priv->data_retry_limit = -1; |
| 302 | priv->ieee_channels = NULL; |
| 303 | priv->ieee_rates = NULL; |
| 304 | priv->band = IEEE80211_BAND_2GHZ; |
| 305 | |
| 306 | priv->iw_mode = IEEE80211_IF_TYPE_STA; |
| 307 | |
| 308 | priv->use_ant_b_for_management_frame = 1; /* start with ant B */ |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 309 | priv->ps_mode = IWL_MIMO_PS_NONE; |
| 310 | |
| 311 | /* Choose which receivers/antennas to use */ |
| 312 | iwl4965_set_rxon_chain(priv); |
| 313 | |
| 314 | iwlcore_reset_qos(priv); |
| 315 | |
| 316 | priv->qos_data.qos_active = 0; |
| 317 | priv->qos_data.qos_cap.val = 0; |
| 318 | |
| 319 | iwlcore_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6); |
| 320 | |
| 321 | priv->rates_mask = IWL_RATES_MASK; |
| 322 | /* If power management is turned on, default to AC mode */ |
| 323 | priv->power_mode = IWL_POWER_AC; |
| 324 | priv->user_txpower_limit = IWL_DEFAULT_TX_POWER; |
| 325 | |
| 326 | ret = iwl_init_channel_map(priv); |
| 327 | if (ret) { |
| 328 | IWL_ERROR("initializing regulatory failed: %d\n", ret); |
| 329 | goto err; |
| 330 | } |
| 331 | |
| 332 | ret = iwl4965_init_geos(priv); |
| 333 | if (ret) { |
| 334 | IWL_ERROR("initializing geos failed: %d\n", ret); |
| 335 | goto err_free_channel_map; |
| 336 | } |
| 337 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 338 | ret = ieee80211_register_hw(priv->hw); |
| 339 | if (ret) { |
| 340 | IWL_ERROR("Failed to register network device (error %d)\n", |
| 341 | ret); |
| 342 | goto err_free_geos; |
| 343 | } |
| 344 | |
| 345 | priv->hw->conf.beacon_int = 100; |
| 346 | priv->mac80211_registered = 1; |
| 347 | |
| 348 | return 0; |
| 349 | |
| 350 | err_free_geos: |
| 351 | iwl4965_free_geos(priv); |
| 352 | err_free_channel_map: |
| 353 | iwl_free_channel_map(priv); |
| 354 | err: |
| 355 | return ret; |
| 356 | } |
| 357 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 358 | static int is_fat_channel(__le32 rxon_flags) |
| 359 | { |
| 360 | return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) || |
| 361 | (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK); |
| 362 | } |
| 363 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 364 | #ifdef CONFIG_IWL4965_HT |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 365 | static u8 is_single_rx_stream(struct iwl_priv *priv) |
| 366 | { |
| 367 | return !priv->current_ht_config.is_ht || |
| 368 | ((priv->current_ht_config.supp_mcs_set[1] == 0) && |
| 369 | (priv->current_ht_config.supp_mcs_set[2] == 0)) || |
| 370 | priv->ps_mode == IWL_MIMO_PS_STATIC; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 371 | } |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 372 | #else |
| 373 | static inline u8 is_single_rx_stream(struct iwl_priv *priv) |
| 374 | { |
| 375 | return 1; |
| 376 | } |
| 377 | #endif /*CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 378 | |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 379 | int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags) |
| 380 | { |
| 381 | int idx = 0; |
| 382 | |
| 383 | /* 4965 HT rate format */ |
| 384 | if (rate_n_flags & RATE_MCS_HT_MSK) { |
| 385 | idx = (rate_n_flags & 0xff); |
| 386 | |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 387 | if (idx >= IWL_RATE_MIMO2_6M_PLCP) |
| 388 | idx = idx - IWL_RATE_MIMO2_6M_PLCP; |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 389 | |
| 390 | idx += IWL_FIRST_OFDM_RATE; |
| 391 | /* skip 9M not supported in ht*/ |
| 392 | if (idx >= IWL_RATE_9M_INDEX) |
| 393 | idx += 1; |
| 394 | if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE)) |
| 395 | return idx; |
| 396 | |
| 397 | /* 4965 legacy rate format, search for match in table */ |
| 398 | } else { |
| 399 | for (idx = 0; idx < ARRAY_SIZE(iwl4965_rates); idx++) |
| 400 | if (iwl4965_rates[idx].plcp == (rate_n_flags & 0xFF)) |
| 401 | return idx; |
| 402 | } |
| 403 | |
| 404 | return -1; |
| 405 | } |
| 406 | |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 407 | /** |
| 408 | * translate ucode response to mac80211 tx status control values |
| 409 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 410 | void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags, |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 411 | struct ieee80211_tx_control *control) |
| 412 | { |
| 413 | int rate_index; |
| 414 | |
| 415 | control->antenna_sel_tx = |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 416 | ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS); |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 417 | if (rate_n_flags & RATE_MCS_HT_MSK) |
| 418 | control->flags |= IEEE80211_TXCTL_OFDM_HT; |
| 419 | if (rate_n_flags & RATE_MCS_GF_MSK) |
| 420 | control->flags |= IEEE80211_TXCTL_GREEN_FIELD; |
| 421 | if (rate_n_flags & RATE_MCS_FAT_MSK) |
| 422 | control->flags |= IEEE80211_TXCTL_40_MHZ_WIDTH; |
| 423 | if (rate_n_flags & RATE_MCS_DUP_MSK) |
| 424 | control->flags |= IEEE80211_TXCTL_DUP_DATA; |
| 425 | if (rate_n_flags & RATE_MCS_SGI_MSK) |
| 426 | control->flags |= IEEE80211_TXCTL_SHORT_GI; |
| 427 | /* since iwl4965_hwrate_to_plcp_idx is band indifferent, we always use |
| 428 | * IEEE80211_BAND_2GHZ band as it contains all the rates */ |
| 429 | rate_index = iwl4965_hwrate_to_plcp_idx(rate_n_flags); |
| 430 | if (rate_index == -1) |
| 431 | control->tx_rate = NULL; |
| 432 | else |
| 433 | control->tx_rate = |
| 434 | &priv->bands[IEEE80211_BAND_2GHZ].bitrates[rate_index]; |
| 435 | } |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 436 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 437 | /* |
| 438 | * Determine how many receiver/antenna chains to use. |
| 439 | * More provides better reception via diversity. Fewer saves power. |
| 440 | * MIMO (dual stream) requires at least 2, but works better with 3. |
| 441 | * This does not determine *which* chains to use, just how many. |
| 442 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 443 | static int iwl4965_get_rx_chain_counter(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 444 | u8 *idle_state, u8 *rx_state) |
| 445 | { |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 446 | u8 is_single = is_single_rx_stream(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 447 | u8 is_cam = test_bit(STATUS_POWER_PMI, &priv->status) ? 0 : 1; |
| 448 | |
| 449 | /* # of Rx chains to use when expecting MIMO. */ |
| 450 | if (is_single || (!is_cam && (priv->ps_mode == IWL_MIMO_PS_STATIC))) |
| 451 | *rx_state = 2; |
| 452 | else |
| 453 | *rx_state = 3; |
| 454 | |
| 455 | /* # Rx chains when idling and maybe trying to save power */ |
| 456 | switch (priv->ps_mode) { |
| 457 | case IWL_MIMO_PS_STATIC: |
| 458 | case IWL_MIMO_PS_DYNAMIC: |
| 459 | *idle_state = (is_cam) ? 2 : 1; |
| 460 | break; |
| 461 | case IWL_MIMO_PS_NONE: |
| 462 | *idle_state = (is_cam) ? *rx_state : 1; |
| 463 | break; |
| 464 | default: |
| 465 | *idle_state = 1; |
| 466 | break; |
| 467 | } |
| 468 | |
| 469 | return 0; |
| 470 | } |
| 471 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 472 | int iwl4965_hw_rxq_stop(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 473 | { |
| 474 | int rc; |
| 475 | unsigned long flags; |
| 476 | |
| 477 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 478 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 479 | if (rc) { |
| 480 | spin_unlock_irqrestore(&priv->lock, flags); |
| 481 | return rc; |
| 482 | } |
| 483 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 484 | /* stop Rx DMA */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 485 | iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); |
| 486 | rc = iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 487 | (1 << 24), 1000); |
| 488 | if (rc < 0) |
| 489 | IWL_ERROR("Can't stop Rx DMA.\n"); |
| 490 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 491 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 492 | spin_unlock_irqrestore(&priv->lock, flags); |
| 493 | |
| 494 | return 0; |
| 495 | } |
| 496 | |
Tomas Winkler | 8614f36 | 2008-04-23 17:14:55 -0700 | [diff] [blame^] | 497 | /* |
| 498 | * EEPROM handlers |
| 499 | */ |
| 500 | |
| 501 | static int iwl4965_eeprom_check_version(struct iwl_priv *priv) |
| 502 | { |
| 503 | u16 eeprom_ver; |
| 504 | u16 calib_ver; |
| 505 | |
| 506 | eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION); |
| 507 | |
| 508 | calib_ver = iwl_eeprom_query16(priv, EEPROM_4965_CALIB_VERSION_OFFSET); |
| 509 | |
| 510 | if (eeprom_ver < EEPROM_4965_EEPROM_VERSION || |
| 511 | calib_ver < EEPROM_4965_TX_POWER_VERSION) |
| 512 | goto err; |
| 513 | |
| 514 | return 0; |
| 515 | err: |
| 516 | IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n", |
| 517 | eeprom_ver, EEPROM_4965_EEPROM_VERSION, |
| 518 | calib_ver, EEPROM_4965_TX_POWER_VERSION); |
| 519 | return -EINVAL; |
| 520 | |
| 521 | } |
Tomas Winkler | 079a253 | 2008-04-17 16:03:39 -0700 | [diff] [blame] | 522 | int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 523 | { |
Tomas Winkler | d860965 | 2007-10-25 17:15:35 +0800 | [diff] [blame] | 524 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 525 | unsigned long flags; |
| 526 | |
| 527 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 528 | ret = iwl_grab_nic_access(priv); |
Tomas Winkler | d860965 | 2007-10-25 17:15:35 +0800 | [diff] [blame] | 529 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 530 | spin_unlock_irqrestore(&priv->lock, flags); |
Tomas Winkler | d860965 | 2007-10-25 17:15:35 +0800 | [diff] [blame] | 531 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 534 | if (src == IWL_PWR_SRC_VAUX) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 535 | u32 val; |
Tomas Winkler | d860965 | 2007-10-25 17:15:35 +0800 | [diff] [blame] | 536 | ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE, |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 537 | &val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 538 | |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 539 | if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 540 | iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 541 | APMG_PS_CTRL_VAL_PWR_SRC_VAUX, |
| 542 | ~APMG_PS_CTRL_MSK_PWR_SRC); |
| 543 | } |
| 544 | } else { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 545 | iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 546 | APMG_PS_CTRL_VAL_PWR_SRC_VMAIN, |
| 547 | ~APMG_PS_CTRL_MSK_PWR_SRC); |
| 548 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 549 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 550 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 551 | spin_unlock_irqrestore(&priv->lock, flags); |
| 552 | |
Tomas Winkler | d860965 | 2007-10-25 17:15:35 +0800 | [diff] [blame] | 553 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 556 | static int iwl4965_rx_init(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 557 | { |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 558 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 559 | unsigned long flags; |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 560 | unsigned int rb_size; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 561 | |
| 562 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 563 | ret = iwl_grab_nic_access(priv); |
| 564 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 565 | spin_unlock_irqrestore(&priv->lock, flags); |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 566 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 569 | if (priv->cfg->mod_params->amsdu_size_8K) |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 570 | rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K; |
| 571 | else |
| 572 | rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K; |
| 573 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 574 | /* Stop Rx DMA */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 575 | iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 576 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 577 | /* Reset driver's Rx queue write index */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 578 | iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 579 | |
| 580 | /* Tell device where to find RBD circular buffer in DRAM */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 581 | iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG, |
| 582 | rxq->dma_addr >> 8); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 583 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 584 | /* Tell device where in DRAM to update its Rx status */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 585 | iwl_write_direct32(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG, |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 586 | (priv->shared_phys + |
| 587 | offsetof(struct iwl4965_shared, rb_closed)) >> 4); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 588 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 589 | /* Enable Rx DMA, enable host interrupt, Rx buffer size 4k, 256 RBDs */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 590 | iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, |
| 591 | FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL | |
| 592 | FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL | |
| 593 | rb_size | |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 594 | /* 0x10 << 4 | */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 595 | (RX_QUEUE_SIZE_LOG << |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 596 | FH_RCSR_RX_CONFIG_RBDCB_SIZE_BITSHIFT)); |
| 597 | |
| 598 | /* |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 599 | * iwl_write32(priv,CSR_INT_COAL_REG,0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 600 | */ |
| 601 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 602 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 603 | spin_unlock_irqrestore(&priv->lock, flags); |
| 604 | |
| 605 | return 0; |
| 606 | } |
| 607 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 608 | /* Tell 4965 where to find the "keep warm" buffer */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 609 | static int iwl4965_kw_init(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 610 | { |
| 611 | unsigned long flags; |
| 612 | int rc; |
| 613 | |
| 614 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 615 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 616 | if (rc) |
| 617 | goto out; |
| 618 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 619 | iwl_write_direct32(priv, IWL_FH_KW_MEM_ADDR_REG, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 620 | priv->kw.dma_addr >> 4); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 621 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 622 | out: |
| 623 | spin_unlock_irqrestore(&priv->lock, flags); |
| 624 | return rc; |
| 625 | } |
| 626 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 627 | static int iwl4965_kw_alloc(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 628 | { |
| 629 | struct pci_dev *dev = priv->pci_dev; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 630 | struct iwl4965_kw *kw = &priv->kw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 631 | |
| 632 | kw->size = IWL4965_KW_SIZE; /* TBW need set somewhere else */ |
| 633 | kw->v_addr = pci_alloc_consistent(dev, kw->size, &kw->dma_addr); |
| 634 | if (!kw->v_addr) |
| 635 | return -ENOMEM; |
| 636 | |
| 637 | return 0; |
| 638 | } |
| 639 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 640 | /** |
| 641 | * iwl4965_kw_free - Free the "keep warm" buffer |
| 642 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 643 | static void iwl4965_kw_free(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 644 | { |
| 645 | struct pci_dev *dev = priv->pci_dev; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 646 | struct iwl4965_kw *kw = &priv->kw; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 647 | |
| 648 | if (kw->v_addr) { |
| 649 | pci_free_consistent(dev, kw->size, kw->v_addr, kw->dma_addr); |
| 650 | memset(kw, 0, sizeof(*kw)); |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * iwl4965_txq_ctx_reset - Reset TX queue context |
| 656 | * Destroys all DMA structures and initialise them again |
| 657 | * |
| 658 | * @param priv |
| 659 | * @return error code |
| 660 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 661 | static int iwl4965_txq_ctx_reset(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 662 | { |
| 663 | int rc = 0; |
| 664 | int txq_id, slots_num; |
| 665 | unsigned long flags; |
| 666 | |
| 667 | iwl4965_kw_free(priv); |
| 668 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 669 | /* Free all tx/cmd queues and keep-warm buffer */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 670 | iwl4965_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 671 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 672 | /* Alloc keep-warm buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 673 | rc = iwl4965_kw_alloc(priv); |
| 674 | if (rc) { |
| 675 | IWL_ERROR("Keep Warm allocation failed"); |
| 676 | goto error_kw; |
| 677 | } |
| 678 | |
| 679 | spin_lock_irqsave(&priv->lock, flags); |
| 680 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 681 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 682 | if (unlikely(rc)) { |
| 683 | IWL_ERROR("TX reset failed"); |
| 684 | spin_unlock_irqrestore(&priv->lock, flags); |
| 685 | goto error_reset; |
| 686 | } |
| 687 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 688 | /* Turn off all Tx DMA channels */ |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 689 | iwl_write_prph(priv, IWL49_SCD_TXFACT, 0); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 690 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 691 | spin_unlock_irqrestore(&priv->lock, flags); |
| 692 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 693 | /* Tell 4965 where to find the keep-warm buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 694 | rc = iwl4965_kw_init(priv); |
| 695 | if (rc) { |
| 696 | IWL_ERROR("kw_init failed\n"); |
| 697 | goto error_reset; |
| 698 | } |
| 699 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 700 | /* Alloc and init all (default 16) Tx queues, |
| 701 | * including the command queue (#4) */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 702 | for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 703 | slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ? |
| 704 | TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 705 | rc = iwl4965_tx_queue_init(priv, &priv->txq[txq_id], slots_num, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 706 | txq_id); |
| 707 | if (rc) { |
| 708 | IWL_ERROR("Tx %d queue init failed\n", txq_id); |
| 709 | goto error; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | return rc; |
| 714 | |
| 715 | error: |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 716 | iwl4965_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 717 | error_reset: |
| 718 | iwl4965_kw_free(priv); |
| 719 | error_kw: |
| 720 | return rc; |
| 721 | } |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 722 | static int iwl4965_apm_init(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 723 | { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 724 | unsigned long flags; |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 725 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 726 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 727 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 728 | iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS, |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 729 | CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 730 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 731 | /* set "initialization complete" bit to move adapter |
| 732 | * D0U* --> D0A* state */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 733 | iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 734 | |
| 735 | /* wait for clock stabilization */ |
| 736 | ret = iwl_poll_bit(priv, CSR_GP_CNTRL, |
| 737 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, |
| 738 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); |
| 739 | if (ret < 0) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 740 | IWL_DEBUG_INFO("Failed to init the card\n"); |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 741 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 744 | ret = iwl_grab_nic_access(priv); |
| 745 | if (ret) |
| 746 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 747 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 748 | /* enable DMA */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 749 | iwl_write_prph(priv, APMG_CLK_CTRL_REG, |
| 750 | APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 751 | |
| 752 | udelay(20); |
| 753 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 754 | iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 755 | APMG_PCIDEV_STT_VAL_L1_ACT_DIS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 756 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 757 | iwl_release_nic_access(priv); |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 758 | out: |
| 759 | spin_unlock_irqrestore(&priv->lock, flags); |
| 760 | return ret; |
| 761 | } |
| 762 | |
| 763 | int iwl4965_hw_nic_init(struct iwl_priv *priv) |
| 764 | { |
| 765 | unsigned long flags; |
| 766 | struct iwl4965_rx_queue *rxq = &priv->rxq; |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 767 | u8 val_link; |
| 768 | u32 val; |
| 769 | int ret; |
| 770 | |
| 771 | /* nic_init */ |
| 772 | priv->cfg->ops->lib->apm_ops.init(priv); |
| 773 | |
| 774 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 775 | iwl_write32(priv, CSR_INT_COALESCING, 512 / 32); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 776 | spin_unlock_irqrestore(&priv->lock, flags); |
| 777 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 778 | ret = priv->cfg->ops->lib->apm_ops.set_pwr_src(priv, IWL_PWR_SRC_VMAIN); |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 779 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 780 | spin_lock_irqsave(&priv->lock, flags); |
| 781 | |
Tomas Winkler | b661c81 | 2008-04-23 17:14:54 -0700 | [diff] [blame] | 782 | if ((priv->rev_id & 0x80) == 0x80 && (priv->rev_id & 0x7f) < 8) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 783 | pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val); |
| 784 | /* Enable No Snoop field */ |
| 785 | pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8, |
| 786 | val & ~(1 << 11)); |
| 787 | } |
| 788 | |
| 789 | spin_unlock_irqrestore(&priv->lock, flags); |
| 790 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 791 | pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link); |
| 792 | |
| 793 | /* disable L1 entry -- workaround for pre-B1 */ |
| 794 | pci_write_config_byte(priv->pci_dev, PCI_LINK_CTRL, val_link & ~0x02); |
| 795 | |
| 796 | spin_lock_irqsave(&priv->lock, flags); |
| 797 | |
| 798 | /* set CSR_HW_CONFIG_REG for uCode use */ |
| 799 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 800 | iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, |
| 801 | CSR49_HW_IF_CONFIG_REG_BIT_4965_R | |
| 802 | CSR49_HW_IF_CONFIG_REG_BIT_RADIO_SI | |
| 803 | CSR49_HW_IF_CONFIG_REG_BIT_MAC_SI); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 804 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 805 | ret = iwl_grab_nic_access(priv); |
| 806 | if (ret < 0) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 807 | spin_unlock_irqrestore(&priv->lock, flags); |
| 808 | IWL_DEBUG_INFO("Failed to init the card\n"); |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 809 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 812 | iwl_read_prph(priv, APMG_PS_CTRL_REG); |
| 813 | iwl_set_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 814 | udelay(5); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 815 | iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 816 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 817 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 818 | spin_unlock_irqrestore(&priv->lock, flags); |
| 819 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 820 | iwl4965_hw_card_show_info(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 821 | |
| 822 | /* end nic_init */ |
| 823 | |
| 824 | /* Allocate the RX queue, or reset if it is already allocated */ |
| 825 | if (!rxq->bd) { |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 826 | ret = iwl4965_rx_queue_alloc(priv); |
| 827 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 828 | IWL_ERROR("Unable to initialize Rx queue\n"); |
| 829 | return -ENOMEM; |
| 830 | } |
| 831 | } else |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 832 | iwl4965_rx_queue_reset(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 833 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 834 | iwl4965_rx_replenish(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 835 | |
| 836 | iwl4965_rx_init(priv, rxq); |
| 837 | |
| 838 | spin_lock_irqsave(&priv->lock, flags); |
| 839 | |
| 840 | rxq->need_update = 1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 841 | iwl4965_rx_queue_update_write_ptr(priv, rxq); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 842 | |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 843 | /* init the txpower calibration pointer */ |
| 844 | priv->calib_info = (struct iwl_eeprom_calib_info *) |
| 845 | iwl_eeprom_query_addr(priv, EEPROM_4965_CALIB_TXPOWER_OFFSET); |
| 846 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 847 | spin_unlock_irqrestore(&priv->lock, flags); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 848 | |
| 849 | /* Allocate and init all Tx and Command queues */ |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 850 | ret = iwl4965_txq_ctx_reset(priv); |
| 851 | if (ret) |
| 852 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 853 | |
| 854 | set_bit(STATUS_INIT, &priv->status); |
| 855 | |
| 856 | return 0; |
| 857 | } |
| 858 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 859 | int iwl4965_hw_nic_stop_master(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 860 | { |
| 861 | int rc = 0; |
| 862 | u32 reg_val; |
| 863 | unsigned long flags; |
| 864 | |
| 865 | spin_lock_irqsave(&priv->lock, flags); |
| 866 | |
| 867 | /* set stop master bit */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 868 | iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 869 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 870 | reg_val = iwl_read32(priv, CSR_GP_CNTRL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 871 | |
| 872 | if (CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE == |
| 873 | (reg_val & CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE)) |
| 874 | IWL_DEBUG_INFO("Card in power save, master is already " |
| 875 | "stopped\n"); |
| 876 | else { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 877 | rc = iwl_poll_bit(priv, CSR_RESET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 878 | CSR_RESET_REG_FLAG_MASTER_DISABLED, |
| 879 | CSR_RESET_REG_FLAG_MASTER_DISABLED, 100); |
| 880 | if (rc < 0) { |
| 881 | spin_unlock_irqrestore(&priv->lock, flags); |
| 882 | return rc; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | spin_unlock_irqrestore(&priv->lock, flags); |
| 887 | IWL_DEBUG_INFO("stop master\n"); |
| 888 | |
| 889 | return rc; |
| 890 | } |
| 891 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 892 | /** |
| 893 | * iwl4965_hw_txq_ctx_stop - Stop all Tx DMA channels, free Tx queue memory |
| 894 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 895 | void iwl4965_hw_txq_ctx_stop(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 896 | { |
| 897 | |
| 898 | int txq_id; |
| 899 | unsigned long flags; |
| 900 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 901 | /* Stop each Tx DMA channel, and wait for it to be idle */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 902 | for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 903 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 904 | if (iwl_grab_nic_access(priv)) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 905 | spin_unlock_irqrestore(&priv->lock, flags); |
| 906 | continue; |
| 907 | } |
| 908 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 909 | iwl_write_direct32(priv, |
| 910 | IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 0x0); |
| 911 | iwl_poll_direct_bit(priv, IWL_FH_TSSR_TX_STATUS_REG, |
| 912 | IWL_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE |
| 913 | (txq_id), 200); |
| 914 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 915 | spin_unlock_irqrestore(&priv->lock, flags); |
| 916 | } |
| 917 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 918 | /* Deallocate memory for all Tx queues */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 919 | iwl4965_hw_txq_ctx_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 922 | int iwl4965_hw_nic_reset(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 923 | { |
| 924 | int rc = 0; |
| 925 | unsigned long flags; |
| 926 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 927 | iwl4965_hw_nic_stop_master(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 928 | |
| 929 | spin_lock_irqsave(&priv->lock, flags); |
| 930 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 931 | iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 932 | |
| 933 | udelay(10); |
| 934 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 935 | iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); |
| 936 | rc = iwl_poll_bit(priv, CSR_RESET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 937 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, |
| 938 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25); |
| 939 | |
| 940 | udelay(10); |
| 941 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 942 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 943 | if (!rc) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 944 | iwl_write_prph(priv, APMG_CLK_EN_REG, |
| 945 | APMG_CLK_VAL_DMA_CLK_RQT | |
| 946 | APMG_CLK_VAL_BSM_CLK_RQT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 947 | |
| 948 | udelay(10); |
| 949 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 950 | iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, |
| 951 | APMG_PCIDEV_STT_VAL_L1_ACT_DIS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 952 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 953 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 957 | wake_up_interruptible(&priv->wait_command_queue); |
| 958 | |
| 959 | spin_unlock_irqrestore(&priv->lock, flags); |
| 960 | |
| 961 | return rc; |
| 962 | |
| 963 | } |
| 964 | |
| 965 | #define REG_RECALIB_PERIOD (60) |
| 966 | |
| 967 | /** |
| 968 | * iwl4965_bg_statistics_periodic - Timer callback to queue statistics |
| 969 | * |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 970 | * This callback is provided in order to send a statistics request. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 971 | * |
| 972 | * This timer function is continually reset to execute within |
| 973 | * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION |
| 974 | * was received. We need to ensure we receive the statistics in order |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 975 | * to update the temperature used for calibrating the TXPOWER. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 976 | */ |
| 977 | static void iwl4965_bg_statistics_periodic(unsigned long data) |
| 978 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 979 | struct iwl_priv *priv = (struct iwl_priv *)data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 980 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 981 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 982 | return; |
| 983 | |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 984 | iwl_send_statistics_request(priv, CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 985 | } |
| 986 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 987 | void iwl4965_rf_kill_ct_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 988 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 989 | struct iwl4965_ct_kill_config cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 990 | unsigned long flags; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 991 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 992 | |
| 993 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 994 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 995 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
| 996 | spin_unlock_irqrestore(&priv->lock, flags); |
| 997 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 998 | cmd.critical_temperature_R = |
Emmanuel Grumbach | b73cdf2 | 2008-04-21 15:41:58 -0700 | [diff] [blame] | 999 | cpu_to_le32(priv->hw_params.ct_kill_threshold); |
| 1000 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1001 | ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD, |
| 1002 | sizeof(cmd), &cmd); |
| 1003 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1004 | IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n"); |
| 1005 | else |
Emmanuel Grumbach | b73cdf2 | 2008-04-21 15:41:58 -0700 | [diff] [blame] | 1006 | IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded, " |
| 1007 | "critical temperature is %d\n", |
| 1008 | cmd.critical_temperature_R); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1011 | #ifdef CONFIG_IWL4965_RUN_TIME_CALIB |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1012 | |
| 1013 | /* Reset differential Rx gains in NIC to prepare for chain noise calibration. |
| 1014 | * Called after every association, but this runs only once! |
| 1015 | * ... once chain noise is calibrated the first time, it's good forever. */ |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1016 | static void iwl4965_chain_noise_reset(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1017 | { |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1018 | struct iwl_chain_noise_data *data = &(priv->chain_noise_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1019 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 1020 | if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1021 | struct iwl4965_calibration_cmd cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1022 | |
| 1023 | memset(&cmd, 0, sizeof(cmd)); |
| 1024 | cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD; |
| 1025 | cmd.diff_gain_a = 0; |
| 1026 | cmd.diff_gain_b = 0; |
| 1027 | cmd.diff_gain_c = 0; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1028 | if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD, |
| 1029 | sizeof(cmd), &cmd)) |
| 1030 | IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1031 | data->state = IWL_CHAIN_NOISE_ACCUMULATE; |
| 1032 | IWL_DEBUG_CALIB("Run chain_noise_calibrate\n"); |
| 1033 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1034 | } |
| 1035 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1036 | static void iwl4965_gain_computation(struct iwl_priv *priv, |
| 1037 | u32 *average_noise, |
| 1038 | u16 min_average_noise_antenna_i, |
| 1039 | u32 min_average_noise) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1040 | { |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1041 | int i, ret; |
| 1042 | struct iwl_chain_noise_data *data = &priv->chain_noise_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1043 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1044 | data->delta_gain_code[min_average_noise_antenna_i] = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1045 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1046 | for (i = 0; i < NUM_RX_CHAINS; i++) { |
| 1047 | s32 delta_g = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1048 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1049 | if (!(data->disconn_array[i]) && |
| 1050 | (data->delta_gain_code[i] == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1051 | CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) { |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1052 | delta_g = average_noise[i] - min_average_noise; |
| 1053 | data->delta_gain_code[i] = (u8)((delta_g * 10) / 15); |
| 1054 | data->delta_gain_code[i] = |
| 1055 | min(data->delta_gain_code[i], |
| 1056 | (u8) CHAIN_NOISE_MAX_DELTA_GAIN_CODE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1057 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1058 | data->delta_gain_code[i] = |
| 1059 | (data->delta_gain_code[i] | (1 << 2)); |
| 1060 | } else { |
| 1061 | data->delta_gain_code[i] = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1062 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1063 | } |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1064 | IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n", |
| 1065 | data->delta_gain_code[0], |
| 1066 | data->delta_gain_code[1], |
| 1067 | data->delta_gain_code[2]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1068 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1069 | /* Differential gain gets sent to uCode only once */ |
| 1070 | if (!data->radio_write) { |
| 1071 | struct iwl4965_calibration_cmd cmd; |
| 1072 | data->radio_write = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1073 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1074 | memset(&cmd, 0, sizeof(cmd)); |
| 1075 | cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD; |
| 1076 | cmd.diff_gain_a = data->delta_gain_code[0]; |
| 1077 | cmd.diff_gain_b = data->delta_gain_code[1]; |
| 1078 | cmd.diff_gain_c = data->delta_gain_code[2]; |
| 1079 | ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD, |
| 1080 | sizeof(cmd), &cmd); |
| 1081 | if (ret) |
| 1082 | IWL_DEBUG_CALIB("fail sending cmd " |
| 1083 | "REPLY_PHY_CALIBRATION_CMD \n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1084 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1085 | /* TODO we might want recalculate |
| 1086 | * rx_chain in rxon cmd */ |
| 1087 | |
| 1088 | /* Mark so we run this algo only once! */ |
| 1089 | data->state = IWL_CHAIN_NOISE_CALIBRATED; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1090 | } |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1091 | data->chain_noise_a = 0; |
| 1092 | data->chain_noise_b = 0; |
| 1093 | data->chain_noise_c = 0; |
| 1094 | data->chain_signal_a = 0; |
| 1095 | data->chain_signal_b = 0; |
| 1096 | data->chain_signal_c = 0; |
| 1097 | data->beacon_count = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | static void iwl4965_bg_sensitivity_work(struct work_struct *work) |
| 1101 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1102 | struct iwl_priv *priv = container_of(work, struct iwl_priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1103 | sensitivity_work); |
| 1104 | |
| 1105 | mutex_lock(&priv->mutex); |
| 1106 | |
| 1107 | if (test_bit(STATUS_EXIT_PENDING, &priv->status) || |
| 1108 | test_bit(STATUS_SCANNING, &priv->status)) { |
| 1109 | mutex_unlock(&priv->mutex); |
| 1110 | return; |
| 1111 | } |
| 1112 | |
| 1113 | if (priv->start_calib) { |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1114 | iwl_chain_noise_calibration(priv, &priv->statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1115 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1116 | iwl_sensitivity_calibration(priv, &priv->statistics); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | mutex_unlock(&priv->mutex); |
| 1120 | return; |
| 1121 | } |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1122 | #endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1123 | |
| 1124 | static void iwl4965_bg_txpower_work(struct work_struct *work) |
| 1125 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1126 | struct iwl_priv *priv = container_of(work, struct iwl_priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1127 | txpower_work); |
| 1128 | |
| 1129 | /* If a scan happened to start before we got here |
| 1130 | * then just return; the statistics notification will |
| 1131 | * kick off another scheduled work to compensate for |
| 1132 | * any temperature delta we missed here. */ |
| 1133 | if (test_bit(STATUS_EXIT_PENDING, &priv->status) || |
| 1134 | test_bit(STATUS_SCANNING, &priv->status)) |
| 1135 | return; |
| 1136 | |
| 1137 | mutex_lock(&priv->mutex); |
| 1138 | |
| 1139 | /* Regardless of if we are assocaited, we must reconfigure the |
| 1140 | * TX power since frames can be sent on non-radar channels while |
| 1141 | * not associated */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1142 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1143 | |
| 1144 | /* Update last_temperature to keep is_calib_needed from running |
| 1145 | * when it isn't needed... */ |
| 1146 | priv->last_temperature = priv->temperature; |
| 1147 | |
| 1148 | mutex_unlock(&priv->mutex); |
| 1149 | } |
| 1150 | |
| 1151 | /* |
| 1152 | * Acquire priv->lock before calling this function ! |
| 1153 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1154 | static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1155 | { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1156 | iwl_write_direct32(priv, HBUS_TARG_WRPTR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1157 | (index & 0xff) | (txq_id << 8)); |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 1158 | iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(txq_id), index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1159 | } |
| 1160 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1161 | /** |
| 1162 | * iwl4965_tx_queue_set_status - (optionally) start Tx/Cmd queue |
| 1163 | * @tx_fifo_id: Tx DMA/FIFO channel (range 0-7) that the queue will feed |
| 1164 | * @scd_retry: (1) Indicates queue will be used in aggregation mode |
| 1165 | * |
| 1166 | * NOTE: Acquire priv->lock before calling this function ! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1167 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1168 | static void iwl4965_tx_queue_set_status(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1169 | struct iwl4965_tx_queue *txq, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1170 | int tx_fifo_id, int scd_retry) |
| 1171 | { |
| 1172 | int txq_id = txq->q.id; |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1173 | |
| 1174 | /* Find out whether to activate Tx queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1175 | int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0; |
| 1176 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1177 | /* Set up and activate */ |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 1178 | iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1179 | (active << SCD_QUEUE_STTS_REG_POS_ACTIVE) | |
| 1180 | (tx_fifo_id << SCD_QUEUE_STTS_REG_POS_TXF) | |
| 1181 | (scd_retry << SCD_QUEUE_STTS_REG_POS_WSL) | |
| 1182 | (scd_retry << SCD_QUEUE_STTS_REG_POS_SCD_ACK) | |
| 1183 | SCD_QUEUE_STTS_REG_MSK); |
| 1184 | |
| 1185 | txq->sched_retry = scd_retry; |
| 1186 | |
| 1187 | IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n", |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1188 | active ? "Activate" : "Deactivate", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1189 | scd_retry ? "BA" : "AC", txq_id, tx_fifo_id); |
| 1190 | } |
| 1191 | |
| 1192 | static const u16 default_queue_to_tx_fifo[] = { |
| 1193 | IWL_TX_FIFO_AC3, |
| 1194 | IWL_TX_FIFO_AC2, |
| 1195 | IWL_TX_FIFO_AC1, |
| 1196 | IWL_TX_FIFO_AC0, |
| 1197 | IWL_CMD_FIFO_NUM, |
| 1198 | IWL_TX_FIFO_HCCA_1, |
| 1199 | IWL_TX_FIFO_HCCA_2 |
| 1200 | }; |
| 1201 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1202 | static inline void iwl4965_txq_ctx_activate(struct iwl_priv *priv, int txq_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1203 | { |
| 1204 | set_bit(txq_id, &priv->txq_ctx_active_msk); |
| 1205 | } |
| 1206 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1207 | static inline void iwl4965_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1208 | { |
| 1209 | clear_bit(txq_id, &priv->txq_ctx_active_msk); |
| 1210 | } |
| 1211 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1212 | int iwl4965_alive_notify(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1213 | { |
| 1214 | u32 a; |
| 1215 | int i = 0; |
| 1216 | unsigned long flags; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1217 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1218 | |
| 1219 | spin_lock_irqsave(&priv->lock, flags); |
| 1220 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1221 | #ifdef CONFIG_IWL4965_RUN_TIME_CALIB |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1222 | memset(&(priv->sensitivity_data), 0, |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1223 | sizeof(struct iwl_sensitivity_data)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1224 | memset(&(priv->chain_noise_data), 0, |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1225 | sizeof(struct iwl_chain_noise_data)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1226 | for (i = 0; i < NUM_RX_CHAINS; i++) |
| 1227 | priv->chain_noise_data.delta_gain_code[i] = |
| 1228 | CHAIN_NOISE_DELTA_GAIN_INIT_VAL; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1229 | #endif /* CONFIG_IWL4965_RUN_TIME_CALIB*/ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1230 | ret = iwl_grab_nic_access(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1231 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1232 | spin_unlock_irqrestore(&priv->lock, flags); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1233 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1234 | } |
| 1235 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1236 | /* Clear 4965's internal Tx Scheduler data base */ |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 1237 | priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1238 | a = priv->scd_base_addr + SCD_CONTEXT_DATA_OFFSET; |
| 1239 | for (; a < priv->scd_base_addr + SCD_TX_STTS_BITMAP_OFFSET; a += 4) |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1240 | iwl_write_targ_mem(priv, a, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1241 | for (; a < priv->scd_base_addr + SCD_TRANSLATE_TBL_OFFSET; a += 4) |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1242 | iwl_write_targ_mem(priv, a, 0); |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1243 | for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4) |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1244 | iwl_write_targ_mem(priv, a, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1245 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1246 | /* Tel 4965 where to find Tx byte count tables */ |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 1247 | iwl_write_prph(priv, IWL49_SCD_DRAM_BASE_ADDR, |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 1248 | (priv->shared_phys + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1249 | offsetof(struct iwl4965_shared, queues_byte_cnt_tbls)) >> 10); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1250 | |
| 1251 | /* Disable chain mode for all queues */ |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 1252 | iwl_write_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1253 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1254 | /* Initialize each Tx queue (including the command queue) */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1255 | for (i = 0; i < priv->hw_params.max_txq_num; i++) { |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1256 | |
| 1257 | /* TFD circular buffer read/write indexes */ |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 1258 | iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(i), 0); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1259 | iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8)); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1260 | |
| 1261 | /* Max Tx Window size for Scheduler-ACK mode */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1262 | iwl_write_targ_mem(priv, priv->scd_base_addr + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1263 | SCD_CONTEXT_QUEUE_OFFSET(i), |
| 1264 | (SCD_WIN_SIZE << |
| 1265 | SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) & |
| 1266 | SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1267 | |
| 1268 | /* Frame limit */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1269 | iwl_write_targ_mem(priv, priv->scd_base_addr + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1270 | SCD_CONTEXT_QUEUE_OFFSET(i) + |
| 1271 | sizeof(u32), |
| 1272 | (SCD_FRAME_LIMIT << |
| 1273 | SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) & |
| 1274 | SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK); |
| 1275 | |
| 1276 | } |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 1277 | iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1278 | (1 << priv->hw_params.max_txq_num) - 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1279 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1280 | /* Activate all Tx DMA/FIFO channels */ |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 1281 | iwl_write_prph(priv, IWL49_SCD_TXFACT, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1282 | SCD_TXFACT_REG_TXFIFO_MASK(0, 7)); |
| 1283 | |
| 1284 | iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1285 | |
| 1286 | /* Map each Tx/cmd queue to its corresponding fifo */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1287 | for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) { |
| 1288 | int ac = default_queue_to_tx_fifo[i]; |
| 1289 | iwl4965_txq_ctx_activate(priv, i); |
| 1290 | iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0); |
| 1291 | } |
| 1292 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 1293 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1294 | spin_unlock_irqrestore(&priv->lock, flags); |
| 1295 | |
Emmanuel Grumbach | 49ea859 | 2008-04-15 16:01:37 -0700 | [diff] [blame] | 1296 | /* Ask for statistics now, the uCode will send statistics notification |
| 1297 | * periodically after association */ |
| 1298 | iwl_send_statistics_request(priv, CMD_ASYNC); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1299 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1300 | } |
| 1301 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1302 | #ifdef CONFIG_IWL4965_RUN_TIME_CALIB |
| 1303 | static struct iwl_sensitivity_ranges iwl4965_sensitivity = { |
| 1304 | .min_nrg_cck = 97, |
| 1305 | .max_nrg_cck = 0, |
| 1306 | |
| 1307 | .auto_corr_min_ofdm = 85, |
| 1308 | .auto_corr_min_ofdm_mrc = 170, |
| 1309 | .auto_corr_min_ofdm_x1 = 105, |
| 1310 | .auto_corr_min_ofdm_mrc_x1 = 220, |
| 1311 | |
| 1312 | .auto_corr_max_ofdm = 120, |
| 1313 | .auto_corr_max_ofdm_mrc = 210, |
| 1314 | .auto_corr_max_ofdm_x1 = 140, |
| 1315 | .auto_corr_max_ofdm_mrc_x1 = 270, |
| 1316 | |
| 1317 | .auto_corr_min_cck = 125, |
| 1318 | .auto_corr_max_cck = 200, |
| 1319 | .auto_corr_min_cck_mrc = 200, |
| 1320 | .auto_corr_max_cck_mrc = 400, |
| 1321 | |
| 1322 | .nrg_th_cck = 100, |
| 1323 | .nrg_th_ofdm = 100, |
| 1324 | }; |
| 1325 | #endif |
| 1326 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1327 | /** |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1328 | * iwl4965_hw_set_hw_params |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1329 | * |
| 1330 | * Called when initializing driver |
| 1331 | */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1332 | int iwl4965_hw_set_hw_params(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1333 | { |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 1334 | |
Ron Rindjunsky | dfe7d45 | 2008-04-15 16:01:45 -0700 | [diff] [blame] | 1335 | if ((priv->cfg->mod_params->num_of_queues > IWL4965_MAX_NUM_QUEUES) || |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 1336 | (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) { |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 1337 | IWL_ERROR("invalid queues_num, should be between %d and %d\n", |
Ron Rindjunsky | dfe7d45 | 2008-04-15 16:01:45 -0700 | [diff] [blame] | 1338 | IWL_MIN_NUM_QUEUES, IWL4965_MAX_NUM_QUEUES); |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 1339 | return -EINVAL; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1342 | priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues; |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 1343 | priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1344 | priv->hw_params.tx_cmd_len = sizeof(struct iwl4965_tx_cmd); |
| 1345 | priv->hw_params.max_rxq_size = RX_QUEUE_SIZE; |
| 1346 | priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG; |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 1347 | if (priv->cfg->mod_params->amsdu_size_8K) |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1348 | priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K; |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 1349 | else |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1350 | priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K; |
| 1351 | priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256; |
| 1352 | priv->hw_params.max_stations = IWL4965_STATION_COUNT; |
| 1353 | priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID; |
Tomas Winkler | 3e82a82 | 2008-02-13 11:32:31 -0800 | [diff] [blame] | 1354 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 1355 | priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE; |
| 1356 | priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE; |
| 1357 | priv->hw_params.max_bsm_size = BSM_SRAM_SIZE; |
| 1358 | priv->hw_params.fat_channel = BIT(IEEE80211_BAND_5GHZ); |
| 1359 | |
Tomas Winkler | ec35cf2 | 2008-04-15 16:01:39 -0700 | [diff] [blame] | 1360 | priv->hw_params.tx_chains_num = 2; |
| 1361 | priv->hw_params.rx_chains_num = 2; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 1362 | priv->hw_params.valid_tx_ant = ANT_A | ANT_B; |
| 1363 | priv->hw_params.valid_rx_ant = ANT_A | ANT_B; |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 1364 | priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD); |
| 1365 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 1366 | #ifdef CONFIG_IWL4965_RUN_TIME_CALIB |
| 1367 | priv->hw_params.sens = &iwl4965_sensitivity; |
| 1368 | #endif |
Tomas Winkler | 3e82a82 | 2008-02-13 11:32:31 -0800 | [diff] [blame] | 1369 | |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 1370 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1374 | * iwl4965_hw_txq_ctx_free - Free TXQ Context |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1375 | * |
| 1376 | * Destroy all TX DMA queues and structures |
| 1377 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1378 | void iwl4965_hw_txq_ctx_free(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1379 | { |
| 1380 | int txq_id; |
| 1381 | |
| 1382 | /* Tx queues */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1383 | for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1384 | iwl4965_tx_queue_free(priv, &priv->txq[txq_id]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1385 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1386 | /* Keep-warm buffer */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1387 | iwl4965_kw_free(priv); |
| 1388 | } |
| 1389 | |
| 1390 | /** |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1391 | * iwl4965_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr] |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1392 | * |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1393 | * Does NOT advance any TFD circular buffer read/write indexes |
| 1394 | * Does NOT free the TFD itself (which is within circular buffer) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1395 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1396 | int iwl4965_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl4965_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1397 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1398 | struct iwl4965_tfd_frame *bd_tmp = (struct iwl4965_tfd_frame *)&txq->bd[0]; |
| 1399 | struct iwl4965_tfd_frame *bd = &bd_tmp[txq->q.read_ptr]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1400 | struct pci_dev *dev = priv->pci_dev; |
| 1401 | int i; |
| 1402 | int counter = 0; |
| 1403 | int index, is_odd; |
| 1404 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1405 | /* Host command buffers stay mapped in memory, nothing to clean */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1406 | if (txq->q.id == IWL_CMD_QUEUE_NUM) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1407 | return 0; |
| 1408 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1409 | /* Sanity check on number of chunks */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1410 | counter = IWL_GET_BITS(*bd, num_tbs); |
| 1411 | if (counter > MAX_NUM_OF_TBS) { |
| 1412 | IWL_ERROR("Too many chunks: %i\n", counter); |
| 1413 | /* @todo issue fatal error, it is quite serious situation */ |
| 1414 | return 0; |
| 1415 | } |
| 1416 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1417 | /* Unmap chunks, if any. |
| 1418 | * TFD info for odd chunks is different format than for even chunks. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1419 | for (i = 0; i < counter; i++) { |
| 1420 | index = i / 2; |
| 1421 | is_odd = i & 0x1; |
| 1422 | |
| 1423 | if (is_odd) |
| 1424 | pci_unmap_single( |
| 1425 | dev, |
| 1426 | IWL_GET_BITS(bd->pa[index], tb2_addr_lo16) | |
| 1427 | (IWL_GET_BITS(bd->pa[index], |
| 1428 | tb2_addr_hi20) << 16), |
| 1429 | IWL_GET_BITS(bd->pa[index], tb2_len), |
| 1430 | PCI_DMA_TODEVICE); |
| 1431 | |
| 1432 | else if (i > 0) |
| 1433 | pci_unmap_single(dev, |
| 1434 | le32_to_cpu(bd->pa[index].tb1_addr), |
| 1435 | IWL_GET_BITS(bd->pa[index], tb1_len), |
| 1436 | PCI_DMA_TODEVICE); |
| 1437 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1438 | /* Free SKB, if any, for this chunk */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1439 | if (txq->txb[txq->q.read_ptr].skb[i]) { |
| 1440 | struct sk_buff *skb = txq->txb[txq->q.read_ptr].skb[i]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1441 | |
| 1442 | dev_kfree_skb(skb); |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1443 | txq->txb[txq->q.read_ptr].skb[i] = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1444 | } |
| 1445 | } |
| 1446 | return 0; |
| 1447 | } |
| 1448 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 1449 | /* set card power command */ |
| 1450 | static int iwl4965_set_power(struct iwl_priv *priv, |
| 1451 | void *cmd) |
| 1452 | { |
| 1453 | int ret = 0; |
| 1454 | |
| 1455 | ret = iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD, |
| 1456 | sizeof(struct iwl4965_powertable_cmd), |
| 1457 | cmd, NULL); |
| 1458 | return ret; |
| 1459 | } |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1460 | int iwl4965_hw_reg_set_txpower(struct iwl_priv *priv, s8 power) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1461 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1462 | IWL_ERROR("TODO: Implement iwl4965_hw_reg_set_txpower!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1463 | return -EINVAL; |
| 1464 | } |
| 1465 | |
| 1466 | static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res) |
| 1467 | { |
| 1468 | s32 sign = 1; |
| 1469 | |
| 1470 | if (num < 0) { |
| 1471 | sign = -sign; |
| 1472 | num = -num; |
| 1473 | } |
| 1474 | if (denom < 0) { |
| 1475 | sign = -sign; |
| 1476 | denom = -denom; |
| 1477 | } |
| 1478 | *res = 1; |
| 1479 | *res = ((num * 2 + denom) / (denom * 2)) * sign; |
| 1480 | |
| 1481 | return 1; |
| 1482 | } |
| 1483 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1484 | /** |
| 1485 | * iwl4965_get_voltage_compensation - Power supply voltage comp for txpower |
| 1486 | * |
| 1487 | * Determines power supply voltage compensation for txpower calculations. |
| 1488 | * Returns number of 1/2-dB steps to subtract from gain table index, |
| 1489 | * to compensate for difference between power supply voltage during |
| 1490 | * factory measurements, vs. current power supply voltage. |
| 1491 | * |
| 1492 | * Voltage indication is higher for lower voltage. |
| 1493 | * Lower voltage requires more gain (lower gain table index). |
| 1494 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1495 | static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage, |
| 1496 | s32 current_voltage) |
| 1497 | { |
| 1498 | s32 comp = 0; |
| 1499 | |
| 1500 | if ((TX_POWER_IWL_ILLEGAL_VOLTAGE == eeprom_voltage) || |
| 1501 | (TX_POWER_IWL_ILLEGAL_VOLTAGE == current_voltage)) |
| 1502 | return 0; |
| 1503 | |
| 1504 | iwl4965_math_div_round(current_voltage - eeprom_voltage, |
| 1505 | TX_POWER_IWL_VOLTAGE_CODES_PER_03V, &comp); |
| 1506 | |
| 1507 | if (current_voltage > eeprom_voltage) |
| 1508 | comp *= 2; |
| 1509 | if ((comp < -2) || (comp > 2)) |
| 1510 | comp = 0; |
| 1511 | |
| 1512 | return comp; |
| 1513 | } |
| 1514 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1515 | static const struct iwl_channel_info * |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1516 | iwl4965_get_channel_txpower_info(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1517 | enum ieee80211_band band, u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1518 | { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1519 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1520 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1521 | ch_info = iwl_get_channel_info(priv, band, channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1522 | |
| 1523 | if (!is_channel_valid(ch_info)) |
| 1524 | return NULL; |
| 1525 | |
| 1526 | return ch_info; |
| 1527 | } |
| 1528 | |
| 1529 | static s32 iwl4965_get_tx_atten_grp(u16 channel) |
| 1530 | { |
| 1531 | if (channel >= CALIB_IWL_TX_ATTEN_GR5_FCH && |
| 1532 | channel <= CALIB_IWL_TX_ATTEN_GR5_LCH) |
| 1533 | return CALIB_CH_GROUP_5; |
| 1534 | |
| 1535 | if (channel >= CALIB_IWL_TX_ATTEN_GR1_FCH && |
| 1536 | channel <= CALIB_IWL_TX_ATTEN_GR1_LCH) |
| 1537 | return CALIB_CH_GROUP_1; |
| 1538 | |
| 1539 | if (channel >= CALIB_IWL_TX_ATTEN_GR2_FCH && |
| 1540 | channel <= CALIB_IWL_TX_ATTEN_GR2_LCH) |
| 1541 | return CALIB_CH_GROUP_2; |
| 1542 | |
| 1543 | if (channel >= CALIB_IWL_TX_ATTEN_GR3_FCH && |
| 1544 | channel <= CALIB_IWL_TX_ATTEN_GR3_LCH) |
| 1545 | return CALIB_CH_GROUP_3; |
| 1546 | |
| 1547 | if (channel >= CALIB_IWL_TX_ATTEN_GR4_FCH && |
| 1548 | channel <= CALIB_IWL_TX_ATTEN_GR4_LCH) |
| 1549 | return CALIB_CH_GROUP_4; |
| 1550 | |
| 1551 | IWL_ERROR("Can't find txatten group for channel %d.\n", channel); |
| 1552 | return -1; |
| 1553 | } |
| 1554 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1555 | static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1556 | { |
| 1557 | s32 b = -1; |
| 1558 | |
| 1559 | for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) { |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1560 | if (priv->calib_info->band_info[b].ch_from == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1561 | continue; |
| 1562 | |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1563 | if ((channel >= priv->calib_info->band_info[b].ch_from) |
| 1564 | && (channel <= priv->calib_info->band_info[b].ch_to)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1565 | break; |
| 1566 | } |
| 1567 | |
| 1568 | return b; |
| 1569 | } |
| 1570 | |
| 1571 | static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2) |
| 1572 | { |
| 1573 | s32 val; |
| 1574 | |
| 1575 | if (x2 == x1) |
| 1576 | return y1; |
| 1577 | else { |
| 1578 | iwl4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val); |
| 1579 | return val + y2; |
| 1580 | } |
| 1581 | } |
| 1582 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1583 | /** |
| 1584 | * iwl4965_interpolate_chan - Interpolate factory measurements for one channel |
| 1585 | * |
| 1586 | * Interpolates factory measurements from the two sample channels within a |
| 1587 | * sub-band, to apply to channel of interest. Interpolation is proportional to |
| 1588 | * differences in channel frequencies, which is proportional to differences |
| 1589 | * in channel number. |
| 1590 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1591 | static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel, |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1592 | struct iwl_eeprom_calib_ch_info *chan_info) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1593 | { |
| 1594 | s32 s = -1; |
| 1595 | u32 c; |
| 1596 | u32 m; |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1597 | const struct iwl_eeprom_calib_measure *m1; |
| 1598 | const struct iwl_eeprom_calib_measure *m2; |
| 1599 | struct iwl_eeprom_calib_measure *omeas; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1600 | u32 ch_i1; |
| 1601 | u32 ch_i2; |
| 1602 | |
| 1603 | s = iwl4965_get_sub_band(priv, channel); |
| 1604 | if (s >= EEPROM_TX_POWER_BANDS) { |
| 1605 | IWL_ERROR("Tx Power can not find channel %d ", channel); |
| 1606 | return -1; |
| 1607 | } |
| 1608 | |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1609 | ch_i1 = priv->calib_info->band_info[s].ch1.ch_num; |
| 1610 | ch_i2 = priv->calib_info->band_info[s].ch2.ch_num; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1611 | chan_info->ch_num = (u8) channel; |
| 1612 | |
| 1613 | IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n", |
| 1614 | channel, s, ch_i1, ch_i2); |
| 1615 | |
| 1616 | for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) { |
| 1617 | for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) { |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1618 | m1 = &(priv->calib_info->band_info[s].ch1. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1619 | measurements[c][m]); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1620 | m2 = &(priv->calib_info->band_info[s].ch2. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1621 | measurements[c][m]); |
| 1622 | omeas = &(chan_info->measurements[c][m]); |
| 1623 | |
| 1624 | omeas->actual_pow = |
| 1625 | (u8) iwl4965_interpolate_value(channel, ch_i1, |
| 1626 | m1->actual_pow, |
| 1627 | ch_i2, |
| 1628 | m2->actual_pow); |
| 1629 | omeas->gain_idx = |
| 1630 | (u8) iwl4965_interpolate_value(channel, ch_i1, |
| 1631 | m1->gain_idx, ch_i2, |
| 1632 | m2->gain_idx); |
| 1633 | omeas->temperature = |
| 1634 | (u8) iwl4965_interpolate_value(channel, ch_i1, |
| 1635 | m1->temperature, |
| 1636 | ch_i2, |
| 1637 | m2->temperature); |
| 1638 | omeas->pa_det = |
| 1639 | (s8) iwl4965_interpolate_value(channel, ch_i1, |
| 1640 | m1->pa_det, ch_i2, |
| 1641 | m2->pa_det); |
| 1642 | |
| 1643 | IWL_DEBUG_TXPOWER |
| 1644 | ("chain %d meas %d AP1=%d AP2=%d AP=%d\n", c, m, |
| 1645 | m1->actual_pow, m2->actual_pow, omeas->actual_pow); |
| 1646 | IWL_DEBUG_TXPOWER |
| 1647 | ("chain %d meas %d NI1=%d NI2=%d NI=%d\n", c, m, |
| 1648 | m1->gain_idx, m2->gain_idx, omeas->gain_idx); |
| 1649 | IWL_DEBUG_TXPOWER |
| 1650 | ("chain %d meas %d PA1=%d PA2=%d PA=%d\n", c, m, |
| 1651 | m1->pa_det, m2->pa_det, omeas->pa_det); |
| 1652 | IWL_DEBUG_TXPOWER |
| 1653 | ("chain %d meas %d T1=%d T2=%d T=%d\n", c, m, |
| 1654 | m1->temperature, m2->temperature, |
| 1655 | omeas->temperature); |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | return 0; |
| 1660 | } |
| 1661 | |
| 1662 | /* bit-rate-dependent table to prevent Tx distortion, in half-dB units, |
| 1663 | * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */ |
| 1664 | static s32 back_off_table[] = { |
| 1665 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */ |
| 1666 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */ |
| 1667 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */ |
| 1668 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */ |
| 1669 | 10 /* CCK */ |
| 1670 | }; |
| 1671 | |
| 1672 | /* Thermal compensation values for txpower for various frequency ranges ... |
| 1673 | * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1674 | static struct iwl4965_txpower_comp_entry { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1675 | s32 degrees_per_05db_a; |
| 1676 | s32 degrees_per_05db_a_denom; |
| 1677 | } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = { |
| 1678 | {9, 2}, /* group 0 5.2, ch 34-43 */ |
| 1679 | {4, 1}, /* group 1 5.2, ch 44-70 */ |
| 1680 | {4, 1}, /* group 2 5.2, ch 71-124 */ |
| 1681 | {4, 1}, /* group 3 5.2, ch 125-200 */ |
| 1682 | {3, 1} /* group 4 2.4, ch all */ |
| 1683 | }; |
| 1684 | |
| 1685 | static s32 get_min_power_index(s32 rate_power_index, u32 band) |
| 1686 | { |
| 1687 | if (!band) { |
| 1688 | if ((rate_power_index & 7) <= 4) |
| 1689 | return MIN_TX_GAIN_INDEX_52GHZ_EXT; |
| 1690 | } |
| 1691 | return MIN_TX_GAIN_INDEX; |
| 1692 | } |
| 1693 | |
| 1694 | struct gain_entry { |
| 1695 | u8 dsp; |
| 1696 | u8 radio; |
| 1697 | }; |
| 1698 | |
| 1699 | static const struct gain_entry gain_table[2][108] = { |
| 1700 | /* 5.2GHz power gain index table */ |
| 1701 | { |
| 1702 | {123, 0x3F}, /* highest txpower */ |
| 1703 | {117, 0x3F}, |
| 1704 | {110, 0x3F}, |
| 1705 | {104, 0x3F}, |
| 1706 | {98, 0x3F}, |
| 1707 | {110, 0x3E}, |
| 1708 | {104, 0x3E}, |
| 1709 | {98, 0x3E}, |
| 1710 | {110, 0x3D}, |
| 1711 | {104, 0x3D}, |
| 1712 | {98, 0x3D}, |
| 1713 | {110, 0x3C}, |
| 1714 | {104, 0x3C}, |
| 1715 | {98, 0x3C}, |
| 1716 | {110, 0x3B}, |
| 1717 | {104, 0x3B}, |
| 1718 | {98, 0x3B}, |
| 1719 | {110, 0x3A}, |
| 1720 | {104, 0x3A}, |
| 1721 | {98, 0x3A}, |
| 1722 | {110, 0x39}, |
| 1723 | {104, 0x39}, |
| 1724 | {98, 0x39}, |
| 1725 | {110, 0x38}, |
| 1726 | {104, 0x38}, |
| 1727 | {98, 0x38}, |
| 1728 | {110, 0x37}, |
| 1729 | {104, 0x37}, |
| 1730 | {98, 0x37}, |
| 1731 | {110, 0x36}, |
| 1732 | {104, 0x36}, |
| 1733 | {98, 0x36}, |
| 1734 | {110, 0x35}, |
| 1735 | {104, 0x35}, |
| 1736 | {98, 0x35}, |
| 1737 | {110, 0x34}, |
| 1738 | {104, 0x34}, |
| 1739 | {98, 0x34}, |
| 1740 | {110, 0x33}, |
| 1741 | {104, 0x33}, |
| 1742 | {98, 0x33}, |
| 1743 | {110, 0x32}, |
| 1744 | {104, 0x32}, |
| 1745 | {98, 0x32}, |
| 1746 | {110, 0x31}, |
| 1747 | {104, 0x31}, |
| 1748 | {98, 0x31}, |
| 1749 | {110, 0x30}, |
| 1750 | {104, 0x30}, |
| 1751 | {98, 0x30}, |
| 1752 | {110, 0x25}, |
| 1753 | {104, 0x25}, |
| 1754 | {98, 0x25}, |
| 1755 | {110, 0x24}, |
| 1756 | {104, 0x24}, |
| 1757 | {98, 0x24}, |
| 1758 | {110, 0x23}, |
| 1759 | {104, 0x23}, |
| 1760 | {98, 0x23}, |
| 1761 | {110, 0x22}, |
| 1762 | {104, 0x18}, |
| 1763 | {98, 0x18}, |
| 1764 | {110, 0x17}, |
| 1765 | {104, 0x17}, |
| 1766 | {98, 0x17}, |
| 1767 | {110, 0x16}, |
| 1768 | {104, 0x16}, |
| 1769 | {98, 0x16}, |
| 1770 | {110, 0x15}, |
| 1771 | {104, 0x15}, |
| 1772 | {98, 0x15}, |
| 1773 | {110, 0x14}, |
| 1774 | {104, 0x14}, |
| 1775 | {98, 0x14}, |
| 1776 | {110, 0x13}, |
| 1777 | {104, 0x13}, |
| 1778 | {98, 0x13}, |
| 1779 | {110, 0x12}, |
| 1780 | {104, 0x08}, |
| 1781 | {98, 0x08}, |
| 1782 | {110, 0x07}, |
| 1783 | {104, 0x07}, |
| 1784 | {98, 0x07}, |
| 1785 | {110, 0x06}, |
| 1786 | {104, 0x06}, |
| 1787 | {98, 0x06}, |
| 1788 | {110, 0x05}, |
| 1789 | {104, 0x05}, |
| 1790 | {98, 0x05}, |
| 1791 | {110, 0x04}, |
| 1792 | {104, 0x04}, |
| 1793 | {98, 0x04}, |
| 1794 | {110, 0x03}, |
| 1795 | {104, 0x03}, |
| 1796 | {98, 0x03}, |
| 1797 | {110, 0x02}, |
| 1798 | {104, 0x02}, |
| 1799 | {98, 0x02}, |
| 1800 | {110, 0x01}, |
| 1801 | {104, 0x01}, |
| 1802 | {98, 0x01}, |
| 1803 | {110, 0x00}, |
| 1804 | {104, 0x00}, |
| 1805 | {98, 0x00}, |
| 1806 | {93, 0x00}, |
| 1807 | {88, 0x00}, |
| 1808 | {83, 0x00}, |
| 1809 | {78, 0x00}, |
| 1810 | }, |
| 1811 | /* 2.4GHz power gain index table */ |
| 1812 | { |
| 1813 | {110, 0x3f}, /* highest txpower */ |
| 1814 | {104, 0x3f}, |
| 1815 | {98, 0x3f}, |
| 1816 | {110, 0x3e}, |
| 1817 | {104, 0x3e}, |
| 1818 | {98, 0x3e}, |
| 1819 | {110, 0x3d}, |
| 1820 | {104, 0x3d}, |
| 1821 | {98, 0x3d}, |
| 1822 | {110, 0x3c}, |
| 1823 | {104, 0x3c}, |
| 1824 | {98, 0x3c}, |
| 1825 | {110, 0x3b}, |
| 1826 | {104, 0x3b}, |
| 1827 | {98, 0x3b}, |
| 1828 | {110, 0x3a}, |
| 1829 | {104, 0x3a}, |
| 1830 | {98, 0x3a}, |
| 1831 | {110, 0x39}, |
| 1832 | {104, 0x39}, |
| 1833 | {98, 0x39}, |
| 1834 | {110, 0x38}, |
| 1835 | {104, 0x38}, |
| 1836 | {98, 0x38}, |
| 1837 | {110, 0x37}, |
| 1838 | {104, 0x37}, |
| 1839 | {98, 0x37}, |
| 1840 | {110, 0x36}, |
| 1841 | {104, 0x36}, |
| 1842 | {98, 0x36}, |
| 1843 | {110, 0x35}, |
| 1844 | {104, 0x35}, |
| 1845 | {98, 0x35}, |
| 1846 | {110, 0x34}, |
| 1847 | {104, 0x34}, |
| 1848 | {98, 0x34}, |
| 1849 | {110, 0x33}, |
| 1850 | {104, 0x33}, |
| 1851 | {98, 0x33}, |
| 1852 | {110, 0x32}, |
| 1853 | {104, 0x32}, |
| 1854 | {98, 0x32}, |
| 1855 | {110, 0x31}, |
| 1856 | {104, 0x31}, |
| 1857 | {98, 0x31}, |
| 1858 | {110, 0x30}, |
| 1859 | {104, 0x30}, |
| 1860 | {98, 0x30}, |
| 1861 | {110, 0x6}, |
| 1862 | {104, 0x6}, |
| 1863 | {98, 0x6}, |
| 1864 | {110, 0x5}, |
| 1865 | {104, 0x5}, |
| 1866 | {98, 0x5}, |
| 1867 | {110, 0x4}, |
| 1868 | {104, 0x4}, |
| 1869 | {98, 0x4}, |
| 1870 | {110, 0x3}, |
| 1871 | {104, 0x3}, |
| 1872 | {98, 0x3}, |
| 1873 | {110, 0x2}, |
| 1874 | {104, 0x2}, |
| 1875 | {98, 0x2}, |
| 1876 | {110, 0x1}, |
| 1877 | {104, 0x1}, |
| 1878 | {98, 0x1}, |
| 1879 | {110, 0x0}, |
| 1880 | {104, 0x0}, |
| 1881 | {98, 0x0}, |
| 1882 | {97, 0}, |
| 1883 | {96, 0}, |
| 1884 | {95, 0}, |
| 1885 | {94, 0}, |
| 1886 | {93, 0}, |
| 1887 | {92, 0}, |
| 1888 | {91, 0}, |
| 1889 | {90, 0}, |
| 1890 | {89, 0}, |
| 1891 | {88, 0}, |
| 1892 | {87, 0}, |
| 1893 | {86, 0}, |
| 1894 | {85, 0}, |
| 1895 | {84, 0}, |
| 1896 | {83, 0}, |
| 1897 | {82, 0}, |
| 1898 | {81, 0}, |
| 1899 | {80, 0}, |
| 1900 | {79, 0}, |
| 1901 | {78, 0}, |
| 1902 | {77, 0}, |
| 1903 | {76, 0}, |
| 1904 | {75, 0}, |
| 1905 | {74, 0}, |
| 1906 | {73, 0}, |
| 1907 | {72, 0}, |
| 1908 | {71, 0}, |
| 1909 | {70, 0}, |
| 1910 | {69, 0}, |
| 1911 | {68, 0}, |
| 1912 | {67, 0}, |
| 1913 | {66, 0}, |
| 1914 | {65, 0}, |
| 1915 | {64, 0}, |
| 1916 | {63, 0}, |
| 1917 | {62, 0}, |
| 1918 | {61, 0}, |
| 1919 | {60, 0}, |
| 1920 | {59, 0}, |
| 1921 | } |
| 1922 | }; |
| 1923 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1924 | static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1925 | u8 is_fat, u8 ctrl_chan_high, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1926 | struct iwl4965_tx_power_db *tx_power_tbl) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1927 | { |
| 1928 | u8 saturation_power; |
| 1929 | s32 target_power; |
| 1930 | s32 user_target_power; |
| 1931 | s32 power_limit; |
| 1932 | s32 current_temp; |
| 1933 | s32 reg_limit; |
| 1934 | s32 current_regulatory; |
| 1935 | s32 txatten_grp = CALIB_CH_GROUP_MAX; |
| 1936 | int i; |
| 1937 | int c; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1938 | const struct iwl_channel_info *ch_info = NULL; |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1939 | struct iwl_eeprom_calib_ch_info ch_eeprom_info; |
| 1940 | const struct iwl_eeprom_calib_measure *measurement; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1941 | s16 voltage; |
| 1942 | s32 init_voltage; |
| 1943 | s32 voltage_compensation; |
| 1944 | s32 degrees_per_05db_num; |
| 1945 | s32 degrees_per_05db_denom; |
| 1946 | s32 factory_temp; |
| 1947 | s32 temperature_comp[2]; |
| 1948 | s32 factory_gain_index[2]; |
| 1949 | s32 factory_actual_pwr[2]; |
| 1950 | s32 power_index; |
| 1951 | |
| 1952 | /* Sanity check requested level (dBm) */ |
| 1953 | if (priv->user_txpower_limit < IWL_TX_POWER_TARGET_POWER_MIN) { |
| 1954 | IWL_WARNING("Requested user TXPOWER %d below limit.\n", |
| 1955 | priv->user_txpower_limit); |
| 1956 | return -EINVAL; |
| 1957 | } |
| 1958 | if (priv->user_txpower_limit > IWL_TX_POWER_TARGET_POWER_MAX) { |
| 1959 | IWL_WARNING("Requested user TXPOWER %d above limit.\n", |
| 1960 | priv->user_txpower_limit); |
| 1961 | return -EINVAL; |
| 1962 | } |
| 1963 | |
| 1964 | /* user_txpower_limit is in dBm, convert to half-dBm (half-dB units |
| 1965 | * are used for indexing into txpower table) */ |
| 1966 | user_target_power = 2 * priv->user_txpower_limit; |
| 1967 | |
| 1968 | /* Get current (RXON) channel, band, width */ |
| 1969 | ch_info = |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1970 | iwl4965_get_channel_txpower_info(priv, priv->band, channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1971 | |
| 1972 | IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band, |
| 1973 | is_fat); |
| 1974 | |
| 1975 | if (!ch_info) |
| 1976 | return -EINVAL; |
| 1977 | |
| 1978 | /* get txatten group, used to select 1) thermal txpower adjustment |
| 1979 | * and 2) mimo txpower balance between Tx chains. */ |
| 1980 | txatten_grp = iwl4965_get_tx_atten_grp(channel); |
| 1981 | if (txatten_grp < 0) |
| 1982 | return -EINVAL; |
| 1983 | |
| 1984 | IWL_DEBUG_TXPOWER("channel %d belongs to txatten group %d\n", |
| 1985 | channel, txatten_grp); |
| 1986 | |
| 1987 | if (is_fat) { |
| 1988 | if (ctrl_chan_high) |
| 1989 | channel -= 2; |
| 1990 | else |
| 1991 | channel += 2; |
| 1992 | } |
| 1993 | |
| 1994 | /* hardware txpower limits ... |
| 1995 | * saturation (clipping distortion) txpowers are in half-dBm */ |
| 1996 | if (band) |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1997 | saturation_power = priv->calib_info->saturation_power24; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1998 | else |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1999 | saturation_power = priv->calib_info->saturation_power52; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2000 | |
| 2001 | if (saturation_power < IWL_TX_POWER_SATURATION_MIN || |
| 2002 | saturation_power > IWL_TX_POWER_SATURATION_MAX) { |
| 2003 | if (band) |
| 2004 | saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_24; |
| 2005 | else |
| 2006 | saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_52; |
| 2007 | } |
| 2008 | |
| 2009 | /* regulatory txpower limits ... reg_limit values are in half-dBm, |
| 2010 | * max_power_avg values are in dBm, convert * 2 */ |
| 2011 | if (is_fat) |
| 2012 | reg_limit = ch_info->fat_max_power_avg * 2; |
| 2013 | else |
| 2014 | reg_limit = ch_info->max_power_avg * 2; |
| 2015 | |
| 2016 | if ((reg_limit < IWL_TX_POWER_REGULATORY_MIN) || |
| 2017 | (reg_limit > IWL_TX_POWER_REGULATORY_MAX)) { |
| 2018 | if (band) |
| 2019 | reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_24; |
| 2020 | else |
| 2021 | reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_52; |
| 2022 | } |
| 2023 | |
| 2024 | /* Interpolate txpower calibration values for this channel, |
| 2025 | * based on factory calibration tests on spaced channels. */ |
| 2026 | iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info); |
| 2027 | |
| 2028 | /* calculate tx gain adjustment based on power supply voltage */ |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 2029 | voltage = priv->calib_info->voltage; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2030 | init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage); |
| 2031 | voltage_compensation = |
| 2032 | iwl4965_get_voltage_compensation(voltage, init_voltage); |
| 2033 | |
| 2034 | IWL_DEBUG_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n", |
| 2035 | init_voltage, |
| 2036 | voltage, voltage_compensation); |
| 2037 | |
| 2038 | /* get current temperature (Celsius) */ |
| 2039 | current_temp = max(priv->temperature, IWL_TX_POWER_TEMPERATURE_MIN); |
| 2040 | current_temp = min(priv->temperature, IWL_TX_POWER_TEMPERATURE_MAX); |
| 2041 | current_temp = KELVIN_TO_CELSIUS(current_temp); |
| 2042 | |
| 2043 | /* select thermal txpower adjustment params, based on channel group |
| 2044 | * (same frequency group used for mimo txatten adjustment) */ |
| 2045 | degrees_per_05db_num = |
| 2046 | tx_power_cmp_tble[txatten_grp].degrees_per_05db_a; |
| 2047 | degrees_per_05db_denom = |
| 2048 | tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom; |
| 2049 | |
| 2050 | /* get per-chain txpower values from factory measurements */ |
| 2051 | for (c = 0; c < 2; c++) { |
| 2052 | measurement = &ch_eeprom_info.measurements[c][1]; |
| 2053 | |
| 2054 | /* txgain adjustment (in half-dB steps) based on difference |
| 2055 | * between factory and current temperature */ |
| 2056 | factory_temp = measurement->temperature; |
| 2057 | iwl4965_math_div_round((current_temp - factory_temp) * |
| 2058 | degrees_per_05db_denom, |
| 2059 | degrees_per_05db_num, |
| 2060 | &temperature_comp[c]); |
| 2061 | |
| 2062 | factory_gain_index[c] = measurement->gain_idx; |
| 2063 | factory_actual_pwr[c] = measurement->actual_pow; |
| 2064 | |
| 2065 | IWL_DEBUG_TXPOWER("chain = %d\n", c); |
| 2066 | IWL_DEBUG_TXPOWER("fctry tmp %d, " |
| 2067 | "curr tmp %d, comp %d steps\n", |
| 2068 | factory_temp, current_temp, |
| 2069 | temperature_comp[c]); |
| 2070 | |
| 2071 | IWL_DEBUG_TXPOWER("fctry idx %d, fctry pwr %d\n", |
| 2072 | factory_gain_index[c], |
| 2073 | factory_actual_pwr[c]); |
| 2074 | } |
| 2075 | |
| 2076 | /* for each of 33 bit-rates (including 1 for CCK) */ |
| 2077 | for (i = 0; i < POWER_TABLE_NUM_ENTRIES; i++) { |
| 2078 | u8 is_mimo_rate; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2079 | union iwl4965_tx_power_dual_stream tx_power; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2080 | |
| 2081 | /* for mimo, reduce each chain's txpower by half |
| 2082 | * (3dB, 6 steps), so total output power is regulatory |
| 2083 | * compliant. */ |
| 2084 | if (i & 0x8) { |
| 2085 | current_regulatory = reg_limit - |
| 2086 | IWL_TX_POWER_MIMO_REGULATORY_COMPENSATION; |
| 2087 | is_mimo_rate = 1; |
| 2088 | } else { |
| 2089 | current_regulatory = reg_limit; |
| 2090 | is_mimo_rate = 0; |
| 2091 | } |
| 2092 | |
| 2093 | /* find txpower limit, either hardware or regulatory */ |
| 2094 | power_limit = saturation_power - back_off_table[i]; |
| 2095 | if (power_limit > current_regulatory) |
| 2096 | power_limit = current_regulatory; |
| 2097 | |
| 2098 | /* reduce user's txpower request if necessary |
| 2099 | * for this rate on this channel */ |
| 2100 | target_power = user_target_power; |
| 2101 | if (target_power > power_limit) |
| 2102 | target_power = power_limit; |
| 2103 | |
| 2104 | IWL_DEBUG_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n", |
| 2105 | i, saturation_power - back_off_table[i], |
| 2106 | current_regulatory, user_target_power, |
| 2107 | target_power); |
| 2108 | |
| 2109 | /* for each of 2 Tx chains (radio transmitters) */ |
| 2110 | for (c = 0; c < 2; c++) { |
| 2111 | s32 atten_value; |
| 2112 | |
| 2113 | if (is_mimo_rate) |
| 2114 | atten_value = |
| 2115 | (s32)le32_to_cpu(priv->card_alive_init. |
| 2116 | tx_atten[txatten_grp][c]); |
| 2117 | else |
| 2118 | atten_value = 0; |
| 2119 | |
| 2120 | /* calculate index; higher index means lower txpower */ |
| 2121 | power_index = (u8) (factory_gain_index[c] - |
| 2122 | (target_power - |
| 2123 | factory_actual_pwr[c]) - |
| 2124 | temperature_comp[c] - |
| 2125 | voltage_compensation + |
| 2126 | atten_value); |
| 2127 | |
| 2128 | /* IWL_DEBUG_TXPOWER("calculated txpower index %d\n", |
| 2129 | power_index); */ |
| 2130 | |
| 2131 | if (power_index < get_min_power_index(i, band)) |
| 2132 | power_index = get_min_power_index(i, band); |
| 2133 | |
| 2134 | /* adjust 5 GHz index to support negative indexes */ |
| 2135 | if (!band) |
| 2136 | power_index += 9; |
| 2137 | |
| 2138 | /* CCK, rate 32, reduce txpower for CCK */ |
| 2139 | if (i == POWER_TABLE_CCK_ENTRY) |
| 2140 | power_index += |
| 2141 | IWL_TX_POWER_CCK_COMPENSATION_C_STEP; |
| 2142 | |
| 2143 | /* stay within the table! */ |
| 2144 | if (power_index > 107) { |
| 2145 | IWL_WARNING("txpower index %d > 107\n", |
| 2146 | power_index); |
| 2147 | power_index = 107; |
| 2148 | } |
| 2149 | if (power_index < 0) { |
| 2150 | IWL_WARNING("txpower index %d < 0\n", |
| 2151 | power_index); |
| 2152 | power_index = 0; |
| 2153 | } |
| 2154 | |
| 2155 | /* fill txpower command for this rate/chain */ |
| 2156 | tx_power.s.radio_tx_gain[c] = |
| 2157 | gain_table[band][power_index].radio; |
| 2158 | tx_power.s.dsp_predis_atten[c] = |
| 2159 | gain_table[band][power_index].dsp; |
| 2160 | |
| 2161 | IWL_DEBUG_TXPOWER("chain %d mimo %d index %d " |
| 2162 | "gain 0x%02x dsp %d\n", |
| 2163 | c, atten_value, power_index, |
| 2164 | tx_power.s.radio_tx_gain[c], |
| 2165 | tx_power.s.dsp_predis_atten[c]); |
| 2166 | }/* for each chain */ |
| 2167 | |
| 2168 | tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw); |
| 2169 | |
| 2170 | }/* for each rate */ |
| 2171 | |
| 2172 | return 0; |
| 2173 | } |
| 2174 | |
| 2175 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2176 | * iwl4965_hw_reg_send_txpower - Configure the TXPOWER level user limit |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2177 | * |
| 2178 | * Uses the active RXON for channel, band, and characteristics (fat, high) |
| 2179 | * The power limit is taken from priv->user_txpower_limit. |
| 2180 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2181 | int iwl4965_hw_reg_send_txpower(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2182 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2183 | struct iwl4965_txpowertable_cmd cmd = { 0 }; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2184 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2185 | u8 band = 0; |
| 2186 | u8 is_fat = 0; |
| 2187 | u8 ctrl_chan_high = 0; |
| 2188 | |
| 2189 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 2190 | /* If this gets hit a lot, switch it to a BUG() and catch |
| 2191 | * the stack trace to find out who is calling this during |
| 2192 | * a scan. */ |
| 2193 | IWL_WARNING("TX Power requested while scanning!\n"); |
| 2194 | return -EAGAIN; |
| 2195 | } |
| 2196 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2197 | band = priv->band == IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2198 | |
| 2199 | is_fat = is_fat_channel(priv->active_rxon.flags); |
| 2200 | |
| 2201 | if (is_fat && |
| 2202 | (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK)) |
| 2203 | ctrl_chan_high = 1; |
| 2204 | |
| 2205 | cmd.band = band; |
| 2206 | cmd.channel = priv->active_rxon.channel; |
| 2207 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2208 | ret = iwl4965_fill_txpower_tbl(priv, band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2209 | le16_to_cpu(priv->active_rxon.channel), |
| 2210 | is_fat, ctrl_chan_high, &cmd.tx_power); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2211 | if (ret) |
| 2212 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2213 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2214 | ret = iwl_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd); |
| 2215 | |
| 2216 | out: |
| 2217 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2218 | } |
| 2219 | |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 2220 | static int iwl4965_send_rxon_assoc(struct iwl_priv *priv) |
| 2221 | { |
| 2222 | int ret = 0; |
| 2223 | struct iwl4965_rxon_assoc_cmd rxon_assoc; |
| 2224 | const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon; |
| 2225 | const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon; |
| 2226 | |
| 2227 | if ((rxon1->flags == rxon2->flags) && |
| 2228 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 2229 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 2230 | (rxon1->ofdm_ht_single_stream_basic_rates == |
| 2231 | rxon2->ofdm_ht_single_stream_basic_rates) && |
| 2232 | (rxon1->ofdm_ht_dual_stream_basic_rates == |
| 2233 | rxon2->ofdm_ht_dual_stream_basic_rates) && |
| 2234 | (rxon1->rx_chain == rxon2->rx_chain) && |
| 2235 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 2236 | IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n"); |
| 2237 | return 0; |
| 2238 | } |
| 2239 | |
| 2240 | rxon_assoc.flags = priv->staging_rxon.flags; |
| 2241 | rxon_assoc.filter_flags = priv->staging_rxon.filter_flags; |
| 2242 | rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates; |
| 2243 | rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates; |
| 2244 | rxon_assoc.reserved = 0; |
| 2245 | rxon_assoc.ofdm_ht_single_stream_basic_rates = |
| 2246 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates; |
| 2247 | rxon_assoc.ofdm_ht_dual_stream_basic_rates = |
| 2248 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates; |
| 2249 | rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain; |
| 2250 | |
| 2251 | ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC, |
| 2252 | sizeof(rxon_assoc), &rxon_assoc, NULL); |
| 2253 | if (ret) |
| 2254 | return ret; |
| 2255 | |
| 2256 | return ret; |
| 2257 | } |
| 2258 | |
| 2259 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2260 | int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2261 | { |
| 2262 | int rc; |
| 2263 | u8 band = 0; |
| 2264 | u8 is_fat = 0; |
| 2265 | u8 ctrl_chan_high = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2266 | struct iwl4965_channel_switch_cmd cmd = { 0 }; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 2267 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2268 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2269 | band = priv->band == IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2270 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 2271 | ch_info = iwl_get_channel_info(priv, priv->band, channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2272 | |
| 2273 | is_fat = is_fat_channel(priv->staging_rxon.flags); |
| 2274 | |
| 2275 | if (is_fat && |
| 2276 | (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK)) |
| 2277 | ctrl_chan_high = 1; |
| 2278 | |
| 2279 | cmd.band = band; |
| 2280 | cmd.expect_beacon = 0; |
| 2281 | cmd.channel = cpu_to_le16(channel); |
| 2282 | cmd.rxon_flags = priv->active_rxon.flags; |
| 2283 | cmd.rxon_filter_flags = priv->active_rxon.filter_flags; |
| 2284 | cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time); |
| 2285 | if (ch_info) |
| 2286 | cmd.expect_beacon = is_channel_radar(ch_info); |
| 2287 | else |
| 2288 | cmd.expect_beacon = 1; |
| 2289 | |
| 2290 | rc = iwl4965_fill_txpower_tbl(priv, band, channel, is_fat, |
| 2291 | ctrl_chan_high, &cmd.tx_power); |
| 2292 | if (rc) { |
| 2293 | IWL_DEBUG_11H("error:%d fill txpower_tbl\n", rc); |
| 2294 | return rc; |
| 2295 | } |
| 2296 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2297 | rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2298 | return rc; |
| 2299 | } |
| 2300 | |
| 2301 | #define RTS_HCCA_RETRY_LIMIT 3 |
| 2302 | #define RTS_DFAULT_RETRY_LIMIT 60 |
| 2303 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2304 | void iwl4965_hw_build_tx_cmd_rate(struct iwl_priv *priv, |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2305 | struct iwl_cmd *cmd, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2306 | struct ieee80211_tx_control *ctrl, |
| 2307 | struct ieee80211_hdr *hdr, int sta_id, |
| 2308 | int is_hcca) |
| 2309 | { |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2310 | struct iwl4965_tx_cmd *tx = &cmd->cmd.tx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2311 | u8 rts_retry_limit = 0; |
| 2312 | u8 data_retry_limit = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2313 | u16 fc = le16_to_cpu(hdr->frame_control); |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2314 | u8 rate_plcp; |
| 2315 | u16 rate_flags = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2316 | int rate_idx = min(ctrl->tx_rate->hw_value & 0xffff, IWL_RATE_COUNT - 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2317 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2318 | rate_plcp = iwl4965_rates[rate_idx].plcp; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2319 | |
| 2320 | rts_retry_limit = (is_hcca) ? |
| 2321 | RTS_HCCA_RETRY_LIMIT : RTS_DFAULT_RETRY_LIMIT; |
| 2322 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2323 | if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE)) |
| 2324 | rate_flags |= RATE_MCS_CCK_MSK; |
| 2325 | |
| 2326 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2327 | if (ieee80211_is_probe_response(fc)) { |
| 2328 | data_retry_limit = 3; |
| 2329 | if (data_retry_limit < rts_retry_limit) |
| 2330 | rts_retry_limit = data_retry_limit; |
| 2331 | } else |
| 2332 | data_retry_limit = IWL_DEFAULT_TX_RETRY; |
| 2333 | |
| 2334 | if (priv->data_retry_limit != -1) |
| 2335 | data_retry_limit = priv->data_retry_limit; |
| 2336 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2337 | |
| 2338 | if (ieee80211_is_data(fc)) { |
| 2339 | tx->initial_rate_index = 0; |
| 2340 | tx->tx_flags |= TX_CMD_FLG_STA_RATE_MSK; |
| 2341 | } else { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2342 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 2343 | case IEEE80211_STYPE_AUTH: |
| 2344 | case IEEE80211_STYPE_DEAUTH: |
| 2345 | case IEEE80211_STYPE_ASSOC_REQ: |
| 2346 | case IEEE80211_STYPE_REASSOC_REQ: |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2347 | if (tx->tx_flags & TX_CMD_FLG_RTS_MSK) { |
| 2348 | tx->tx_flags &= ~TX_CMD_FLG_RTS_MSK; |
| 2349 | tx->tx_flags |= TX_CMD_FLG_CTS_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2350 | } |
| 2351 | break; |
| 2352 | default: |
| 2353 | break; |
| 2354 | } |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2355 | |
| 2356 | /* Alternate between antenna A and B for successive frames */ |
| 2357 | if (priv->use_ant_b_for_management_frame) { |
| 2358 | priv->use_ant_b_for_management_frame = 0; |
| 2359 | rate_flags |= RATE_MCS_ANT_B_MSK; |
| 2360 | } else { |
| 2361 | priv->use_ant_b_for_management_frame = 1; |
| 2362 | rate_flags |= RATE_MCS_ANT_A_MSK; |
| 2363 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
Tomas Winkler | 87e4f7d | 2008-01-14 17:46:16 -0800 | [diff] [blame] | 2366 | tx->rts_retry_limit = rts_retry_limit; |
| 2367 | tx->data_retry_limit = data_retry_limit; |
| 2368 | tx->rate_n_flags = iwl4965_hw_set_rate_n_flags(rate_plcp, rate_flags); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2369 | } |
| 2370 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2371 | int iwl4965_hw_get_rx_read(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2372 | { |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 2373 | struct iwl4965_shared *s = priv->shared_virt; |
| 2374 | return le32_to_cpu(s->rb_closed) & 0xFFF; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2375 | } |
| 2376 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2377 | int iwl4965_hw_get_temperature(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2378 | { |
| 2379 | return priv->temperature; |
| 2380 | } |
| 2381 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2382 | unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2383 | struct iwl4965_frame *frame, u8 rate) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2384 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2385 | struct iwl4965_tx_beacon_cmd *tx_beacon_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2386 | unsigned int frame_size; |
| 2387 | |
| 2388 | tx_beacon_cmd = &frame->u.beacon; |
| 2389 | memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd)); |
| 2390 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 2391 | tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2392 | tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 2393 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2394 | frame_size = iwl4965_fill_beacon_frame(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2395 | tx_beacon_cmd->frame, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2396 | iwl4965_broadcast_addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2397 | sizeof(frame->u) - sizeof(*tx_beacon_cmd)); |
| 2398 | |
| 2399 | BUG_ON(frame_size > MAX_MPDU_SIZE); |
| 2400 | tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size); |
| 2401 | |
| 2402 | if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP)) |
| 2403 | tx_beacon_cmd->tx.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2404 | iwl4965_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2405 | else |
| 2406 | tx_beacon_cmd->tx.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2407 | iwl4965_hw_set_rate_n_flags(rate, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2408 | |
| 2409 | tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK | |
| 2410 | TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK); |
| 2411 | return (sizeof(*tx_beacon_cmd) + frame_size); |
| 2412 | } |
| 2413 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2414 | /* |
| 2415 | * Tell 4965 where to find circular buffer of Tx Frame Descriptors for |
| 2416 | * given Tx queue, and enable the DMA channel used for that queue. |
| 2417 | * |
| 2418 | * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA |
| 2419 | * channels supported in hardware. |
| 2420 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2421 | int iwl4965_hw_tx_queue_init(struct iwl_priv *priv, struct iwl4965_tx_queue *txq) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2422 | { |
| 2423 | int rc; |
| 2424 | unsigned long flags; |
| 2425 | int txq_id = txq->q.id; |
| 2426 | |
| 2427 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2428 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2429 | if (rc) { |
| 2430 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2431 | return rc; |
| 2432 | } |
| 2433 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2434 | /* Circular buffer (TFD queue in DRAM) physical base address */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2435 | iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2436 | txq->q.dma_addr >> 8); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2437 | |
| 2438 | /* Enable DMA channel, using same id as for TFD queue */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2439 | iwl_write_direct32( |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2440 | priv, IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), |
| 2441 | IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE | |
| 2442 | IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2443 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2444 | spin_unlock_irqrestore(&priv->lock, flags); |
| 2445 | |
| 2446 | return 0; |
| 2447 | } |
| 2448 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2449 | int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2450 | dma_addr_t addr, u16 len) |
| 2451 | { |
| 2452 | int index, is_odd; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2453 | struct iwl4965_tfd_frame *tfd = ptr; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2454 | u32 num_tbs = IWL_GET_BITS(*tfd, num_tbs); |
| 2455 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2456 | /* Each TFD can point to a maximum 20 Tx buffers */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2457 | if ((num_tbs >= MAX_NUM_OF_TBS) || (num_tbs < 0)) { |
| 2458 | IWL_ERROR("Error can not send more than %d chunks\n", |
| 2459 | MAX_NUM_OF_TBS); |
| 2460 | return -EINVAL; |
| 2461 | } |
| 2462 | |
| 2463 | index = num_tbs / 2; |
| 2464 | is_odd = num_tbs & 0x1; |
| 2465 | |
| 2466 | if (!is_odd) { |
| 2467 | tfd->pa[index].tb1_addr = cpu_to_le32(addr); |
| 2468 | IWL_SET_BITS(tfd->pa[index], tb1_addr_hi, |
Tomas Winkler | 6a218f6 | 2008-01-14 17:46:15 -0800 | [diff] [blame] | 2469 | iwl_get_dma_hi_address(addr)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2470 | IWL_SET_BITS(tfd->pa[index], tb1_len, len); |
| 2471 | } else { |
| 2472 | IWL_SET_BITS(tfd->pa[index], tb2_addr_lo16, |
| 2473 | (u32) (addr & 0xffff)); |
| 2474 | IWL_SET_BITS(tfd->pa[index], tb2_addr_hi20, addr >> 16); |
| 2475 | IWL_SET_BITS(tfd->pa[index], tb2_len, len); |
| 2476 | } |
| 2477 | |
| 2478 | IWL_SET_BITS(*tfd, num_tbs, num_tbs + 1); |
| 2479 | |
| 2480 | return 0; |
| 2481 | } |
| 2482 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2483 | static void iwl4965_hw_card_show_info(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2484 | { |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 2485 | u16 hw_version = iwl_eeprom_query16(priv, EEPROM_4965_BOARD_REVISION); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2486 | |
| 2487 | IWL_DEBUG_INFO("4965ABGN HW Version %u.%u.%u\n", |
| 2488 | ((hw_version >> 8) & 0x0F), |
| 2489 | ((hw_version >> 8) >> 4), (hw_version & 0x00FF)); |
| 2490 | |
| 2491 | IWL_DEBUG_INFO("4965ABGN PBA Number %.16s\n", |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 2492 | &priv->eeprom[EEPROM_4965_BOARD_PBA]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2493 | } |
| 2494 | |
| 2495 | #define IWL_TX_CRC_SIZE 4 |
| 2496 | #define IWL_TX_DELIMITER_SIZE 4 |
| 2497 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2498 | /** |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 2499 | * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2500 | */ |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 2501 | static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv, |
| 2502 | struct iwl4965_tx_queue *txq, |
| 2503 | u16 byte_cnt) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2504 | { |
| 2505 | int len; |
| 2506 | int txq_id = txq->q.id; |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 2507 | struct iwl4965_shared *shared_data = priv->shared_virt; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2508 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2509 | len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE; |
| 2510 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2511 | /* Set up byte count within first 256 entries */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2512 | IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id]. |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2513 | tfd_offset[txq->q.write_ptr], byte_cnt, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2514 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2515 | /* If within first 64 entries, duplicate at end */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2516 | if (txq->q.write_ptr < IWL4965_MAX_WIN_SIZE) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2517 | IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id]. |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 2518 | tfd_offset[IWL4965_QUEUE_SIZE + txq->q.write_ptr], |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2519 | byte_cnt, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2522 | /** |
| 2523 | * iwl4965_set_rxon_chain - Set up Rx chain usage in "staging" RXON image |
| 2524 | * |
| 2525 | * Selects how many and which Rx receivers/antennas/chains to use. |
| 2526 | * This should not be used for scan command ... it puts data in wrong place. |
| 2527 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2528 | void iwl4965_set_rxon_chain(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2529 | { |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 2530 | u8 is_single = is_single_rx_stream(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2531 | u8 idle_state, rx_state; |
| 2532 | |
| 2533 | priv->staging_rxon.rx_chain = 0; |
| 2534 | rx_state = idle_state = 3; |
| 2535 | |
| 2536 | /* Tell uCode which antennas are actually connected. |
| 2537 | * Before first association, we assume all antennas are connected. |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 2538 | * Just after first association, iwl_chain_noise_calibration() |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2539 | * checks which antennas actually *are* connected. */ |
| 2540 | priv->staging_rxon.rx_chain |= |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 2541 | cpu_to_le16(priv->hw_params.valid_rx_ant << |
| 2542 | RXON_RX_CHAIN_VALID_POS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2543 | |
| 2544 | /* How many receivers should we use? */ |
| 2545 | iwl4965_get_rx_chain_counter(priv, &idle_state, &rx_state); |
| 2546 | priv->staging_rxon.rx_chain |= |
| 2547 | cpu_to_le16(rx_state << RXON_RX_CHAIN_MIMO_CNT_POS); |
| 2548 | priv->staging_rxon.rx_chain |= |
| 2549 | cpu_to_le16(idle_state << RXON_RX_CHAIN_CNT_POS); |
| 2550 | |
| 2551 | if (!is_single && (rx_state >= 2) && |
| 2552 | !test_bit(STATUS_POWER_PMI, &priv->status)) |
| 2553 | priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK; |
| 2554 | else |
| 2555 | priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK; |
| 2556 | |
| 2557 | IWL_DEBUG_ASSOC("rx chain %X\n", priv->staging_rxon.rx_chain); |
| 2558 | } |
| 2559 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2560 | /** |
| 2561 | * sign_extend - Sign extend a value using specified bit as sign-bit |
| 2562 | * |
| 2563 | * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1 |
| 2564 | * and bit0..2 is 001b which when sign extended to 1111111111111001b is -7. |
| 2565 | * |
| 2566 | * @param oper value to sign extend |
| 2567 | * @param index 0 based bit index (0<=index<32) to sign bit |
| 2568 | */ |
| 2569 | static s32 sign_extend(u32 oper, int index) |
| 2570 | { |
| 2571 | u8 shift = 31 - index; |
| 2572 | |
| 2573 | return (s32)(oper << shift) >> shift; |
| 2574 | } |
| 2575 | |
| 2576 | /** |
| 2577 | * iwl4965_get_temperature - return the calibrated temperature (in Kelvin) |
| 2578 | * @statistics: Provides the temperature reading from the uCode |
| 2579 | * |
| 2580 | * A return of <0 indicates bogus data in the statistics |
| 2581 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2582 | int iwl4965_get_temperature(const struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2583 | { |
| 2584 | s32 temperature; |
| 2585 | s32 vt; |
| 2586 | s32 R1, R2, R3; |
| 2587 | u32 R4; |
| 2588 | |
| 2589 | if (test_bit(STATUS_TEMPERATURE, &priv->status) && |
| 2590 | (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)) { |
| 2591 | IWL_DEBUG_TEMP("Running FAT temperature calibration\n"); |
| 2592 | R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]); |
| 2593 | R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]); |
| 2594 | R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]); |
| 2595 | R4 = le32_to_cpu(priv->card_alive_init.therm_r4[1]); |
| 2596 | } else { |
| 2597 | IWL_DEBUG_TEMP("Running temperature calibration\n"); |
| 2598 | R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]); |
| 2599 | R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]); |
| 2600 | R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]); |
| 2601 | R4 = le32_to_cpu(priv->card_alive_init.therm_r4[0]); |
| 2602 | } |
| 2603 | |
| 2604 | /* |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2605 | * Temperature is only 23 bits, so sign extend out to 32. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2606 | * |
| 2607 | * NOTE If we haven't received a statistics notification yet |
| 2608 | * with an updated temperature, use R4 provided to us in the |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2609 | * "initialize" ALIVE response. |
| 2610 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2611 | if (!test_bit(STATUS_TEMPERATURE, &priv->status)) |
| 2612 | vt = sign_extend(R4, 23); |
| 2613 | else |
| 2614 | vt = sign_extend( |
| 2615 | le32_to_cpu(priv->statistics.general.temperature), 23); |
| 2616 | |
| 2617 | IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n", |
| 2618 | R1, R2, R3, vt); |
| 2619 | |
| 2620 | if (R3 == R1) { |
| 2621 | IWL_ERROR("Calibration conflict R1 == R3\n"); |
| 2622 | return -1; |
| 2623 | } |
| 2624 | |
| 2625 | /* Calculate temperature in degrees Kelvin, adjust by 97%. |
| 2626 | * Add offset to center the adjustment around 0 degrees Centigrade. */ |
| 2627 | temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2); |
| 2628 | temperature /= (R3 - R1); |
| 2629 | temperature = (temperature * 97) / 100 + |
| 2630 | TEMPERATURE_CALIB_KELVIN_OFFSET; |
| 2631 | |
| 2632 | IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n", temperature, |
| 2633 | KELVIN_TO_CELSIUS(temperature)); |
| 2634 | |
| 2635 | return temperature; |
| 2636 | } |
| 2637 | |
| 2638 | /* Adjust Txpower only if temperature variance is greater than threshold. */ |
| 2639 | #define IWL_TEMPERATURE_THRESHOLD 3 |
| 2640 | |
| 2641 | /** |
| 2642 | * iwl4965_is_temp_calib_needed - determines if new calibration is needed |
| 2643 | * |
| 2644 | * If the temperature changed has changed sufficiently, then a recalibration |
| 2645 | * is needed. |
| 2646 | * |
| 2647 | * Assumes caller will replace priv->last_temperature once calibration |
| 2648 | * executed. |
| 2649 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2650 | static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2651 | { |
| 2652 | int temp_diff; |
| 2653 | |
| 2654 | if (!test_bit(STATUS_STATISTICS, &priv->status)) { |
| 2655 | IWL_DEBUG_TEMP("Temperature not updated -- no statistics.\n"); |
| 2656 | return 0; |
| 2657 | } |
| 2658 | |
| 2659 | temp_diff = priv->temperature - priv->last_temperature; |
| 2660 | |
| 2661 | /* get absolute value */ |
| 2662 | if (temp_diff < 0) { |
| 2663 | IWL_DEBUG_POWER("Getting cooler, delta %d, \n", temp_diff); |
| 2664 | temp_diff = -temp_diff; |
| 2665 | } else if (temp_diff == 0) |
| 2666 | IWL_DEBUG_POWER("Same temp, \n"); |
| 2667 | else |
| 2668 | IWL_DEBUG_POWER("Getting warmer, delta %d, \n", temp_diff); |
| 2669 | |
| 2670 | if (temp_diff < IWL_TEMPERATURE_THRESHOLD) { |
| 2671 | IWL_DEBUG_POWER("Thermal txpower calib not needed\n"); |
| 2672 | return 0; |
| 2673 | } |
| 2674 | |
| 2675 | IWL_DEBUG_POWER("Thermal txpower calib needed\n"); |
| 2676 | |
| 2677 | return 1; |
| 2678 | } |
| 2679 | |
| 2680 | /* Calculate noise level, based on measurements during network silence just |
| 2681 | * before arriving beacon. This measurement can be done only if we know |
| 2682 | * exactly when to expect beacons, therefore only when we're associated. */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2683 | static void iwl4965_rx_calc_noise(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2684 | { |
| 2685 | struct statistics_rx_non_phy *rx_info |
| 2686 | = &(priv->statistics.rx.general); |
| 2687 | int num_active_rx = 0; |
| 2688 | int total_silence = 0; |
| 2689 | int bcn_silence_a = |
| 2690 | le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER; |
| 2691 | int bcn_silence_b = |
| 2692 | le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER; |
| 2693 | int bcn_silence_c = |
| 2694 | le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER; |
| 2695 | |
| 2696 | if (bcn_silence_a) { |
| 2697 | total_silence += bcn_silence_a; |
| 2698 | num_active_rx++; |
| 2699 | } |
| 2700 | if (bcn_silence_b) { |
| 2701 | total_silence += bcn_silence_b; |
| 2702 | num_active_rx++; |
| 2703 | } |
| 2704 | if (bcn_silence_c) { |
| 2705 | total_silence += bcn_silence_c; |
| 2706 | num_active_rx++; |
| 2707 | } |
| 2708 | |
| 2709 | /* Average among active antennas */ |
| 2710 | if (num_active_rx) |
| 2711 | priv->last_rx_noise = (total_silence / num_active_rx) - 107; |
| 2712 | else |
| 2713 | priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE; |
| 2714 | |
| 2715 | IWL_DEBUG_CALIB("inband silence a %u, b %u, c %u, dBm %d\n", |
| 2716 | bcn_silence_a, bcn_silence_b, bcn_silence_c, |
| 2717 | priv->last_rx_noise); |
| 2718 | } |
| 2719 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2720 | void iwl4965_hw_rx_statistics(struct iwl_priv *priv, struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2721 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2722 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2723 | int change; |
| 2724 | s32 temp; |
| 2725 | |
| 2726 | IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n", |
| 2727 | (int)sizeof(priv->statistics), pkt->len); |
| 2728 | |
| 2729 | change = ((priv->statistics.general.temperature != |
| 2730 | pkt->u.stats.general.temperature) || |
| 2731 | ((priv->statistics.flag & |
| 2732 | STATISTICS_REPLY_FLG_FAT_MODE_MSK) != |
| 2733 | (pkt->u.stats.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK))); |
| 2734 | |
| 2735 | memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics)); |
| 2736 | |
| 2737 | set_bit(STATUS_STATISTICS, &priv->status); |
| 2738 | |
| 2739 | /* Reschedule the statistics timer to occur in |
| 2740 | * REG_RECALIB_PERIOD seconds to ensure we get a |
| 2741 | * thermal update even if the uCode doesn't give |
| 2742 | * us one */ |
| 2743 | mod_timer(&priv->statistics_periodic, jiffies + |
| 2744 | msecs_to_jiffies(REG_RECALIB_PERIOD * 1000)); |
| 2745 | |
| 2746 | if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) && |
| 2747 | (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) { |
| 2748 | iwl4965_rx_calc_noise(priv); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 2749 | #ifdef CONFIG_IWL4965_RUN_TIME_CALIB |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2750 | queue_work(priv->workqueue, &priv->sensitivity_work); |
| 2751 | #endif |
| 2752 | } |
| 2753 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2754 | iwl_leds_background(priv); |
| 2755 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2756 | /* If the hardware hasn't reported a change in |
| 2757 | * temperature then don't bother computing a |
| 2758 | * calibrated temperature value */ |
| 2759 | if (!change) |
| 2760 | return; |
| 2761 | |
| 2762 | temp = iwl4965_get_temperature(priv); |
| 2763 | if (temp < 0) |
| 2764 | return; |
| 2765 | |
| 2766 | if (priv->temperature != temp) { |
| 2767 | if (priv->temperature) |
| 2768 | IWL_DEBUG_TEMP("Temperature changed " |
| 2769 | "from %dC to %dC\n", |
| 2770 | KELVIN_TO_CELSIUS(priv->temperature), |
| 2771 | KELVIN_TO_CELSIUS(temp)); |
| 2772 | else |
| 2773 | IWL_DEBUG_TEMP("Temperature " |
| 2774 | "initialized to %dC\n", |
| 2775 | KELVIN_TO_CELSIUS(temp)); |
| 2776 | } |
| 2777 | |
| 2778 | priv->temperature = temp; |
| 2779 | set_bit(STATUS_TEMPERATURE, &priv->status); |
| 2780 | |
| 2781 | if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) && |
| 2782 | iwl4965_is_temp_calib_needed(priv)) |
| 2783 | queue_work(priv->workqueue, &priv->txpower_work); |
| 2784 | } |
| 2785 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2786 | static void iwl4965_add_radiotap(struct iwl_priv *priv, |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2787 | struct sk_buff *skb, |
| 2788 | struct iwl4965_rx_phy_res *rx_start, |
| 2789 | struct ieee80211_rx_status *stats, |
| 2790 | u32 ampdu_status) |
| 2791 | { |
| 2792 | s8 signal = stats->ssi; |
| 2793 | s8 noise = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2794 | int rate = stats->rate_idx; |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2795 | u64 tsf = stats->mactime; |
Johannes Berg | a0b484f | 2008-04-01 17:51:47 +0200 | [diff] [blame] | 2796 | __le16 antenna; |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2797 | __le16 phy_flags_hw = rx_start->phy_flags; |
| 2798 | struct iwl4965_rt_rx_hdr { |
| 2799 | struct ieee80211_radiotap_header rt_hdr; |
| 2800 | __le64 rt_tsf; /* TSF */ |
| 2801 | u8 rt_flags; /* radiotap packet flags */ |
| 2802 | u8 rt_rate; /* rate in 500kb/s */ |
| 2803 | __le16 rt_channelMHz; /* channel in MHz */ |
| 2804 | __le16 rt_chbitmask; /* channel bitfield */ |
| 2805 | s8 rt_dbmsignal; /* signal in dBm, kluged to signed */ |
| 2806 | s8 rt_dbmnoise; |
| 2807 | u8 rt_antenna; /* antenna number */ |
| 2808 | } __attribute__ ((packed)) *iwl4965_rt; |
| 2809 | |
| 2810 | /* TODO: We won't have enough headroom for HT frames. Fix it later. */ |
| 2811 | if (skb_headroom(skb) < sizeof(*iwl4965_rt)) { |
| 2812 | if (net_ratelimit()) |
| 2813 | printk(KERN_ERR "not enough headroom [%d] for " |
Miguel Botón | 01c2098 | 2008-01-04 23:34:35 +0100 | [diff] [blame] | 2814 | "radiotap head [%zd]\n", |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2815 | skb_headroom(skb), sizeof(*iwl4965_rt)); |
| 2816 | return; |
| 2817 | } |
| 2818 | |
| 2819 | /* put radiotap header in front of 802.11 header and data */ |
| 2820 | iwl4965_rt = (void *)skb_push(skb, sizeof(*iwl4965_rt)); |
| 2821 | |
| 2822 | /* initialise radiotap header */ |
| 2823 | iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 2824 | iwl4965_rt->rt_hdr.it_pad = 0; |
| 2825 | |
| 2826 | /* total header + data */ |
| 2827 | put_unaligned(cpu_to_le16(sizeof(*iwl4965_rt)), |
| 2828 | &iwl4965_rt->rt_hdr.it_len); |
| 2829 | |
| 2830 | /* Indicate all the fields we add to the radiotap header */ |
| 2831 | put_unaligned(cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) | |
| 2832 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
| 2833 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 2834 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 2835 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
| 2836 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
| 2837 | (1 << IEEE80211_RADIOTAP_ANTENNA)), |
| 2838 | &iwl4965_rt->rt_hdr.it_present); |
| 2839 | |
| 2840 | /* Zero the flags, we'll add to them as we go */ |
| 2841 | iwl4965_rt->rt_flags = 0; |
| 2842 | |
| 2843 | put_unaligned(cpu_to_le64(tsf), &iwl4965_rt->rt_tsf); |
| 2844 | |
| 2845 | iwl4965_rt->rt_dbmsignal = signal; |
| 2846 | iwl4965_rt->rt_dbmnoise = noise; |
| 2847 | |
| 2848 | /* Convert the channel frequency and set the flags */ |
| 2849 | put_unaligned(cpu_to_le16(stats->freq), &iwl4965_rt->rt_channelMHz); |
| 2850 | if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK)) |
| 2851 | put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 2852 | IEEE80211_CHAN_5GHZ), |
| 2853 | &iwl4965_rt->rt_chbitmask); |
| 2854 | else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK) |
| 2855 | put_unaligned(cpu_to_le16(IEEE80211_CHAN_CCK | |
| 2856 | IEEE80211_CHAN_2GHZ), |
| 2857 | &iwl4965_rt->rt_chbitmask); |
| 2858 | else /* 802.11g */ |
| 2859 | put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 2860 | IEEE80211_CHAN_2GHZ), |
| 2861 | &iwl4965_rt->rt_chbitmask); |
| 2862 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2863 | if (rate == -1) |
| 2864 | iwl4965_rt->rt_rate = 0; |
| 2865 | else |
| 2866 | iwl4965_rt->rt_rate = iwl4965_rates[rate].ieee; |
| 2867 | |
| 2868 | /* |
| 2869 | * "antenna number" |
| 2870 | * |
| 2871 | * It seems that the antenna field in the phy flags value |
| 2872 | * is actually a bitfield. This is undefined by radiotap, |
| 2873 | * it wants an actual antenna number but I always get "7" |
| 2874 | * for most legacy frames I receive indicating that the |
| 2875 | * same frame was received on all three RX chains. |
| 2876 | * |
| 2877 | * I think this field should be removed in favour of a |
| 2878 | * new 802.11n radiotap field "RX chains" that is defined |
| 2879 | * as a bitmask. |
| 2880 | */ |
Johannes Berg | a0b484f | 2008-04-01 17:51:47 +0200 | [diff] [blame] | 2881 | antenna = phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK; |
| 2882 | iwl4965_rt->rt_antenna = le16_to_cpu(antenna) >> 4; |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2883 | |
| 2884 | /* set the preamble flag if appropriate */ |
| 2885 | if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) |
| 2886 | iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 2887 | |
| 2888 | stats->flag |= RX_FLAG_RADIOTAP; |
| 2889 | } |
| 2890 | |
Tomas Winkler | 19758be | 2008-03-12 16:58:51 -0700 | [diff] [blame] | 2891 | static void iwl_update_rx_stats(struct iwl_priv *priv, u16 fc, u16 len) |
| 2892 | { |
| 2893 | /* 0 - mgmt, 1 - cnt, 2 - data */ |
| 2894 | int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2; |
| 2895 | priv->rx_stats[idx].cnt++; |
| 2896 | priv->rx_stats[idx].bytes += len; |
| 2897 | } |
| 2898 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 2899 | /* |
| 2900 | * returns non-zero if packet should be dropped |
| 2901 | */ |
| 2902 | static int iwl4965_set_decrypted_flag(struct iwl_priv *priv, |
| 2903 | struct ieee80211_hdr *hdr, |
| 2904 | u32 decrypt_res, |
| 2905 | struct ieee80211_rx_status *stats) |
| 2906 | { |
| 2907 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2908 | |
| 2909 | if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
| 2910 | return 0; |
| 2911 | |
| 2912 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 2913 | return 0; |
| 2914 | |
| 2915 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 2916 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 2917 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 2918 | /* The uCode has got a bad phase 1 Key, pushes the packet. |
| 2919 | * Decryption will be done in SW. */ |
| 2920 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2921 | RX_RES_STATUS_BAD_KEY_TTAK) |
| 2922 | break; |
| 2923 | |
| 2924 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2925 | RX_RES_STATUS_BAD_ICV_MIC) { |
| 2926 | /* bad ICV, the packet is destroyed since the |
| 2927 | * decryption is inplace, drop it */ |
| 2928 | IWL_DEBUG_RX("Packet destroyed\n"); |
| 2929 | return -1; |
| 2930 | } |
| 2931 | case RX_RES_STATUS_SEC_TYPE_WEP: |
| 2932 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 2933 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2934 | RX_RES_STATUS_DECRYPT_OK) { |
| 2935 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 2936 | stats->flag |= RX_FLAG_DECRYPTED; |
| 2937 | } |
| 2938 | break; |
| 2939 | |
| 2940 | default: |
| 2941 | break; |
| 2942 | } |
| 2943 | return 0; |
| 2944 | } |
| 2945 | |
Emmanuel Grumbach | 17e476b | 2008-03-19 16:41:42 -0700 | [diff] [blame] | 2946 | static u32 iwl4965_translate_rx_status(u32 decrypt_in) |
| 2947 | { |
| 2948 | u32 decrypt_out = 0; |
| 2949 | |
| 2950 | if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) == |
| 2951 | RX_RES_STATUS_STATION_FOUND) |
| 2952 | decrypt_out |= (RX_RES_STATUS_STATION_FOUND | |
| 2953 | RX_RES_STATUS_NO_STATION_INFO_MISMATCH); |
| 2954 | |
| 2955 | decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK); |
| 2956 | |
| 2957 | /* packet was not encrypted */ |
| 2958 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == |
| 2959 | RX_RES_STATUS_SEC_TYPE_NONE) |
| 2960 | return decrypt_out; |
| 2961 | |
| 2962 | /* packet was encrypted with unknown alg */ |
| 2963 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == |
| 2964 | RX_RES_STATUS_SEC_TYPE_ERR) |
| 2965 | return decrypt_out; |
| 2966 | |
| 2967 | /* decryption was not done in HW */ |
| 2968 | if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) != |
| 2969 | RX_MPDU_RES_STATUS_DEC_DONE_MSK) |
| 2970 | return decrypt_out; |
| 2971 | |
| 2972 | switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 2973 | |
| 2974 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 2975 | /* alg is CCM: check MIC only */ |
| 2976 | if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK)) |
| 2977 | /* Bad MIC */ |
| 2978 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; |
| 2979 | else |
| 2980 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; |
| 2981 | |
| 2982 | break; |
| 2983 | |
| 2984 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 2985 | if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) { |
| 2986 | /* Bad TTAK */ |
| 2987 | decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK; |
| 2988 | break; |
| 2989 | } |
| 2990 | /* fall through if TTAK OK */ |
| 2991 | default: |
| 2992 | if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK)) |
| 2993 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; |
| 2994 | else |
| 2995 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; |
| 2996 | break; |
| 2997 | }; |
| 2998 | |
| 2999 | IWL_DEBUG_RX("decrypt_in:0x%x decrypt_out = 0x%x\n", |
| 3000 | decrypt_in, decrypt_out); |
| 3001 | |
| 3002 | return decrypt_out; |
| 3003 | } |
| 3004 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3005 | static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3006 | int include_phy, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3007 | struct iwl4965_rx_mem_buffer *rxb, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3008 | struct ieee80211_rx_status *stats) |
| 3009 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3010 | struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3011 | struct iwl4965_rx_phy_res *rx_start = (include_phy) ? |
| 3012 | (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : NULL; |
| 3013 | struct ieee80211_hdr *hdr; |
| 3014 | u16 len; |
| 3015 | __le32 *rx_end; |
| 3016 | unsigned int skblen; |
| 3017 | u32 ampdu_status; |
Emmanuel Grumbach | 17e476b | 2008-03-19 16:41:42 -0700 | [diff] [blame] | 3018 | u32 ampdu_status_legacy; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3019 | |
| 3020 | if (!include_phy && priv->last_phy_res[0]) |
| 3021 | rx_start = (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1]; |
| 3022 | |
| 3023 | if (!rx_start) { |
| 3024 | IWL_ERROR("MPDU frame without a PHY data\n"); |
| 3025 | return; |
| 3026 | } |
| 3027 | if (include_phy) { |
| 3028 | hdr = (struct ieee80211_hdr *)((u8 *) & rx_start[1] + |
| 3029 | rx_start->cfg_phy_cnt); |
| 3030 | |
| 3031 | len = le16_to_cpu(rx_start->byte_count); |
| 3032 | |
| 3033 | rx_end = (__le32 *) ((u8 *) & pkt->u.raw[0] + |
| 3034 | sizeof(struct iwl4965_rx_phy_res) + |
| 3035 | rx_start->cfg_phy_cnt + len); |
| 3036 | |
| 3037 | } else { |
| 3038 | struct iwl4965_rx_mpdu_res_start *amsdu = |
| 3039 | (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw; |
| 3040 | |
| 3041 | hdr = (struct ieee80211_hdr *)(pkt->u.raw + |
| 3042 | sizeof(struct iwl4965_rx_mpdu_res_start)); |
| 3043 | len = le16_to_cpu(amsdu->byte_count); |
| 3044 | rx_start->byte_count = amsdu->byte_count; |
| 3045 | rx_end = (__le32 *) (((u8 *) hdr) + len); |
| 3046 | } |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3047 | if (len > priv->hw_params.max_pkt_size || len < 16) { |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 3048 | IWL_WARNING("byte count out of range [16,4K] : %d\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3049 | return; |
| 3050 | } |
| 3051 | |
| 3052 | ampdu_status = le32_to_cpu(*rx_end); |
| 3053 | skblen = ((u8 *) rx_end - (u8 *) & pkt->u.raw[0]) + sizeof(u32); |
| 3054 | |
Emmanuel Grumbach | 17e476b | 2008-03-19 16:41:42 -0700 | [diff] [blame] | 3055 | if (!include_phy) { |
| 3056 | /* New status scheme, need to translate */ |
| 3057 | ampdu_status_legacy = ampdu_status; |
| 3058 | ampdu_status = iwl4965_translate_rx_status(ampdu_status); |
| 3059 | } |
| 3060 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3061 | /* start from MAC */ |
| 3062 | skb_reserve(rxb->skb, (void *)hdr - (void *)pkt); |
| 3063 | skb_put(rxb->skb, len); /* end where data ends */ |
| 3064 | |
| 3065 | /* We only process data packets if the interface is open */ |
| 3066 | if (unlikely(!priv->is_open)) { |
| 3067 | IWL_DEBUG_DROP_LIMIT |
| 3068 | ("Dropping packet while interface is not open.\n"); |
| 3069 | return; |
| 3070 | } |
| 3071 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3072 | stats->flag = 0; |
| 3073 | hdr = (struct ieee80211_hdr *)rxb->skb->data; |
| 3074 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 3075 | /* in case of HW accelerated crypto and bad decryption, drop */ |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 3076 | if (!priv->hw_params.sw_crypto && |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 3077 | iwl4965_set_decrypted_flag(priv, hdr, ampdu_status, stats)) |
| 3078 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3079 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 3080 | if (priv->add_radiotap) |
| 3081 | iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status); |
| 3082 | |
Tomas Winkler | 19758be | 2008-03-12 16:58:51 -0700 | [diff] [blame] | 3083 | iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3084 | ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats); |
| 3085 | priv->alloc_rxb_skb--; |
| 3086 | rxb->skb = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3087 | } |
| 3088 | |
| 3089 | /* Calc max signal level (dBm) among 3 possible receivers */ |
| 3090 | static int iwl4965_calc_rssi(struct iwl4965_rx_phy_res *rx_resp) |
| 3091 | { |
| 3092 | /* data from PHY/DSP regarding signal strength, etc., |
| 3093 | * contents are always there, not configurable by host. */ |
| 3094 | struct iwl4965_rx_non_cfg_phy *ncphy = |
| 3095 | (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy; |
| 3096 | u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL_AGC_DB_MASK) |
| 3097 | >> IWL_AGC_DB_POS; |
| 3098 | |
| 3099 | u32 valid_antennae = |
| 3100 | (le16_to_cpu(rx_resp->phy_flags) & RX_PHY_FLAGS_ANTENNAE_MASK) |
| 3101 | >> RX_PHY_FLAGS_ANTENNAE_OFFSET; |
| 3102 | u8 max_rssi = 0; |
| 3103 | u32 i; |
| 3104 | |
| 3105 | /* Find max rssi among 3 possible receivers. |
| 3106 | * These values are measured by the digital signal processor (DSP). |
| 3107 | * They should stay fairly constant even as the signal strength varies, |
| 3108 | * if the radio's automatic gain control (AGC) is working right. |
| 3109 | * AGC value (see below) will provide the "interesting" info. */ |
| 3110 | for (i = 0; i < 3; i++) |
| 3111 | if (valid_antennae & (1 << i)) |
| 3112 | max_rssi = max(ncphy->rssi_info[i << 1], max_rssi); |
| 3113 | |
| 3114 | IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n", |
| 3115 | ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4], |
| 3116 | max_rssi, agc); |
| 3117 | |
| 3118 | /* dBm = max_rssi dB - agc dB - constant. |
| 3119 | * Higher AGC (higher radio gain) means lower signal. */ |
| 3120 | return (max_rssi - agc - IWL_RSSI_OFFSET); |
| 3121 | } |
| 3122 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3123 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3124 | |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 3125 | void iwl4965_init_ht_hw_capab(const struct iwl_priv *priv, |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 3126 | struct ieee80211_ht_info *ht_info, |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3127 | enum ieee80211_band band) |
Ron Rindjunsky | 326eeee | 2007-11-26 16:14:37 +0200 | [diff] [blame] | 3128 | { |
| 3129 | ht_info->cap = 0; |
| 3130 | memset(ht_info->supp_mcs_set, 0, 16); |
| 3131 | |
| 3132 | ht_info->ht_supported = 1; |
| 3133 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 3134 | if (priv->hw_params.fat_channel & BIT(band)) { |
Ron Rindjunsky | 326eeee | 2007-11-26 16:14:37 +0200 | [diff] [blame] | 3135 | ht_info->cap |= (u16)IEEE80211_HT_CAP_SUP_WIDTH; |
| 3136 | ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_40; |
| 3137 | ht_info->supp_mcs_set[4] = 0x01; |
| 3138 | } |
| 3139 | ht_info->cap |= (u16)IEEE80211_HT_CAP_GRN_FLD; |
| 3140 | ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_20; |
| 3141 | ht_info->cap |= (u16)(IEEE80211_HT_CAP_MIMO_PS & |
| 3142 | (IWL_MIMO_PS_NONE << 2)); |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 3143 | |
| 3144 | if (priv->cfg->mod_params->amsdu_size_8K) |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 3145 | ht_info->cap |= (u16)IEEE80211_HT_CAP_MAX_AMSDU; |
Ron Rindjunsky | 326eeee | 2007-11-26 16:14:37 +0200 | [diff] [blame] | 3146 | |
| 3147 | ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF; |
| 3148 | ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF; |
| 3149 | |
| 3150 | ht_info->supp_mcs_set[0] = 0xFF; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 3151 | if (priv->hw_params.tx_chains_num >= 2) |
| 3152 | ht_info->supp_mcs_set[1] = 0xFF; |
| 3153 | if (priv->hw_params.tx_chains_num >= 3) |
| 3154 | ht_info->supp_mcs_set[2] = 0xFF; |
Ron Rindjunsky | 326eeee | 2007-11-26 16:14:37 +0200 | [diff] [blame] | 3155 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3156 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3157 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3158 | static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3159 | { |
| 3160 | unsigned long flags; |
| 3161 | |
| 3162 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 3163 | priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK; |
| 3164 | priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK; |
| 3165 | priv->stations[sta_id].sta.sta.modify_mask = 0; |
| 3166 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3167 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 3168 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3169 | iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3170 | } |
| 3171 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3172 | static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3173 | { |
| 3174 | /* FIXME: need locking over ps_status ??? */ |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 3175 | u8 sta_id = iwl_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3176 | |
| 3177 | if (sta_id != IWL_INVALID_STATION) { |
| 3178 | u8 sta_awake = priv->stations[sta_id]. |
| 3179 | ps_status == STA_PS_STATUS_WAKE; |
| 3180 | |
| 3181 | if (sta_awake && ps_bit) |
| 3182 | priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP; |
| 3183 | else if (!sta_awake && !ps_bit) { |
| 3184 | iwl4965_sta_modify_ps_wake(priv, sta_id); |
| 3185 | priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE; |
| 3186 | } |
| 3187 | } |
| 3188 | } |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3189 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3190 | |
| 3191 | /** |
| 3192 | * iwl4965_dbg_report_frame - dump frame to syslog during debug sessions |
| 3193 | * |
| 3194 | * You may hack this function to show different aspects of received frames, |
| 3195 | * including selective frame dumps. |
| 3196 | * group100 parameter selects whether to show 1 out of 100 good frames. |
| 3197 | * |
| 3198 | * TODO: This was originally written for 3945, need to audit for |
| 3199 | * proper operation with 4965. |
| 3200 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3201 | static void iwl4965_dbg_report_frame(struct iwl_priv *priv, |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3202 | struct iwl4965_rx_packet *pkt, |
| 3203 | struct ieee80211_hdr *header, int group100) |
| 3204 | { |
| 3205 | u32 to_us; |
| 3206 | u32 print_summary = 0; |
| 3207 | u32 print_dump = 0; /* set to 1 to dump all frames' contents */ |
| 3208 | u32 hundred = 0; |
| 3209 | u32 dataframe = 0; |
| 3210 | u16 fc; |
| 3211 | u16 seq_ctl; |
| 3212 | u16 channel; |
| 3213 | u16 phy_flags; |
| 3214 | int rate_sym; |
| 3215 | u16 length; |
| 3216 | u16 status; |
| 3217 | u16 bcn_tmr; |
| 3218 | u32 tsf_low; |
| 3219 | u64 tsf; |
| 3220 | u8 rssi; |
| 3221 | u8 agc; |
| 3222 | u16 sig_avg; |
| 3223 | u16 noise_diff; |
| 3224 | struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); |
| 3225 | struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); |
| 3226 | struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt); |
| 3227 | u8 *data = IWL_RX_DATA(pkt); |
| 3228 | |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3229 | if (likely(!(iwl_debug_level & IWL_DL_RX))) |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3230 | return; |
| 3231 | |
| 3232 | /* MAC header */ |
| 3233 | fc = le16_to_cpu(header->frame_control); |
| 3234 | seq_ctl = le16_to_cpu(header->seq_ctrl); |
| 3235 | |
| 3236 | /* metadata */ |
| 3237 | channel = le16_to_cpu(rx_hdr->channel); |
| 3238 | phy_flags = le16_to_cpu(rx_hdr->phy_flags); |
| 3239 | rate_sym = rx_hdr->rate; |
| 3240 | length = le16_to_cpu(rx_hdr->len); |
| 3241 | |
| 3242 | /* end-of-frame status and timestamp */ |
| 3243 | status = le32_to_cpu(rx_end->status); |
| 3244 | bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp); |
| 3245 | tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff; |
| 3246 | tsf = le64_to_cpu(rx_end->timestamp); |
| 3247 | |
| 3248 | /* signal statistics */ |
| 3249 | rssi = rx_stats->rssi; |
| 3250 | agc = rx_stats->agc; |
| 3251 | sig_avg = le16_to_cpu(rx_stats->sig_avg); |
| 3252 | noise_diff = le16_to_cpu(rx_stats->noise_diff); |
| 3253 | |
| 3254 | to_us = !compare_ether_addr(header->addr1, priv->mac_addr); |
| 3255 | |
| 3256 | /* if data frame is to us and all is good, |
| 3257 | * (optionally) print summary for only 1 out of every 100 */ |
| 3258 | if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) == |
| 3259 | (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) { |
| 3260 | dataframe = 1; |
| 3261 | if (!group100) |
| 3262 | print_summary = 1; /* print each frame */ |
| 3263 | else if (priv->framecnt_to_us < 100) { |
| 3264 | priv->framecnt_to_us++; |
| 3265 | print_summary = 0; |
| 3266 | } else { |
| 3267 | priv->framecnt_to_us = 0; |
| 3268 | print_summary = 1; |
| 3269 | hundred = 1; |
| 3270 | } |
| 3271 | } else { |
| 3272 | /* print summary for all other frames */ |
| 3273 | print_summary = 1; |
| 3274 | } |
| 3275 | |
| 3276 | if (print_summary) { |
| 3277 | char *title; |
| 3278 | int rate_idx; |
| 3279 | u32 bitrate; |
| 3280 | |
| 3281 | if (hundred) |
| 3282 | title = "100Frames"; |
| 3283 | else if (fc & IEEE80211_FCTL_RETRY) |
| 3284 | title = "Retry"; |
| 3285 | else if (ieee80211_is_assoc_response(fc)) |
| 3286 | title = "AscRsp"; |
| 3287 | else if (ieee80211_is_reassoc_response(fc)) |
| 3288 | title = "RasRsp"; |
| 3289 | else if (ieee80211_is_probe_response(fc)) { |
| 3290 | title = "PrbRsp"; |
| 3291 | print_dump = 1; /* dump frame contents */ |
| 3292 | } else if (ieee80211_is_beacon(fc)) { |
| 3293 | title = "Beacon"; |
| 3294 | print_dump = 1; /* dump frame contents */ |
| 3295 | } else if (ieee80211_is_atim(fc)) |
| 3296 | title = "ATIM"; |
| 3297 | else if (ieee80211_is_auth(fc)) |
| 3298 | title = "Auth"; |
| 3299 | else if (ieee80211_is_deauth(fc)) |
| 3300 | title = "DeAuth"; |
| 3301 | else if (ieee80211_is_disassoc(fc)) |
| 3302 | title = "DisAssoc"; |
| 3303 | else |
| 3304 | title = "Frame"; |
| 3305 | |
| 3306 | rate_idx = iwl4965_hwrate_to_plcp_idx(rate_sym); |
| 3307 | if (unlikely(rate_idx == -1)) |
| 3308 | bitrate = 0; |
| 3309 | else |
| 3310 | bitrate = iwl4965_rates[rate_idx].ieee / 2; |
| 3311 | |
| 3312 | /* print frame summary. |
| 3313 | * MAC addresses show just the last byte (for brevity), |
| 3314 | * but you can hack it to show more, if you'd like to. */ |
| 3315 | if (dataframe) |
| 3316 | IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, " |
| 3317 | "len=%u, rssi=%d, chnl=%d, rate=%u, \n", |
| 3318 | title, fc, header->addr1[5], |
| 3319 | length, rssi, channel, bitrate); |
| 3320 | else { |
| 3321 | /* src/dst addresses assume managed mode */ |
| 3322 | IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, " |
| 3323 | "src=0x%02x, rssi=%u, tim=%lu usec, " |
| 3324 | "phy=0x%02x, chnl=%d\n", |
| 3325 | title, fc, header->addr1[5], |
| 3326 | header->addr3[5], rssi, |
| 3327 | tsf_low - priv->scan_start_tsf, |
| 3328 | phy_flags, channel); |
| 3329 | } |
| 3330 | } |
| 3331 | if (print_dump) |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 3332 | iwl_print_hex_dump(IWL_DL_RX, data, length); |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3333 | } |
| 3334 | #else |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3335 | static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv, |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3336 | struct iwl4965_rx_packet *pkt, |
| 3337 | struct ieee80211_hdr *header, |
| 3338 | int group100) |
| 3339 | { |
| 3340 | } |
| 3341 | #endif |
| 3342 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3343 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 3344 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3345 | /* Called for REPLY_RX (legacy ABG frames), or |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3346 | * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3347 | static void iwl4965_rx_reply_rx(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3348 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3349 | { |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3350 | struct ieee80211_hdr *header; |
| 3351 | struct ieee80211_rx_status rx_status; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3352 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3353 | /* Use phy data (Rx signal strength, etc.) contained within |
| 3354 | * this rx packet for legacy frames, |
| 3355 | * or phy data cached from REPLY_RX_PHY_CMD for HT frames. */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3356 | int include_phy = (pkt->hdr.cmd == REPLY_RX); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3357 | struct iwl4965_rx_phy_res *rx_start = (include_phy) ? |
| 3358 | (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : |
| 3359 | (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1]; |
| 3360 | __le32 *rx_end; |
| 3361 | unsigned int len = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3362 | u16 fc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3363 | u8 network_packet; |
| 3364 | |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3365 | rx_status.mactime = le64_to_cpu(rx_start->timestamp); |
Tomas Winkler | dc92e49 | 2008-04-03 16:05:22 -0700 | [diff] [blame] | 3366 | rx_status.freq = |
| 3367 | ieee80211_frequency_to_channel(le16_to_cpu(rx_start->channel)); |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3368 | rx_status.band = (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? |
| 3369 | IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ; |
Tomas Winkler | dc92e49 | 2008-04-03 16:05:22 -0700 | [diff] [blame] | 3370 | rx_status.rate_idx = |
| 3371 | iwl4965_hwrate_to_plcp_idx(le32_to_cpu(rx_start->rate_n_flags)); |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3372 | if (rx_status.band == IEEE80211_BAND_5GHZ) |
| 3373 | rx_status.rate_idx -= IWL_FIRST_OFDM_RATE; |
| 3374 | |
| 3375 | rx_status.antenna = 0; |
| 3376 | rx_status.flag = 0; |
| 3377 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3378 | if ((unlikely(rx_start->cfg_phy_cnt > 20))) { |
Tomas Winkler | dc92e49 | 2008-04-03 16:05:22 -0700 | [diff] [blame] | 3379 | IWL_DEBUG_DROP("dsp size out of range [0,20]: %d/n", |
| 3380 | rx_start->cfg_phy_cnt); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3381 | return; |
| 3382 | } |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3383 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3384 | if (!include_phy) { |
| 3385 | if (priv->last_phy_res[0]) |
| 3386 | rx_start = (struct iwl4965_rx_phy_res *) |
| 3387 | &priv->last_phy_res[1]; |
| 3388 | else |
| 3389 | rx_start = NULL; |
| 3390 | } |
| 3391 | |
| 3392 | if (!rx_start) { |
| 3393 | IWL_ERROR("MPDU frame without a PHY data\n"); |
| 3394 | return; |
| 3395 | } |
| 3396 | |
| 3397 | if (include_phy) { |
| 3398 | header = (struct ieee80211_hdr *)((u8 *) & rx_start[1] |
| 3399 | + rx_start->cfg_phy_cnt); |
| 3400 | |
| 3401 | len = le16_to_cpu(rx_start->byte_count); |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3402 | rx_end = (__le32 *)(pkt->u.raw + rx_start->cfg_phy_cnt + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3403 | sizeof(struct iwl4965_rx_phy_res) + len); |
| 3404 | } else { |
| 3405 | struct iwl4965_rx_mpdu_res_start *amsdu = |
| 3406 | (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw; |
| 3407 | |
| 3408 | header = (void *)(pkt->u.raw + |
| 3409 | sizeof(struct iwl4965_rx_mpdu_res_start)); |
| 3410 | len = le16_to_cpu(amsdu->byte_count); |
| 3411 | rx_end = (__le32 *) (pkt->u.raw + |
| 3412 | sizeof(struct iwl4965_rx_mpdu_res_start) + len); |
| 3413 | } |
| 3414 | |
| 3415 | if (!(*rx_end & RX_RES_STATUS_NO_CRC32_ERROR) || |
| 3416 | !(*rx_end & RX_RES_STATUS_NO_RXE_OVERFLOW)) { |
| 3417 | IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n", |
| 3418 | le32_to_cpu(*rx_end)); |
| 3419 | return; |
| 3420 | } |
| 3421 | |
| 3422 | priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp); |
| 3423 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3424 | /* Find max signal strength (dBm) among 3 antenna/receiver chains */ |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3425 | rx_status.ssi = iwl4965_calc_rssi(rx_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3426 | |
| 3427 | /* Meaningful noise values are available only from beacon statistics, |
| 3428 | * which are gathered only when associated, and indicate noise |
| 3429 | * only for the associated network channel ... |
| 3430 | * Ignore these noise values while scanning (other channels) */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3431 | if (iwl_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3432 | !test_bit(STATUS_SCANNING, &priv->status)) { |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3433 | rx_status.noise = priv->last_rx_noise; |
| 3434 | rx_status.signal = iwl4965_calc_sig_qual(rx_status.ssi, |
| 3435 | rx_status.noise); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3436 | } else { |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3437 | rx_status.noise = IWL_NOISE_MEAS_NOT_AVAILABLE; |
| 3438 | rx_status.signal = iwl4965_calc_sig_qual(rx_status.ssi, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3439 | } |
| 3440 | |
| 3441 | /* Reset beacon noise level if not associated. */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 3442 | if (!iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3443 | priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE; |
| 3444 | |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3445 | /* Set "1" to report good data frames in groups of 100 */ |
| 3446 | /* FIXME: need to optimze the call: */ |
| 3447 | iwl4965_dbg_report_frame(priv, pkt, header, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3448 | |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3449 | IWL_DEBUG_STATS_LIMIT("Rssi %d, noise %d, qual %d, TSF %llu\n", |
| 3450 | rx_status.ssi, rx_status.noise, rx_status.signal, |
John W. Linville | 06501d2 | 2008-04-01 17:38:47 -0400 | [diff] [blame] | 3451 | (unsigned long long)rx_status.mactime); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3452 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3453 | network_packet = iwl4965_is_network_packet(priv, header); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3454 | if (network_packet) { |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3455 | priv->last_rx_rssi = rx_status.ssi; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3456 | priv->last_beacon_time = priv->ucode_beacon_time; |
| 3457 | priv->last_tsf = le64_to_cpu(rx_start->timestamp); |
| 3458 | } |
| 3459 | |
| 3460 | fc = le16_to_cpu(header->frame_control); |
| 3461 | switch (fc & IEEE80211_FCTL_FTYPE) { |
| 3462 | case IEEE80211_FTYPE_MGMT: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3463 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
| 3464 | iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM, |
| 3465 | header->addr2); |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3466 | iwl4965_handle_data_packet(priv, 0, include_phy, rxb, &rx_status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3467 | break; |
| 3468 | |
| 3469 | case IEEE80211_FTYPE_CTL: |
Ron Rindjunsky | 9ab4617 | 2007-12-25 17:00:38 +0200 | [diff] [blame] | 3470 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3471 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 3472 | case IEEE80211_STYPE_BACK_REQ: |
| 3473 | IWL_DEBUG_HT("IEEE80211_STYPE_BACK_REQ arrived\n"); |
| 3474 | iwl4965_handle_data_packet(priv, 0, include_phy, |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3475 | rxb, &rx_status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3476 | break; |
| 3477 | default: |
| 3478 | break; |
| 3479 | } |
| 3480 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3481 | break; |
| 3482 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3483 | case IEEE80211_FTYPE_DATA: { |
| 3484 | DECLARE_MAC_BUF(mac1); |
| 3485 | DECLARE_MAC_BUF(mac2); |
| 3486 | DECLARE_MAC_BUF(mac3); |
| 3487 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3488 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
| 3489 | iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM, |
| 3490 | header->addr2); |
| 3491 | |
| 3492 | if (unlikely(!network_packet)) |
| 3493 | IWL_DEBUG_DROP("Dropping (non network): " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3494 | "%s, %s, %s\n", |
| 3495 | print_mac(mac1, header->addr1), |
| 3496 | print_mac(mac2, header->addr2), |
| 3497 | print_mac(mac3, header->addr3)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3498 | else if (unlikely(iwl4965_is_duplicate_packet(priv, header))) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3499 | IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n", |
| 3500 | print_mac(mac1, header->addr1), |
| 3501 | print_mac(mac2, header->addr2), |
| 3502 | print_mac(mac3, header->addr3)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3503 | else |
| 3504 | iwl4965_handle_data_packet(priv, 1, include_phy, rxb, |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 3505 | &rx_status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3506 | break; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3507 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3508 | default: |
| 3509 | break; |
| 3510 | |
| 3511 | } |
| 3512 | } |
| 3513 | |
| 3514 | /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD). |
| 3515 | * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3516 | static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3517 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3518 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3519 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3520 | priv->last_phy_res[0] = 1; |
| 3521 | memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]), |
| 3522 | sizeof(struct iwl4965_rx_phy_res)); |
| 3523 | } |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3524 | static void iwl4965_rx_missed_beacon_notif(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3525 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3526 | |
| 3527 | { |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 3528 | #ifdef CONFIG_IWL4965_RUN_TIME_CALIB |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3529 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3530 | struct iwl4965_missed_beacon_notif *missed_beacon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3531 | |
| 3532 | missed_beacon = &pkt->u.missed_beacon; |
| 3533 | if (le32_to_cpu(missed_beacon->consequtive_missed_beacons) > 5) { |
| 3534 | IWL_DEBUG_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n", |
| 3535 | le32_to_cpu(missed_beacon->consequtive_missed_beacons), |
| 3536 | le32_to_cpu(missed_beacon->total_missed_becons), |
| 3537 | le32_to_cpu(missed_beacon->num_recvd_beacons), |
| 3538 | le32_to_cpu(missed_beacon->num_expected_beacons)); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 3539 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
| 3540 | iwl_init_sensitivity(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3541 | } |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 3542 | #endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3543 | } |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3544 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3545 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3546 | /** |
| 3547 | * iwl4965_sta_modify_enable_tid_tx - Enable Tx for this TID in station table |
| 3548 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3549 | static void iwl4965_sta_modify_enable_tid_tx(struct iwl_priv *priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3550 | int sta_id, int tid) |
| 3551 | { |
| 3552 | unsigned long flags; |
| 3553 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3554 | /* Remove "disable" flag, to enable Tx for this TID */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3555 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 3556 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX; |
| 3557 | priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid)); |
| 3558 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3559 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 3560 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3561 | iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3562 | } |
| 3563 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3564 | /** |
| 3565 | * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack |
| 3566 | * |
| 3567 | * Go through block-ack's bitmap of ACK'd frames, update driver's record of |
| 3568 | * ACK vs. not. This gets sent to mac80211, then to rate scaling algo. |
| 3569 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3570 | static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3571 | struct iwl4965_ht_agg *agg, |
| 3572 | struct iwl4965_compressed_ba_resp* |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3573 | ba_resp) |
| 3574 | |
| 3575 | { |
| 3576 | int i, sh, ack; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3577 | u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl); |
| 3578 | u16 scd_flow = le16_to_cpu(ba_resp->scd_flow); |
| 3579 | u64 bitmap; |
| 3580 | int successes = 0; |
| 3581 | struct ieee80211_tx_status *tx_status; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3582 | |
| 3583 | if (unlikely(!agg->wait_for_ba)) { |
| 3584 | IWL_ERROR("Received BA when not expected\n"); |
| 3585 | return -EINVAL; |
| 3586 | } |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3587 | |
| 3588 | /* Mark that the expected block-ack response arrived */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3589 | agg->wait_for_ba = 0; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3590 | IWL_DEBUG_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->seq_ctl); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3591 | |
| 3592 | /* Calculate shift to align block-ack bits with our Tx window bits */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3593 | sh = agg->start_idx - SEQ_TO_INDEX(seq_ctl>>4); |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3594 | if (sh < 0) /* tbw something is wrong with indices */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3595 | sh += 0x100; |
| 3596 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3597 | /* don't use 64-bit values for now */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3598 | bitmap = le64_to_cpu(ba_resp->bitmap) >> sh; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3599 | |
| 3600 | if (agg->frame_count > (64 - sh)) { |
| 3601 | IWL_DEBUG_TX_REPLY("more frames than bitmap size"); |
| 3602 | return -1; |
| 3603 | } |
| 3604 | |
| 3605 | /* check for success or failure according to the |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3606 | * transmitted bitmap and block-ack bitmap */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3607 | bitmap &= agg->bitmap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3608 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3609 | /* For each frame attempted in aggregation, |
| 3610 | * update driver's record of tx frame's status. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3611 | for (i = 0; i < agg->frame_count ; i++) { |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3612 | ack = bitmap & (1 << i); |
| 3613 | successes += !!ack; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3614 | IWL_DEBUG_TX_REPLY("%s ON i=%d idx=%d raw=%d\n", |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3615 | ack? "ACK":"NACK", i, (agg->start_idx + i) & 0xff, |
| 3616 | agg->start_idx + i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3617 | } |
| 3618 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3619 | tx_status = &priv->txq[scd_flow].txb[agg->start_idx].status; |
| 3620 | tx_status->flags = IEEE80211_TX_STATUS_ACK; |
Ron Rindjunsky | 9955643 | 2008-01-28 14:07:25 +0200 | [diff] [blame] | 3621 | tx_status->flags |= IEEE80211_TX_STATUS_AMPDU; |
| 3622 | tx_status->ampdu_ack_map = successes; |
| 3623 | tx_status->ampdu_ack_len = agg->frame_count; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 3624 | iwl4965_hwrate_to_tx_control(priv, agg->rate_n_flags, |
| 3625 | &tx_status->control); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3626 | |
John W. Linville | f868f4e | 2008-03-07 16:38:43 -0500 | [diff] [blame] | 3627 | IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3628 | |
| 3629 | return 0; |
| 3630 | } |
| 3631 | |
| 3632 | /** |
| 3633 | * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration |
| 3634 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3635 | static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3636 | u16 txq_id) |
| 3637 | { |
| 3638 | /* Simply stop the queue, but don't change any configuration; |
| 3639 | * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3640 | iwl_write_prph(priv, |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 3641 | IWL49_SCD_QUEUE_STATUS_BITS(txq_id), |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3642 | (0 << SCD_QUEUE_STTS_REG_POS_ACTIVE)| |
| 3643 | (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN)); |
| 3644 | } |
| 3645 | |
| 3646 | /** |
| 3647 | * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 3648 | * priv->lock must be held by the caller |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3649 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3650 | static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3651 | u16 ssn_idx, u8 tx_fifo) |
| 3652 | { |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 3653 | int ret = 0; |
| 3654 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3655 | if (IWL_BACK_QUEUE_FIRST_ID > txq_id) { |
| 3656 | IWL_WARNING("queue number too small: %d, must be > %d\n", |
| 3657 | txq_id, IWL_BACK_QUEUE_FIRST_ID); |
| 3658 | return -EINVAL; |
| 3659 | } |
| 3660 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3661 | ret = iwl_grab_nic_access(priv); |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 3662 | if (ret) |
| 3663 | return ret; |
| 3664 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3665 | iwl4965_tx_queue_stop_scheduler(priv, txq_id); |
| 3666 | |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 3667 | iwl_clear_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id)); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3668 | |
| 3669 | priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff); |
| 3670 | priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff); |
| 3671 | /* supposes that ssn_idx is valid (!= 0xFFF) */ |
| 3672 | iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx); |
| 3673 | |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 3674 | iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id)); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3675 | iwl4965_txq_ctx_deactivate(priv, txq_id); |
| 3676 | iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0); |
| 3677 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3678 | iwl_release_nic_access(priv); |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 3679 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3680 | return 0; |
| 3681 | } |
| 3682 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3683 | int iwl4965_check_empty_hw_queue(struct iwl_priv *priv, int sta_id, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3684 | u8 tid, int txq_id) |
| 3685 | { |
| 3686 | struct iwl4965_queue *q = &priv->txq[txq_id].q; |
| 3687 | u8 *addr = priv->stations[sta_id].sta.sta.addr; |
| 3688 | struct iwl4965_tid_data *tid_data = &priv->stations[sta_id].tid[tid]; |
| 3689 | |
| 3690 | switch (priv->stations[sta_id].tid[tid].agg.state) { |
| 3691 | case IWL_EMPTYING_HW_QUEUE_DELBA: |
| 3692 | /* We are reclaiming the last packet of the */ |
| 3693 | /* aggregated HW queue */ |
| 3694 | if (txq_id == tid_data->agg.txq_id && |
| 3695 | q->read_ptr == q->write_ptr) { |
| 3696 | u16 ssn = SEQ_TO_SN(tid_data->seq_number); |
| 3697 | int tx_fifo = default_tid_to_tx_fifo[tid]; |
| 3698 | IWL_DEBUG_HT("HW queue empty: continue DELBA flow\n"); |
| 3699 | iwl4965_tx_queue_agg_disable(priv, txq_id, |
| 3700 | ssn, tx_fifo); |
| 3701 | tid_data->agg.state = IWL_AGG_OFF; |
| 3702 | ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, addr, tid); |
| 3703 | } |
| 3704 | break; |
| 3705 | case IWL_EMPTYING_HW_QUEUE_ADDBA: |
| 3706 | /* We are reclaiming the last packet of the queue */ |
| 3707 | if (tid_data->tfds_in_queue == 0) { |
| 3708 | IWL_DEBUG_HT("HW queue empty: continue ADDBA flow\n"); |
| 3709 | tid_data->agg.state = IWL_AGG_ON; |
| 3710 | ieee80211_start_tx_ba_cb_irqsafe(priv->hw, addr, tid); |
| 3711 | } |
| 3712 | break; |
| 3713 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3714 | return 0; |
| 3715 | } |
| 3716 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3717 | /** |
| 3718 | * iwl4965_queue_dec_wrap - Decrement queue index, wrap back to end if needed |
| 3719 | * @index -- current index |
| 3720 | * @n_bd -- total number of entries in queue (s/b power of 2) |
| 3721 | */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3722 | static inline int iwl4965_queue_dec_wrap(int index, int n_bd) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3723 | { |
| 3724 | return (index == 0) ? n_bd - 1 : index - 1; |
| 3725 | } |
| 3726 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3727 | /** |
| 3728 | * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA |
| 3729 | * |
| 3730 | * Handles block-acknowledge notification from device, which reports success |
| 3731 | * of frames sent via aggregation. |
| 3732 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3733 | static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3734 | struct iwl4965_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3735 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3736 | struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data; |
| 3737 | struct iwl4965_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3738 | int index; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3739 | struct iwl4965_tx_queue *txq = NULL; |
| 3740 | struct iwl4965_ht_agg *agg; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3741 | DECLARE_MAC_BUF(mac); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3742 | |
| 3743 | /* "flow" corresponds to Tx queue */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3744 | u16 scd_flow = le16_to_cpu(ba_resp->scd_flow); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3745 | |
| 3746 | /* "ssn" is start of block-ack Tx window, corresponds to index |
| 3747 | * (in Tx queue's circular buffer) of first TFD/frame in window */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3748 | u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn); |
| 3749 | |
Ron Rindjunsky | dfe7d45 | 2008-04-15 16:01:45 -0700 | [diff] [blame] | 3750 | if (scd_flow >= priv->hw_params.max_txq_num) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3751 | IWL_ERROR("BUG_ON scd_flow is bigger than number of queues"); |
| 3752 | return; |
| 3753 | } |
| 3754 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3755 | txq = &priv->txq[scd_flow]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3756 | agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg; |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3757 | |
| 3758 | /* Find index just before block-ack window */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3759 | index = iwl4965_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3760 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 3761 | /* TODO: Need to get this copy more safely - now good for debug */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3762 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3763 | IWL_DEBUG_TX_REPLY("REPLY_COMPRESSED_BA [%d]Received from %s, " |
| 3764 | "sta_id = %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3765 | agg->wait_for_ba, |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 3766 | print_mac(mac, (u8*) &ba_resp->sta_addr_lo32), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3767 | ba_resp->sta_id); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3768 | IWL_DEBUG_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3769 | "%d, scd_ssn = %d\n", |
| 3770 | ba_resp->tid, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3771 | ba_resp->seq_ctl, |
Tomas Winkler | 0310ae7 | 2008-03-11 16:17:19 -0700 | [diff] [blame] | 3772 | (unsigned long long)le64_to_cpu(ba_resp->bitmap), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3773 | ba_resp->scd_flow, |
| 3774 | ba_resp->scd_ssn); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3775 | IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx \n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3776 | agg->start_idx, |
John W. Linville | f868f4e | 2008-03-07 16:38:43 -0500 | [diff] [blame] | 3777 | (unsigned long long)agg->bitmap); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3778 | |
| 3779 | /* Update driver's record of ACK vs. not for each frame in window */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3780 | iwl4965_tx_status_reply_compressed_ba(priv, agg, ba_resp); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3781 | |
| 3782 | /* Release all TFDs before the SSN, i.e. all TFDs in front of |
| 3783 | * block-ack window (we assume that they've been successfully |
| 3784 | * transmitted ... if not, it's too late anyway). */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3785 | if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) { |
| 3786 | int freed = iwl4965_tx_queue_reclaim(priv, scd_flow, index); |
| 3787 | priv->stations[ba_resp->sta_id]. |
| 3788 | tid[ba_resp->tid].tfds_in_queue -= freed; |
| 3789 | if (iwl4965_queue_space(&txq->q) > txq->q.low_mark && |
| 3790 | priv->mac80211_registered && |
| 3791 | agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) |
| 3792 | ieee80211_wake_queue(priv->hw, scd_flow); |
| 3793 | iwl4965_check_empty_hw_queue(priv, ba_resp->sta_id, |
| 3794 | ba_resp->tid, scd_flow); |
| 3795 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3796 | } |
| 3797 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3798 | /** |
| 3799 | * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue |
| 3800 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3801 | static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3802 | u16 txq_id) |
| 3803 | { |
| 3804 | u32 tbl_dw_addr; |
| 3805 | u32 tbl_dw; |
| 3806 | u16 scd_q2ratid; |
| 3807 | |
| 3808 | scd_q2ratid = ra_tid & SCD_QUEUE_RA_TID_MAP_RATID_MSK; |
| 3809 | |
| 3810 | tbl_dw_addr = priv->scd_base_addr + |
| 3811 | SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id); |
| 3812 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3813 | tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3814 | |
| 3815 | if (txq_id & 0x1) |
| 3816 | tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF); |
| 3817 | else |
| 3818 | tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000); |
| 3819 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3820 | iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3821 | |
| 3822 | return 0; |
| 3823 | } |
| 3824 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3825 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3826 | /** |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3827 | * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue |
| 3828 | * |
| 3829 | * NOTE: txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID, |
| 3830 | * i.e. it must be one of the higher queues used for aggregation |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3831 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3832 | static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3833 | int tx_fifo, int sta_id, int tid, |
| 3834 | u16 ssn_idx) |
| 3835 | { |
| 3836 | unsigned long flags; |
| 3837 | int rc; |
| 3838 | u16 ra_tid; |
| 3839 | |
| 3840 | if (IWL_BACK_QUEUE_FIRST_ID > txq_id) |
| 3841 | IWL_WARNING("queue number too small: %d, must be > %d\n", |
| 3842 | txq_id, IWL_BACK_QUEUE_FIRST_ID); |
| 3843 | |
| 3844 | ra_tid = BUILD_RAxTID(sta_id, tid); |
| 3845 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3846 | /* Modify device's station table to Tx this TID */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3847 | iwl4965_sta_modify_enable_tid_tx(priv, sta_id, tid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3848 | |
| 3849 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3850 | rc = iwl_grab_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3851 | if (rc) { |
| 3852 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3853 | return rc; |
| 3854 | } |
| 3855 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3856 | /* Stop this Tx queue before configuring it */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3857 | iwl4965_tx_queue_stop_scheduler(priv, txq_id); |
| 3858 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3859 | /* Map receiver-address / traffic-ID to this queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3860 | iwl4965_tx_queue_set_q2ratid(priv, ra_tid, txq_id); |
| 3861 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3862 | /* Set this queue as a chain-building queue */ |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 3863 | iwl_set_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3864 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3865 | /* Place first TFD at index corresponding to start sequence number. |
| 3866 | * Assumes that ssn_idx is valid (!= 0xFFF) */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3867 | priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff); |
| 3868 | priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3869 | iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx); |
| 3870 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3871 | /* Set up Tx window size and frame limit for this queue */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3872 | iwl_write_targ_mem(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3873 | priv->scd_base_addr + SCD_CONTEXT_QUEUE_OFFSET(txq_id), |
| 3874 | (SCD_WIN_SIZE << SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) & |
| 3875 | SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK); |
| 3876 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3877 | iwl_write_targ_mem(priv, priv->scd_base_addr + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3878 | SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32), |
| 3879 | (SCD_FRAME_LIMIT << SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) |
| 3880 | & SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK); |
| 3881 | |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 3882 | iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3883 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3884 | /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3885 | iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1); |
| 3886 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3887 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3888 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3889 | |
| 3890 | return 0; |
| 3891 | } |
| 3892 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3893 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3894 | |
| 3895 | /** |
| 3896 | * iwl4965_add_station - Initialize a station's hardware rate table |
| 3897 | * |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3898 | * The uCode's station table contains a table of fallback rates |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3899 | * for automatic fallback during transmission. |
| 3900 | * |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3901 | * NOTE: This sets up a default set of values. These will be replaced later |
| 3902 | * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of |
| 3903 | * rc80211_simple. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3904 | * |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3905 | * NOTE: Run REPLY_ADD_STA command to set up station table entry, before |
| 3906 | * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD, |
| 3907 | * which requires station table entry to exist). |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3908 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3909 | void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3910 | { |
| 3911 | int i, r; |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 3912 | struct iwl_link_quality_cmd link_cmd = { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3913 | .reserved1 = 0, |
| 3914 | }; |
| 3915 | u16 rate_flags; |
| 3916 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3917 | /* Set up the rate scaling to start at selected rate, fall back |
| 3918 | * all the way down to 1M in IEEE order, and then spin on 1M */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3919 | if (is_ap) |
| 3920 | r = IWL_RATE_54M_INDEX; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3921 | else if (priv->band == IEEE80211_BAND_5GHZ) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3922 | r = IWL_RATE_6M_INDEX; |
| 3923 | else |
| 3924 | r = IWL_RATE_1M_INDEX; |
| 3925 | |
| 3926 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
| 3927 | rate_flags = 0; |
| 3928 | if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE) |
| 3929 | rate_flags |= RATE_MCS_CCK_MSK; |
| 3930 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3931 | /* Use Tx antenna B only */ |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 3932 | rate_flags |= RATE_MCS_ANT_B_MSK; /*FIXME:RS*/ |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3933 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3934 | link_cmd.rs_table[i].rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3935 | iwl4965_hw_set_rate_n_flags(iwl4965_rates[r].plcp, rate_flags); |
| 3936 | r = iwl4965_get_prev_ieee_rate(r); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3937 | } |
| 3938 | |
| 3939 | link_cmd.general_params.single_stream_ant_msk = 2; |
| 3940 | link_cmd.general_params.dual_stream_ant_msk = 3; |
| 3941 | link_cmd.agg_params.agg_dis_start_th = 3; |
| 3942 | link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000); |
| 3943 | |
| 3944 | /* Update the rate scaling for control frame Tx to AP */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3945 | link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3946 | |
Tomas Winkler | e547297 | 2008-03-28 16:21:12 -0700 | [diff] [blame] | 3947 | iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD, |
| 3948 | sizeof(link_cmd), &link_cmd, NULL); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3949 | } |
| 3950 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 3951 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3952 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3953 | static u8 iwl4965_is_channel_extension(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 3954 | enum ieee80211_band band, |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3955 | u16 channel, u8 extension_chan_offset) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3956 | { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 3957 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3958 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 3959 | ch_info = iwl_get_channel_info(priv, band, channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3960 | if (!is_channel_valid(ch_info)) |
| 3961 | return 0; |
| 3962 | |
Guy Cohen | 134eb5d | 2008-03-04 18:09:25 -0800 | [diff] [blame] | 3963 | if (extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_NONE) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3964 | return 0; |
| 3965 | |
| 3966 | if ((ch_info->fat_extension_channel == extension_chan_offset) || |
| 3967 | (ch_info->fat_extension_channel == HT_IE_EXT_CHANNEL_MAX)) |
| 3968 | return 1; |
| 3969 | |
| 3970 | return 0; |
| 3971 | } |
| 3972 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3973 | static u8 iwl4965_is_fat_tx_allowed(struct iwl_priv *priv, |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 3974 | struct ieee80211_ht_info *sta_ht_inf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3975 | { |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 3976 | struct iwl_ht_info *iwl_ht_conf = &priv->current_ht_config; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3977 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 3978 | if ((!iwl_ht_conf->is_ht) || |
| 3979 | (iwl_ht_conf->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ) || |
Guy Cohen | 134eb5d | 2008-03-04 18:09:25 -0800 | [diff] [blame] | 3980 | (iwl_ht_conf->extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_NONE)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3981 | return 0; |
| 3982 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 3983 | if (sta_ht_inf) { |
| 3984 | if ((!sta_ht_inf->ht_supported) || |
Roel Kluin | 194c7ca | 2008-02-02 20:48:48 +0100 | [diff] [blame] | 3985 | (!(sta_ht_inf->cap & IEEE80211_HT_CAP_SUP_WIDTH))) |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 3986 | return 0; |
| 3987 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3988 | |
Tomas Winkler | 78330fd | 2008-02-06 02:37:18 +0200 | [diff] [blame] | 3989 | return (iwl4965_is_channel_extension(priv, priv->band, |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 3990 | iwl_ht_conf->control_channel, |
| 3991 | iwl_ht_conf->extension_chan_offset)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3992 | } |
| 3993 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3994 | void iwl4965_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3995 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 3996 | struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3997 | u32 val; |
| 3998 | |
| 3999 | if (!ht_info->is_ht) |
| 4000 | return; |
| 4001 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 4002 | /* Set up channel bandwidth: 20 MHz only, or 20/40 mixed if fat ok */ |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 4003 | if (iwl4965_is_fat_tx_allowed(priv, NULL)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4004 | rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED_MSK; |
| 4005 | else |
| 4006 | rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK | |
| 4007 | RXON_FLG_CHANNEL_MODE_PURE_40_MSK); |
| 4008 | |
| 4009 | if (le16_to_cpu(rxon->channel) != ht_info->control_channel) { |
| 4010 | IWL_DEBUG_ASSOC("control diff than current %d %d\n", |
| 4011 | le16_to_cpu(rxon->channel), |
| 4012 | ht_info->control_channel); |
| 4013 | rxon->channel = cpu_to_le16(ht_info->control_channel); |
| 4014 | return; |
| 4015 | } |
| 4016 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 4017 | /* Note: control channel is opposite of extension channel */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4018 | switch (ht_info->extension_chan_offset) { |
| 4019 | case IWL_EXT_CHANNEL_OFFSET_ABOVE: |
| 4020 | rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); |
| 4021 | break; |
| 4022 | case IWL_EXT_CHANNEL_OFFSET_BELOW: |
| 4023 | rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; |
| 4024 | break; |
Guy Cohen | 134eb5d | 2008-03-04 18:09:25 -0800 | [diff] [blame] | 4025 | case IWL_EXT_CHANNEL_OFFSET_NONE: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4026 | default: |
| 4027 | rxon->flags &= ~RXON_FLG_CHANNEL_MODE_MIXED_MSK; |
| 4028 | break; |
| 4029 | } |
| 4030 | |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 4031 | val = ht_info->ht_protection; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4032 | |
| 4033 | rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS); |
| 4034 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4035 | iwl4965_set_rxon_chain(priv); |
| 4036 | |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 4037 | IWL_DEBUG_ASSOC("supported HT rate 0x%X 0x%X 0x%X " |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4038 | "rxon flags 0x%X operation mode :0x%X " |
| 4039 | "extension channel offset 0x%x " |
| 4040 | "control chan %d\n", |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 4041 | ht_info->supp_mcs_set[0], |
| 4042 | ht_info->supp_mcs_set[1], |
| 4043 | ht_info->supp_mcs_set[2], |
Ron Rindjunsky | fd105e7 | 2007-11-26 16:14:39 +0200 | [diff] [blame] | 4044 | le32_to_cpu(rxon->flags), ht_info->ht_protection, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4045 | ht_info->extension_chan_offset, |
| 4046 | ht_info->control_channel); |
| 4047 | return; |
| 4048 | } |
| 4049 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4050 | void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index, |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 4051 | struct ieee80211_ht_info *sta_ht_inf) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4052 | { |
| 4053 | __le32 sta_flags; |
Tomas Winkler | e53cfe0 | 2008-01-30 22:05:13 -0800 | [diff] [blame] | 4054 | u8 mimo_ps_mode; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4055 | |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 4056 | if (!sta_ht_inf || !sta_ht_inf->ht_supported) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4057 | goto done; |
| 4058 | |
Tomas Winkler | e53cfe0 | 2008-01-30 22:05:13 -0800 | [diff] [blame] | 4059 | mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2; |
| 4060 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4061 | sta_flags = priv->stations[index].sta.station_flags; |
| 4062 | |
Tomas Winkler | e53cfe0 | 2008-01-30 22:05:13 -0800 | [diff] [blame] | 4063 | sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK); |
| 4064 | |
| 4065 | switch (mimo_ps_mode) { |
| 4066 | case WLAN_HT_CAP_MIMO_PS_STATIC: |
| 4067 | sta_flags |= STA_FLG_MIMO_DIS_MSK; |
| 4068 | break; |
| 4069 | case WLAN_HT_CAP_MIMO_PS_DYNAMIC: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4070 | sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK; |
Tomas Winkler | e53cfe0 | 2008-01-30 22:05:13 -0800 | [diff] [blame] | 4071 | break; |
| 4072 | case WLAN_HT_CAP_MIMO_PS_DISABLED: |
| 4073 | break; |
| 4074 | default: |
| 4075 | IWL_WARNING("Invalid MIMO PS mode %d", mimo_ps_mode); |
| 4076 | break; |
| 4077 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4078 | |
| 4079 | sta_flags |= cpu_to_le32( |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 4080 | (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4081 | |
| 4082 | sta_flags |= cpu_to_le32( |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 4083 | (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4084 | |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 4085 | if (iwl4965_is_fat_tx_allowed(priv, sta_ht_inf)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4086 | sta_flags |= STA_FLG_FAT_EN_MSK; |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 4087 | else |
Tomas Winkler | e53cfe0 | 2008-01-30 22:05:13 -0800 | [diff] [blame] | 4088 | sta_flags &= ~STA_FLG_FAT_EN_MSK; |
Ron Rindjunsky | 67d6203 | 2007-11-26 16:14:40 +0200 | [diff] [blame] | 4089 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4090 | priv->stations[index].sta.station_flags = sta_flags; |
| 4091 | done: |
| 4092 | return; |
| 4093 | } |
| 4094 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4095 | static int iwl4965_rx_agg_start(struct iwl_priv *priv, |
| 4096 | const u8 *addr, int tid, u16 ssn) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4097 | { |
| 4098 | unsigned long flags; |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4099 | int sta_id; |
| 4100 | |
| 4101 | sta_id = iwl_find_station(priv, addr); |
| 4102 | if (sta_id == IWL_INVALID_STATION) |
| 4103 | return -ENXIO; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4104 | |
| 4105 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 4106 | priv->stations[sta_id].sta.station_flags_msk = 0; |
| 4107 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK; |
| 4108 | priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid; |
| 4109 | priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn); |
| 4110 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 4111 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 4112 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4113 | return iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, |
| 4114 | CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4115 | } |
| 4116 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4117 | static int iwl4965_rx_agg_stop(struct iwl_priv *priv, |
| 4118 | const u8 *addr, int tid) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4119 | { |
| 4120 | unsigned long flags; |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4121 | int sta_id; |
| 4122 | |
| 4123 | sta_id = iwl_find_station(priv, addr); |
| 4124 | if (sta_id == IWL_INVALID_STATION) |
| 4125 | return -ENXIO; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4126 | |
| 4127 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 4128 | priv->stations[sta_id].sta.station_flags_msk = 0; |
| 4129 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK; |
| 4130 | priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid; |
| 4131 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 4132 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 4133 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4134 | return iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, |
| 4135 | CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4136 | } |
| 4137 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 4138 | /* |
| 4139 | * Find first available (lowest unused) Tx Queue, mark it "active". |
| 4140 | * Called only when finding queue for aggregation. |
| 4141 | * Should never return anything < 7, because they should already |
| 4142 | * be in use as EDCA AC (0-3), Command (4), HCCA (5, 6). |
| 4143 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4144 | static int iwl4965_txq_ctx_activate_free(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4145 | { |
| 4146 | int txq_id; |
| 4147 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 4148 | for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4149 | if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk)) |
| 4150 | return txq_id; |
| 4151 | return -1; |
| 4152 | } |
| 4153 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4154 | static int iwl4965_tx_agg_start(struct ieee80211_hw *hw, const u8 *ra, |
| 4155 | u16 tid, u16 *start_seq_num) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4156 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4157 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4158 | int sta_id; |
| 4159 | int tx_fifo; |
| 4160 | int txq_id; |
| 4161 | int ssn = -1; |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 4162 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4163 | unsigned long flags; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4164 | struct iwl4965_tid_data *tid_data; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4165 | DECLARE_MAC_BUF(mac); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4166 | |
| 4167 | if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo))) |
| 4168 | tx_fifo = default_tid_to_tx_fifo[tid]; |
| 4169 | else |
| 4170 | return -EINVAL; |
| 4171 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4172 | IWL_WARNING("%s on ra = %s tid = %d\n", |
| 4173 | __func__, print_mac(mac, ra), tid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4174 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4175 | sta_id = iwl_find_station(priv, ra); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4176 | if (sta_id == IWL_INVALID_STATION) |
| 4177 | return -ENXIO; |
| 4178 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 4179 | if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) { |
| 4180 | IWL_ERROR("Start AGG when state is not IWL_AGG_OFF !\n"); |
| 4181 | return -ENXIO; |
| 4182 | } |
| 4183 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4184 | txq_id = iwl4965_txq_ctx_activate_free(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4185 | if (txq_id == -1) |
| 4186 | return -ENXIO; |
| 4187 | |
| 4188 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 4189 | tid_data = &priv->stations[sta_id].tid[tid]; |
| 4190 | ssn = SEQ_TO_SN(tid_data->seq_number); |
| 4191 | tid_data->agg.txq_id = txq_id; |
| 4192 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 4193 | |
| 4194 | *start_seq_num = ssn; |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 4195 | ret = iwl4965_tx_queue_agg_enable(priv, txq_id, tx_fifo, |
| 4196 | sta_id, tid, ssn); |
| 4197 | if (ret) |
| 4198 | return ret; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 4199 | |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 4200 | ret = 0; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 4201 | if (tid_data->tfds_in_queue == 0) { |
| 4202 | printk(KERN_ERR "HW queue is empty\n"); |
| 4203 | tid_data->agg.state = IWL_AGG_ON; |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4204 | ieee80211_start_tx_ba_cb_irqsafe(hw, ra, tid); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 4205 | } else { |
| 4206 | IWL_DEBUG_HT("HW queue is NOT empty: %d packets in HW queue\n", |
| 4207 | tid_data->tfds_in_queue); |
| 4208 | tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA; |
| 4209 | } |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 4210 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4211 | } |
| 4212 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4213 | static int iwl4965_tx_agg_stop(struct ieee80211_hw *hw, const u8 *ra, u16 tid) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4214 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4215 | struct iwl_priv *priv = hw->priv; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4216 | int tx_fifo_id, txq_id, sta_id, ssn = -1; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 4217 | struct iwl4965_tid_data *tid_data; |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 4218 | int ret, write_ptr, read_ptr; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 4219 | unsigned long flags; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 4220 | DECLARE_MAC_BUF(mac); |
| 4221 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4222 | if (!ra) { |
| 4223 | IWL_ERROR("ra = NULL\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4224 | return -EINVAL; |
| 4225 | } |
| 4226 | |
| 4227 | if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo))) |
| 4228 | tx_fifo_id = default_tid_to_tx_fifo[tid]; |
| 4229 | else |
| 4230 | return -EINVAL; |
| 4231 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4232 | sta_id = iwl_find_station(priv, ra); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4233 | |
| 4234 | if (sta_id == IWL_INVALID_STATION) |
| 4235 | return -ENXIO; |
| 4236 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 4237 | if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON) |
| 4238 | IWL_WARNING("Stopping AGG while state not IWL_AGG_ON\n"); |
| 4239 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4240 | tid_data = &priv->stations[sta_id].tid[tid]; |
| 4241 | ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4; |
| 4242 | txq_id = tid_data->agg.txq_id; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 4243 | write_ptr = priv->txq[txq_id].q.write_ptr; |
| 4244 | read_ptr = priv->txq[txq_id].q.read_ptr; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4245 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 4246 | /* The queue is not empty */ |
| 4247 | if (write_ptr != read_ptr) { |
| 4248 | IWL_DEBUG_HT("Stopping a non empty AGG HW QUEUE\n"); |
| 4249 | priv->stations[sta_id].tid[tid].agg.state = |
| 4250 | IWL_EMPTYING_HW_QUEUE_DELBA; |
| 4251 | return 0; |
| 4252 | } |
| 4253 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4254 | IWL_DEBUG_HT("HW queue is empty\n"); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 4255 | priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF; |
| 4256 | |
| 4257 | spin_lock_irqsave(&priv->lock, flags); |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 4258 | ret = iwl4965_tx_queue_agg_disable(priv, txq_id, ssn, tx_fifo_id); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 4259 | spin_unlock_irqrestore(&priv->lock, flags); |
| 4260 | |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 4261 | if (ret) |
| 4262 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4263 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4264 | ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, ra, tid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4265 | |
| 4266 | return 0; |
| 4267 | } |
| 4268 | |
Ron Rindjunsky | 8114fcf | 2008-01-28 14:07:23 +0200 | [diff] [blame] | 4269 | int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw, |
| 4270 | enum ieee80211_ampdu_mlme_action action, |
| 4271 | const u8 *addr, u16 tid, u16 *ssn) |
| 4272 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4273 | struct iwl_priv *priv = hw->priv; |
Ron Rindjunsky | 8114fcf | 2008-01-28 14:07:23 +0200 | [diff] [blame] | 4274 | DECLARE_MAC_BUF(mac); |
| 4275 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4276 | IWL_DEBUG_HT("A-MPDU action on addr %s tid %d\n", |
| 4277 | print_mac(mac, addr), tid); |
| 4278 | |
Ron Rindjunsky | 8114fcf | 2008-01-28 14:07:23 +0200 | [diff] [blame] | 4279 | switch (action) { |
| 4280 | case IEEE80211_AMPDU_RX_START: |
| 4281 | IWL_DEBUG_HT("start Rx\n"); |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4282 | return iwl4965_rx_agg_start(priv, addr, tid, *ssn); |
Ron Rindjunsky | 8114fcf | 2008-01-28 14:07:23 +0200 | [diff] [blame] | 4283 | case IEEE80211_AMPDU_RX_STOP: |
| 4284 | IWL_DEBUG_HT("stop Rx\n"); |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4285 | return iwl4965_rx_agg_stop(priv, addr, tid); |
Ron Rindjunsky | 8114fcf | 2008-01-28 14:07:23 +0200 | [diff] [blame] | 4286 | case IEEE80211_AMPDU_TX_START: |
| 4287 | IWL_DEBUG_HT("start Tx\n"); |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4288 | return iwl4965_tx_agg_start(hw, addr, tid, ssn); |
Ron Rindjunsky | 8114fcf | 2008-01-28 14:07:23 +0200 | [diff] [blame] | 4289 | case IEEE80211_AMPDU_TX_STOP: |
| 4290 | IWL_DEBUG_HT("stop Tx\n"); |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 4291 | return iwl4965_tx_agg_stop(hw, addr, tid); |
Ron Rindjunsky | 8114fcf | 2008-01-28 14:07:23 +0200 | [diff] [blame] | 4292 | default: |
| 4293 | IWL_DEBUG_HT("unknown\n"); |
| 4294 | return -EINVAL; |
| 4295 | break; |
| 4296 | } |
| 4297 | return 0; |
| 4298 | } |
| 4299 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4300 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4301 | |
| 4302 | /* Set up 4965-specific Rx frame reply handlers */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4303 | void iwl4965_hw_rx_handler_setup(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4304 | { |
| 4305 | /* Legacy Rx frames */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4306 | priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4307 | |
| 4308 | /* High-throughput (HT) Rx frames */ |
| 4309 | priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy; |
| 4310 | priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx; |
| 4311 | |
| 4312 | priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] = |
| 4313 | iwl4965_rx_missed_beacon_notif; |
| 4314 | |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4315 | #ifdef CONFIG_IWL4965_HT |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4316 | priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba; |
Christoph Hellwig | c8b0e6e | 2007-10-25 17:15:51 +0800 | [diff] [blame] | 4317 | #endif /* CONFIG_IWL4965_HT */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4318 | } |
| 4319 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4320 | void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4321 | { |
| 4322 | INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work); |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 4323 | #ifdef CONFIG_IWL4965_RUN_TIME_CALIB |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4324 | INIT_WORK(&priv->sensitivity_work, iwl4965_bg_sensitivity_work); |
| 4325 | #endif |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4326 | init_timer(&priv->statistics_periodic); |
| 4327 | priv->statistics_periodic.data = (unsigned long)priv; |
| 4328 | priv->statistics_periodic.function = iwl4965_bg_statistics_periodic; |
| 4329 | } |
| 4330 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 4331 | void iwl4965_hw_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 4332 | { |
| 4333 | del_timer_sync(&priv->statistics_periodic); |
| 4334 | |
| 4335 | cancel_delayed_work(&priv->init_alive_start); |
| 4336 | } |
| 4337 | |
Tomas Winkler | 3c424c2 | 2008-04-15 16:01:42 -0700 | [diff] [blame] | 4338 | |
| 4339 | static struct iwl_hcmd_ops iwl4965_hcmd = { |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 4340 | .rxon_assoc = iwl4965_send_rxon_assoc, |
Tomas Winkler | 3c424c2 | 2008-04-15 16:01:42 -0700 | [diff] [blame] | 4341 | }; |
| 4342 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4343 | static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = { |
| 4344 | .enqueue_hcmd = iwl4965_enqueue_hcmd, |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 4345 | #ifdef CONFIG_IWL4965_RUN_TIME_CALIB |
| 4346 | .chain_noise_reset = iwl4965_chain_noise_reset, |
| 4347 | .gain_computation = iwl4965_gain_computation, |
| 4348 | #endif |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4349 | }; |
| 4350 | |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 4351 | static struct iwl_lib_ops iwl4965_lib = { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 4352 | .init_drv = iwl4965_init_drv, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 4353 | .set_hw_params = iwl4965_hw_set_hw_params, |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 4354 | .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl, |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 4355 | .hw_nic_init = iwl4965_hw_nic_init, |
| 4356 | .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr, |
| 4357 | .alive_notify = iwl4965_alive_notify, |
| 4358 | .load_ucode = iwl4965_load_bsm, |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 4359 | .apm_ops = { |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 4360 | .init = iwl4965_apm_init, |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 4361 | .set_pwr_src = iwl4965_set_pwr_src, |
| 4362 | }, |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 4363 | .eeprom_ops = { |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 4364 | .regulatory_bands = { |
| 4365 | EEPROM_REGULATORY_BAND_1_CHANNELS, |
| 4366 | EEPROM_REGULATORY_BAND_2_CHANNELS, |
| 4367 | EEPROM_REGULATORY_BAND_3_CHANNELS, |
| 4368 | EEPROM_REGULATORY_BAND_4_CHANNELS, |
| 4369 | EEPROM_REGULATORY_BAND_5_CHANNELS, |
| 4370 | EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS, |
| 4371 | EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS |
| 4372 | }, |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 4373 | .verify_signature = iwlcore_eeprom_verify_signature, |
| 4374 | .acquire_semaphore = iwlcore_eeprom_acquire_semaphore, |
| 4375 | .release_semaphore = iwlcore_eeprom_release_semaphore, |
Tomas Winkler | 8614f36 | 2008-04-23 17:14:55 -0700 | [diff] [blame^] | 4376 | .check_version = iwl4965_eeprom_check_version, |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 4377 | .query_addr = iwlcore_eeprom_query_addr, |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 4378 | }, |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 4379 | .radio_kill_sw = iwl4965_radio_kill_sw, |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4380 | .set_power = iwl4965_set_power, |
| 4381 | .update_chain_flags = iwl4965_update_chain_flags, |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 4382 | }; |
| 4383 | |
| 4384 | static struct iwl_ops iwl4965_ops = { |
| 4385 | .lib = &iwl4965_lib, |
Tomas Winkler | 3c424c2 | 2008-04-15 16:01:42 -0700 | [diff] [blame] | 4386 | .hcmd = &iwl4965_hcmd, |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 4387 | .utils = &iwl4965_hcmd_utils, |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 4388 | }; |
| 4389 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 4390 | struct iwl_cfg iwl4965_agn_cfg = { |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4391 | .name = "4965AGN", |
Tomas Winkler | 4bf775c | 2008-03-04 18:09:31 -0800 | [diff] [blame] | 4392 | .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode", |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4393 | .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N, |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 4394 | .eeprom_size = IWL4965_EEPROM_IMG_SIZE, |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 4395 | .ops = &iwl4965_ops, |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 4396 | .mod_params = &iwl4965_mod_params, |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 4397 | }; |
| 4398 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 4399 | module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444); |
| 4400 | MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); |
| 4401 | module_param_named(disable, iwl4965_mod_params.disable, int, 0444); |
| 4402 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Emmanuel Grumbach | fcc76c6 | 2008-04-15 16:01:47 -0700 | [diff] [blame] | 4403 | module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444); |
| 4404 | MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])\n"); |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 4405 | module_param_named(debug, iwl4965_mod_params.debug, int, 0444); |
| 4406 | MODULE_PARM_DESC(debug, "debug output mask"); |
| 4407 | module_param_named( |
| 4408 | disable_hw_scan, iwl4965_mod_params.disable_hw_scan, int, 0444); |
| 4409 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 4410 | |
| 4411 | module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444); |
| 4412 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 4413 | |
| 4414 | /* QoS */ |
| 4415 | module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444); |
| 4416 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionality"); |
| 4417 | module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444); |
| 4418 | MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size"); |
| 4419 | |