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" |
Tomas Winkler | 3e0d4cb | 2008-04-24 11:55:38 -0700 | [diff] [blame] | 42 | #include "iwl-dev.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" |
Tomas Winkler | 5083e56 | 2008-05-29 16:35:15 +0800 | [diff] [blame] | 47 | #include "iwl-sta.h" |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 48 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 49 | /* module parameters */ |
| 50 | static struct iwl_mod_params iwl4965_mod_params = { |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 51 | .num_of_queues = IWL49_NUM_QUEUES, |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 52 | .enable_qos = 1, |
| 53 | .amsdu_size_8K = 1, |
Ester Kummer | 3a1081e | 2008-05-06 11:05:14 +0800 | [diff] [blame] | 54 | .restart_fw = 1, |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 55 | /* the rest are 0 by default */ |
| 56 | }; |
| 57 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 58 | /* check contents of special bootstrap uCode SRAM */ |
| 59 | static int iwl4965_verify_bsm(struct iwl_priv *priv) |
| 60 | { |
| 61 | __le32 *image = priv->ucode_boot.v_addr; |
| 62 | u32 len = priv->ucode_boot.len; |
| 63 | u32 reg; |
| 64 | u32 val; |
| 65 | |
| 66 | IWL_DEBUG_INFO("Begin verify bsm\n"); |
| 67 | |
| 68 | /* verify BSM SRAM contents */ |
| 69 | val = iwl_read_prph(priv, BSM_WR_DWCOUNT_REG); |
| 70 | for (reg = BSM_SRAM_LOWER_BOUND; |
| 71 | reg < BSM_SRAM_LOWER_BOUND + len; |
| 72 | reg += sizeof(u32), image++) { |
| 73 | val = iwl_read_prph(priv, reg); |
| 74 | if (val != le32_to_cpu(*image)) { |
| 75 | IWL_ERROR("BSM uCode verification failed at " |
| 76 | "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n", |
| 77 | BSM_SRAM_LOWER_BOUND, |
| 78 | reg - BSM_SRAM_LOWER_BOUND, len, |
| 79 | val, le32_to_cpu(*image)); |
| 80 | return -EIO; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n"); |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * iwl4965_load_bsm - Load bootstrap instructions |
| 91 | * |
| 92 | * BSM operation: |
| 93 | * |
| 94 | * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program |
| 95 | * in special SRAM that does not power down during RFKILL. When powering back |
| 96 | * up after power-saving sleeps (or during initial uCode load), the BSM loads |
| 97 | * the bootstrap program into the on-board processor, and starts it. |
| 98 | * |
| 99 | * The bootstrap program loads (via DMA) instructions and data for a new |
| 100 | * program from host DRAM locations indicated by the host driver in the |
| 101 | * BSM_DRAM_* registers. Once the new program is loaded, it starts |
| 102 | * automatically. |
| 103 | * |
| 104 | * When initializing the NIC, the host driver points the BSM to the |
| 105 | * "initialize" uCode image. This uCode sets up some internal data, then |
| 106 | * notifies host via "initialize alive" that it is complete. |
| 107 | * |
| 108 | * The host then replaces the BSM_DRAM_* pointer values to point to the |
| 109 | * normal runtime uCode instructions and a backup uCode data cache buffer |
| 110 | * (filled initially with starting data values for the on-board processor), |
| 111 | * then triggers the "initialize" uCode to load and launch the runtime uCode, |
| 112 | * which begins normal operation. |
| 113 | * |
| 114 | * When doing a power-save shutdown, runtime uCode saves data SRAM into |
| 115 | * the backup data cache in DRAM before SRAM is powered down. |
| 116 | * |
| 117 | * When powering back up, the BSM loads the bootstrap program. This reloads |
| 118 | * the runtime uCode instructions and the backup data cache into SRAM, |
| 119 | * and re-launches the runtime uCode from where it left off. |
| 120 | */ |
| 121 | static int iwl4965_load_bsm(struct iwl_priv *priv) |
| 122 | { |
| 123 | __le32 *image = priv->ucode_boot.v_addr; |
| 124 | u32 len = priv->ucode_boot.len; |
| 125 | dma_addr_t pinst; |
| 126 | dma_addr_t pdata; |
| 127 | u32 inst_len; |
| 128 | u32 data_len; |
| 129 | int i; |
| 130 | u32 done; |
| 131 | u32 reg_offset; |
| 132 | int ret; |
| 133 | |
| 134 | IWL_DEBUG_INFO("Begin load bsm\n"); |
| 135 | |
Ron Rindjunsky | fe9b6b7 | 2008-05-29 16:35:06 +0800 | [diff] [blame] | 136 | priv->ucode_type = UCODE_RT; |
| 137 | |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 138 | /* make sure bootstrap program is no larger than BSM's SRAM size */ |
| 139 | if (len > IWL_MAX_BSM_SIZE) |
| 140 | return -EINVAL; |
| 141 | |
| 142 | /* Tell bootstrap uCode where to find the "Initialize" uCode |
| 143 | * in host DRAM ... host DRAM physical address bits 35:4 for 4965. |
Tomas Winkler | 2d87889 | 2008-05-29 16:34:51 +0800 | [diff] [blame] | 144 | * NOTE: iwl_init_alive_start() will replace these values, |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 145 | * after the "initialize" uCode has run, to point to |
Tomas Winkler | 2d87889 | 2008-05-29 16:34:51 +0800 | [diff] [blame] | 146 | * runtime/protocol instructions and backup data cache. |
| 147 | */ |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 148 | pinst = priv->ucode_init.p_addr >> 4; |
| 149 | pdata = priv->ucode_init_data.p_addr >> 4; |
| 150 | inst_len = priv->ucode_init.len; |
| 151 | data_len = priv->ucode_init_data.len; |
| 152 | |
| 153 | ret = iwl_grab_nic_access(priv); |
| 154 | if (ret) |
| 155 | return ret; |
| 156 | |
| 157 | iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 158 | iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 159 | iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len); |
| 160 | iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len); |
| 161 | |
| 162 | /* Fill BSM memory with bootstrap instructions */ |
| 163 | for (reg_offset = BSM_SRAM_LOWER_BOUND; |
| 164 | reg_offset < BSM_SRAM_LOWER_BOUND + len; |
| 165 | reg_offset += sizeof(u32), image++) |
| 166 | _iwl_write_prph(priv, reg_offset, le32_to_cpu(*image)); |
| 167 | |
| 168 | ret = iwl4965_verify_bsm(priv); |
| 169 | if (ret) { |
| 170 | iwl_release_nic_access(priv); |
| 171 | return ret; |
| 172 | } |
| 173 | |
| 174 | /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */ |
| 175 | iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0); |
| 176 | iwl_write_prph(priv, BSM_WR_MEM_DST_REG, RTC_INST_LOWER_BOUND); |
| 177 | iwl_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32)); |
| 178 | |
| 179 | /* Load bootstrap code into instruction SRAM now, |
| 180 | * to prepare to load "initialize" uCode */ |
| 181 | iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START); |
| 182 | |
| 183 | /* Wait for load of bootstrap uCode to finish */ |
| 184 | for (i = 0; i < 100; i++) { |
| 185 | done = iwl_read_prph(priv, BSM_WR_CTRL_REG); |
| 186 | if (!(done & BSM_WR_CTRL_REG_BIT_START)) |
| 187 | break; |
| 188 | udelay(10); |
| 189 | } |
| 190 | if (i < 100) |
| 191 | IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i); |
| 192 | else { |
| 193 | IWL_ERROR("BSM write did not complete!\n"); |
| 194 | return -EIO; |
| 195 | } |
| 196 | |
| 197 | /* Enable future boot loads whenever power management unit triggers it |
| 198 | * (e.g. when powering back up after power-save shutdown) */ |
| 199 | iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN); |
| 200 | |
| 201 | iwl_release_nic_access(priv); |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
Emmanuel Grumbach | f3ccc08 | 2008-05-05 10:22:45 +0800 | [diff] [blame] | 206 | /** |
| 207 | * iwl4965_set_ucode_ptrs - Set uCode address location |
| 208 | * |
| 209 | * Tell initialization uCode where to find runtime uCode. |
| 210 | * |
| 211 | * BSM registers initially contain pointers to initialization uCode. |
| 212 | * We need to replace them to load runtime uCode inst and data, |
| 213 | * and to save runtime data when powering down. |
| 214 | */ |
| 215 | static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv) |
| 216 | { |
| 217 | dma_addr_t pinst; |
| 218 | dma_addr_t pdata; |
| 219 | unsigned long flags; |
| 220 | int ret = 0; |
| 221 | |
| 222 | /* bits 35:4 for 4965 */ |
| 223 | pinst = priv->ucode_code.p_addr >> 4; |
| 224 | pdata = priv->ucode_data_backup.p_addr >> 4; |
| 225 | |
| 226 | spin_lock_irqsave(&priv->lock, flags); |
| 227 | ret = iwl_grab_nic_access(priv); |
| 228 | if (ret) { |
| 229 | spin_unlock_irqrestore(&priv->lock, flags); |
| 230 | return ret; |
| 231 | } |
| 232 | |
| 233 | /* Tell bootstrap uCode where to find image to load */ |
| 234 | iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst); |
| 235 | iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata); |
| 236 | iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, |
| 237 | priv->ucode_data.len); |
| 238 | |
| 239 | /* Inst bytecount must be last to set up, bit 31 signals uCode |
| 240 | * that all new ptr/size info is in place */ |
| 241 | iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, |
| 242 | priv->ucode_code.len | BSM_DRAM_INST_LOAD); |
| 243 | iwl_release_nic_access(priv); |
| 244 | |
| 245 | spin_unlock_irqrestore(&priv->lock, flags); |
| 246 | |
| 247 | IWL_DEBUG_INFO("Runtime uCode pointers are set.\n"); |
| 248 | |
| 249 | return ret; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received |
| 254 | * |
| 255 | * Called after REPLY_ALIVE notification received from "initialize" uCode. |
| 256 | * |
| 257 | * The 4965 "initialize" ALIVE reply contains calibration data for: |
| 258 | * Voltage, temperature, and MIMO tx gain correction, now stored in priv |
| 259 | * (3945 does not contain this data). |
| 260 | * |
| 261 | * Tell "initialize" uCode to go ahead and load the runtime uCode. |
| 262 | */ |
| 263 | static void iwl4965_init_alive_start(struct iwl_priv *priv) |
| 264 | { |
| 265 | /* Check alive response for "valid" sign from uCode */ |
| 266 | if (priv->card_alive_init.is_valid != UCODE_VALID_OK) { |
| 267 | /* We had an error bringing up the hardware, so take it |
| 268 | * all the way back down so we can try again */ |
| 269 | IWL_DEBUG_INFO("Initialize Alive failed.\n"); |
| 270 | goto restart; |
| 271 | } |
| 272 | |
| 273 | /* Bootstrap uCode has loaded initialize uCode ... verify inst image. |
| 274 | * This is a paranoid check, because we would not have gotten the |
| 275 | * "initialize" alive if code weren't properly loaded. */ |
| 276 | if (iwl_verify_ucode(priv)) { |
| 277 | /* Runtime instruction load was bad; |
| 278 | * take it all the way back down so we can try again */ |
| 279 | IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n"); |
| 280 | goto restart; |
| 281 | } |
| 282 | |
| 283 | /* Calculate temperature */ |
| 284 | priv->temperature = iwl4965_get_temperature(priv); |
| 285 | |
| 286 | /* Send pointers to protocol/runtime uCode image ... init code will |
| 287 | * load and launch runtime uCode, which will send us another "Alive" |
| 288 | * notification. */ |
| 289 | IWL_DEBUG_INFO("Initialization Alive received.\n"); |
| 290 | if (iwl4965_set_ucode_ptrs(priv)) { |
| 291 | /* Runtime instruction load won't happen; |
| 292 | * take it all the way back down so we can try again */ |
| 293 | IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n"); |
| 294 | goto restart; |
| 295 | } |
| 296 | return; |
| 297 | |
| 298 | restart: |
| 299 | queue_work(priv->workqueue, &priv->restart); |
| 300 | } |
| 301 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 302 | static int is_fat_channel(__le32 rxon_flags) |
| 303 | { |
| 304 | return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) || |
| 305 | (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK); |
| 306 | } |
| 307 | |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 308 | int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags) |
| 309 | { |
| 310 | int idx = 0; |
| 311 | |
| 312 | /* 4965 HT rate format */ |
| 313 | if (rate_n_flags & RATE_MCS_HT_MSK) { |
| 314 | idx = (rate_n_flags & 0xff); |
| 315 | |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 316 | if (idx >= IWL_RATE_MIMO2_6M_PLCP) |
| 317 | idx = idx - IWL_RATE_MIMO2_6M_PLCP; |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 318 | |
| 319 | idx += IWL_FIRST_OFDM_RATE; |
| 320 | /* skip 9M not supported in ht*/ |
| 321 | if (idx >= IWL_RATE_9M_INDEX) |
| 322 | idx += 1; |
| 323 | if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE)) |
| 324 | return idx; |
| 325 | |
| 326 | /* 4965 legacy rate format, search for match in table */ |
| 327 | } else { |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 328 | for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++) |
| 329 | if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF)) |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 330 | return idx; |
| 331 | } |
| 332 | |
| 333 | return -1; |
| 334 | } |
| 335 | |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 336 | /** |
| 337 | * translate ucode response to mac80211 tx status control values |
| 338 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 339 | void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 340 | struct ieee80211_tx_info *control) |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 341 | { |
| 342 | int rate_index; |
| 343 | |
| 344 | control->antenna_sel_tx = |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 345 | ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS); |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 346 | if (rate_n_flags & RATE_MCS_HT_MSK) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 347 | control->flags |= IEEE80211_TX_CTL_OFDM_HT; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 348 | if (rate_n_flags & RATE_MCS_GF_MSK) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 349 | control->flags |= IEEE80211_TX_CTL_GREEN_FIELD; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 350 | if (rate_n_flags & RATE_MCS_FAT_MSK) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 351 | control->flags |= IEEE80211_TX_CTL_40_MHZ_WIDTH; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 352 | if (rate_n_flags & RATE_MCS_DUP_MSK) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 353 | control->flags |= IEEE80211_TX_CTL_DUP_DATA; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 354 | if (rate_n_flags & RATE_MCS_SGI_MSK) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 355 | control->flags |= IEEE80211_TX_CTL_SHORT_GI; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 356 | rate_index = iwl4965_hwrate_to_plcp_idx(rate_n_flags); |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 357 | if (control->band == IEEE80211_BAND_5GHZ) |
| 358 | rate_index -= IWL_FIRST_OFDM_RATE; |
| 359 | control->tx_rate_idx = rate_index; |
Ron Rindjunsky | 4c424e4 | 2008-03-04 18:09:27 -0800 | [diff] [blame] | 360 | } |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 361 | |
Tomas Winkler | 8614f36 | 2008-04-23 17:14:55 -0700 | [diff] [blame] | 362 | /* |
| 363 | * EEPROM handlers |
| 364 | */ |
| 365 | |
| 366 | static int iwl4965_eeprom_check_version(struct iwl_priv *priv) |
| 367 | { |
| 368 | u16 eeprom_ver; |
| 369 | u16 calib_ver; |
| 370 | |
| 371 | eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION); |
| 372 | |
| 373 | calib_ver = iwl_eeprom_query16(priv, EEPROM_4965_CALIB_VERSION_OFFSET); |
| 374 | |
| 375 | if (eeprom_ver < EEPROM_4965_EEPROM_VERSION || |
| 376 | calib_ver < EEPROM_4965_TX_POWER_VERSION) |
| 377 | goto err; |
| 378 | |
| 379 | return 0; |
| 380 | err: |
| 381 | IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n", |
| 382 | eeprom_ver, EEPROM_4965_EEPROM_VERSION, |
| 383 | calib_ver, EEPROM_4965_TX_POWER_VERSION); |
| 384 | return -EINVAL; |
| 385 | |
| 386 | } |
Tomas Winkler | 079a253 | 2008-04-17 16:03:39 -0700 | [diff] [blame] | 387 | 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] | 388 | { |
Tomas Winkler | d860965 | 2007-10-25 17:15:35 +0800 | [diff] [blame] | 389 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 390 | unsigned long flags; |
| 391 | |
| 392 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 393 | ret = iwl_grab_nic_access(priv); |
Tomas Winkler | d860965 | 2007-10-25 17:15:35 +0800 | [diff] [blame] | 394 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 395 | spin_unlock_irqrestore(&priv->lock, flags); |
Tomas Winkler | d860965 | 2007-10-25 17:15:35 +0800 | [diff] [blame] | 396 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 399 | if (src == IWL_PWR_SRC_VAUX) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 400 | u32 val; |
Tomas Winkler | d860965 | 2007-10-25 17:15:35 +0800 | [diff] [blame] | 401 | ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE, |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 402 | &val); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 403 | |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 404 | if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT) { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 405 | iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 406 | APMG_PS_CTRL_VAL_PWR_SRC_VAUX, |
| 407 | ~APMG_PS_CTRL_MSK_PWR_SRC); |
| 408 | } |
| 409 | } else { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 410 | iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG, |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 411 | APMG_PS_CTRL_VAL_PWR_SRC_VMAIN, |
| 412 | ~APMG_PS_CTRL_MSK_PWR_SRC); |
| 413 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 414 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 415 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 416 | spin_unlock_irqrestore(&priv->lock, flags); |
| 417 | |
Tomas Winkler | d860965 | 2007-10-25 17:15:35 +0800 | [diff] [blame] | 418 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Tomas Winkler | da1bc45 | 2008-05-29 16:35:00 +0800 | [diff] [blame] | 421 | /* |
| 422 | * Activate/Deactivat Tx DMA/FIFO channels according tx fifos mask |
| 423 | * must be called under priv->lock and mac access |
| 424 | */ |
| 425 | static void iwl4965_txq_set_sched(struct iwl_priv *priv, u32 mask) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 426 | { |
Tomas Winkler | da1bc45 | 2008-05-29 16:35:00 +0800 | [diff] [blame] | 427 | iwl_write_prph(priv, IWL49_SCD_TXFACT, mask); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 428 | } |
Ron Rindjunsky | 5a676bb | 2008-05-05 10:22:42 +0800 | [diff] [blame] | 429 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 430 | static int iwl4965_apm_init(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 431 | { |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 432 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 433 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 434 | iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS, |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 435 | CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 436 | |
Tomas Winkler | 8f06189 | 2008-05-29 16:34:56 +0800 | [diff] [blame] | 437 | /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */ |
| 438 | iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS, |
| 439 | CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX); |
| 440 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 441 | /* set "initialization complete" bit to move adapter |
| 442 | * D0U* --> D0A* state */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 443 | 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] | 444 | |
| 445 | /* wait for clock stabilization */ |
| 446 | ret = iwl_poll_bit(priv, CSR_GP_CNTRL, |
| 447 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, |
| 448 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000); |
| 449 | if (ret < 0) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 450 | IWL_DEBUG_INFO("Failed to init the card\n"); |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 451 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 454 | ret = iwl_grab_nic_access(priv); |
| 455 | if (ret) |
| 456 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 457 | |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 458 | /* enable DMA */ |
Tomas Winkler | 8f06189 | 2008-05-29 16:34:56 +0800 | [diff] [blame] | 459 | iwl_write_prph(priv, APMG_CLK_CTRL_REG, APMG_CLK_VAL_DMA_CLK_RQT | |
| 460 | APMG_CLK_VAL_BSM_CLK_RQT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 461 | |
| 462 | udelay(20); |
| 463 | |
Tomas Winkler | 8f06189 | 2008-05-29 16:34:56 +0800 | [diff] [blame] | 464 | /* disable L1-Active */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 465 | iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 466 | APMG_PCIDEV_STT_VAL_L1_ACT_DIS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 467 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 468 | iwl_release_nic_access(priv); |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 469 | out: |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 470 | return ret; |
| 471 | } |
| 472 | |
Tomas Winkler | 694cc56 | 2008-04-24 11:55:22 -0700 | [diff] [blame] | 473 | |
| 474 | static void iwl4965_nic_config(struct iwl_priv *priv) |
| 475 | { |
| 476 | unsigned long flags; |
| 477 | u32 val; |
| 478 | u16 radio_cfg; |
| 479 | u8 val_link; |
| 480 | |
| 481 | spin_lock_irqsave(&priv->lock, flags); |
| 482 | |
| 483 | if ((priv->rev_id & 0x80) == 0x80 && (priv->rev_id & 0x7f) < 8) { |
| 484 | pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val); |
| 485 | /* Enable No Snoop field */ |
| 486 | pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8, |
| 487 | val & ~(1 << 11)); |
| 488 | } |
| 489 | |
| 490 | pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link); |
| 491 | |
Tomas Winkler | 8f06189 | 2008-05-29 16:34:56 +0800 | [diff] [blame] | 492 | /* L1 is enabled by BIOS */ |
| 493 | if ((val_link & PCI_LINK_VAL_L1_EN) == PCI_LINK_VAL_L1_EN) |
| 494 | /* diable L0S disabled L1A enabled */ |
| 495 | iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED); |
| 496 | else |
| 497 | /* L0S enabled L1A disabled */ |
| 498 | iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED); |
Tomas Winkler | 694cc56 | 2008-04-24 11:55:22 -0700 | [diff] [blame] | 499 | |
| 500 | radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG); |
| 501 | |
| 502 | /* write radio config values to register */ |
| 503 | if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX) |
| 504 | iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, |
| 505 | EEPROM_RF_CFG_TYPE_MSK(radio_cfg) | |
| 506 | EEPROM_RF_CFG_STEP_MSK(radio_cfg) | |
| 507 | EEPROM_RF_CFG_DASH_MSK(radio_cfg)); |
| 508 | |
| 509 | /* set CSR_HW_CONFIG_REG for uCode use */ |
| 510 | iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG, |
| 511 | CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI | |
| 512 | CSR_HW_IF_CONFIG_REG_BIT_MAC_SI); |
| 513 | |
| 514 | priv->calib_info = (struct iwl_eeprom_calib_info *) |
| 515 | iwl_eeprom_query_addr(priv, EEPROM_4965_CALIB_TXPOWER_OFFSET); |
| 516 | |
| 517 | spin_unlock_irqrestore(&priv->lock, flags); |
| 518 | } |
| 519 | |
Tomas Winkler | 46315e0 | 2008-05-29 16:34:59 +0800 | [diff] [blame] | 520 | static int iwl4965_apm_stop_master(struct iwl_priv *priv) |
| 521 | { |
| 522 | int ret = 0; |
| 523 | unsigned long flags; |
| 524 | |
| 525 | spin_lock_irqsave(&priv->lock, flags); |
| 526 | |
| 527 | /* set stop master bit */ |
| 528 | iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER); |
| 529 | |
| 530 | ret = iwl_poll_bit(priv, CSR_RESET, |
| 531 | CSR_RESET_REG_FLAG_MASTER_DISABLED, |
| 532 | CSR_RESET_REG_FLAG_MASTER_DISABLED, 100); |
| 533 | if (ret < 0) |
| 534 | goto out; |
| 535 | |
| 536 | out: |
| 537 | spin_unlock_irqrestore(&priv->lock, flags); |
| 538 | IWL_DEBUG_INFO("stop master\n"); |
| 539 | |
| 540 | return ret; |
| 541 | } |
| 542 | |
Tomas Winkler | f118a91 | 2008-05-29 16:34:58 +0800 | [diff] [blame] | 543 | static void iwl4965_apm_stop(struct iwl_priv *priv) |
| 544 | { |
| 545 | unsigned long flags; |
| 546 | |
Tomas Winkler | 46315e0 | 2008-05-29 16:34:59 +0800 | [diff] [blame] | 547 | iwl4965_apm_stop_master(priv); |
Tomas Winkler | f118a91 | 2008-05-29 16:34:58 +0800 | [diff] [blame] | 548 | |
| 549 | spin_lock_irqsave(&priv->lock, flags); |
| 550 | |
| 551 | iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
| 552 | |
| 553 | udelay(10); |
| 554 | |
| 555 | iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); |
| 556 | spin_unlock_irqrestore(&priv->lock, flags); |
| 557 | } |
| 558 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 559 | static int iwl4965_apm_reset(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 560 | { |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 561 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 562 | unsigned long flags; |
| 563 | |
Tomas Winkler | 46315e0 | 2008-05-29 16:34:59 +0800 | [diff] [blame] | 564 | iwl4965_apm_stop_master(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 565 | |
| 566 | spin_lock_irqsave(&priv->lock, flags); |
| 567 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 568 | iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 569 | |
| 570 | udelay(10); |
| 571 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 572 | /* FIXME: put here L1A -L0S w/a */ |
| 573 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 574 | iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE); |
Tomas Winkler | f118a91 | 2008-05-29 16:34:58 +0800 | [diff] [blame] | 575 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 576 | ret = iwl_poll_bit(priv, CSR_RESET, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 577 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, |
| 578 | CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25); |
| 579 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 580 | if (ret) |
| 581 | goto out; |
| 582 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 583 | udelay(10); |
| 584 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 585 | ret = iwl_grab_nic_access(priv); |
| 586 | if (ret) |
| 587 | goto out; |
| 588 | /* Enable DMA and BSM Clock */ |
| 589 | iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT | |
| 590 | APMG_CLK_VAL_BSM_CLK_RQT); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 591 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 592 | udelay(10); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 593 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 594 | /* disable L1A */ |
| 595 | iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG, |
| 596 | APMG_PCIDEV_STT_VAL_L1_ACT_DIS); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 597 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 598 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 599 | |
| 600 | clear_bit(STATUS_HCMD_ACTIVE, &priv->status); |
| 601 | wake_up_interruptible(&priv->wait_command_queue); |
| 602 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 603 | out: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 604 | spin_unlock_irqrestore(&priv->lock, flags); |
| 605 | |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 606 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | #define REG_RECALIB_PERIOD (60) |
| 610 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 611 | void iwl4965_rf_kill_ct_config(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 612 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 613 | struct iwl4965_ct_kill_config cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 614 | unsigned long flags; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 615 | int ret = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 616 | |
| 617 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 618 | iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 619 | CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT); |
| 620 | spin_unlock_irqrestore(&priv->lock, flags); |
| 621 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 622 | cmd.critical_temperature_R = |
Emmanuel Grumbach | b73cdf2 | 2008-04-21 15:41:58 -0700 | [diff] [blame] | 623 | cpu_to_le32(priv->hw_params.ct_kill_threshold); |
| 624 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 625 | ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD, |
| 626 | sizeof(cmd), &cmd); |
| 627 | if (ret) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 628 | IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n"); |
| 629 | else |
Emmanuel Grumbach | b73cdf2 | 2008-04-21 15:41:58 -0700 | [diff] [blame] | 630 | IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded, " |
| 631 | "critical temperature is %d\n", |
| 632 | cmd.critical_temperature_R); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 635 | /* Reset differential Rx gains in NIC to prepare for chain noise calibration. |
| 636 | * Called after every association, but this runs only once! |
| 637 | * ... once chain noise is calibrated the first time, it's good forever. */ |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 638 | static void iwl4965_chain_noise_reset(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 639 | { |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 640 | struct iwl_chain_noise_data *data = &(priv->chain_noise_data); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 641 | |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 642 | if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 643 | struct iwl4965_calibration_cmd cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 644 | |
| 645 | memset(&cmd, 0, sizeof(cmd)); |
| 646 | cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD; |
| 647 | cmd.diff_gain_a = 0; |
| 648 | cmd.diff_gain_b = 0; |
| 649 | cmd.diff_gain_c = 0; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 650 | if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD, |
| 651 | sizeof(cmd), &cmd)) |
| 652 | IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 653 | data->state = IWL_CHAIN_NOISE_ACCUMULATE; |
| 654 | IWL_DEBUG_CALIB("Run chain_noise_calibrate\n"); |
| 655 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 658 | static void iwl4965_gain_computation(struct iwl_priv *priv, |
| 659 | u32 *average_noise, |
| 660 | u16 min_average_noise_antenna_i, |
| 661 | u32 min_average_noise) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 662 | { |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 663 | int i, ret; |
| 664 | struct iwl_chain_noise_data *data = &priv->chain_noise_data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 665 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 666 | data->delta_gain_code[min_average_noise_antenna_i] = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 667 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 668 | for (i = 0; i < NUM_RX_CHAINS; i++) { |
| 669 | s32 delta_g = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 670 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 671 | if (!(data->disconn_array[i]) && |
| 672 | (data->delta_gain_code[i] == |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 673 | CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) { |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 674 | delta_g = average_noise[i] - min_average_noise; |
| 675 | data->delta_gain_code[i] = (u8)((delta_g * 10) / 15); |
| 676 | data->delta_gain_code[i] = |
| 677 | min(data->delta_gain_code[i], |
| 678 | (u8) CHAIN_NOISE_MAX_DELTA_GAIN_CODE); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 679 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 680 | data->delta_gain_code[i] = |
| 681 | (data->delta_gain_code[i] | (1 << 2)); |
| 682 | } else { |
| 683 | data->delta_gain_code[i] = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 684 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 685 | } |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 686 | IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n", |
| 687 | data->delta_gain_code[0], |
| 688 | data->delta_gain_code[1], |
| 689 | data->delta_gain_code[2]); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 690 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 691 | /* Differential gain gets sent to uCode only once */ |
| 692 | if (!data->radio_write) { |
| 693 | struct iwl4965_calibration_cmd cmd; |
| 694 | data->radio_write = 1; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 695 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 696 | memset(&cmd, 0, sizeof(cmd)); |
| 697 | cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD; |
| 698 | cmd.diff_gain_a = data->delta_gain_code[0]; |
| 699 | cmd.diff_gain_b = data->delta_gain_code[1]; |
| 700 | cmd.diff_gain_c = data->delta_gain_code[2]; |
| 701 | ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD, |
| 702 | sizeof(cmd), &cmd); |
| 703 | if (ret) |
| 704 | IWL_DEBUG_CALIB("fail sending cmd " |
| 705 | "REPLY_PHY_CALIBRATION_CMD \n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 706 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 707 | /* TODO we might want recalculate |
| 708 | * rx_chain in rxon cmd */ |
| 709 | |
| 710 | /* Mark so we run this algo only once! */ |
| 711 | data->state = IWL_CHAIN_NOISE_CALIBRATED; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 712 | } |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 713 | data->chain_noise_a = 0; |
| 714 | data->chain_noise_b = 0; |
| 715 | data->chain_noise_c = 0; |
| 716 | data->chain_signal_a = 0; |
| 717 | data->chain_signal_b = 0; |
| 718 | data->chain_signal_c = 0; |
| 719 | data->beacon_count = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 720 | } |
| 721 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 722 | static void iwl4965_bg_txpower_work(struct work_struct *work) |
| 723 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 724 | struct iwl_priv *priv = container_of(work, struct iwl_priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 725 | txpower_work); |
| 726 | |
| 727 | /* If a scan happened to start before we got here |
| 728 | * then just return; the statistics notification will |
| 729 | * kick off another scheduled work to compensate for |
| 730 | * any temperature delta we missed here. */ |
| 731 | if (test_bit(STATUS_EXIT_PENDING, &priv->status) || |
| 732 | test_bit(STATUS_SCANNING, &priv->status)) |
| 733 | return; |
| 734 | |
| 735 | mutex_lock(&priv->mutex); |
| 736 | |
| 737 | /* Regardless of if we are assocaited, we must reconfigure the |
| 738 | * TX power since frames can be sent on non-radar channels while |
| 739 | * not associated */ |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 740 | iwl4965_hw_reg_send_txpower(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 741 | |
| 742 | /* Update last_temperature to keep is_calib_needed from running |
| 743 | * when it isn't needed... */ |
| 744 | priv->last_temperature = priv->temperature; |
| 745 | |
| 746 | mutex_unlock(&priv->mutex); |
| 747 | } |
| 748 | |
| 749 | /* |
| 750 | * Acquire priv->lock before calling this function ! |
| 751 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 752 | 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] | 753 | { |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 754 | iwl_write_direct32(priv, HBUS_TARG_WRPTR, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 755 | (index & 0xff) | (txq_id << 8)); |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 756 | iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(txq_id), index); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 757 | } |
| 758 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 759 | /** |
| 760 | * iwl4965_tx_queue_set_status - (optionally) start Tx/Cmd queue |
| 761 | * @tx_fifo_id: Tx DMA/FIFO channel (range 0-7) that the queue will feed |
| 762 | * @scd_retry: (1) Indicates queue will be used in aggregation mode |
| 763 | * |
| 764 | * NOTE: Acquire priv->lock before calling this function ! |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 765 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 766 | static void iwl4965_tx_queue_set_status(struct iwl_priv *priv, |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 767 | struct iwl_tx_queue *txq, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 768 | int tx_fifo_id, int scd_retry) |
| 769 | { |
| 770 | int txq_id = txq->q.id; |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 771 | |
| 772 | /* Find out whether to activate Tx queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 773 | int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0; |
| 774 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 775 | /* Set up and activate */ |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 776 | iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id), |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 777 | (active << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) | |
| 778 | (tx_fifo_id << IWL49_SCD_QUEUE_STTS_REG_POS_TXF) | |
| 779 | (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_WSL) | |
| 780 | (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) | |
| 781 | IWL49_SCD_QUEUE_STTS_REG_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 782 | |
| 783 | txq->sched_retry = scd_retry; |
| 784 | |
| 785 | IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n", |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 786 | active ? "Activate" : "Deactivate", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 787 | scd_retry ? "BA" : "AC", txq_id, tx_fifo_id); |
| 788 | } |
| 789 | |
| 790 | static const u16 default_queue_to_tx_fifo[] = { |
| 791 | IWL_TX_FIFO_AC3, |
| 792 | IWL_TX_FIFO_AC2, |
| 793 | IWL_TX_FIFO_AC1, |
| 794 | IWL_TX_FIFO_AC0, |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 795 | IWL49_CMD_FIFO_NUM, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 796 | IWL_TX_FIFO_HCCA_1, |
| 797 | IWL_TX_FIFO_HCCA_2 |
| 798 | }; |
| 799 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 800 | int iwl4965_alive_notify(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 801 | { |
| 802 | u32 a; |
| 803 | int i = 0; |
| 804 | unsigned long flags; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 805 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 806 | |
| 807 | spin_lock_irqsave(&priv->lock, flags); |
| 808 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 809 | ret = iwl_grab_nic_access(priv); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 810 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 811 | spin_unlock_irqrestore(&priv->lock, flags); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 812 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 815 | /* Clear 4965's internal Tx Scheduler data base */ |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 816 | priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR); |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 817 | a = priv->scd_base_addr + IWL49_SCD_CONTEXT_DATA_OFFSET; |
| 818 | for (; a < priv->scd_base_addr + IWL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4) |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 819 | iwl_write_targ_mem(priv, a, 0); |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 820 | for (; a < priv->scd_base_addr + IWL49_SCD_TRANSLATE_TBL_OFFSET; a += 4) |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 821 | iwl_write_targ_mem(priv, a, 0); |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 822 | for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4) |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 823 | iwl_write_targ_mem(priv, a, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 824 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 825 | /* Tel 4965 where to find Tx byte count tables */ |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 826 | iwl_write_prph(priv, IWL49_SCD_DRAM_BASE_ADDR, |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 827 | (priv->shared_phys + |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 828 | offsetof(struct iwl4965_shared, queues_byte_cnt_tbls)) >> 10); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 829 | |
| 830 | /* Disable chain mode for all queues */ |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 831 | iwl_write_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 832 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 833 | /* Initialize each Tx queue (including the command queue) */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 834 | for (i = 0; i < priv->hw_params.max_txq_num; i++) { |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 835 | |
| 836 | /* TFD circular buffer read/write indexes */ |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 837 | iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(i), 0); |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 838 | iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8)); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 839 | |
| 840 | /* Max Tx Window size for Scheduler-ACK mode */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 841 | iwl_write_targ_mem(priv, priv->scd_base_addr + |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 842 | IWL49_SCD_CONTEXT_QUEUE_OFFSET(i), |
| 843 | (SCD_WIN_SIZE << |
| 844 | IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) & |
| 845 | IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 846 | |
| 847 | /* Frame limit */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 848 | iwl_write_targ_mem(priv, priv->scd_base_addr + |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 849 | IWL49_SCD_CONTEXT_QUEUE_OFFSET(i) + |
| 850 | sizeof(u32), |
| 851 | (SCD_FRAME_LIMIT << |
| 852 | IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) & |
| 853 | IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 854 | |
| 855 | } |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 856 | iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK, |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 857 | (1 << priv->hw_params.max_txq_num) - 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 858 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 859 | /* Activate all Tx DMA/FIFO channels */ |
Tomas Winkler | da1bc45 | 2008-05-29 16:35:00 +0800 | [diff] [blame] | 860 | priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 861 | |
| 862 | iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 863 | |
| 864 | /* Map each Tx/cmd queue to its corresponding fifo */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 865 | for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) { |
| 866 | int ac = default_queue_to_tx_fifo[i]; |
Ron Rindjunsky | 3647074 | 2008-05-15 13:54:10 +0800 | [diff] [blame] | 867 | iwl_txq_ctx_activate(priv, i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 868 | iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0); |
| 869 | } |
| 870 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 871 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 872 | spin_unlock_irqrestore(&priv->lock, flags); |
| 873 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 874 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 877 | static struct iwl_sensitivity_ranges iwl4965_sensitivity = { |
| 878 | .min_nrg_cck = 97, |
| 879 | .max_nrg_cck = 0, |
| 880 | |
| 881 | .auto_corr_min_ofdm = 85, |
| 882 | .auto_corr_min_ofdm_mrc = 170, |
| 883 | .auto_corr_min_ofdm_x1 = 105, |
| 884 | .auto_corr_min_ofdm_mrc_x1 = 220, |
| 885 | |
| 886 | .auto_corr_max_ofdm = 120, |
| 887 | .auto_corr_max_ofdm_mrc = 210, |
| 888 | .auto_corr_max_ofdm_x1 = 140, |
| 889 | .auto_corr_max_ofdm_mrc_x1 = 270, |
| 890 | |
| 891 | .auto_corr_min_cck = 125, |
| 892 | .auto_corr_max_cck = 200, |
| 893 | .auto_corr_min_cck_mrc = 200, |
| 894 | .auto_corr_max_cck_mrc = 400, |
| 895 | |
| 896 | .nrg_th_cck = 100, |
| 897 | .nrg_th_ofdm = 100, |
| 898 | }; |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 899 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 900 | /** |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 901 | * iwl4965_hw_set_hw_params |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 902 | * |
| 903 | * Called when initializing driver |
| 904 | */ |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 905 | int iwl4965_hw_set_hw_params(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 906 | { |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 907 | |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 908 | if ((priv->cfg->mod_params->num_of_queues > IWL49_NUM_QUEUES) || |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 909 | (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) { |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 910 | IWL_ERROR("invalid queues_num, should be between %d and %d\n", |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 911 | IWL_MIN_NUM_QUEUES, IWL49_NUM_QUEUES); |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 912 | return -EINVAL; |
Assaf Krauss | 316c30d | 2008-03-14 10:38:46 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 915 | 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] | 916 | priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto; |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 917 | priv->hw_params.max_rxq_size = RX_QUEUE_SIZE; |
| 918 | priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG; |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 919 | if (priv->cfg->mod_params->amsdu_size_8K) |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 920 | priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K; |
Ron Rindjunsky | 9ee1ba4 | 2007-11-26 16:14:42 +0200 | [diff] [blame] | 921 | else |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 922 | priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K; |
| 923 | priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256; |
| 924 | priv->hw_params.max_stations = IWL4965_STATION_COUNT; |
| 925 | priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID; |
Tomas Winkler | 3e82a82 | 2008-02-13 11:32:31 -0800 | [diff] [blame] | 926 | |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 927 | priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE; |
| 928 | priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE; |
| 929 | priv->hw_params.max_bsm_size = BSM_SRAM_SIZE; |
| 930 | priv->hw_params.fat_channel = BIT(IEEE80211_BAND_5GHZ); |
| 931 | |
Tomas Winkler | ec35cf2 | 2008-04-15 16:01:39 -0700 | [diff] [blame] | 932 | priv->hw_params.tx_chains_num = 2; |
| 933 | priv->hw_params.rx_chains_num = 2; |
Guy Cohen | fde0db3 | 2008-04-21 15:42:01 -0700 | [diff] [blame] | 934 | priv->hw_params.valid_tx_ant = ANT_A | ANT_B; |
| 935 | priv->hw_params.valid_rx_ant = ANT_A | ANT_B; |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 936 | priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD); |
| 937 | |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 938 | priv->hw_params.sens = &iwl4965_sensitivity; |
Tomas Winkler | 3e82a82 | 2008-02-13 11:32:31 -0800 | [diff] [blame] | 939 | |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 940 | return 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 943 | /* set card power command */ |
| 944 | static int iwl4965_set_power(struct iwl_priv *priv, |
| 945 | void *cmd) |
| 946 | { |
| 947 | int ret = 0; |
| 948 | |
| 949 | ret = iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD, |
| 950 | sizeof(struct iwl4965_powertable_cmd), |
| 951 | cmd, NULL); |
| 952 | return ret; |
| 953 | } |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 954 | int iwl4965_hw_reg_set_txpower(struct iwl_priv *priv, s8 power) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 955 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 956 | IWL_ERROR("TODO: Implement iwl4965_hw_reg_set_txpower!\n"); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 957 | return -EINVAL; |
| 958 | } |
| 959 | |
| 960 | static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res) |
| 961 | { |
| 962 | s32 sign = 1; |
| 963 | |
| 964 | if (num < 0) { |
| 965 | sign = -sign; |
| 966 | num = -num; |
| 967 | } |
| 968 | if (denom < 0) { |
| 969 | sign = -sign; |
| 970 | denom = -denom; |
| 971 | } |
| 972 | *res = 1; |
| 973 | *res = ((num * 2 + denom) / (denom * 2)) * sign; |
| 974 | |
| 975 | return 1; |
| 976 | } |
| 977 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 978 | /** |
| 979 | * iwl4965_get_voltage_compensation - Power supply voltage comp for txpower |
| 980 | * |
| 981 | * Determines power supply voltage compensation for txpower calculations. |
| 982 | * Returns number of 1/2-dB steps to subtract from gain table index, |
| 983 | * to compensate for difference between power supply voltage during |
| 984 | * factory measurements, vs. current power supply voltage. |
| 985 | * |
| 986 | * Voltage indication is higher for lower voltage. |
| 987 | * Lower voltage requires more gain (lower gain table index). |
| 988 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 989 | static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage, |
| 990 | s32 current_voltage) |
| 991 | { |
| 992 | s32 comp = 0; |
| 993 | |
| 994 | if ((TX_POWER_IWL_ILLEGAL_VOLTAGE == eeprom_voltage) || |
| 995 | (TX_POWER_IWL_ILLEGAL_VOLTAGE == current_voltage)) |
| 996 | return 0; |
| 997 | |
| 998 | iwl4965_math_div_round(current_voltage - eeprom_voltage, |
| 999 | TX_POWER_IWL_VOLTAGE_CODES_PER_03V, &comp); |
| 1000 | |
| 1001 | if (current_voltage > eeprom_voltage) |
| 1002 | comp *= 2; |
| 1003 | if ((comp < -2) || (comp > 2)) |
| 1004 | comp = 0; |
| 1005 | |
| 1006 | return comp; |
| 1007 | } |
| 1008 | |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1009 | static const struct iwl_channel_info * |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1010 | iwl4965_get_channel_txpower_info(struct iwl_priv *priv, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1011 | enum ieee80211_band band, u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1012 | { |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1013 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1014 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1015 | ch_info = iwl_get_channel_info(priv, band, channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1016 | |
| 1017 | if (!is_channel_valid(ch_info)) |
| 1018 | return NULL; |
| 1019 | |
| 1020 | return ch_info; |
| 1021 | } |
| 1022 | |
| 1023 | static s32 iwl4965_get_tx_atten_grp(u16 channel) |
| 1024 | { |
| 1025 | if (channel >= CALIB_IWL_TX_ATTEN_GR5_FCH && |
| 1026 | channel <= CALIB_IWL_TX_ATTEN_GR5_LCH) |
| 1027 | return CALIB_CH_GROUP_5; |
| 1028 | |
| 1029 | if (channel >= CALIB_IWL_TX_ATTEN_GR1_FCH && |
| 1030 | channel <= CALIB_IWL_TX_ATTEN_GR1_LCH) |
| 1031 | return CALIB_CH_GROUP_1; |
| 1032 | |
| 1033 | if (channel >= CALIB_IWL_TX_ATTEN_GR2_FCH && |
| 1034 | channel <= CALIB_IWL_TX_ATTEN_GR2_LCH) |
| 1035 | return CALIB_CH_GROUP_2; |
| 1036 | |
| 1037 | if (channel >= CALIB_IWL_TX_ATTEN_GR3_FCH && |
| 1038 | channel <= CALIB_IWL_TX_ATTEN_GR3_LCH) |
| 1039 | return CALIB_CH_GROUP_3; |
| 1040 | |
| 1041 | if (channel >= CALIB_IWL_TX_ATTEN_GR4_FCH && |
| 1042 | channel <= CALIB_IWL_TX_ATTEN_GR4_LCH) |
| 1043 | return CALIB_CH_GROUP_4; |
| 1044 | |
| 1045 | IWL_ERROR("Can't find txatten group for channel %d.\n", channel); |
| 1046 | return -1; |
| 1047 | } |
| 1048 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1049 | 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] | 1050 | { |
| 1051 | s32 b = -1; |
| 1052 | |
| 1053 | for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) { |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1054 | if (priv->calib_info->band_info[b].ch_from == 0) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1055 | continue; |
| 1056 | |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1057 | if ((channel >= priv->calib_info->band_info[b].ch_from) |
| 1058 | && (channel <= priv->calib_info->band_info[b].ch_to)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1059 | break; |
| 1060 | } |
| 1061 | |
| 1062 | return b; |
| 1063 | } |
| 1064 | |
| 1065 | static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2) |
| 1066 | { |
| 1067 | s32 val; |
| 1068 | |
| 1069 | if (x2 == x1) |
| 1070 | return y1; |
| 1071 | else { |
| 1072 | iwl4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val); |
| 1073 | return val + y2; |
| 1074 | } |
| 1075 | } |
| 1076 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1077 | /** |
| 1078 | * iwl4965_interpolate_chan - Interpolate factory measurements for one channel |
| 1079 | * |
| 1080 | * Interpolates factory measurements from the two sample channels within a |
| 1081 | * sub-band, to apply to channel of interest. Interpolation is proportional to |
| 1082 | * differences in channel frequencies, which is proportional to differences |
| 1083 | * in channel number. |
| 1084 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1085 | static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel, |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1086 | struct iwl_eeprom_calib_ch_info *chan_info) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1087 | { |
| 1088 | s32 s = -1; |
| 1089 | u32 c; |
| 1090 | u32 m; |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1091 | const struct iwl_eeprom_calib_measure *m1; |
| 1092 | const struct iwl_eeprom_calib_measure *m2; |
| 1093 | struct iwl_eeprom_calib_measure *omeas; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1094 | u32 ch_i1; |
| 1095 | u32 ch_i2; |
| 1096 | |
| 1097 | s = iwl4965_get_sub_band(priv, channel); |
| 1098 | if (s >= EEPROM_TX_POWER_BANDS) { |
| 1099 | IWL_ERROR("Tx Power can not find channel %d ", channel); |
| 1100 | return -1; |
| 1101 | } |
| 1102 | |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1103 | ch_i1 = priv->calib_info->band_info[s].ch1.ch_num; |
| 1104 | ch_i2 = priv->calib_info->band_info[s].ch2.ch_num; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1105 | chan_info->ch_num = (u8) channel; |
| 1106 | |
| 1107 | IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n", |
| 1108 | channel, s, ch_i1, ch_i2); |
| 1109 | |
| 1110 | for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) { |
| 1111 | for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) { |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1112 | m1 = &(priv->calib_info->band_info[s].ch1. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1113 | measurements[c][m]); |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1114 | m2 = &(priv->calib_info->band_info[s].ch2. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1115 | measurements[c][m]); |
| 1116 | omeas = &(chan_info->measurements[c][m]); |
| 1117 | |
| 1118 | omeas->actual_pow = |
| 1119 | (u8) iwl4965_interpolate_value(channel, ch_i1, |
| 1120 | m1->actual_pow, |
| 1121 | ch_i2, |
| 1122 | m2->actual_pow); |
| 1123 | omeas->gain_idx = |
| 1124 | (u8) iwl4965_interpolate_value(channel, ch_i1, |
| 1125 | m1->gain_idx, ch_i2, |
| 1126 | m2->gain_idx); |
| 1127 | omeas->temperature = |
| 1128 | (u8) iwl4965_interpolate_value(channel, ch_i1, |
| 1129 | m1->temperature, |
| 1130 | ch_i2, |
| 1131 | m2->temperature); |
| 1132 | omeas->pa_det = |
| 1133 | (s8) iwl4965_interpolate_value(channel, ch_i1, |
| 1134 | m1->pa_det, ch_i2, |
| 1135 | m2->pa_det); |
| 1136 | |
| 1137 | IWL_DEBUG_TXPOWER |
| 1138 | ("chain %d meas %d AP1=%d AP2=%d AP=%d\n", c, m, |
| 1139 | m1->actual_pow, m2->actual_pow, omeas->actual_pow); |
| 1140 | IWL_DEBUG_TXPOWER |
| 1141 | ("chain %d meas %d NI1=%d NI2=%d NI=%d\n", c, m, |
| 1142 | m1->gain_idx, m2->gain_idx, omeas->gain_idx); |
| 1143 | IWL_DEBUG_TXPOWER |
| 1144 | ("chain %d meas %d PA1=%d PA2=%d PA=%d\n", c, m, |
| 1145 | m1->pa_det, m2->pa_det, omeas->pa_det); |
| 1146 | IWL_DEBUG_TXPOWER |
| 1147 | ("chain %d meas %d T1=%d T2=%d T=%d\n", c, m, |
| 1148 | m1->temperature, m2->temperature, |
| 1149 | omeas->temperature); |
| 1150 | } |
| 1151 | } |
| 1152 | |
| 1153 | return 0; |
| 1154 | } |
| 1155 | |
| 1156 | /* bit-rate-dependent table to prevent Tx distortion, in half-dB units, |
| 1157 | * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */ |
| 1158 | static s32 back_off_table[] = { |
| 1159 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */ |
| 1160 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */ |
| 1161 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */ |
| 1162 | 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */ |
| 1163 | 10 /* CCK */ |
| 1164 | }; |
| 1165 | |
| 1166 | /* Thermal compensation values for txpower for various frequency ranges ... |
| 1167 | * 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] | 1168 | static struct iwl4965_txpower_comp_entry { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1169 | s32 degrees_per_05db_a; |
| 1170 | s32 degrees_per_05db_a_denom; |
| 1171 | } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = { |
| 1172 | {9, 2}, /* group 0 5.2, ch 34-43 */ |
| 1173 | {4, 1}, /* group 1 5.2, ch 44-70 */ |
| 1174 | {4, 1}, /* group 2 5.2, ch 71-124 */ |
| 1175 | {4, 1}, /* group 3 5.2, ch 125-200 */ |
| 1176 | {3, 1} /* group 4 2.4, ch all */ |
| 1177 | }; |
| 1178 | |
| 1179 | static s32 get_min_power_index(s32 rate_power_index, u32 band) |
| 1180 | { |
| 1181 | if (!band) { |
| 1182 | if ((rate_power_index & 7) <= 4) |
| 1183 | return MIN_TX_GAIN_INDEX_52GHZ_EXT; |
| 1184 | } |
| 1185 | return MIN_TX_GAIN_INDEX; |
| 1186 | } |
| 1187 | |
| 1188 | struct gain_entry { |
| 1189 | u8 dsp; |
| 1190 | u8 radio; |
| 1191 | }; |
| 1192 | |
| 1193 | static const struct gain_entry gain_table[2][108] = { |
| 1194 | /* 5.2GHz power gain index table */ |
| 1195 | { |
| 1196 | {123, 0x3F}, /* highest txpower */ |
| 1197 | {117, 0x3F}, |
| 1198 | {110, 0x3F}, |
| 1199 | {104, 0x3F}, |
| 1200 | {98, 0x3F}, |
| 1201 | {110, 0x3E}, |
| 1202 | {104, 0x3E}, |
| 1203 | {98, 0x3E}, |
| 1204 | {110, 0x3D}, |
| 1205 | {104, 0x3D}, |
| 1206 | {98, 0x3D}, |
| 1207 | {110, 0x3C}, |
| 1208 | {104, 0x3C}, |
| 1209 | {98, 0x3C}, |
| 1210 | {110, 0x3B}, |
| 1211 | {104, 0x3B}, |
| 1212 | {98, 0x3B}, |
| 1213 | {110, 0x3A}, |
| 1214 | {104, 0x3A}, |
| 1215 | {98, 0x3A}, |
| 1216 | {110, 0x39}, |
| 1217 | {104, 0x39}, |
| 1218 | {98, 0x39}, |
| 1219 | {110, 0x38}, |
| 1220 | {104, 0x38}, |
| 1221 | {98, 0x38}, |
| 1222 | {110, 0x37}, |
| 1223 | {104, 0x37}, |
| 1224 | {98, 0x37}, |
| 1225 | {110, 0x36}, |
| 1226 | {104, 0x36}, |
| 1227 | {98, 0x36}, |
| 1228 | {110, 0x35}, |
| 1229 | {104, 0x35}, |
| 1230 | {98, 0x35}, |
| 1231 | {110, 0x34}, |
| 1232 | {104, 0x34}, |
| 1233 | {98, 0x34}, |
| 1234 | {110, 0x33}, |
| 1235 | {104, 0x33}, |
| 1236 | {98, 0x33}, |
| 1237 | {110, 0x32}, |
| 1238 | {104, 0x32}, |
| 1239 | {98, 0x32}, |
| 1240 | {110, 0x31}, |
| 1241 | {104, 0x31}, |
| 1242 | {98, 0x31}, |
| 1243 | {110, 0x30}, |
| 1244 | {104, 0x30}, |
| 1245 | {98, 0x30}, |
| 1246 | {110, 0x25}, |
| 1247 | {104, 0x25}, |
| 1248 | {98, 0x25}, |
| 1249 | {110, 0x24}, |
| 1250 | {104, 0x24}, |
| 1251 | {98, 0x24}, |
| 1252 | {110, 0x23}, |
| 1253 | {104, 0x23}, |
| 1254 | {98, 0x23}, |
| 1255 | {110, 0x22}, |
| 1256 | {104, 0x18}, |
| 1257 | {98, 0x18}, |
| 1258 | {110, 0x17}, |
| 1259 | {104, 0x17}, |
| 1260 | {98, 0x17}, |
| 1261 | {110, 0x16}, |
| 1262 | {104, 0x16}, |
| 1263 | {98, 0x16}, |
| 1264 | {110, 0x15}, |
| 1265 | {104, 0x15}, |
| 1266 | {98, 0x15}, |
| 1267 | {110, 0x14}, |
| 1268 | {104, 0x14}, |
| 1269 | {98, 0x14}, |
| 1270 | {110, 0x13}, |
| 1271 | {104, 0x13}, |
| 1272 | {98, 0x13}, |
| 1273 | {110, 0x12}, |
| 1274 | {104, 0x08}, |
| 1275 | {98, 0x08}, |
| 1276 | {110, 0x07}, |
| 1277 | {104, 0x07}, |
| 1278 | {98, 0x07}, |
| 1279 | {110, 0x06}, |
| 1280 | {104, 0x06}, |
| 1281 | {98, 0x06}, |
| 1282 | {110, 0x05}, |
| 1283 | {104, 0x05}, |
| 1284 | {98, 0x05}, |
| 1285 | {110, 0x04}, |
| 1286 | {104, 0x04}, |
| 1287 | {98, 0x04}, |
| 1288 | {110, 0x03}, |
| 1289 | {104, 0x03}, |
| 1290 | {98, 0x03}, |
| 1291 | {110, 0x02}, |
| 1292 | {104, 0x02}, |
| 1293 | {98, 0x02}, |
| 1294 | {110, 0x01}, |
| 1295 | {104, 0x01}, |
| 1296 | {98, 0x01}, |
| 1297 | {110, 0x00}, |
| 1298 | {104, 0x00}, |
| 1299 | {98, 0x00}, |
| 1300 | {93, 0x00}, |
| 1301 | {88, 0x00}, |
| 1302 | {83, 0x00}, |
| 1303 | {78, 0x00}, |
| 1304 | }, |
| 1305 | /* 2.4GHz power gain index table */ |
| 1306 | { |
| 1307 | {110, 0x3f}, /* highest txpower */ |
| 1308 | {104, 0x3f}, |
| 1309 | {98, 0x3f}, |
| 1310 | {110, 0x3e}, |
| 1311 | {104, 0x3e}, |
| 1312 | {98, 0x3e}, |
| 1313 | {110, 0x3d}, |
| 1314 | {104, 0x3d}, |
| 1315 | {98, 0x3d}, |
| 1316 | {110, 0x3c}, |
| 1317 | {104, 0x3c}, |
| 1318 | {98, 0x3c}, |
| 1319 | {110, 0x3b}, |
| 1320 | {104, 0x3b}, |
| 1321 | {98, 0x3b}, |
| 1322 | {110, 0x3a}, |
| 1323 | {104, 0x3a}, |
| 1324 | {98, 0x3a}, |
| 1325 | {110, 0x39}, |
| 1326 | {104, 0x39}, |
| 1327 | {98, 0x39}, |
| 1328 | {110, 0x38}, |
| 1329 | {104, 0x38}, |
| 1330 | {98, 0x38}, |
| 1331 | {110, 0x37}, |
| 1332 | {104, 0x37}, |
| 1333 | {98, 0x37}, |
| 1334 | {110, 0x36}, |
| 1335 | {104, 0x36}, |
| 1336 | {98, 0x36}, |
| 1337 | {110, 0x35}, |
| 1338 | {104, 0x35}, |
| 1339 | {98, 0x35}, |
| 1340 | {110, 0x34}, |
| 1341 | {104, 0x34}, |
| 1342 | {98, 0x34}, |
| 1343 | {110, 0x33}, |
| 1344 | {104, 0x33}, |
| 1345 | {98, 0x33}, |
| 1346 | {110, 0x32}, |
| 1347 | {104, 0x32}, |
| 1348 | {98, 0x32}, |
| 1349 | {110, 0x31}, |
| 1350 | {104, 0x31}, |
| 1351 | {98, 0x31}, |
| 1352 | {110, 0x30}, |
| 1353 | {104, 0x30}, |
| 1354 | {98, 0x30}, |
| 1355 | {110, 0x6}, |
| 1356 | {104, 0x6}, |
| 1357 | {98, 0x6}, |
| 1358 | {110, 0x5}, |
| 1359 | {104, 0x5}, |
| 1360 | {98, 0x5}, |
| 1361 | {110, 0x4}, |
| 1362 | {104, 0x4}, |
| 1363 | {98, 0x4}, |
| 1364 | {110, 0x3}, |
| 1365 | {104, 0x3}, |
| 1366 | {98, 0x3}, |
| 1367 | {110, 0x2}, |
| 1368 | {104, 0x2}, |
| 1369 | {98, 0x2}, |
| 1370 | {110, 0x1}, |
| 1371 | {104, 0x1}, |
| 1372 | {98, 0x1}, |
| 1373 | {110, 0x0}, |
| 1374 | {104, 0x0}, |
| 1375 | {98, 0x0}, |
| 1376 | {97, 0}, |
| 1377 | {96, 0}, |
| 1378 | {95, 0}, |
| 1379 | {94, 0}, |
| 1380 | {93, 0}, |
| 1381 | {92, 0}, |
| 1382 | {91, 0}, |
| 1383 | {90, 0}, |
| 1384 | {89, 0}, |
| 1385 | {88, 0}, |
| 1386 | {87, 0}, |
| 1387 | {86, 0}, |
| 1388 | {85, 0}, |
| 1389 | {84, 0}, |
| 1390 | {83, 0}, |
| 1391 | {82, 0}, |
| 1392 | {81, 0}, |
| 1393 | {80, 0}, |
| 1394 | {79, 0}, |
| 1395 | {78, 0}, |
| 1396 | {77, 0}, |
| 1397 | {76, 0}, |
| 1398 | {75, 0}, |
| 1399 | {74, 0}, |
| 1400 | {73, 0}, |
| 1401 | {72, 0}, |
| 1402 | {71, 0}, |
| 1403 | {70, 0}, |
| 1404 | {69, 0}, |
| 1405 | {68, 0}, |
| 1406 | {67, 0}, |
| 1407 | {66, 0}, |
| 1408 | {65, 0}, |
| 1409 | {64, 0}, |
| 1410 | {63, 0}, |
| 1411 | {62, 0}, |
| 1412 | {61, 0}, |
| 1413 | {60, 0}, |
| 1414 | {59, 0}, |
| 1415 | } |
| 1416 | }; |
| 1417 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1418 | 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] | 1419 | u8 is_fat, u8 ctrl_chan_high, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1420 | struct iwl4965_tx_power_db *tx_power_tbl) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1421 | { |
| 1422 | u8 saturation_power; |
| 1423 | s32 target_power; |
| 1424 | s32 user_target_power; |
| 1425 | s32 power_limit; |
| 1426 | s32 current_temp; |
| 1427 | s32 reg_limit; |
| 1428 | s32 current_regulatory; |
| 1429 | s32 txatten_grp = CALIB_CH_GROUP_MAX; |
| 1430 | int i; |
| 1431 | int c; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1432 | const struct iwl_channel_info *ch_info = NULL; |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1433 | struct iwl_eeprom_calib_ch_info ch_eeprom_info; |
| 1434 | const struct iwl_eeprom_calib_measure *measurement; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1435 | s16 voltage; |
| 1436 | s32 init_voltage; |
| 1437 | s32 voltage_compensation; |
| 1438 | s32 degrees_per_05db_num; |
| 1439 | s32 degrees_per_05db_denom; |
| 1440 | s32 factory_temp; |
| 1441 | s32 temperature_comp[2]; |
| 1442 | s32 factory_gain_index[2]; |
| 1443 | s32 factory_actual_pwr[2]; |
| 1444 | s32 power_index; |
| 1445 | |
| 1446 | /* Sanity check requested level (dBm) */ |
| 1447 | if (priv->user_txpower_limit < IWL_TX_POWER_TARGET_POWER_MIN) { |
| 1448 | IWL_WARNING("Requested user TXPOWER %d below limit.\n", |
| 1449 | priv->user_txpower_limit); |
| 1450 | return -EINVAL; |
| 1451 | } |
| 1452 | if (priv->user_txpower_limit > IWL_TX_POWER_TARGET_POWER_MAX) { |
| 1453 | IWL_WARNING("Requested user TXPOWER %d above limit.\n", |
| 1454 | priv->user_txpower_limit); |
| 1455 | return -EINVAL; |
| 1456 | } |
| 1457 | |
| 1458 | /* user_txpower_limit is in dBm, convert to half-dBm (half-dB units |
| 1459 | * are used for indexing into txpower table) */ |
| 1460 | user_target_power = 2 * priv->user_txpower_limit; |
| 1461 | |
| 1462 | /* Get current (RXON) channel, band, width */ |
| 1463 | ch_info = |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1464 | iwl4965_get_channel_txpower_info(priv, priv->band, channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1465 | |
| 1466 | IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band, |
| 1467 | is_fat); |
| 1468 | |
| 1469 | if (!ch_info) |
| 1470 | return -EINVAL; |
| 1471 | |
| 1472 | /* get txatten group, used to select 1) thermal txpower adjustment |
| 1473 | * and 2) mimo txpower balance between Tx chains. */ |
| 1474 | txatten_grp = iwl4965_get_tx_atten_grp(channel); |
| 1475 | if (txatten_grp < 0) |
| 1476 | return -EINVAL; |
| 1477 | |
| 1478 | IWL_DEBUG_TXPOWER("channel %d belongs to txatten group %d\n", |
| 1479 | channel, txatten_grp); |
| 1480 | |
| 1481 | if (is_fat) { |
| 1482 | if (ctrl_chan_high) |
| 1483 | channel -= 2; |
| 1484 | else |
| 1485 | channel += 2; |
| 1486 | } |
| 1487 | |
| 1488 | /* hardware txpower limits ... |
| 1489 | * saturation (clipping distortion) txpowers are in half-dBm */ |
| 1490 | if (band) |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1491 | saturation_power = priv->calib_info->saturation_power24; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1492 | else |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1493 | saturation_power = priv->calib_info->saturation_power52; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1494 | |
| 1495 | if (saturation_power < IWL_TX_POWER_SATURATION_MIN || |
| 1496 | saturation_power > IWL_TX_POWER_SATURATION_MAX) { |
| 1497 | if (band) |
| 1498 | saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_24; |
| 1499 | else |
| 1500 | saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_52; |
| 1501 | } |
| 1502 | |
| 1503 | /* regulatory txpower limits ... reg_limit values are in half-dBm, |
| 1504 | * max_power_avg values are in dBm, convert * 2 */ |
| 1505 | if (is_fat) |
| 1506 | reg_limit = ch_info->fat_max_power_avg * 2; |
| 1507 | else |
| 1508 | reg_limit = ch_info->max_power_avg * 2; |
| 1509 | |
| 1510 | if ((reg_limit < IWL_TX_POWER_REGULATORY_MIN) || |
| 1511 | (reg_limit > IWL_TX_POWER_REGULATORY_MAX)) { |
| 1512 | if (band) |
| 1513 | reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_24; |
| 1514 | else |
| 1515 | reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_52; |
| 1516 | } |
| 1517 | |
| 1518 | /* Interpolate txpower calibration values for this channel, |
| 1519 | * based on factory calibration tests on spaced channels. */ |
| 1520 | iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info); |
| 1521 | |
| 1522 | /* calculate tx gain adjustment based on power supply voltage */ |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 1523 | voltage = priv->calib_info->voltage; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1524 | init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage); |
| 1525 | voltage_compensation = |
| 1526 | iwl4965_get_voltage_compensation(voltage, init_voltage); |
| 1527 | |
| 1528 | IWL_DEBUG_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n", |
| 1529 | init_voltage, |
| 1530 | voltage, voltage_compensation); |
| 1531 | |
| 1532 | /* get current temperature (Celsius) */ |
| 1533 | current_temp = max(priv->temperature, IWL_TX_POWER_TEMPERATURE_MIN); |
| 1534 | current_temp = min(priv->temperature, IWL_TX_POWER_TEMPERATURE_MAX); |
| 1535 | current_temp = KELVIN_TO_CELSIUS(current_temp); |
| 1536 | |
| 1537 | /* select thermal txpower adjustment params, based on channel group |
| 1538 | * (same frequency group used for mimo txatten adjustment) */ |
| 1539 | degrees_per_05db_num = |
| 1540 | tx_power_cmp_tble[txatten_grp].degrees_per_05db_a; |
| 1541 | degrees_per_05db_denom = |
| 1542 | tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom; |
| 1543 | |
| 1544 | /* get per-chain txpower values from factory measurements */ |
| 1545 | for (c = 0; c < 2; c++) { |
| 1546 | measurement = &ch_eeprom_info.measurements[c][1]; |
| 1547 | |
| 1548 | /* txgain adjustment (in half-dB steps) based on difference |
| 1549 | * between factory and current temperature */ |
| 1550 | factory_temp = measurement->temperature; |
| 1551 | iwl4965_math_div_round((current_temp - factory_temp) * |
| 1552 | degrees_per_05db_denom, |
| 1553 | degrees_per_05db_num, |
| 1554 | &temperature_comp[c]); |
| 1555 | |
| 1556 | factory_gain_index[c] = measurement->gain_idx; |
| 1557 | factory_actual_pwr[c] = measurement->actual_pow; |
| 1558 | |
| 1559 | IWL_DEBUG_TXPOWER("chain = %d\n", c); |
| 1560 | IWL_DEBUG_TXPOWER("fctry tmp %d, " |
| 1561 | "curr tmp %d, comp %d steps\n", |
| 1562 | factory_temp, current_temp, |
| 1563 | temperature_comp[c]); |
| 1564 | |
| 1565 | IWL_DEBUG_TXPOWER("fctry idx %d, fctry pwr %d\n", |
| 1566 | factory_gain_index[c], |
| 1567 | factory_actual_pwr[c]); |
| 1568 | } |
| 1569 | |
| 1570 | /* for each of 33 bit-rates (including 1 for CCK) */ |
| 1571 | for (i = 0; i < POWER_TABLE_NUM_ENTRIES; i++) { |
| 1572 | u8 is_mimo_rate; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1573 | union iwl4965_tx_power_dual_stream tx_power; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1574 | |
| 1575 | /* for mimo, reduce each chain's txpower by half |
| 1576 | * (3dB, 6 steps), so total output power is regulatory |
| 1577 | * compliant. */ |
| 1578 | if (i & 0x8) { |
| 1579 | current_regulatory = reg_limit - |
| 1580 | IWL_TX_POWER_MIMO_REGULATORY_COMPENSATION; |
| 1581 | is_mimo_rate = 1; |
| 1582 | } else { |
| 1583 | current_regulatory = reg_limit; |
| 1584 | is_mimo_rate = 0; |
| 1585 | } |
| 1586 | |
| 1587 | /* find txpower limit, either hardware or regulatory */ |
| 1588 | power_limit = saturation_power - back_off_table[i]; |
| 1589 | if (power_limit > current_regulatory) |
| 1590 | power_limit = current_regulatory; |
| 1591 | |
| 1592 | /* reduce user's txpower request if necessary |
| 1593 | * for this rate on this channel */ |
| 1594 | target_power = user_target_power; |
| 1595 | if (target_power > power_limit) |
| 1596 | target_power = power_limit; |
| 1597 | |
| 1598 | IWL_DEBUG_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n", |
| 1599 | i, saturation_power - back_off_table[i], |
| 1600 | current_regulatory, user_target_power, |
| 1601 | target_power); |
| 1602 | |
| 1603 | /* for each of 2 Tx chains (radio transmitters) */ |
| 1604 | for (c = 0; c < 2; c++) { |
| 1605 | s32 atten_value; |
| 1606 | |
| 1607 | if (is_mimo_rate) |
| 1608 | atten_value = |
| 1609 | (s32)le32_to_cpu(priv->card_alive_init. |
| 1610 | tx_atten[txatten_grp][c]); |
| 1611 | else |
| 1612 | atten_value = 0; |
| 1613 | |
| 1614 | /* calculate index; higher index means lower txpower */ |
| 1615 | power_index = (u8) (factory_gain_index[c] - |
| 1616 | (target_power - |
| 1617 | factory_actual_pwr[c]) - |
| 1618 | temperature_comp[c] - |
| 1619 | voltage_compensation + |
| 1620 | atten_value); |
| 1621 | |
| 1622 | /* IWL_DEBUG_TXPOWER("calculated txpower index %d\n", |
| 1623 | power_index); */ |
| 1624 | |
| 1625 | if (power_index < get_min_power_index(i, band)) |
| 1626 | power_index = get_min_power_index(i, band); |
| 1627 | |
| 1628 | /* adjust 5 GHz index to support negative indexes */ |
| 1629 | if (!band) |
| 1630 | power_index += 9; |
| 1631 | |
| 1632 | /* CCK, rate 32, reduce txpower for CCK */ |
| 1633 | if (i == POWER_TABLE_CCK_ENTRY) |
| 1634 | power_index += |
| 1635 | IWL_TX_POWER_CCK_COMPENSATION_C_STEP; |
| 1636 | |
| 1637 | /* stay within the table! */ |
| 1638 | if (power_index > 107) { |
| 1639 | IWL_WARNING("txpower index %d > 107\n", |
| 1640 | power_index); |
| 1641 | power_index = 107; |
| 1642 | } |
| 1643 | if (power_index < 0) { |
| 1644 | IWL_WARNING("txpower index %d < 0\n", |
| 1645 | power_index); |
| 1646 | power_index = 0; |
| 1647 | } |
| 1648 | |
| 1649 | /* fill txpower command for this rate/chain */ |
| 1650 | tx_power.s.radio_tx_gain[c] = |
| 1651 | gain_table[band][power_index].radio; |
| 1652 | tx_power.s.dsp_predis_atten[c] = |
| 1653 | gain_table[band][power_index].dsp; |
| 1654 | |
| 1655 | IWL_DEBUG_TXPOWER("chain %d mimo %d index %d " |
| 1656 | "gain 0x%02x dsp %d\n", |
| 1657 | c, atten_value, power_index, |
| 1658 | tx_power.s.radio_tx_gain[c], |
| 1659 | tx_power.s.dsp_predis_atten[c]); |
| 1660 | }/* for each chain */ |
| 1661 | |
| 1662 | tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw); |
| 1663 | |
| 1664 | }/* for each rate */ |
| 1665 | |
| 1666 | return 0; |
| 1667 | } |
| 1668 | |
| 1669 | /** |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1670 | * iwl4965_hw_reg_send_txpower - Configure the TXPOWER level user limit |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1671 | * |
| 1672 | * Uses the active RXON for channel, band, and characteristics (fat, high) |
| 1673 | * The power limit is taken from priv->user_txpower_limit. |
| 1674 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1675 | int iwl4965_hw_reg_send_txpower(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1676 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1677 | struct iwl4965_txpowertable_cmd cmd = { 0 }; |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1678 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1679 | u8 band = 0; |
| 1680 | u8 is_fat = 0; |
| 1681 | u8 ctrl_chan_high = 0; |
| 1682 | |
| 1683 | if (test_bit(STATUS_SCANNING, &priv->status)) { |
| 1684 | /* If this gets hit a lot, switch it to a BUG() and catch |
| 1685 | * the stack trace to find out who is calling this during |
| 1686 | * a scan. */ |
| 1687 | IWL_WARNING("TX Power requested while scanning!\n"); |
| 1688 | return -EAGAIN; |
| 1689 | } |
| 1690 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1691 | band = priv->band == IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1692 | |
| 1693 | is_fat = is_fat_channel(priv->active_rxon.flags); |
| 1694 | |
| 1695 | if (is_fat && |
| 1696 | (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK)) |
| 1697 | ctrl_chan_high = 1; |
| 1698 | |
| 1699 | cmd.band = band; |
| 1700 | cmd.channel = priv->active_rxon.channel; |
| 1701 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1702 | ret = iwl4965_fill_txpower_tbl(priv, band, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1703 | le16_to_cpu(priv->active_rxon.channel), |
| 1704 | is_fat, ctrl_chan_high, &cmd.tx_power); |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1705 | if (ret) |
| 1706 | goto out; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1707 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1708 | ret = iwl_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd); |
| 1709 | |
| 1710 | out: |
| 1711 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 1714 | static int iwl4965_send_rxon_assoc(struct iwl_priv *priv) |
| 1715 | { |
| 1716 | int ret = 0; |
| 1717 | struct iwl4965_rxon_assoc_cmd rxon_assoc; |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 1718 | const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon; |
| 1719 | const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon; |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 1720 | |
| 1721 | if ((rxon1->flags == rxon2->flags) && |
| 1722 | (rxon1->filter_flags == rxon2->filter_flags) && |
| 1723 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && |
| 1724 | (rxon1->ofdm_ht_single_stream_basic_rates == |
| 1725 | rxon2->ofdm_ht_single_stream_basic_rates) && |
| 1726 | (rxon1->ofdm_ht_dual_stream_basic_rates == |
| 1727 | rxon2->ofdm_ht_dual_stream_basic_rates) && |
| 1728 | (rxon1->rx_chain == rxon2->rx_chain) && |
| 1729 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { |
| 1730 | IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n"); |
| 1731 | return 0; |
| 1732 | } |
| 1733 | |
| 1734 | rxon_assoc.flags = priv->staging_rxon.flags; |
| 1735 | rxon_assoc.filter_flags = priv->staging_rxon.filter_flags; |
| 1736 | rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates; |
| 1737 | rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates; |
| 1738 | rxon_assoc.reserved = 0; |
| 1739 | rxon_assoc.ofdm_ht_single_stream_basic_rates = |
| 1740 | priv->staging_rxon.ofdm_ht_single_stream_basic_rates; |
| 1741 | rxon_assoc.ofdm_ht_dual_stream_basic_rates = |
| 1742 | priv->staging_rxon.ofdm_ht_dual_stream_basic_rates; |
| 1743 | rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain; |
| 1744 | |
| 1745 | ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC, |
| 1746 | sizeof(rxon_assoc), &rxon_assoc, NULL); |
| 1747 | if (ret) |
| 1748 | return ret; |
| 1749 | |
| 1750 | return ret; |
| 1751 | } |
| 1752 | |
| 1753 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1754 | int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1755 | { |
| 1756 | int rc; |
| 1757 | u8 band = 0; |
| 1758 | u8 is_fat = 0; |
| 1759 | u8 ctrl_chan_high = 0; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1760 | struct iwl4965_channel_switch_cmd cmd = { 0 }; |
Assaf Krauss | bf85ea4 | 2008-03-14 10:38:49 -0700 | [diff] [blame] | 1761 | const struct iwl_channel_info *ch_info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1762 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1763 | band = priv->band == IEEE80211_BAND_2GHZ; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1764 | |
Assaf Krauss | 8622e70 | 2008-03-21 13:53:43 -0700 | [diff] [blame] | 1765 | ch_info = iwl_get_channel_info(priv, priv->band, channel); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1766 | |
| 1767 | is_fat = is_fat_channel(priv->staging_rxon.flags); |
| 1768 | |
| 1769 | if (is_fat && |
| 1770 | (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK)) |
| 1771 | ctrl_chan_high = 1; |
| 1772 | |
| 1773 | cmd.band = band; |
| 1774 | cmd.expect_beacon = 0; |
| 1775 | cmd.channel = cpu_to_le16(channel); |
| 1776 | cmd.rxon_flags = priv->active_rxon.flags; |
| 1777 | cmd.rxon_filter_flags = priv->active_rxon.filter_flags; |
| 1778 | cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time); |
| 1779 | if (ch_info) |
| 1780 | cmd.expect_beacon = is_channel_radar(ch_info); |
| 1781 | else |
| 1782 | cmd.expect_beacon = 1; |
| 1783 | |
| 1784 | rc = iwl4965_fill_txpower_tbl(priv, band, channel, is_fat, |
| 1785 | ctrl_chan_high, &cmd.tx_power); |
| 1786 | if (rc) { |
| 1787 | IWL_DEBUG_11H("error:%d fill txpower_tbl\n", rc); |
| 1788 | return rc; |
| 1789 | } |
| 1790 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 1791 | rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1792 | return rc; |
| 1793 | } |
| 1794 | |
Ron Rindjunsky | d67f548 | 2008-05-05 10:22:49 +0800 | [diff] [blame] | 1795 | static int iwl4965_shared_mem_rx_idx(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1796 | { |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 1797 | struct iwl4965_shared *s = priv->shared_virt; |
| 1798 | return le32_to_cpu(s->rb_closed) & 0xFFF; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1801 | int iwl4965_hw_get_temperature(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1802 | { |
| 1803 | return priv->temperature; |
| 1804 | } |
| 1805 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1806 | unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv, |
Tomas Winkler | fcab423 | 2008-05-15 13:54:01 +0800 | [diff] [blame] | 1807 | struct iwl_frame *frame, u8 rate) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1808 | { |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1809 | struct iwl4965_tx_beacon_cmd *tx_beacon_cmd; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1810 | unsigned int frame_size; |
| 1811 | |
| 1812 | tx_beacon_cmd = &frame->u.beacon; |
| 1813 | memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd)); |
| 1814 | |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 1815 | tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1816 | tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 1817 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1818 | frame_size = iwl4965_fill_beacon_frame(priv, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1819 | tx_beacon_cmd->frame, |
Tomas Winkler | 57bd1be | 2008-05-15 13:54:03 +0800 | [diff] [blame] | 1820 | iwl_bcast_addr, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1821 | sizeof(frame->u) - sizeof(*tx_beacon_cmd)); |
| 1822 | |
| 1823 | BUG_ON(frame_size > MAX_MPDU_SIZE); |
| 1824 | tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size); |
| 1825 | |
| 1826 | if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP)) |
| 1827 | tx_beacon_cmd->tx.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1828 | iwl4965_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1829 | else |
| 1830 | tx_beacon_cmd->tx.rate_n_flags = |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 1831 | iwl4965_hw_set_rate_n_flags(rate, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1832 | |
| 1833 | tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK | |
| 1834 | TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK); |
| 1835 | return (sizeof(*tx_beacon_cmd) + frame_size); |
| 1836 | } |
| 1837 | |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 1838 | static int iwl4965_alloc_shared_mem(struct iwl_priv *priv) |
| 1839 | { |
| 1840 | priv->shared_virt = pci_alloc_consistent(priv->pci_dev, |
| 1841 | sizeof(struct iwl4965_shared), |
| 1842 | &priv->shared_phys); |
| 1843 | if (!priv->shared_virt) |
| 1844 | return -ENOMEM; |
| 1845 | |
| 1846 | memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared)); |
| 1847 | |
Ron Rindjunsky | d67f548 | 2008-05-05 10:22:49 +0800 | [diff] [blame] | 1848 | priv->rb_closed_offset = offsetof(struct iwl4965_shared, rb_closed); |
| 1849 | |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 1850 | return 0; |
| 1851 | } |
| 1852 | |
| 1853 | static void iwl4965_free_shared_mem(struct iwl_priv *priv) |
| 1854 | { |
| 1855 | if (priv->shared_virt) |
| 1856 | pci_free_consistent(priv->pci_dev, |
| 1857 | sizeof(struct iwl4965_shared), |
| 1858 | priv->shared_virt, |
| 1859 | priv->shared_phys); |
| 1860 | } |
| 1861 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1862 | /** |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 1863 | * 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] | 1864 | */ |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 1865 | static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv, |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 1866 | struct iwl_tx_queue *txq, |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 1867 | u16 byte_cnt) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1868 | { |
| 1869 | int len; |
| 1870 | int txq_id = txq->q.id; |
Tomas Winkler | 059ff82 | 2008-04-14 21:16:14 -0700 | [diff] [blame] | 1871 | struct iwl4965_shared *shared_data = priv->shared_virt; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1872 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1873 | len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE; |
| 1874 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1875 | /* Set up byte count within first 256 entries */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1876 | IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id]. |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 1877 | tfd_offset[txq->q.write_ptr], byte_cnt, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1878 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1879 | /* If within first 64 entries, duplicate at end */ |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 1880 | if (txq->q.write_ptr < IWL49_MAX_WIN_SIZE) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1881 | IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id]. |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 1882 | tfd_offset[IWL49_QUEUE_SIZE + txq->q.write_ptr], |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1883 | byte_cnt, len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1884 | } |
| 1885 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1886 | /** |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1887 | * sign_extend - Sign extend a value using specified bit as sign-bit |
| 1888 | * |
| 1889 | * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1 |
| 1890 | * and bit0..2 is 001b which when sign extended to 1111111111111001b is -7. |
| 1891 | * |
| 1892 | * @param oper value to sign extend |
| 1893 | * @param index 0 based bit index (0<=index<32) to sign bit |
| 1894 | */ |
| 1895 | static s32 sign_extend(u32 oper, int index) |
| 1896 | { |
| 1897 | u8 shift = 31 - index; |
| 1898 | |
| 1899 | return (s32)(oper << shift) >> shift; |
| 1900 | } |
| 1901 | |
| 1902 | /** |
| 1903 | * iwl4965_get_temperature - return the calibrated temperature (in Kelvin) |
| 1904 | * @statistics: Provides the temperature reading from the uCode |
| 1905 | * |
| 1906 | * A return of <0 indicates bogus data in the statistics |
| 1907 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1908 | int iwl4965_get_temperature(const struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1909 | { |
| 1910 | s32 temperature; |
| 1911 | s32 vt; |
| 1912 | s32 R1, R2, R3; |
| 1913 | u32 R4; |
| 1914 | |
| 1915 | if (test_bit(STATUS_TEMPERATURE, &priv->status) && |
| 1916 | (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)) { |
| 1917 | IWL_DEBUG_TEMP("Running FAT temperature calibration\n"); |
| 1918 | R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]); |
| 1919 | R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]); |
| 1920 | R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]); |
| 1921 | R4 = le32_to_cpu(priv->card_alive_init.therm_r4[1]); |
| 1922 | } else { |
| 1923 | IWL_DEBUG_TEMP("Running temperature calibration\n"); |
| 1924 | R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]); |
| 1925 | R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]); |
| 1926 | R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]); |
| 1927 | R4 = le32_to_cpu(priv->card_alive_init.therm_r4[0]); |
| 1928 | } |
| 1929 | |
| 1930 | /* |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1931 | * Temperature is only 23 bits, so sign extend out to 32. |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1932 | * |
| 1933 | * NOTE If we haven't received a statistics notification yet |
| 1934 | * with an updated temperature, use R4 provided to us in the |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 1935 | * "initialize" ALIVE response. |
| 1936 | */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1937 | if (!test_bit(STATUS_TEMPERATURE, &priv->status)) |
| 1938 | vt = sign_extend(R4, 23); |
| 1939 | else |
| 1940 | vt = sign_extend( |
| 1941 | le32_to_cpu(priv->statistics.general.temperature), 23); |
| 1942 | |
| 1943 | IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n", |
| 1944 | R1, R2, R3, vt); |
| 1945 | |
| 1946 | if (R3 == R1) { |
| 1947 | IWL_ERROR("Calibration conflict R1 == R3\n"); |
| 1948 | return -1; |
| 1949 | } |
| 1950 | |
| 1951 | /* Calculate temperature in degrees Kelvin, adjust by 97%. |
| 1952 | * Add offset to center the adjustment around 0 degrees Centigrade. */ |
| 1953 | temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2); |
| 1954 | temperature /= (R3 - R1); |
| 1955 | temperature = (temperature * 97) / 100 + |
| 1956 | TEMPERATURE_CALIB_KELVIN_OFFSET; |
| 1957 | |
| 1958 | IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n", temperature, |
| 1959 | KELVIN_TO_CELSIUS(temperature)); |
| 1960 | |
| 1961 | return temperature; |
| 1962 | } |
| 1963 | |
| 1964 | /* Adjust Txpower only if temperature variance is greater than threshold. */ |
| 1965 | #define IWL_TEMPERATURE_THRESHOLD 3 |
| 1966 | |
| 1967 | /** |
| 1968 | * iwl4965_is_temp_calib_needed - determines if new calibration is needed |
| 1969 | * |
| 1970 | * If the temperature changed has changed sufficiently, then a recalibration |
| 1971 | * is needed. |
| 1972 | * |
| 1973 | * Assumes caller will replace priv->last_temperature once calibration |
| 1974 | * executed. |
| 1975 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 1976 | static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 1977 | { |
| 1978 | int temp_diff; |
| 1979 | |
| 1980 | if (!test_bit(STATUS_STATISTICS, &priv->status)) { |
| 1981 | IWL_DEBUG_TEMP("Temperature not updated -- no statistics.\n"); |
| 1982 | return 0; |
| 1983 | } |
| 1984 | |
| 1985 | temp_diff = priv->temperature - priv->last_temperature; |
| 1986 | |
| 1987 | /* get absolute value */ |
| 1988 | if (temp_diff < 0) { |
| 1989 | IWL_DEBUG_POWER("Getting cooler, delta %d, \n", temp_diff); |
| 1990 | temp_diff = -temp_diff; |
| 1991 | } else if (temp_diff == 0) |
| 1992 | IWL_DEBUG_POWER("Same temp, \n"); |
| 1993 | else |
| 1994 | IWL_DEBUG_POWER("Getting warmer, delta %d, \n", temp_diff); |
| 1995 | |
| 1996 | if (temp_diff < IWL_TEMPERATURE_THRESHOLD) { |
| 1997 | IWL_DEBUG_POWER("Thermal txpower calib not needed\n"); |
| 1998 | return 0; |
| 1999 | } |
| 2000 | |
| 2001 | IWL_DEBUG_POWER("Thermal txpower calib needed\n"); |
| 2002 | |
| 2003 | return 1; |
| 2004 | } |
| 2005 | |
| 2006 | /* Calculate noise level, based on measurements during network silence just |
| 2007 | * before arriving beacon. This measurement can be done only if we know |
| 2008 | * exactly when to expect beacons, therefore only when we're associated. */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2009 | static void iwl4965_rx_calc_noise(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2010 | { |
| 2011 | struct statistics_rx_non_phy *rx_info |
| 2012 | = &(priv->statistics.rx.general); |
| 2013 | int num_active_rx = 0; |
| 2014 | int total_silence = 0; |
| 2015 | int bcn_silence_a = |
| 2016 | le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER; |
| 2017 | int bcn_silence_b = |
| 2018 | le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER; |
| 2019 | int bcn_silence_c = |
| 2020 | le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER; |
| 2021 | |
| 2022 | if (bcn_silence_a) { |
| 2023 | total_silence += bcn_silence_a; |
| 2024 | num_active_rx++; |
| 2025 | } |
| 2026 | if (bcn_silence_b) { |
| 2027 | total_silence += bcn_silence_b; |
| 2028 | num_active_rx++; |
| 2029 | } |
| 2030 | if (bcn_silence_c) { |
| 2031 | total_silence += bcn_silence_c; |
| 2032 | num_active_rx++; |
| 2033 | } |
| 2034 | |
| 2035 | /* Average among active antennas */ |
| 2036 | if (num_active_rx) |
| 2037 | priv->last_rx_noise = (total_silence / num_active_rx) - 107; |
| 2038 | else |
| 2039 | priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE; |
| 2040 | |
| 2041 | IWL_DEBUG_CALIB("inband silence a %u, b %u, c %u, dBm %d\n", |
| 2042 | bcn_silence_a, bcn_silence_b, bcn_silence_c, |
| 2043 | priv->last_rx_noise); |
| 2044 | } |
| 2045 | |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2046 | void iwl4965_hw_rx_statistics(struct iwl_priv *priv, |
| 2047 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2048 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2049 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2050 | int change; |
| 2051 | s32 temp; |
| 2052 | |
| 2053 | IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n", |
| 2054 | (int)sizeof(priv->statistics), pkt->len); |
| 2055 | |
| 2056 | change = ((priv->statistics.general.temperature != |
| 2057 | pkt->u.stats.general.temperature) || |
| 2058 | ((priv->statistics.flag & |
| 2059 | STATISTICS_REPLY_FLG_FAT_MODE_MSK) != |
| 2060 | (pkt->u.stats.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK))); |
| 2061 | |
| 2062 | memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics)); |
| 2063 | |
| 2064 | set_bit(STATUS_STATISTICS, &priv->status); |
| 2065 | |
| 2066 | /* Reschedule the statistics timer to occur in |
| 2067 | * REG_RECALIB_PERIOD seconds to ensure we get a |
| 2068 | * thermal update even if the uCode doesn't give |
| 2069 | * us one */ |
| 2070 | mod_timer(&priv->statistics_periodic, jiffies + |
| 2071 | msecs_to_jiffies(REG_RECALIB_PERIOD * 1000)); |
| 2072 | |
| 2073 | if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) && |
| 2074 | (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) { |
| 2075 | iwl4965_rx_calc_noise(priv); |
Emmanuel Grumbach | 16e727e | 2008-06-12 09:46:52 +0800 | [diff] [blame] | 2076 | queue_work(priv->workqueue, &priv->run_time_calib_work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
Mohamed Abbas | ab53d8a | 2008-03-25 16:33:36 -0700 | [diff] [blame] | 2079 | iwl_leds_background(priv); |
| 2080 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2081 | /* If the hardware hasn't reported a change in |
| 2082 | * temperature then don't bother computing a |
| 2083 | * calibrated temperature value */ |
| 2084 | if (!change) |
| 2085 | return; |
| 2086 | |
| 2087 | temp = iwl4965_get_temperature(priv); |
| 2088 | if (temp < 0) |
| 2089 | return; |
| 2090 | |
| 2091 | if (priv->temperature != temp) { |
| 2092 | if (priv->temperature) |
| 2093 | IWL_DEBUG_TEMP("Temperature changed " |
| 2094 | "from %dC to %dC\n", |
| 2095 | KELVIN_TO_CELSIUS(priv->temperature), |
| 2096 | KELVIN_TO_CELSIUS(temp)); |
| 2097 | else |
| 2098 | IWL_DEBUG_TEMP("Temperature " |
| 2099 | "initialized to %dC\n", |
| 2100 | KELVIN_TO_CELSIUS(temp)); |
| 2101 | } |
| 2102 | |
| 2103 | priv->temperature = temp; |
| 2104 | set_bit(STATUS_TEMPERATURE, &priv->status); |
| 2105 | |
Emmanuel Grumbach | 203566f | 2008-06-12 09:46:54 +0800 | [diff] [blame^] | 2106 | if (!priv->disable_tx_power_cal && |
| 2107 | unlikely(!test_bit(STATUS_SCANNING, &priv->status)) && |
| 2108 | iwl4965_is_temp_calib_needed(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2109 | queue_work(priv->workqueue, &priv->txpower_work); |
| 2110 | } |
| 2111 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2112 | static void iwl4965_add_radiotap(struct iwl_priv *priv, |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2113 | struct sk_buff *skb, |
| 2114 | struct iwl4965_rx_phy_res *rx_start, |
| 2115 | struct ieee80211_rx_status *stats, |
| 2116 | u32 ampdu_status) |
| 2117 | { |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 2118 | s8 signal = stats->signal; |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2119 | s8 noise = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2120 | int rate = stats->rate_idx; |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2121 | u64 tsf = stats->mactime; |
Johannes Berg | a0b484f | 2008-04-01 17:51:47 +0200 | [diff] [blame] | 2122 | __le16 antenna; |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2123 | __le16 phy_flags_hw = rx_start->phy_flags; |
| 2124 | struct iwl4965_rt_rx_hdr { |
| 2125 | struct ieee80211_radiotap_header rt_hdr; |
| 2126 | __le64 rt_tsf; /* TSF */ |
| 2127 | u8 rt_flags; /* radiotap packet flags */ |
| 2128 | u8 rt_rate; /* rate in 500kb/s */ |
| 2129 | __le16 rt_channelMHz; /* channel in MHz */ |
| 2130 | __le16 rt_chbitmask; /* channel bitfield */ |
| 2131 | s8 rt_dbmsignal; /* signal in dBm, kluged to signed */ |
| 2132 | s8 rt_dbmnoise; |
| 2133 | u8 rt_antenna; /* antenna number */ |
| 2134 | } __attribute__ ((packed)) *iwl4965_rt; |
| 2135 | |
| 2136 | /* TODO: We won't have enough headroom for HT frames. Fix it later. */ |
| 2137 | if (skb_headroom(skb) < sizeof(*iwl4965_rt)) { |
| 2138 | if (net_ratelimit()) |
| 2139 | printk(KERN_ERR "not enough headroom [%d] for " |
Miguel Botón | 01c2098 | 2008-01-04 23:34:35 +0100 | [diff] [blame] | 2140 | "radiotap head [%zd]\n", |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2141 | skb_headroom(skb), sizeof(*iwl4965_rt)); |
| 2142 | return; |
| 2143 | } |
| 2144 | |
| 2145 | /* put radiotap header in front of 802.11 header and data */ |
| 2146 | iwl4965_rt = (void *)skb_push(skb, sizeof(*iwl4965_rt)); |
| 2147 | |
| 2148 | /* initialise radiotap header */ |
| 2149 | iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION; |
| 2150 | iwl4965_rt->rt_hdr.it_pad = 0; |
| 2151 | |
| 2152 | /* total header + data */ |
| 2153 | put_unaligned(cpu_to_le16(sizeof(*iwl4965_rt)), |
| 2154 | &iwl4965_rt->rt_hdr.it_len); |
| 2155 | |
| 2156 | /* Indicate all the fields we add to the radiotap header */ |
| 2157 | put_unaligned(cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) | |
| 2158 | (1 << IEEE80211_RADIOTAP_FLAGS) | |
| 2159 | (1 << IEEE80211_RADIOTAP_RATE) | |
| 2160 | (1 << IEEE80211_RADIOTAP_CHANNEL) | |
| 2161 | (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) | |
| 2162 | (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) | |
| 2163 | (1 << IEEE80211_RADIOTAP_ANTENNA)), |
| 2164 | &iwl4965_rt->rt_hdr.it_present); |
| 2165 | |
| 2166 | /* Zero the flags, we'll add to them as we go */ |
| 2167 | iwl4965_rt->rt_flags = 0; |
| 2168 | |
| 2169 | put_unaligned(cpu_to_le64(tsf), &iwl4965_rt->rt_tsf); |
| 2170 | |
| 2171 | iwl4965_rt->rt_dbmsignal = signal; |
| 2172 | iwl4965_rt->rt_dbmnoise = noise; |
| 2173 | |
| 2174 | /* Convert the channel frequency and set the flags */ |
| 2175 | put_unaligned(cpu_to_le16(stats->freq), &iwl4965_rt->rt_channelMHz); |
| 2176 | if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK)) |
| 2177 | put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 2178 | IEEE80211_CHAN_5GHZ), |
| 2179 | &iwl4965_rt->rt_chbitmask); |
| 2180 | else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK) |
| 2181 | put_unaligned(cpu_to_le16(IEEE80211_CHAN_CCK | |
| 2182 | IEEE80211_CHAN_2GHZ), |
| 2183 | &iwl4965_rt->rt_chbitmask); |
| 2184 | else /* 802.11g */ |
| 2185 | put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM | |
| 2186 | IEEE80211_CHAN_2GHZ), |
| 2187 | &iwl4965_rt->rt_chbitmask); |
| 2188 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2189 | if (rate == -1) |
| 2190 | iwl4965_rt->rt_rate = 0; |
| 2191 | else |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 2192 | iwl4965_rt->rt_rate = iwl_rates[rate].ieee; |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2193 | |
| 2194 | /* |
| 2195 | * "antenna number" |
| 2196 | * |
| 2197 | * It seems that the antenna field in the phy flags value |
| 2198 | * is actually a bitfield. This is undefined by radiotap, |
| 2199 | * it wants an actual antenna number but I always get "7" |
| 2200 | * for most legacy frames I receive indicating that the |
| 2201 | * same frame was received on all three RX chains. |
| 2202 | * |
| 2203 | * I think this field should be removed in favour of a |
| 2204 | * new 802.11n radiotap field "RX chains" that is defined |
| 2205 | * as a bitmask. |
| 2206 | */ |
Johannes Berg | a0b484f | 2008-04-01 17:51:47 +0200 | [diff] [blame] | 2207 | antenna = phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK; |
| 2208 | iwl4965_rt->rt_antenna = le16_to_cpu(antenna) >> 4; |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2209 | |
| 2210 | /* set the preamble flag if appropriate */ |
| 2211 | if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) |
| 2212 | iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE; |
| 2213 | |
| 2214 | stats->flag |= RX_FLAG_RADIOTAP; |
| 2215 | } |
| 2216 | |
Tomas Winkler | 19758be | 2008-03-12 16:58:51 -0700 | [diff] [blame] | 2217 | static void iwl_update_rx_stats(struct iwl_priv *priv, u16 fc, u16 len) |
| 2218 | { |
| 2219 | /* 0 - mgmt, 1 - cnt, 2 - data */ |
| 2220 | int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2; |
| 2221 | priv->rx_stats[idx].cnt++; |
| 2222 | priv->rx_stats[idx].bytes += len; |
| 2223 | } |
| 2224 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 2225 | /* |
| 2226 | * returns non-zero if packet should be dropped |
| 2227 | */ |
| 2228 | static int iwl4965_set_decrypted_flag(struct iwl_priv *priv, |
| 2229 | struct ieee80211_hdr *hdr, |
| 2230 | u32 decrypt_res, |
| 2231 | struct ieee80211_rx_status *stats) |
| 2232 | { |
| 2233 | u16 fc = le16_to_cpu(hdr->frame_control); |
| 2234 | |
| 2235 | if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) |
| 2236 | return 0; |
| 2237 | |
| 2238 | if (!(fc & IEEE80211_FCTL_PROTECTED)) |
| 2239 | return 0; |
| 2240 | |
| 2241 | IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res); |
| 2242 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 2243 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 2244 | /* The uCode has got a bad phase 1 Key, pushes the packet. |
| 2245 | * Decryption will be done in SW. */ |
| 2246 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2247 | RX_RES_STATUS_BAD_KEY_TTAK) |
| 2248 | break; |
| 2249 | |
Emmanuel Grumbach | ccc038a | 2008-05-15 13:54:09 +0800 | [diff] [blame] | 2250 | case RX_RES_STATUS_SEC_TYPE_WEP: |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 2251 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2252 | RX_RES_STATUS_BAD_ICV_MIC) { |
| 2253 | /* bad ICV, the packet is destroyed since the |
| 2254 | * decryption is inplace, drop it */ |
| 2255 | IWL_DEBUG_RX("Packet destroyed\n"); |
| 2256 | return -1; |
| 2257 | } |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 2258 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 2259 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == |
| 2260 | RX_RES_STATUS_DECRYPT_OK) { |
| 2261 | IWL_DEBUG_RX("hw decrypt successfully!!!\n"); |
| 2262 | stats->flag |= RX_FLAG_DECRYPTED; |
| 2263 | } |
| 2264 | break; |
| 2265 | |
| 2266 | default: |
| 2267 | break; |
| 2268 | } |
| 2269 | return 0; |
| 2270 | } |
| 2271 | |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2272 | static u32 iwl4965_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in) |
Emmanuel Grumbach | 17e476b | 2008-03-19 16:41:42 -0700 | [diff] [blame] | 2273 | { |
| 2274 | u32 decrypt_out = 0; |
| 2275 | |
| 2276 | if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) == |
| 2277 | RX_RES_STATUS_STATION_FOUND) |
| 2278 | decrypt_out |= (RX_RES_STATUS_STATION_FOUND | |
| 2279 | RX_RES_STATUS_NO_STATION_INFO_MISMATCH); |
| 2280 | |
| 2281 | decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK); |
| 2282 | |
| 2283 | /* packet was not encrypted */ |
| 2284 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == |
| 2285 | RX_RES_STATUS_SEC_TYPE_NONE) |
| 2286 | return decrypt_out; |
| 2287 | |
| 2288 | /* packet was encrypted with unknown alg */ |
| 2289 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == |
| 2290 | RX_RES_STATUS_SEC_TYPE_ERR) |
| 2291 | return decrypt_out; |
| 2292 | |
| 2293 | /* decryption was not done in HW */ |
| 2294 | if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) != |
| 2295 | RX_MPDU_RES_STATUS_DEC_DONE_MSK) |
| 2296 | return decrypt_out; |
| 2297 | |
| 2298 | switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) { |
| 2299 | |
| 2300 | case RX_RES_STATUS_SEC_TYPE_CCMP: |
| 2301 | /* alg is CCM: check MIC only */ |
| 2302 | if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK)) |
| 2303 | /* Bad MIC */ |
| 2304 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; |
| 2305 | else |
| 2306 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; |
| 2307 | |
| 2308 | break; |
| 2309 | |
| 2310 | case RX_RES_STATUS_SEC_TYPE_TKIP: |
| 2311 | if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) { |
| 2312 | /* Bad TTAK */ |
| 2313 | decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK; |
| 2314 | break; |
| 2315 | } |
| 2316 | /* fall through if TTAK OK */ |
| 2317 | default: |
| 2318 | if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK)) |
| 2319 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; |
| 2320 | else |
| 2321 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; |
| 2322 | break; |
| 2323 | }; |
| 2324 | |
| 2325 | IWL_DEBUG_RX("decrypt_in:0x%x decrypt_out = 0x%x\n", |
| 2326 | decrypt_in, decrypt_out); |
| 2327 | |
| 2328 | return decrypt_out; |
| 2329 | } |
| 2330 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2331 | 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] | 2332 | int include_phy, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2333 | struct iwl_rx_mem_buffer *rxb, |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2334 | struct ieee80211_rx_status *stats) |
| 2335 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2336 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2337 | struct iwl4965_rx_phy_res *rx_start = (include_phy) ? |
| 2338 | (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : NULL; |
| 2339 | struct ieee80211_hdr *hdr; |
| 2340 | u16 len; |
| 2341 | __le32 *rx_end; |
| 2342 | unsigned int skblen; |
| 2343 | u32 ampdu_status; |
Emmanuel Grumbach | 17e476b | 2008-03-19 16:41:42 -0700 | [diff] [blame] | 2344 | u32 ampdu_status_legacy; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2345 | |
| 2346 | if (!include_phy && priv->last_phy_res[0]) |
| 2347 | rx_start = (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1]; |
| 2348 | |
| 2349 | if (!rx_start) { |
| 2350 | IWL_ERROR("MPDU frame without a PHY data\n"); |
| 2351 | return; |
| 2352 | } |
| 2353 | if (include_phy) { |
| 2354 | hdr = (struct ieee80211_hdr *)((u8 *) & rx_start[1] + |
| 2355 | rx_start->cfg_phy_cnt); |
| 2356 | |
| 2357 | len = le16_to_cpu(rx_start->byte_count); |
| 2358 | |
| 2359 | rx_end = (__le32 *) ((u8 *) & pkt->u.raw[0] + |
| 2360 | sizeof(struct iwl4965_rx_phy_res) + |
| 2361 | rx_start->cfg_phy_cnt + len); |
| 2362 | |
| 2363 | } else { |
| 2364 | struct iwl4965_rx_mpdu_res_start *amsdu = |
| 2365 | (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw; |
| 2366 | |
| 2367 | hdr = (struct ieee80211_hdr *)(pkt->u.raw + |
| 2368 | sizeof(struct iwl4965_rx_mpdu_res_start)); |
| 2369 | len = le16_to_cpu(amsdu->byte_count); |
| 2370 | rx_start->byte_count = amsdu->byte_count; |
| 2371 | rx_end = (__le32 *) (((u8 *) hdr) + len); |
| 2372 | } |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 2373 | /* In monitor mode allow 802.11 ACk frames (10 bytes) */ |
| 2374 | if (len > priv->hw_params.max_pkt_size || |
| 2375 | len < ((priv->iw_mode == IEEE80211_IF_TYPE_MNTR) ? 10 : 16)) { |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2376 | IWL_WARNING("byte count out of range [16,4K] : %d\n", len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2377 | return; |
| 2378 | } |
| 2379 | |
| 2380 | ampdu_status = le32_to_cpu(*rx_end); |
| 2381 | skblen = ((u8 *) rx_end - (u8 *) & pkt->u.raw[0]) + sizeof(u32); |
| 2382 | |
Emmanuel Grumbach | 17e476b | 2008-03-19 16:41:42 -0700 | [diff] [blame] | 2383 | if (!include_phy) { |
| 2384 | /* New status scheme, need to translate */ |
| 2385 | ampdu_status_legacy = ampdu_status; |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2386 | ampdu_status = iwl4965_translate_rx_status(priv, ampdu_status); |
Emmanuel Grumbach | 17e476b | 2008-03-19 16:41:42 -0700 | [diff] [blame] | 2387 | } |
| 2388 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2389 | /* start from MAC */ |
| 2390 | skb_reserve(rxb->skb, (void *)hdr - (void *)pkt); |
| 2391 | skb_put(rxb->skb, len); /* end where data ends */ |
| 2392 | |
| 2393 | /* We only process data packets if the interface is open */ |
| 2394 | if (unlikely(!priv->is_open)) { |
| 2395 | IWL_DEBUG_DROP_LIMIT |
| 2396 | ("Dropping packet while interface is not open.\n"); |
| 2397 | return; |
| 2398 | } |
| 2399 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2400 | stats->flag = 0; |
| 2401 | hdr = (struct ieee80211_hdr *)rxb->skb->data; |
| 2402 | |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 2403 | /* in case of HW accelerated crypto and bad decryption, drop */ |
Ron Rindjunsky | 099b40b | 2008-04-21 15:41:53 -0700 | [diff] [blame] | 2404 | if (!priv->hw_params.sw_crypto && |
Emmanuel Grumbach | 3ec4773 | 2008-04-17 16:03:36 -0700 | [diff] [blame] | 2405 | iwl4965_set_decrypted_flag(priv, hdr, ampdu_status, stats)) |
| 2406 | return; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2407 | |
Zhu Yi | 12342c4 | 2007-12-20 11:27:32 +0800 | [diff] [blame] | 2408 | if (priv->add_radiotap) |
| 2409 | iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status); |
| 2410 | |
Tomas Winkler | 19758be | 2008-03-12 16:58:51 -0700 | [diff] [blame] | 2411 | iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2412 | ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats); |
| 2413 | priv->alloc_rxb_skb--; |
| 2414 | rxb->skb = NULL; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2415 | } |
| 2416 | |
| 2417 | /* Calc max signal level (dBm) among 3 possible receivers */ |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2418 | static int iwl4965_calc_rssi(struct iwl_priv *priv, |
| 2419 | struct iwl4965_rx_phy_res *rx_resp) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2420 | { |
| 2421 | /* data from PHY/DSP regarding signal strength, etc., |
| 2422 | * contents are always there, not configurable by host. */ |
| 2423 | struct iwl4965_rx_non_cfg_phy *ncphy = |
| 2424 | (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy; |
| 2425 | u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL_AGC_DB_MASK) |
| 2426 | >> IWL_AGC_DB_POS; |
| 2427 | |
| 2428 | u32 valid_antennae = |
| 2429 | (le16_to_cpu(rx_resp->phy_flags) & RX_PHY_FLAGS_ANTENNAE_MASK) |
| 2430 | >> RX_PHY_FLAGS_ANTENNAE_OFFSET; |
| 2431 | u8 max_rssi = 0; |
| 2432 | u32 i; |
| 2433 | |
| 2434 | /* Find max rssi among 3 possible receivers. |
| 2435 | * These values are measured by the digital signal processor (DSP). |
| 2436 | * They should stay fairly constant even as the signal strength varies, |
| 2437 | * if the radio's automatic gain control (AGC) is working right. |
| 2438 | * AGC value (see below) will provide the "interesting" info. */ |
| 2439 | for (i = 0; i < 3; i++) |
| 2440 | if (valid_antennae & (1 << i)) |
| 2441 | max_rssi = max(ncphy->rssi_info[i << 1], max_rssi); |
| 2442 | |
| 2443 | IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n", |
| 2444 | ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4], |
| 2445 | max_rssi, agc); |
| 2446 | |
| 2447 | /* dBm = max_rssi dB - agc dB - constant. |
| 2448 | * Higher AGC (higher radio gain) means lower signal. */ |
| 2449 | return (max_rssi - agc - IWL_RSSI_OFFSET); |
| 2450 | } |
| 2451 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2452 | 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] | 2453 | { |
| 2454 | unsigned long flags; |
| 2455 | |
| 2456 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 2457 | priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK; |
| 2458 | priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK; |
| 2459 | priv->stations[sta_id].sta.sta.modify_mask = 0; |
| 2460 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 2461 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 2462 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 2463 | iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2464 | } |
| 2465 | |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2466 | 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] | 2467 | { |
| 2468 | /* FIXME: need locking over ps_status ??? */ |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 2469 | u8 sta_id = iwl_find_station(priv, addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2470 | |
| 2471 | if (sta_id != IWL_INVALID_STATION) { |
| 2472 | u8 sta_awake = priv->stations[sta_id]. |
| 2473 | ps_status == STA_PS_STATUS_WAKE; |
| 2474 | |
| 2475 | if (sta_awake && ps_bit) |
| 2476 | priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP; |
| 2477 | else if (!sta_awake && !ps_bit) { |
| 2478 | iwl4965_sta_modify_ps_wake(priv, sta_id); |
| 2479 | priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE; |
| 2480 | } |
| 2481 | } |
| 2482 | } |
Tomas Winkler | 0a6857e | 2008-03-12 16:58:49 -0700 | [diff] [blame] | 2483 | #ifdef CONFIG_IWLWIFI_DEBUG |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2484 | |
| 2485 | /** |
| 2486 | * iwl4965_dbg_report_frame - dump frame to syslog during debug sessions |
| 2487 | * |
| 2488 | * You may hack this function to show different aspects of received frames, |
| 2489 | * including selective frame dumps. |
| 2490 | * group100 parameter selects whether to show 1 out of 100 good frames. |
| 2491 | * |
| 2492 | * TODO: This was originally written for 3945, need to audit for |
| 2493 | * proper operation with 4965. |
| 2494 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2495 | static void iwl4965_dbg_report_frame(struct iwl_priv *priv, |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2496 | struct iwl_rx_packet *pkt, |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2497 | struct ieee80211_hdr *header, int group100) |
| 2498 | { |
| 2499 | u32 to_us; |
| 2500 | u32 print_summary = 0; |
| 2501 | u32 print_dump = 0; /* set to 1 to dump all frames' contents */ |
| 2502 | u32 hundred = 0; |
| 2503 | u32 dataframe = 0; |
| 2504 | u16 fc; |
| 2505 | u16 seq_ctl; |
| 2506 | u16 channel; |
| 2507 | u16 phy_flags; |
| 2508 | int rate_sym; |
| 2509 | u16 length; |
| 2510 | u16 status; |
| 2511 | u16 bcn_tmr; |
| 2512 | u32 tsf_low; |
| 2513 | u64 tsf; |
| 2514 | u8 rssi; |
| 2515 | u8 agc; |
| 2516 | u16 sig_avg; |
| 2517 | u16 noise_diff; |
| 2518 | struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt); |
| 2519 | struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt); |
| 2520 | struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt); |
| 2521 | u8 *data = IWL_RX_DATA(pkt); |
| 2522 | |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2523 | if (likely(!(priv->debug_level & IWL_DL_RX))) |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2524 | return; |
| 2525 | |
| 2526 | /* MAC header */ |
| 2527 | fc = le16_to_cpu(header->frame_control); |
| 2528 | seq_ctl = le16_to_cpu(header->seq_ctrl); |
| 2529 | |
| 2530 | /* metadata */ |
| 2531 | channel = le16_to_cpu(rx_hdr->channel); |
| 2532 | phy_flags = le16_to_cpu(rx_hdr->phy_flags); |
| 2533 | rate_sym = rx_hdr->rate; |
| 2534 | length = le16_to_cpu(rx_hdr->len); |
| 2535 | |
| 2536 | /* end-of-frame status and timestamp */ |
| 2537 | status = le32_to_cpu(rx_end->status); |
| 2538 | bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp); |
| 2539 | tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff; |
| 2540 | tsf = le64_to_cpu(rx_end->timestamp); |
| 2541 | |
| 2542 | /* signal statistics */ |
| 2543 | rssi = rx_stats->rssi; |
| 2544 | agc = rx_stats->agc; |
| 2545 | sig_avg = le16_to_cpu(rx_stats->sig_avg); |
| 2546 | noise_diff = le16_to_cpu(rx_stats->noise_diff); |
| 2547 | |
| 2548 | to_us = !compare_ether_addr(header->addr1, priv->mac_addr); |
| 2549 | |
| 2550 | /* if data frame is to us and all is good, |
| 2551 | * (optionally) print summary for only 1 out of every 100 */ |
| 2552 | if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) == |
| 2553 | (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) { |
| 2554 | dataframe = 1; |
| 2555 | if (!group100) |
| 2556 | print_summary = 1; /* print each frame */ |
| 2557 | else if (priv->framecnt_to_us < 100) { |
| 2558 | priv->framecnt_to_us++; |
| 2559 | print_summary = 0; |
| 2560 | } else { |
| 2561 | priv->framecnt_to_us = 0; |
| 2562 | print_summary = 1; |
| 2563 | hundred = 1; |
| 2564 | } |
| 2565 | } else { |
| 2566 | /* print summary for all other frames */ |
| 2567 | print_summary = 1; |
| 2568 | } |
| 2569 | |
| 2570 | if (print_summary) { |
| 2571 | char *title; |
| 2572 | int rate_idx; |
| 2573 | u32 bitrate; |
| 2574 | |
| 2575 | if (hundred) |
| 2576 | title = "100Frames"; |
| 2577 | else if (fc & IEEE80211_FCTL_RETRY) |
| 2578 | title = "Retry"; |
| 2579 | else if (ieee80211_is_assoc_response(fc)) |
| 2580 | title = "AscRsp"; |
| 2581 | else if (ieee80211_is_reassoc_response(fc)) |
| 2582 | title = "RasRsp"; |
| 2583 | else if (ieee80211_is_probe_response(fc)) { |
| 2584 | title = "PrbRsp"; |
| 2585 | print_dump = 1; /* dump frame contents */ |
| 2586 | } else if (ieee80211_is_beacon(fc)) { |
| 2587 | title = "Beacon"; |
| 2588 | print_dump = 1; /* dump frame contents */ |
| 2589 | } else if (ieee80211_is_atim(fc)) |
| 2590 | title = "ATIM"; |
| 2591 | else if (ieee80211_is_auth(fc)) |
| 2592 | title = "Auth"; |
| 2593 | else if (ieee80211_is_deauth(fc)) |
| 2594 | title = "DeAuth"; |
| 2595 | else if (ieee80211_is_disassoc(fc)) |
| 2596 | title = "DisAssoc"; |
| 2597 | else |
| 2598 | title = "Frame"; |
| 2599 | |
| 2600 | rate_idx = iwl4965_hwrate_to_plcp_idx(rate_sym); |
| 2601 | if (unlikely(rate_idx == -1)) |
| 2602 | bitrate = 0; |
| 2603 | else |
Tomas Winkler | 1826dcc | 2008-05-15 13:54:02 +0800 | [diff] [blame] | 2604 | bitrate = iwl_rates[rate_idx].ieee / 2; |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2605 | |
| 2606 | /* print frame summary. |
| 2607 | * MAC addresses show just the last byte (for brevity), |
| 2608 | * but you can hack it to show more, if you'd like to. */ |
| 2609 | if (dataframe) |
| 2610 | IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, " |
| 2611 | "len=%u, rssi=%d, chnl=%d, rate=%u, \n", |
| 2612 | title, fc, header->addr1[5], |
| 2613 | length, rssi, channel, bitrate); |
| 2614 | else { |
| 2615 | /* src/dst addresses assume managed mode */ |
| 2616 | IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, " |
| 2617 | "src=0x%02x, rssi=%u, tim=%lu usec, " |
| 2618 | "phy=0x%02x, chnl=%d\n", |
| 2619 | title, fc, header->addr1[5], |
| 2620 | header->addr3[5], rssi, |
| 2621 | tsf_low - priv->scan_start_tsf, |
| 2622 | phy_flags, channel); |
| 2623 | } |
| 2624 | } |
| 2625 | if (print_dump) |
Ester Kummer | bf403db | 2008-05-05 10:22:40 +0800 | [diff] [blame] | 2626 | iwl_print_hex_dump(priv, IWL_DL_RX, data, length); |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2627 | } |
| 2628 | #else |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2629 | static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv, |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2630 | struct iwl_rx_packet *pkt, |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2631 | struct ieee80211_hdr *header, |
| 2632 | int group100) |
| 2633 | { |
| 2634 | } |
| 2635 | #endif |
| 2636 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2637 | |
Mohamed Abbas | 7878a5a | 2007-11-29 11:10:13 +0800 | [diff] [blame] | 2638 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2639 | /* Called for REPLY_RX (legacy ABG frames), or |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2640 | * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */ |
Ron Rindjunsky | 37a4421 | 2008-05-29 16:35:18 +0800 | [diff] [blame] | 2641 | void iwl4965_rx_reply_rx(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2642 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2643 | { |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2644 | struct ieee80211_hdr *header; |
| 2645 | struct ieee80211_rx_status rx_status; |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2646 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2647 | /* Use phy data (Rx signal strength, etc.) contained within |
| 2648 | * this rx packet for legacy frames, |
| 2649 | * or phy data cached from REPLY_RX_PHY_CMD for HT frames. */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 2650 | int include_phy = (pkt->hdr.cmd == REPLY_RX); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2651 | struct iwl4965_rx_phy_res *rx_start = (include_phy) ? |
| 2652 | (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : |
| 2653 | (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1]; |
| 2654 | __le32 *rx_end; |
| 2655 | unsigned int len = 0; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2656 | u16 fc; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2657 | u8 network_packet; |
| 2658 | |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2659 | rx_status.mactime = le64_to_cpu(rx_start->timestamp); |
Tomas Winkler | dc92e49 | 2008-04-03 16:05:22 -0700 | [diff] [blame] | 2660 | rx_status.freq = |
Emmanuel Grumbach | c018607 | 2008-05-08 11:34:05 +0800 | [diff] [blame] | 2661 | ieee80211_channel_to_frequency(le16_to_cpu(rx_start->channel)); |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2662 | rx_status.band = (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? |
| 2663 | IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ; |
Tomas Winkler | dc92e49 | 2008-04-03 16:05:22 -0700 | [diff] [blame] | 2664 | rx_status.rate_idx = |
| 2665 | 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] | 2666 | if (rx_status.band == IEEE80211_BAND_5GHZ) |
| 2667 | rx_status.rate_idx -= IWL_FIRST_OFDM_RATE; |
| 2668 | |
| 2669 | rx_status.antenna = 0; |
| 2670 | rx_status.flag = 0; |
| 2671 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2672 | if ((unlikely(rx_start->cfg_phy_cnt > 20))) { |
Tomas Winkler | dc92e49 | 2008-04-03 16:05:22 -0700 | [diff] [blame] | 2673 | IWL_DEBUG_DROP("dsp size out of range [0,20]: %d/n", |
| 2674 | rx_start->cfg_phy_cnt); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2675 | return; |
| 2676 | } |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2677 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2678 | if (!include_phy) { |
| 2679 | if (priv->last_phy_res[0]) |
| 2680 | rx_start = (struct iwl4965_rx_phy_res *) |
| 2681 | &priv->last_phy_res[1]; |
| 2682 | else |
| 2683 | rx_start = NULL; |
| 2684 | } |
| 2685 | |
| 2686 | if (!rx_start) { |
| 2687 | IWL_ERROR("MPDU frame without a PHY data\n"); |
| 2688 | return; |
| 2689 | } |
| 2690 | |
| 2691 | if (include_phy) { |
| 2692 | header = (struct ieee80211_hdr *)((u8 *) & rx_start[1] |
| 2693 | + rx_start->cfg_phy_cnt); |
| 2694 | |
| 2695 | len = le16_to_cpu(rx_start->byte_count); |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2696 | rx_end = (__le32 *)(pkt->u.raw + rx_start->cfg_phy_cnt + |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2697 | sizeof(struct iwl4965_rx_phy_res) + len); |
| 2698 | } else { |
| 2699 | struct iwl4965_rx_mpdu_res_start *amsdu = |
| 2700 | (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw; |
| 2701 | |
| 2702 | header = (void *)(pkt->u.raw + |
| 2703 | sizeof(struct iwl4965_rx_mpdu_res_start)); |
| 2704 | len = le16_to_cpu(amsdu->byte_count); |
| 2705 | rx_end = (__le32 *) (pkt->u.raw + |
| 2706 | sizeof(struct iwl4965_rx_mpdu_res_start) + len); |
| 2707 | } |
| 2708 | |
| 2709 | if (!(*rx_end & RX_RES_STATUS_NO_CRC32_ERROR) || |
| 2710 | !(*rx_end & RX_RES_STATUS_NO_RXE_OVERFLOW)) { |
| 2711 | IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n", |
| 2712 | le32_to_cpu(*rx_end)); |
| 2713 | return; |
| 2714 | } |
| 2715 | |
| 2716 | priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp); |
| 2717 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2718 | /* Find max signal strength (dBm) among 3 antenna/receiver chains */ |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 2719 | rx_status.signal = iwl4965_calc_rssi(priv, rx_start); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2720 | |
| 2721 | /* Meaningful noise values are available only from beacon statistics, |
| 2722 | * which are gathered only when associated, and indicate noise |
| 2723 | * only for the associated network channel ... |
| 2724 | * Ignore these noise values while scanning (other channels) */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2725 | if (iwl_is_associated(priv) && |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2726 | !test_bit(STATUS_SCANNING, &priv->status)) { |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2727 | rx_status.noise = priv->last_rx_noise; |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 2728 | rx_status.qual = iwl4965_calc_sig_qual(rx_status.signal, |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2729 | rx_status.noise); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2730 | } else { |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2731 | rx_status.noise = IWL_NOISE_MEAS_NOT_AVAILABLE; |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 2732 | rx_status.qual = iwl4965_calc_sig_qual(rx_status.signal, 0); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | /* Reset beacon noise level if not associated. */ |
Tomas Winkler | 3109ece | 2008-03-28 16:33:35 -0700 | [diff] [blame] | 2736 | if (!iwl_is_associated(priv)) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2737 | priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE; |
| 2738 | |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2739 | /* Set "1" to report good data frames in groups of 100 */ |
| 2740 | /* FIXME: need to optimze the call: */ |
| 2741 | iwl4965_dbg_report_frame(priv, pkt, header, 1); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2742 | |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2743 | IWL_DEBUG_STATS_LIMIT("Rssi %d, noise %d, qual %d, TSF %llu\n", |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 2744 | rx_status.signal, rx_status.noise, rx_status.signal, |
John W. Linville | 06501d2 | 2008-04-01 17:38:47 -0400 | [diff] [blame] | 2745 | (unsigned long long)rx_status.mactime); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2746 | |
Abhijeet Kolekar | 4419e39 | 2008-05-05 10:22:47 +0800 | [diff] [blame] | 2747 | |
| 2748 | if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) { |
| 2749 | iwl4965_handle_data_packet(priv, 1, include_phy, |
| 2750 | rxb, &rx_status); |
| 2751 | return; |
| 2752 | } |
| 2753 | |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2754 | network_packet = iwl4965_is_network_packet(priv, header); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2755 | if (network_packet) { |
Bruno Randolf | 566bfe5 | 2008-05-08 19:15:40 +0200 | [diff] [blame] | 2756 | priv->last_rx_rssi = rx_status.signal; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2757 | priv->last_beacon_time = priv->ucode_beacon_time; |
| 2758 | priv->last_tsf = le64_to_cpu(rx_start->timestamp); |
| 2759 | } |
| 2760 | |
| 2761 | fc = le16_to_cpu(header->frame_control); |
| 2762 | switch (fc & IEEE80211_FCTL_FTYPE) { |
| 2763 | case IEEE80211_FTYPE_MGMT: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2764 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
| 2765 | iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM, |
| 2766 | header->addr2); |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2767 | iwl4965_handle_data_packet(priv, 0, include_phy, rxb, &rx_status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2768 | break; |
| 2769 | |
| 2770 | case IEEE80211_FTYPE_CTL: |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2771 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 2772 | case IEEE80211_STYPE_BACK_REQ: |
| 2773 | IWL_DEBUG_HT("IEEE80211_STYPE_BACK_REQ arrived\n"); |
| 2774 | iwl4965_handle_data_packet(priv, 0, include_phy, |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2775 | rxb, &rx_status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2776 | break; |
| 2777 | default: |
| 2778 | break; |
| 2779 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2780 | break; |
| 2781 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2782 | case IEEE80211_FTYPE_DATA: { |
| 2783 | DECLARE_MAC_BUF(mac1); |
| 2784 | DECLARE_MAC_BUF(mac2); |
| 2785 | DECLARE_MAC_BUF(mac3); |
| 2786 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2787 | if (priv->iw_mode == IEEE80211_IF_TYPE_AP) |
| 2788 | iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM, |
| 2789 | header->addr2); |
| 2790 | |
| 2791 | if (unlikely(!network_packet)) |
| 2792 | IWL_DEBUG_DROP("Dropping (non network): " |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2793 | "%s, %s, %s\n", |
| 2794 | print_mac(mac1, header->addr1), |
| 2795 | print_mac(mac2, header->addr2), |
| 2796 | print_mac(mac3, header->addr3)); |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2797 | else if (unlikely(iwl4965_is_duplicate_packet(priv, header))) |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2798 | IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n", |
| 2799 | print_mac(mac1, header->addr1), |
| 2800 | print_mac(mac2, header->addr2), |
| 2801 | print_mac(mac3, header->addr3)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2802 | else |
| 2803 | iwl4965_handle_data_packet(priv, 1, include_phy, rxb, |
Tomas Winkler | 17744ff | 2008-03-02 01:52:00 +0200 | [diff] [blame] | 2804 | &rx_status); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2805 | break; |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2806 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2807 | default: |
| 2808 | break; |
| 2809 | |
| 2810 | } |
| 2811 | } |
| 2812 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2813 | /** |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2814 | * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack |
| 2815 | * |
| 2816 | * Go through block-ack's bitmap of ACK'd frames, update driver's record of |
| 2817 | * ACK vs. not. This gets sent to mac80211, then to rate scaling algo. |
| 2818 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2819 | static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv, |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 2820 | struct iwl_ht_agg *agg, |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2821 | struct iwl4965_compressed_ba_resp* |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2822 | ba_resp) |
| 2823 | |
| 2824 | { |
| 2825 | int i, sh, ack; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2826 | u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl); |
| 2827 | u16 scd_flow = le16_to_cpu(ba_resp->scd_flow); |
| 2828 | u64 bitmap; |
| 2829 | int successes = 0; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2830 | struct ieee80211_tx_info *info; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2831 | |
| 2832 | if (unlikely(!agg->wait_for_ba)) { |
| 2833 | IWL_ERROR("Received BA when not expected\n"); |
| 2834 | return -EINVAL; |
| 2835 | } |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2836 | |
| 2837 | /* Mark that the expected block-ack response arrived */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2838 | agg->wait_for_ba = 0; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2839 | 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] | 2840 | |
| 2841 | /* Calculate shift to align block-ack bits with our Tx window bits */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2842 | sh = agg->start_idx - SEQ_TO_INDEX(seq_ctl>>4); |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2843 | if (sh < 0) /* tbw something is wrong with indices */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2844 | sh += 0x100; |
| 2845 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2846 | /* don't use 64-bit values for now */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2847 | bitmap = le64_to_cpu(ba_resp->bitmap) >> sh; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2848 | |
| 2849 | if (agg->frame_count > (64 - sh)) { |
| 2850 | IWL_DEBUG_TX_REPLY("more frames than bitmap size"); |
| 2851 | return -1; |
| 2852 | } |
| 2853 | |
| 2854 | /* check for success or failure according to the |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2855 | * transmitted bitmap and block-ack bitmap */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2856 | bitmap &= agg->bitmap; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2857 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2858 | /* For each frame attempted in aggregation, |
| 2859 | * update driver's record of tx frame's status. */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2860 | for (i = 0; i < agg->frame_count ; i++) { |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2861 | ack = bitmap & (1 << i); |
| 2862 | successes += !!ack; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2863 | 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] | 2864 | ack? "ACK":"NACK", i, (agg->start_idx + i) & 0xff, |
| 2865 | agg->start_idx + i); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2866 | } |
| 2867 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 2868 | info = IEEE80211_SKB_CB(priv->txq[scd_flow].txb[agg->start_idx].skb[0]); |
| 2869 | memset(&info->status, 0, sizeof(info->status)); |
| 2870 | info->flags = IEEE80211_TX_STAT_ACK; |
| 2871 | info->flags |= IEEE80211_TX_STAT_AMPDU; |
| 2872 | info->status.ampdu_ack_map = successes; |
| 2873 | info->status.ampdu_ack_len = agg->frame_count; |
| 2874 | iwl4965_hwrate_to_tx_control(priv, agg->rate_n_flags, info); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2875 | |
John W. Linville | f868f4e | 2008-03-07 16:38:43 -0500 | [diff] [blame] | 2876 | IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2877 | |
| 2878 | return 0; |
| 2879 | } |
| 2880 | |
| 2881 | /** |
| 2882 | * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration |
| 2883 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2884 | static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2885 | u16 txq_id) |
| 2886 | { |
| 2887 | /* Simply stop the queue, but don't change any configuration; |
| 2888 | * 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] | 2889 | iwl_write_prph(priv, |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 2890 | IWL49_SCD_QUEUE_STATUS_BITS(txq_id), |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 2891 | (0 << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE)| |
| 2892 | (1 << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN)); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2893 | } |
| 2894 | |
| 2895 | /** |
| 2896 | * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 2897 | * priv->lock must be held by the caller |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2898 | */ |
Tomas Winkler | 30e553e | 2008-05-29 16:35:16 +0800 | [diff] [blame] | 2899 | static int iwl4965_txq_agg_disable(struct iwl_priv *priv, u16 txq_id, |
| 2900 | u16 ssn_idx, u8 tx_fifo) |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2901 | { |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 2902 | int ret = 0; |
| 2903 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2904 | if (IWL_BACK_QUEUE_FIRST_ID > txq_id) { |
| 2905 | IWL_WARNING("queue number too small: %d, must be > %d\n", |
| 2906 | txq_id, IWL_BACK_QUEUE_FIRST_ID); |
| 2907 | return -EINVAL; |
| 2908 | } |
| 2909 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2910 | ret = iwl_grab_nic_access(priv); |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 2911 | if (ret) |
| 2912 | return ret; |
| 2913 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2914 | iwl4965_tx_queue_stop_scheduler(priv, txq_id); |
| 2915 | |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 2916 | iwl_clear_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id)); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2917 | |
| 2918 | priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff); |
| 2919 | priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff); |
| 2920 | /* supposes that ssn_idx is valid (!= 0xFFF) */ |
| 2921 | iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx); |
| 2922 | |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 2923 | iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id)); |
Ron Rindjunsky | 3647074 | 2008-05-15 13:54:10 +0800 | [diff] [blame] | 2924 | iwl_txq_ctx_deactivate(priv, txq_id); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2925 | iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0); |
| 2926 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 2927 | iwl_release_nic_access(priv); |
Ron Rindjunsky | b095d03a7 | 2008-03-06 17:36:56 -0800 | [diff] [blame] | 2928 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2929 | return 0; |
| 2930 | } |
| 2931 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2932 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2933 | /** |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2934 | * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA |
| 2935 | * |
| 2936 | * Handles block-acknowledge notification from device, which reports success |
| 2937 | * of frames sent via aggregation. |
| 2938 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 2939 | static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv, |
Tomas Winkler | a55360e | 2008-05-05 10:22:28 +0800 | [diff] [blame] | 2940 | struct iwl_rx_mem_buffer *rxb) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2941 | { |
Tomas Winkler | db11d63 | 2008-05-05 10:22:33 +0800 | [diff] [blame] | 2942 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
Christoph Hellwig | bb8c093 | 2008-01-27 16:41:47 -0800 | [diff] [blame] | 2943 | struct iwl4965_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2944 | int index; |
Ron Rindjunsky | 1646690 | 2008-05-05 10:22:50 +0800 | [diff] [blame] | 2945 | struct iwl_tx_queue *txq = NULL; |
Tomas Winkler | 6def976 | 2008-05-05 10:22:31 +0800 | [diff] [blame] | 2946 | struct iwl_ht_agg *agg; |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2947 | DECLARE_MAC_BUF(mac); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2948 | |
| 2949 | /* "flow" corresponds to Tx queue */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2950 | u16 scd_flow = le16_to_cpu(ba_resp->scd_flow); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2951 | |
| 2952 | /* "ssn" is start of block-ack Tx window, corresponds to index |
| 2953 | * (in Tx queue's circular buffer) of first TFD/frame in window */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2954 | u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn); |
| 2955 | |
Ron Rindjunsky | dfe7d45 | 2008-04-15 16:01:45 -0700 | [diff] [blame] | 2956 | if (scd_flow >= priv->hw_params.max_txq_num) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2957 | IWL_ERROR("BUG_ON scd_flow is bigger than number of queues"); |
| 2958 | return; |
| 2959 | } |
| 2960 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2961 | txq = &priv->txq[scd_flow]; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2962 | 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] | 2963 | |
| 2964 | /* Find index just before block-ack window */ |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 2965 | index = iwl_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2966 | |
Ian Schram | 01ebd06 | 2007-10-25 17:15:22 +0800 | [diff] [blame] | 2967 | /* TODO: Need to get this copy more safely - now good for debug */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2968 | |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2969 | IWL_DEBUG_TX_REPLY("REPLY_COMPRESSED_BA [%d]Received from %s, " |
| 2970 | "sta_id = %d\n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2971 | agg->wait_for_ba, |
Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 2972 | print_mac(mac, (u8*) &ba_resp->sta_addr_lo32), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2973 | ba_resp->sta_id); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2974 | 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] | 2975 | "%d, scd_ssn = %d\n", |
| 2976 | ba_resp->tid, |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2977 | ba_resp->seq_ctl, |
Tomas Winkler | 0310ae7 | 2008-03-11 16:17:19 -0700 | [diff] [blame] | 2978 | (unsigned long long)le64_to_cpu(ba_resp->bitmap), |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2979 | ba_resp->scd_flow, |
| 2980 | ba_resp->scd_ssn); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2981 | IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx \n", |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 2982 | agg->start_idx, |
John W. Linville | f868f4e | 2008-03-07 16:38:43 -0500 | [diff] [blame] | 2983 | (unsigned long long)agg->bitmap); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2984 | |
| 2985 | /* 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] | 2986 | iwl4965_tx_status_reply_compressed_ba(priv, agg, ba_resp); |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 2987 | |
| 2988 | /* Release all TFDs before the SSN, i.e. all TFDs in front of |
| 2989 | * block-ack window (we assume that they've been successfully |
| 2990 | * transmitted ... if not, it's too late anyway). */ |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2991 | if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) { |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 2992 | /* calculate mac80211 ampdu sw queue to wake */ |
| 2993 | int ampdu_q = |
| 2994 | scd_flow - IWL_BACK_QUEUE_FIRST_ID + priv->hw->queues; |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 2995 | int freed = iwl_tx_queue_reclaim(priv, scd_flow, index); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2996 | priv->stations[ba_resp->sta_id]. |
| 2997 | tid[ba_resp->tid].tfds_in_queue -= freed; |
Tomas Winkler | 443cfd4 | 2008-05-15 13:53:57 +0800 | [diff] [blame] | 2998 | if (iwl_queue_space(&txq->q) > txq->q.low_mark && |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 2999 | priv->mac80211_registered && |
| 3000 | agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) |
Ron Rindjunsky | 0d0b2c1 | 2008-05-04 14:48:18 +0300 | [diff] [blame] | 3001 | ieee80211_wake_queue(priv->hw, ampdu_q); |
Tomas Winkler | 30e553e | 2008-05-29 16:35:16 +0800 | [diff] [blame] | 3002 | |
| 3003 | iwl_txq_check_empty(priv, ba_resp->sta_id, |
| 3004 | ba_resp->tid, scd_flow); |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3005 | } |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3006 | } |
| 3007 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3008 | /** |
| 3009 | * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue |
| 3010 | */ |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3011 | 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] | 3012 | u16 txq_id) |
| 3013 | { |
| 3014 | u32 tbl_dw_addr; |
| 3015 | u32 tbl_dw; |
| 3016 | u16 scd_q2ratid; |
| 3017 | |
Tomas Winkler | 30e553e | 2008-05-29 16:35:16 +0800 | [diff] [blame] | 3018 | scd_q2ratid = ra_tid & IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3019 | |
| 3020 | tbl_dw_addr = priv->scd_base_addr + |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 3021 | IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3022 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3023 | tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3024 | |
| 3025 | if (txq_id & 0x1) |
| 3026 | tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF); |
| 3027 | else |
| 3028 | tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000); |
| 3029 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3030 | iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3031 | |
| 3032 | return 0; |
| 3033 | } |
| 3034 | |
Ron Rindjunsky | fe01b47 | 2008-01-28 14:07:24 +0200 | [diff] [blame] | 3035 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3036 | /** |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3037 | * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue |
| 3038 | * |
| 3039 | * NOTE: txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID, |
| 3040 | * 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] | 3041 | */ |
Tomas Winkler | 30e553e | 2008-05-29 16:35:16 +0800 | [diff] [blame] | 3042 | static int iwl4965_txq_agg_enable(struct iwl_priv *priv, int txq_id, |
| 3043 | int tx_fifo, int sta_id, int tid, u16 ssn_idx) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3044 | { |
| 3045 | unsigned long flags; |
Tomas Winkler | 30e553e | 2008-05-29 16:35:16 +0800 | [diff] [blame] | 3046 | int ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3047 | u16 ra_tid; |
| 3048 | |
| 3049 | if (IWL_BACK_QUEUE_FIRST_ID > txq_id) |
| 3050 | IWL_WARNING("queue number too small: %d, must be > %d\n", |
| 3051 | txq_id, IWL_BACK_QUEUE_FIRST_ID); |
| 3052 | |
| 3053 | ra_tid = BUILD_RAxTID(sta_id, tid); |
| 3054 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3055 | /* Modify device's station table to Tx this TID */ |
Tomas Winkler | 5083e56 | 2008-05-29 16:35:15 +0800 | [diff] [blame] | 3056 | iwl_sta_modify_enable_tid_tx(priv, sta_id, tid); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3057 | |
| 3058 | spin_lock_irqsave(&priv->lock, flags); |
Tomas Winkler | 30e553e | 2008-05-29 16:35:16 +0800 | [diff] [blame] | 3059 | ret = iwl_grab_nic_access(priv); |
| 3060 | if (ret) { |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3061 | spin_unlock_irqrestore(&priv->lock, flags); |
Tomas Winkler | 30e553e | 2008-05-29 16:35:16 +0800 | [diff] [blame] | 3062 | return ret; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3063 | } |
| 3064 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3065 | /* Stop this Tx queue before configuring it */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3066 | iwl4965_tx_queue_stop_scheduler(priv, txq_id); |
| 3067 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3068 | /* Map receiver-address / traffic-ID to this queue */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3069 | iwl4965_tx_queue_set_q2ratid(priv, ra_tid, txq_id); |
| 3070 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3071 | /* Set this queue as a chain-building queue */ |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 3072 | iwl_set_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3073 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3074 | /* Place first TFD at index corresponding to start sequence number. |
| 3075 | * Assumes that ssn_idx is valid (!= 0xFFF) */ |
Tomas Winkler | fc4b685 | 2007-10-25 17:15:24 +0800 | [diff] [blame] | 3076 | priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff); |
| 3077 | priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3078 | iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx); |
| 3079 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3080 | /* Set up Tx window size and frame limit for this queue */ |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3081 | iwl_write_targ_mem(priv, |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 3082 | priv->scd_base_addr + IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id), |
| 3083 | (SCD_WIN_SIZE << IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) & |
| 3084 | IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3085 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3086 | iwl_write_targ_mem(priv, priv->scd_base_addr + |
Emmanuel Grumbach | 038669e | 2008-04-23 17:15:04 -0700 | [diff] [blame] | 3087 | IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32), |
| 3088 | (SCD_FRAME_LIMIT << IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) |
| 3089 | & IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3090 | |
Tomas Winkler | 12a81f6 | 2008-04-03 16:05:20 -0700 | [diff] [blame] | 3091 | iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id)); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3092 | |
Cahill, Ben M | 8b6eaea | 2007-11-29 11:09:54 +0800 | [diff] [blame] | 3093 | /* 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] | 3094 | iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1); |
| 3095 | |
Tomas Winkler | 3395f6e | 2008-03-25 16:33:37 -0700 | [diff] [blame] | 3096 | iwl_release_nic_access(priv); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3097 | spin_unlock_irqrestore(&priv->lock, flags); |
| 3098 | |
| 3099 | return 0; |
| 3100 | } |
| 3101 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 3102 | static int iwl4965_rx_agg_start(struct iwl_priv *priv, |
| 3103 | const u8 *addr, int tid, u16 ssn) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3104 | { |
| 3105 | unsigned long flags; |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 3106 | int sta_id; |
| 3107 | |
| 3108 | sta_id = iwl_find_station(priv, addr); |
| 3109 | if (sta_id == IWL_INVALID_STATION) |
| 3110 | return -ENXIO; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3111 | |
| 3112 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 3113 | priv->stations[sta_id].sta.station_flags_msk = 0; |
| 3114 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK; |
| 3115 | priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid; |
| 3116 | priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn); |
| 3117 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3118 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 3119 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 3120 | return iwl_send_add_sta(priv, &priv->stations[sta_id].sta, |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 3121 | CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3122 | } |
| 3123 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 3124 | static int iwl4965_rx_agg_stop(struct iwl_priv *priv, |
| 3125 | const u8 *addr, int tid) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3126 | { |
| 3127 | unsigned long flags; |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 3128 | int sta_id; |
| 3129 | |
| 3130 | sta_id = iwl_find_station(priv, addr); |
| 3131 | if (sta_id == IWL_INVALID_STATION) |
| 3132 | return -ENXIO; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3133 | |
| 3134 | spin_lock_irqsave(&priv->sta_lock, flags); |
| 3135 | priv->stations[sta_id].sta.station_flags_msk = 0; |
| 3136 | priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK; |
| 3137 | priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid; |
| 3138 | priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK; |
| 3139 | spin_unlock_irqrestore(&priv->sta_lock, flags); |
| 3140 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 3141 | return iwl_send_add_sta(priv, &priv->stations[sta_id].sta, |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 3142 | CMD_ASYNC); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3143 | } |
| 3144 | |
Ron Rindjunsky | 8114fcf | 2008-01-28 14:07:23 +0200 | [diff] [blame] | 3145 | int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw, |
| 3146 | enum ieee80211_ampdu_mlme_action action, |
| 3147 | const u8 *addr, u16 tid, u16 *ssn) |
| 3148 | { |
Tomas Winkler | c79dd5b | 2008-03-12 16:58:50 -0700 | [diff] [blame] | 3149 | struct iwl_priv *priv = hw->priv; |
Ron Rindjunsky | 8114fcf | 2008-01-28 14:07:23 +0200 | [diff] [blame] | 3150 | DECLARE_MAC_BUF(mac); |
| 3151 | |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 3152 | IWL_DEBUG_HT("A-MPDU action on addr %s tid %d\n", |
| 3153 | print_mac(mac, addr), tid); |
| 3154 | |
Ron Rindjunsky | 8114fcf | 2008-01-28 14:07:23 +0200 | [diff] [blame] | 3155 | switch (action) { |
| 3156 | case IEEE80211_AMPDU_RX_START: |
| 3157 | IWL_DEBUG_HT("start Rx\n"); |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 3158 | return iwl4965_rx_agg_start(priv, addr, tid, *ssn); |
Ron Rindjunsky | 8114fcf | 2008-01-28 14:07:23 +0200 | [diff] [blame] | 3159 | case IEEE80211_AMPDU_RX_STOP: |
| 3160 | IWL_DEBUG_HT("stop Rx\n"); |
Ron Rindjunsky | fe07aa7 | 2008-04-17 16:03:37 -0700 | [diff] [blame] | 3161 | return iwl4965_rx_agg_stop(priv, addr, tid); |
Ron Rindjunsky | 8114fcf | 2008-01-28 14:07:23 +0200 | [diff] [blame] | 3162 | case IEEE80211_AMPDU_TX_START: |
| 3163 | IWL_DEBUG_HT("start Tx\n"); |
Tomas Winkler | 30e553e | 2008-05-29 16:35:16 +0800 | [diff] [blame] | 3164 | return iwl_tx_agg_start(priv, addr, tid, ssn); |
Ron Rindjunsky | 8114fcf | 2008-01-28 14:07:23 +0200 | [diff] [blame] | 3165 | case IEEE80211_AMPDU_TX_STOP: |
| 3166 | IWL_DEBUG_HT("stop Tx\n"); |
Tomas Winkler | 30e553e | 2008-05-29 16:35:16 +0800 | [diff] [blame] | 3167 | return iwl_tx_agg_stop(priv, addr, tid); |
Ron Rindjunsky | 8114fcf | 2008-01-28 14:07:23 +0200 | [diff] [blame] | 3168 | default: |
| 3169 | IWL_DEBUG_HT("unknown\n"); |
| 3170 | return -EINVAL; |
| 3171 | break; |
| 3172 | } |
| 3173 | return 0; |
| 3174 | } |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 3175 | |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 3176 | static u16 iwl4965_get_hcmd_size(u8 cmd_id, u16 len) |
| 3177 | { |
| 3178 | switch (cmd_id) { |
| 3179 | case REPLY_RXON: |
| 3180 | return (u16) sizeof(struct iwl4965_rxon_cmd); |
| 3181 | default: |
| 3182 | return len; |
| 3183 | } |
| 3184 | } |
| 3185 | |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 3186 | static u16 iwl4965_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data) |
| 3187 | { |
| 3188 | struct iwl4965_addsta_cmd *addsta = (struct iwl4965_addsta_cmd *)data; |
| 3189 | addsta->mode = cmd->mode; |
| 3190 | memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify)); |
| 3191 | memcpy(&addsta->key, &cmd->key, sizeof(struct iwl4965_keyinfo)); |
| 3192 | addsta->station_flags = cmd->station_flags; |
| 3193 | addsta->station_flags_msk = cmd->station_flags_msk; |
| 3194 | addsta->tid_disable_tx = cmd->tid_disable_tx; |
| 3195 | addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid; |
| 3196 | addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid; |
| 3197 | addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn; |
| 3198 | addsta->reserved1 = __constant_cpu_to_le16(0); |
| 3199 | addsta->reserved2 = __constant_cpu_to_le32(0); |
| 3200 | |
| 3201 | return (u16)sizeof(struct iwl4965_addsta_cmd); |
| 3202 | } |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3203 | |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3204 | static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp) |
| 3205 | { |
| 3206 | __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status + |
| 3207 | tx_resp->frame_count); |
| 3208 | return le32_to_cpu(*scd_ssn) & MAX_SN; |
| 3209 | |
| 3210 | } |
| 3211 | |
| 3212 | /** |
| 3213 | * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue |
| 3214 | */ |
| 3215 | static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv, |
| 3216 | struct iwl_ht_agg *agg, |
| 3217 | struct iwl4965_tx_resp_agg *tx_resp, |
| 3218 | u16 start_idx) |
| 3219 | { |
| 3220 | u16 status; |
| 3221 | struct agg_tx_status *frame_status = &tx_resp->status; |
| 3222 | struct ieee80211_tx_info *info = NULL; |
| 3223 | struct ieee80211_hdr *hdr = NULL; |
| 3224 | int i, sh; |
| 3225 | int txq_id, idx; |
| 3226 | u16 seq; |
| 3227 | |
| 3228 | if (agg->wait_for_ba) |
| 3229 | IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n"); |
| 3230 | |
| 3231 | agg->frame_count = tx_resp->frame_count; |
| 3232 | agg->start_idx = start_idx; |
| 3233 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
| 3234 | agg->bitmap = 0; |
| 3235 | |
| 3236 | /* # frames attempted by Tx command */ |
| 3237 | if (agg->frame_count == 1) { |
| 3238 | /* Only one frame was attempted; no block-ack will arrive */ |
| 3239 | status = le16_to_cpu(frame_status[0].status); |
| 3240 | seq = le16_to_cpu(frame_status[0].sequence); |
| 3241 | idx = SEQ_TO_INDEX(seq); |
| 3242 | txq_id = SEQ_TO_QUEUE(seq); |
| 3243 | |
| 3244 | /* FIXME: code repetition */ |
| 3245 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n", |
| 3246 | agg->frame_count, agg->start_idx, idx); |
| 3247 | |
| 3248 | info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]); |
| 3249 | info->status.retry_count = tx_resp->failure_frame; |
| 3250 | info->flags &= ~IEEE80211_TX_CTL_AMPDU; |
| 3251 | info->flags |= iwl_is_tx_success(status)? |
| 3252 | IEEE80211_TX_STAT_ACK : 0; |
| 3253 | iwl4965_hwrate_to_tx_control(priv, |
| 3254 | le32_to_cpu(tx_resp->rate_n_flags), |
| 3255 | info); |
| 3256 | /* FIXME: code repetition end */ |
| 3257 | |
| 3258 | IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n", |
| 3259 | status & 0xff, tx_resp->failure_frame); |
| 3260 | IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", |
| 3261 | iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags)); |
| 3262 | |
| 3263 | agg->wait_for_ba = 0; |
| 3264 | } else { |
| 3265 | /* Two or more frames were attempted; expect block-ack */ |
| 3266 | u64 bitmap = 0; |
| 3267 | int start = agg->start_idx; |
| 3268 | |
| 3269 | /* Construct bit-map of pending frames within Tx window */ |
| 3270 | for (i = 0; i < agg->frame_count; i++) { |
| 3271 | u16 sc; |
| 3272 | status = le16_to_cpu(frame_status[i].status); |
| 3273 | seq = le16_to_cpu(frame_status[i].sequence); |
| 3274 | idx = SEQ_TO_INDEX(seq); |
| 3275 | txq_id = SEQ_TO_QUEUE(seq); |
| 3276 | |
| 3277 | if (status & (AGG_TX_STATE_FEW_BYTES_MSK | |
| 3278 | AGG_TX_STATE_ABORT_MSK)) |
| 3279 | continue; |
| 3280 | |
| 3281 | IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n", |
| 3282 | agg->frame_count, txq_id, idx); |
| 3283 | |
| 3284 | hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx); |
| 3285 | |
| 3286 | sc = le16_to_cpu(hdr->seq_ctrl); |
| 3287 | if (idx != (SEQ_TO_SN(sc) & 0xff)) { |
| 3288 | IWL_ERROR("BUG_ON idx doesn't match seq control" |
| 3289 | " idx=%d, seq_idx=%d, seq=%d\n", |
| 3290 | idx, SEQ_TO_SN(sc), |
| 3291 | hdr->seq_ctrl); |
| 3292 | return -1; |
| 3293 | } |
| 3294 | |
| 3295 | IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", |
| 3296 | i, idx, SEQ_TO_SN(sc)); |
| 3297 | |
| 3298 | sh = idx - start; |
| 3299 | if (sh > 64) { |
| 3300 | sh = (start - idx) + 0xff; |
| 3301 | bitmap = bitmap << sh; |
| 3302 | sh = 0; |
| 3303 | start = idx; |
| 3304 | } else if (sh < -64) |
| 3305 | sh = 0xff - (start - idx); |
| 3306 | else if (sh < 0) { |
| 3307 | sh = start - idx; |
| 3308 | start = idx; |
| 3309 | bitmap = bitmap << sh; |
| 3310 | sh = 0; |
| 3311 | } |
| 3312 | bitmap |= (1 << sh); |
| 3313 | IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n", |
| 3314 | start, (u32)(bitmap & 0xFFFFFFFF)); |
| 3315 | } |
| 3316 | |
| 3317 | agg->bitmap = bitmap; |
| 3318 | agg->start_idx = start; |
| 3319 | agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); |
| 3320 | IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n", |
| 3321 | agg->frame_count, agg->start_idx, |
| 3322 | (unsigned long long)agg->bitmap); |
| 3323 | |
| 3324 | if (bitmap) |
| 3325 | agg->wait_for_ba = 1; |
| 3326 | } |
| 3327 | return 0; |
| 3328 | } |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3329 | |
| 3330 | /** |
| 3331 | * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response |
| 3332 | */ |
| 3333 | static void iwl4965_rx_reply_tx(struct iwl_priv *priv, |
| 3334 | struct iwl_rx_mem_buffer *rxb) |
| 3335 | { |
| 3336 | struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; |
| 3337 | u16 sequence = le16_to_cpu(pkt->hdr.sequence); |
| 3338 | int txq_id = SEQ_TO_QUEUE(sequence); |
| 3339 | int index = SEQ_TO_INDEX(sequence); |
| 3340 | struct iwl_tx_queue *txq = &priv->txq[txq_id]; |
| 3341 | struct ieee80211_tx_info *info; |
| 3342 | struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0]; |
| 3343 | u32 status = le32_to_cpu(tx_resp->status); |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3344 | int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION; |
| 3345 | u16 fc; |
| 3346 | struct ieee80211_hdr *hdr; |
| 3347 | u8 *qc = NULL; |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3348 | |
| 3349 | if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) { |
| 3350 | IWL_ERROR("Read index for DMA queue txq_id (%d) index %d " |
| 3351 | "is out of range [0-%d] %d %d\n", txq_id, |
| 3352 | index, txq->q.n_bd, txq->q.write_ptr, |
| 3353 | txq->q.read_ptr); |
| 3354 | return; |
| 3355 | } |
| 3356 | |
| 3357 | info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]); |
| 3358 | memset(&info->status, 0, sizeof(info->status)); |
| 3359 | |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3360 | hdr = iwl_tx_queue_get_hdr(priv, txq_id, index); |
| 3361 | fc = le16_to_cpu(hdr->frame_control); |
| 3362 | if (ieee80211_is_qos_data(fc)) { |
| 3363 | qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc)); |
| 3364 | tid = qc[0] & 0xf; |
| 3365 | } |
| 3366 | |
| 3367 | sta_id = iwl_get_ra_sta_id(priv, hdr); |
| 3368 | if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) { |
| 3369 | IWL_ERROR("Station not known\n"); |
| 3370 | return; |
| 3371 | } |
| 3372 | |
| 3373 | if (txq->sched_retry) { |
| 3374 | const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp); |
| 3375 | struct iwl_ht_agg *agg = NULL; |
| 3376 | |
| 3377 | if (!qc) |
| 3378 | return; |
| 3379 | |
| 3380 | agg = &priv->stations[sta_id].tid[tid].agg; |
| 3381 | |
| 3382 | iwl4965_tx_status_reply_tx(priv, agg, |
| 3383 | (struct iwl4965_tx_resp_agg *)tx_resp, index); |
| 3384 | |
| 3385 | if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status)) { |
| 3386 | /* TODO: send BAR */ |
| 3387 | } |
| 3388 | |
| 3389 | if (txq->q.read_ptr != (scd_ssn & 0xff)) { |
| 3390 | int freed, ampdu_q; |
| 3391 | index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd); |
| 3392 | IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn " |
| 3393 | "%d index %d\n", scd_ssn , index); |
Tomas Winkler | 17b8892 | 2008-05-29 16:35:12 +0800 | [diff] [blame] | 3394 | freed = iwl_tx_queue_reclaim(priv, txq_id, index); |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3395 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
| 3396 | |
| 3397 | if (iwl_queue_space(&txq->q) > txq->q.low_mark && |
| 3398 | txq_id >= 0 && priv->mac80211_registered && |
| 3399 | agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) { |
| 3400 | /* calculate mac80211 ampdu sw queue to wake */ |
| 3401 | ampdu_q = txq_id - IWL_BACK_QUEUE_FIRST_ID + |
| 3402 | priv->hw->queues; |
| 3403 | if (agg->state == IWL_AGG_OFF) |
| 3404 | ieee80211_wake_queue(priv->hw, txq_id); |
| 3405 | else |
| 3406 | ieee80211_wake_queue(priv->hw, ampdu_q); |
| 3407 | } |
Tomas Winkler | 30e553e | 2008-05-29 16:35:16 +0800 | [diff] [blame] | 3408 | iwl_txq_check_empty(priv, sta_id, tid, txq_id); |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3409 | } |
| 3410 | } else { |
Ron Rindjunsky | 4f85f5b | 2008-06-09 22:54:35 +0300 | [diff] [blame] | 3411 | info->status.retry_count = tx_resp->failure_frame; |
| 3412 | info->flags |= |
| 3413 | iwl_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0; |
| 3414 | iwl4965_hwrate_to_tx_control(priv, |
| 3415 | le32_to_cpu(tx_resp->rate_n_flags), |
| 3416 | info); |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3417 | |
Ron Rindjunsky | 4f85f5b | 2008-06-09 22:54:35 +0300 | [diff] [blame] | 3418 | IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags " |
| 3419 | "0x%x retries %d\n", txq_id, |
| 3420 | iwl_get_tx_fail_reason(status), |
| 3421 | status, le32_to_cpu(tx_resp->rate_n_flags), |
| 3422 | tx_resp->failure_frame); |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3423 | |
Ron Rindjunsky | 4f85f5b | 2008-06-09 22:54:35 +0300 | [diff] [blame] | 3424 | IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index); |
| 3425 | if (index != -1) { |
| 3426 | int freed = iwl_tx_queue_reclaim(priv, txq_id, index); |
| 3427 | if (tid != MAX_TID_COUNT) |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3428 | priv->stations[sta_id].tid[tid].tfds_in_queue -= freed; |
Ron Rindjunsky | 4f85f5b | 2008-06-09 22:54:35 +0300 | [diff] [blame] | 3429 | if (iwl_queue_space(&txq->q) > txq->q.low_mark && |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3430 | (txq_id >= 0) && priv->mac80211_registered) |
| 3431 | ieee80211_wake_queue(priv->hw, txq_id); |
Ron Rindjunsky | 4f85f5b | 2008-06-09 22:54:35 +0300 | [diff] [blame] | 3432 | if (tid != MAX_TID_COUNT) |
Tomas Winkler | 30e553e | 2008-05-29 16:35:16 +0800 | [diff] [blame] | 3433 | iwl_txq_check_empty(priv, sta_id, tid, txq_id); |
Ron Rindjunsky | 4f85f5b | 2008-06-09 22:54:35 +0300 | [diff] [blame] | 3434 | } |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3435 | } |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3436 | |
| 3437 | if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK)) |
| 3438 | IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n"); |
| 3439 | } |
| 3440 | |
| 3441 | |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3442 | /* Set up 4965-specific Rx frame reply handlers */ |
Emmanuel Grumbach | d4789ef | 2008-04-24 11:55:20 -0700 | [diff] [blame] | 3443 | static void iwl4965_rx_handler_setup(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3444 | { |
| 3445 | /* Legacy Rx frames */ |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3446 | priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx; |
Ron Rindjunsky | 37a4421 | 2008-05-29 16:35:18 +0800 | [diff] [blame] | 3447 | /* Tx response */ |
Tomas Winkler | f20217d | 2008-05-29 16:35:10 +0800 | [diff] [blame] | 3448 | priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx; |
Ron Rindjunsky | 4f85f5b | 2008-06-09 22:54:35 +0300 | [diff] [blame] | 3449 | /* block ack */ |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3450 | priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba; |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3451 | } |
| 3452 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 3453 | static void iwl4965_setup_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3454 | { |
| 3455 | INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3456 | } |
| 3457 | |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 3458 | static void iwl4965_cancel_deferred_work(struct iwl_priv *priv) |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3459 | { |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 3460 | cancel_work_sync(&priv->txpower_work); |
Zhu Yi | b481de9 | 2007-09-25 17:54:57 -0700 | [diff] [blame] | 3461 | } |
| 3462 | |
Tomas Winkler | 3c424c2 | 2008-04-15 16:01:42 -0700 | [diff] [blame] | 3463 | |
| 3464 | static struct iwl_hcmd_ops iwl4965_hcmd = { |
Tomas Winkler | 7e8c519 | 2008-04-15 16:01:43 -0700 | [diff] [blame] | 3465 | .rxon_assoc = iwl4965_send_rxon_assoc, |
Tomas Winkler | 3c424c2 | 2008-04-15 16:01:42 -0700 | [diff] [blame] | 3466 | }; |
| 3467 | |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3468 | static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = { |
Gregory Greenman | c1adf9f | 2008-05-15 13:53:59 +0800 | [diff] [blame] | 3469 | .get_hcmd_size = iwl4965_get_hcmd_size, |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 3470 | .build_addsta_hcmd = iwl4965_build_addsta_hcmd, |
Emmanuel Grumbach | f0832f1 | 2008-04-16 16:34:47 -0700 | [diff] [blame] | 3471 | .chain_noise_reset = iwl4965_chain_noise_reset, |
| 3472 | .gain_computation = iwl4965_gain_computation, |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3473 | }; |
| 3474 | |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 3475 | static struct iwl_lib_ops iwl4965_lib = { |
Tomas Winkler | 5425e49 | 2008-04-15 16:01:38 -0700 | [diff] [blame] | 3476 | .set_hw_params = iwl4965_hw_set_hw_params, |
Ron Rindjunsky | 399f490 | 2008-04-23 17:14:56 -0700 | [diff] [blame] | 3477 | .alloc_shared_mem = iwl4965_alloc_shared_mem, |
| 3478 | .free_shared_mem = iwl4965_free_shared_mem, |
Ron Rindjunsky | d67f548 | 2008-05-05 10:22:49 +0800 | [diff] [blame] | 3479 | .shared_mem_rx_idx = iwl4965_shared_mem_rx_idx, |
Tomas Winkler | e2a722e | 2008-04-14 21:16:10 -0700 | [diff] [blame] | 3480 | .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl, |
Tomas Winkler | da1bc45 | 2008-05-29 16:35:00 +0800 | [diff] [blame] | 3481 | .txq_set_sched = iwl4965_txq_set_sched, |
Tomas Winkler | 30e553e | 2008-05-29 16:35:16 +0800 | [diff] [blame] | 3482 | .txq_agg_enable = iwl4965_txq_agg_enable, |
| 3483 | .txq_agg_disable = iwl4965_txq_agg_disable, |
Emmanuel Grumbach | d4789ef | 2008-04-24 11:55:20 -0700 | [diff] [blame] | 3484 | .rx_handler_setup = iwl4965_rx_handler_setup, |
Emmanuel Grumbach | 4e39317 | 2008-06-12 09:46:53 +0800 | [diff] [blame] | 3485 | .setup_deferred_work = iwl4965_setup_deferred_work, |
| 3486 | .cancel_deferred_work = iwl4965_cancel_deferred_work, |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3487 | .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr, |
| 3488 | .alive_notify = iwl4965_alive_notify, |
Emmanuel Grumbach | f3ccc08 | 2008-05-05 10:22:45 +0800 | [diff] [blame] | 3489 | .init_alive_start = iwl4965_init_alive_start, |
Tomas Winkler | 57aab75 | 2008-04-14 21:16:03 -0700 | [diff] [blame] | 3490 | .load_ucode = iwl4965_load_bsm, |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 3491 | .apm_ops = { |
Tomas Winkler | 9123871 | 2008-04-23 17:14:53 -0700 | [diff] [blame] | 3492 | .init = iwl4965_apm_init, |
Tomas Winkler | 7f06610 | 2008-05-29 16:34:57 +0800 | [diff] [blame] | 3493 | .reset = iwl4965_apm_reset, |
Tomas Winkler | f118a91 | 2008-05-29 16:34:58 +0800 | [diff] [blame] | 3494 | .stop = iwl4965_apm_stop, |
Tomas Winkler | 694cc56 | 2008-04-24 11:55:22 -0700 | [diff] [blame] | 3495 | .config = iwl4965_nic_config, |
Tomas Winkler | 6f4083a | 2008-04-16 16:34:49 -0700 | [diff] [blame] | 3496 | .set_pwr_src = iwl4965_set_pwr_src, |
| 3497 | }, |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 3498 | .eeprom_ops = { |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 3499 | .regulatory_bands = { |
| 3500 | EEPROM_REGULATORY_BAND_1_CHANNELS, |
| 3501 | EEPROM_REGULATORY_BAND_2_CHANNELS, |
| 3502 | EEPROM_REGULATORY_BAND_3_CHANNELS, |
| 3503 | EEPROM_REGULATORY_BAND_4_CHANNELS, |
| 3504 | EEPROM_REGULATORY_BAND_5_CHANNELS, |
| 3505 | EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS, |
| 3506 | EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS |
| 3507 | }, |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 3508 | .verify_signature = iwlcore_eeprom_verify_signature, |
| 3509 | .acquire_semaphore = iwlcore_eeprom_acquire_semaphore, |
| 3510 | .release_semaphore = iwlcore_eeprom_release_semaphore, |
Tomas Winkler | 8614f36 | 2008-04-23 17:14:55 -0700 | [diff] [blame] | 3511 | .check_version = iwl4965_eeprom_check_version, |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 3512 | .query_addr = iwlcore_eeprom_query_addr, |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 3513 | }, |
Mohamed Abbas | ad97edd | 2008-03-28 16:21:06 -0700 | [diff] [blame] | 3514 | .radio_kill_sw = iwl4965_radio_kill_sw, |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 3515 | .set_power = iwl4965_set_power, |
| 3516 | .update_chain_flags = iwl4965_update_chain_flags, |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 3517 | }; |
| 3518 | |
| 3519 | static struct iwl_ops iwl4965_ops = { |
| 3520 | .lib = &iwl4965_lib, |
Tomas Winkler | 3c424c2 | 2008-04-15 16:01:42 -0700 | [diff] [blame] | 3521 | .hcmd = &iwl4965_hcmd, |
Tomas Winkler | 857485c | 2008-03-21 13:53:44 -0700 | [diff] [blame] | 3522 | .utils = &iwl4965_hcmd_utils, |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 3523 | }; |
| 3524 | |
Ron Rindjunsky | fed9017 | 2008-04-15 16:01:41 -0700 | [diff] [blame] | 3525 | struct iwl_cfg iwl4965_agn_cfg = { |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 3526 | .name = "4965AGN", |
Tomas Winkler | 4bf775c | 2008-03-04 18:09:31 -0800 | [diff] [blame] | 3527 | .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode", |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 3528 | .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N, |
Tomas Winkler | 073d3f5 | 2008-04-21 15:41:52 -0700 | [diff] [blame] | 3529 | .eeprom_size = IWL4965_EEPROM_IMG_SIZE, |
Assaf Krauss | 6bc913b | 2008-03-11 16:17:18 -0700 | [diff] [blame] | 3530 | .ops = &iwl4965_ops, |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 3531 | .mod_params = &iwl4965_mod_params, |
Tomas Winkler | 82b9a12 | 2008-03-04 18:09:30 -0800 | [diff] [blame] | 3532 | }; |
| 3533 | |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 3534 | module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444); |
| 3535 | MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])"); |
| 3536 | module_param_named(disable, iwl4965_mod_params.disable, int, 0444); |
| 3537 | MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])"); |
Emmanuel Grumbach | fcc76c6 | 2008-04-15 16:01:47 -0700 | [diff] [blame] | 3538 | module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444); |
| 3539 | MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])\n"); |
Assaf Krauss | 1ea8739 | 2008-03-18 14:57:50 -0700 | [diff] [blame] | 3540 | module_param_named(debug, iwl4965_mod_params.debug, int, 0444); |
| 3541 | MODULE_PARM_DESC(debug, "debug output mask"); |
| 3542 | module_param_named( |
| 3543 | disable_hw_scan, iwl4965_mod_params.disable_hw_scan, int, 0444); |
| 3544 | MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)"); |
| 3545 | |
| 3546 | module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444); |
| 3547 | MODULE_PARM_DESC(queues_num, "number of hw queues."); |
| 3548 | |
| 3549 | /* QoS */ |
| 3550 | module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444); |
| 3551 | MODULE_PARM_DESC(qos_enable, "enable all QoS functionality"); |
| 3552 | module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444); |
| 3553 | MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size"); |
Ester Kummer | 3a1081e | 2008-05-06 11:05:14 +0800 | [diff] [blame] | 3554 | module_param_named(fw_restart4965, iwl4965_mod_params.restart_fw, int, 0444); |
| 3555 | MODULE_PARM_DESC(fw_restart4965, "restart firmware in case of error"); |