Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 4 | * redistributing this file, you may do so under either license. |
| 5 | * |
| 6 | * GPL LICENSE SUMMARY |
| 7 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 8 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Eran Harary | 8d193ca | 2015-04-27 10:29:31 +0300 | [diff] [blame] | 9 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Sara Sharon | 43413a9 | 2015-12-31 11:49:18 +0200 | [diff] [blame] | 10 | * Copyright(c) 2016 Intel Deutschland GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of version 2 of the GNU General Public License as |
| 14 | * published by the Free Software Foundation. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 24 | * USA |
| 25 | * |
| 26 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 27 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 28 | * |
| 29 | * Contact Information: |
Emmanuel Grumbach | cb2f827 | 2015-11-17 15:39:56 +0200 | [diff] [blame] | 30 | * Intel Linux Wireless <linuxwifi@intel.com> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 31 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 32 | * |
| 33 | * BSD LICENSE |
| 34 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 35 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Eran Harary | 8d193ca | 2015-04-27 10:29:31 +0300 | [diff] [blame] | 36 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 37 | * All rights reserved. |
| 38 | * |
| 39 | * Redistribution and use in source and binary forms, with or without |
| 40 | * modification, are permitted provided that the following conditions |
| 41 | * are met: |
| 42 | * |
| 43 | * * Redistributions of source code must retain the above copyright |
| 44 | * notice, this list of conditions and the following disclaimer. |
| 45 | * * Redistributions in binary form must reproduce the above copyright |
| 46 | * notice, this list of conditions and the following disclaimer in |
| 47 | * the documentation and/or other materials provided with the |
| 48 | * distribution. |
| 49 | * * Neither the name Intel Corporation nor the names of its |
| 50 | * contributors may be used to endorse or promote products derived |
| 51 | * from this software without specific prior written permission. |
| 52 | * |
| 53 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 54 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 55 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 56 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 57 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 58 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 59 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 60 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 61 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 62 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 63 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 64 | * |
| 65 | *****************************************************************************/ |
| 66 | #include <net/mac80211.h> |
Sara Sharon | 854d773 | 2016-03-22 15:55:58 +0200 | [diff] [blame] | 67 | #include <linux/netdevice.h> |
Luca Coelho | da2830a | 2016-05-30 13:00:44 +0300 | [diff] [blame] | 68 | #include <linux/acpi.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 69 | |
| 70 | #include "iwl-trans.h" |
| 71 | #include "iwl-op-mode.h" |
| 72 | #include "iwl-fw.h" |
| 73 | #include "iwl-debug.h" |
| 74 | #include "iwl-csr.h" /* for iwl_mvm_rx_card_state_notif */ |
| 75 | #include "iwl-io.h" /* for iwl_mvm_rx_card_state_notif */ |
Emmanuel Grumbach | 8c23f95 | 2014-12-04 10:07:47 +0200 | [diff] [blame] | 76 | #include "iwl-prph.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 77 | #include "iwl-eeprom-parse.h" |
| 78 | |
| 79 | #include "mvm.h" |
Golan Ben-Ami | 2f89a5d | 2015-10-27 19:17:14 +0200 | [diff] [blame] | 80 | #include "fw-dbg.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 81 | #include "iwl-phy-db.h" |
| 82 | |
| 83 | #define MVM_UCODE_ALIVE_TIMEOUT HZ |
| 84 | #define MVM_UCODE_CALIB_TIMEOUT (2*HZ) |
| 85 | |
| 86 | #define UCODE_VALID_OK cpu_to_le32(0x1) |
| 87 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 88 | struct iwl_mvm_alive_data { |
| 89 | bool valid; |
| 90 | u32 scd_base_addr; |
| 91 | }; |
| 92 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 93 | static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant) |
| 94 | { |
| 95 | struct iwl_tx_ant_cfg_cmd tx_ant_cmd = { |
| 96 | .valid = cpu_to_le32(valid_tx_ant), |
| 97 | }; |
| 98 | |
Emmanuel Grumbach | 3322354 | 2013-03-09 20:38:19 +0200 | [diff] [blame] | 99 | IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant); |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 100 | return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 101 | sizeof(tx_ant_cmd), &tx_ant_cmd); |
| 102 | } |
| 103 | |
Sara Sharon | 43413a9 | 2015-12-31 11:49:18 +0200 | [diff] [blame] | 104 | static int iwl_send_rss_cfg_cmd(struct iwl_mvm *mvm) |
| 105 | { |
| 106 | int i; |
| 107 | struct iwl_rss_config_cmd cmd = { |
| 108 | .flags = cpu_to_le32(IWL_RSS_ENABLE), |
| 109 | .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP | |
Sara Sharon | 854d773 | 2016-03-22 15:55:58 +0200 | [diff] [blame] | 110 | IWL_RSS_HASH_TYPE_IPV4_UDP | |
Sara Sharon | 43413a9 | 2015-12-31 11:49:18 +0200 | [diff] [blame] | 111 | IWL_RSS_HASH_TYPE_IPV4_PAYLOAD | |
| 112 | IWL_RSS_HASH_TYPE_IPV6_TCP | |
Sara Sharon | 854d773 | 2016-03-22 15:55:58 +0200 | [diff] [blame] | 113 | IWL_RSS_HASH_TYPE_IPV6_UDP | |
Sara Sharon | 43413a9 | 2015-12-31 11:49:18 +0200 | [diff] [blame] | 114 | IWL_RSS_HASH_TYPE_IPV6_PAYLOAD, |
| 115 | }; |
| 116 | |
Sara Sharon | f43495f | 2016-05-04 14:22:10 +0300 | [diff] [blame] | 117 | if (mvm->trans->num_rx_queues == 1) |
| 118 | return 0; |
| 119 | |
Sara Sharon | 854d773 | 2016-03-22 15:55:58 +0200 | [diff] [blame] | 120 | /* Do not direct RSS traffic to Q 0 which is our fallback queue */ |
Sara Sharon | 43413a9 | 2015-12-31 11:49:18 +0200 | [diff] [blame] | 121 | for (i = 0; i < ARRAY_SIZE(cmd.indirection_table); i++) |
Sara Sharon | 854d773 | 2016-03-22 15:55:58 +0200 | [diff] [blame] | 122 | cmd.indirection_table[i] = |
| 123 | 1 + (i % (mvm->trans->num_rx_queues - 1)); |
| 124 | netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key)); |
Sara Sharon | 43413a9 | 2015-12-31 11:49:18 +0200 | [diff] [blame] | 125 | |
| 126 | return iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd); |
| 127 | } |
| 128 | |
Liad Kaufman | 97d5be7 | 2015-08-31 14:33:23 +0300 | [diff] [blame] | 129 | static int iwl_mvm_send_dqa_cmd(struct iwl_mvm *mvm) |
| 130 | { |
| 131 | struct iwl_dqa_enable_cmd dqa_cmd = { |
| 132 | .cmd_queue = cpu_to_le32(IWL_MVM_DQA_CMD_QUEUE), |
| 133 | }; |
| 134 | u32 cmd_id = iwl_cmd_id(DQA_ENABLE_CMD, DATA_PATH_GROUP, 0); |
| 135 | int ret; |
| 136 | |
| 137 | ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(dqa_cmd), &dqa_cmd); |
| 138 | if (ret) |
| 139 | IWL_ERR(mvm, "Failed to send DQA enabling command: %d\n", ret); |
| 140 | else |
| 141 | IWL_DEBUG_FW(mvm, "Working in DQA mode\n"); |
| 142 | |
| 143 | return ret; |
| 144 | } |
| 145 | |
Matti Gottlieb | 905e36a | 2016-02-14 17:05:39 +0200 | [diff] [blame] | 146 | void iwl_free_fw_paging(struct iwl_mvm *mvm) |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 147 | { |
| 148 | int i; |
| 149 | |
| 150 | if (!mvm->fw_paging_db[0].fw_paging_block) |
| 151 | return; |
| 152 | |
| 153 | for (i = 0; i < NUM_OF_FW_PAGING_BLOCKS; i++) { |
Emmanuel Grumbach | 3edbc7d | 2016-06-19 20:57:02 +0300 | [diff] [blame] | 154 | struct iwl_fw_paging *paging = &mvm->fw_paging_db[i]; |
| 155 | |
| 156 | if (!paging->fw_paging_block) { |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 157 | IWL_DEBUG_FW(mvm, |
| 158 | "Paging: block %d already freed, continue to next page\n", |
| 159 | i); |
| 160 | |
| 161 | continue; |
| 162 | } |
Emmanuel Grumbach | 3edbc7d | 2016-06-19 20:57:02 +0300 | [diff] [blame] | 163 | dma_unmap_page(mvm->trans->dev, paging->fw_paging_phys, |
| 164 | paging->fw_paging_size, DMA_BIDIRECTIONAL); |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 165 | |
Emmanuel Grumbach | 3edbc7d | 2016-06-19 20:57:02 +0300 | [diff] [blame] | 166 | __free_pages(paging->fw_paging_block, |
| 167 | get_order(paging->fw_paging_size)); |
| 168 | paging->fw_paging_block = NULL; |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 169 | } |
Matti Gottlieb | e112018 | 2015-07-19 11:15:07 +0300 | [diff] [blame] | 170 | kfree(mvm->trans->paging_download_buf); |
Matti Gottlieb | 905e36a | 2016-02-14 17:05:39 +0200 | [diff] [blame] | 171 | mvm->trans->paging_download_buf = NULL; |
Matti Gottlieb | f742aaf | 2016-04-10 10:53:57 +0300 | [diff] [blame] | 172 | mvm->trans->paging_db = NULL; |
Matti Gottlieb | 905e36a | 2016-02-14 17:05:39 +0200 | [diff] [blame] | 173 | |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 174 | memset(mvm->fw_paging_db, 0, sizeof(mvm->fw_paging_db)); |
| 175 | } |
| 176 | |
| 177 | static int iwl_fill_paging_mem(struct iwl_mvm *mvm, const struct fw_img *image) |
| 178 | { |
| 179 | int sec_idx, idx; |
| 180 | u32 offset = 0; |
| 181 | |
| 182 | /* |
| 183 | * find where is the paging image start point: |
| 184 | * if CPU2 exist and it's in paging format, then the image looks like: |
| 185 | * CPU1 sections (2 or more) |
| 186 | * CPU1_CPU2_SEPARATOR_SECTION delimiter - separate between CPU1 to CPU2 |
| 187 | * CPU2 sections (not paged) |
| 188 | * PAGING_SEPARATOR_SECTION delimiter - separate between CPU2 |
| 189 | * non paged to CPU2 paging sec |
| 190 | * CPU2 paging CSS |
| 191 | * CPU2 paging image (including instruction and data) |
| 192 | */ |
| 193 | for (sec_idx = 0; sec_idx < IWL_UCODE_SECTION_MAX; sec_idx++) { |
| 194 | if (image->sec[sec_idx].offset == PAGING_SEPARATOR_SECTION) { |
| 195 | sec_idx++; |
| 196 | break; |
| 197 | } |
| 198 | } |
| 199 | |
Matti Gottlieb | cd47a3d | 2016-03-10 16:18:26 +0200 | [diff] [blame] | 200 | /* |
| 201 | * If paging is enabled there should be at least 2 more sections left |
| 202 | * (one for CSS and one for Paging data) |
| 203 | */ |
| 204 | if (sec_idx >= ARRAY_SIZE(image->sec) - 1) { |
| 205 | IWL_ERR(mvm, "Paging: Missing CSS and/or paging sections\n"); |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 206 | iwl_free_fw_paging(mvm); |
| 207 | return -EINVAL; |
| 208 | } |
| 209 | |
| 210 | /* copy the CSS block to the dram */ |
| 211 | IWL_DEBUG_FW(mvm, "Paging: load paging CSS to FW, sec = %d\n", |
| 212 | sec_idx); |
| 213 | |
| 214 | memcpy(page_address(mvm->fw_paging_db[0].fw_paging_block), |
| 215 | image->sec[sec_idx].data, |
| 216 | mvm->fw_paging_db[0].fw_paging_size); |
| 217 | |
| 218 | IWL_DEBUG_FW(mvm, |
| 219 | "Paging: copied %d CSS bytes to first block\n", |
| 220 | mvm->fw_paging_db[0].fw_paging_size); |
| 221 | |
| 222 | sec_idx++; |
| 223 | |
| 224 | /* |
| 225 | * copy the paging blocks to the dram |
| 226 | * loop index start from 1 since that CSS block already copied to dram |
| 227 | * and CSS index is 0. |
| 228 | * loop stop at num_of_paging_blk since that last block is not full. |
| 229 | */ |
| 230 | for (idx = 1; idx < mvm->num_of_paging_blk; idx++) { |
| 231 | memcpy(page_address(mvm->fw_paging_db[idx].fw_paging_block), |
| 232 | image->sec[sec_idx].data + offset, |
| 233 | mvm->fw_paging_db[idx].fw_paging_size); |
| 234 | |
| 235 | IWL_DEBUG_FW(mvm, |
| 236 | "Paging: copied %d paging bytes to block %d\n", |
| 237 | mvm->fw_paging_db[idx].fw_paging_size, |
| 238 | idx); |
| 239 | |
| 240 | offset += mvm->fw_paging_db[idx].fw_paging_size; |
| 241 | } |
| 242 | |
| 243 | /* copy the last paging block */ |
| 244 | if (mvm->num_of_pages_in_last_blk > 0) { |
| 245 | memcpy(page_address(mvm->fw_paging_db[idx].fw_paging_block), |
| 246 | image->sec[sec_idx].data + offset, |
| 247 | FW_PAGING_SIZE * mvm->num_of_pages_in_last_blk); |
| 248 | |
| 249 | IWL_DEBUG_FW(mvm, |
| 250 | "Paging: copied %d pages in the last block %d\n", |
| 251 | mvm->num_of_pages_in_last_blk, idx); |
| 252 | } |
| 253 | |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | static int iwl_alloc_fw_paging_mem(struct iwl_mvm *mvm, |
| 258 | const struct fw_img *image) |
| 259 | { |
| 260 | struct page *block; |
| 261 | dma_addr_t phys = 0; |
Sara Sharon | 08d785f | 2016-10-27 17:27:23 +0300 | [diff] [blame] | 262 | int blk_idx, order, num_of_pages, size, dma_enabled; |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 263 | |
| 264 | if (mvm->fw_paging_db[0].fw_paging_block) |
| 265 | return 0; |
| 266 | |
| 267 | dma_enabled = is_device_dma_capable(mvm->trans->dev); |
| 268 | |
| 269 | /* ensure BLOCK_2_EXP_SIZE is power of 2 of PAGING_BLOCK_SIZE */ |
| 270 | BUILD_BUG_ON(BIT(BLOCK_2_EXP_SIZE) != PAGING_BLOCK_SIZE); |
| 271 | |
| 272 | num_of_pages = image->paging_mem_size / FW_PAGING_SIZE; |
Sara Sharon | 850fe9a | 2016-10-27 17:58:27 +0300 | [diff] [blame^] | 273 | mvm->num_of_paging_blk = |
| 274 | DIV_ROUND_UP(num_of_pages, NUM_OF_PAGE_PER_GROUP); |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 275 | mvm->num_of_pages_in_last_blk = |
| 276 | num_of_pages - |
| 277 | NUM_OF_PAGE_PER_GROUP * (mvm->num_of_paging_blk - 1); |
| 278 | |
| 279 | IWL_DEBUG_FW(mvm, |
| 280 | "Paging: allocating mem for %d paging blocks, each block holds 8 pages, last block holds %d pages\n", |
| 281 | mvm->num_of_paging_blk, |
| 282 | mvm->num_of_pages_in_last_blk); |
| 283 | |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 284 | /* |
Sara Sharon | 08d785f | 2016-10-27 17:27:23 +0300 | [diff] [blame] | 285 | * Allocate CSS and paging blocks in dram. |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 286 | */ |
Sara Sharon | 08d785f | 2016-10-27 17:27:23 +0300 | [diff] [blame] | 287 | for (blk_idx = 0; blk_idx < mvm->num_of_paging_blk + 1; blk_idx++) { |
| 288 | /* For CSS allocate 4KB, for others PAGING_BLOCK_SIZE (32K) */ |
| 289 | size = blk_idx ? PAGING_BLOCK_SIZE : FW_PAGING_SIZE; |
| 290 | order = get_order(size); |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 291 | block = alloc_pages(GFP_KERNEL, order); |
| 292 | if (!block) { |
| 293 | /* free all the previous pages since we failed */ |
| 294 | iwl_free_fw_paging(mvm); |
| 295 | return -ENOMEM; |
| 296 | } |
| 297 | |
| 298 | mvm->fw_paging_db[blk_idx].fw_paging_block = block; |
Sara Sharon | 08d785f | 2016-10-27 17:27:23 +0300 | [diff] [blame] | 299 | mvm->fw_paging_db[blk_idx].fw_paging_size = size; |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 300 | |
| 301 | if (dma_enabled) { |
| 302 | phys = dma_map_page(mvm->trans->dev, block, 0, |
| 303 | PAGE_SIZE << order, |
| 304 | DMA_BIDIRECTIONAL); |
| 305 | if (dma_mapping_error(mvm->trans->dev, phys)) { |
| 306 | /* |
| 307 | * free the previous pages and the current one |
| 308 | * since we failed to map_page. |
| 309 | */ |
| 310 | iwl_free_fw_paging(mvm); |
| 311 | return -ENOMEM; |
| 312 | } |
| 313 | mvm->fw_paging_db[blk_idx].fw_paging_phys = phys; |
Matti Gottlieb | e112018 | 2015-07-19 11:15:07 +0300 | [diff] [blame] | 314 | } else { |
| 315 | mvm->fw_paging_db[blk_idx].fw_paging_phys = |
| 316 | PAGING_ADDR_SIG | |
| 317 | blk_idx << BLOCK_2_EXP_SIZE; |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 318 | } |
| 319 | |
Sara Sharon | 08d785f | 2016-10-27 17:27:23 +0300 | [diff] [blame] | 320 | if (!blk_idx) |
| 321 | IWL_DEBUG_FW(mvm, |
| 322 | "Paging: allocated 4K(CSS) bytes (order %d) for firmware paging.\n", |
| 323 | order); |
| 324 | else |
| 325 | IWL_DEBUG_FW(mvm, |
| 326 | "Paging: allocated 32K bytes (order %d) for firmware paging.\n", |
| 327 | order); |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | static int iwl_save_fw_paging(struct iwl_mvm *mvm, |
| 334 | const struct fw_img *fw) |
| 335 | { |
| 336 | int ret; |
| 337 | |
| 338 | ret = iwl_alloc_fw_paging_mem(mvm, fw); |
| 339 | if (ret) |
| 340 | return ret; |
| 341 | |
| 342 | return iwl_fill_paging_mem(mvm, fw); |
| 343 | } |
| 344 | |
| 345 | /* send paging cmd to FW in case CPU2 has paging image */ |
| 346 | static int iwl_send_paging_cmd(struct iwl_mvm *mvm, const struct fw_img *fw) |
| 347 | { |
Sara Sharon | d975d72 | 2016-07-04 11:52:07 +0300 | [diff] [blame] | 348 | struct iwl_fw_paging_cmd paging_cmd = { |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 349 | .flags = |
| 350 | cpu_to_le32(PAGING_CMD_IS_SECURED | |
| 351 | PAGING_CMD_IS_ENABLED | |
| 352 | (mvm->num_of_pages_in_last_blk << |
| 353 | PAGING_CMD_NUM_OF_PAGES_IN_LAST_GRP_POS)), |
| 354 | .block_size = cpu_to_le32(BLOCK_2_EXP_SIZE), |
| 355 | .block_num = cpu_to_le32(mvm->num_of_paging_blk), |
| 356 | }; |
Sara Sharon | d975d72 | 2016-07-04 11:52:07 +0300 | [diff] [blame] | 357 | int blk_idx, size = sizeof(paging_cmd); |
| 358 | |
| 359 | /* A bit hard coded - but this is the old API and will be deprecated */ |
| 360 | if (!iwl_mvm_has_new_tx_api(mvm)) |
| 361 | size -= NUM_OF_FW_PAGING_BLOCKS * 4; |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 362 | |
| 363 | /* loop for for all paging blocks + CSS block */ |
| 364 | for (blk_idx = 0; blk_idx < mvm->num_of_paging_blk + 1; blk_idx++) { |
Sara Sharon | d975d72 | 2016-07-04 11:52:07 +0300 | [diff] [blame] | 365 | dma_addr_t addr = mvm->fw_paging_db[blk_idx].fw_paging_phys; |
| 366 | |
| 367 | addr = addr >> PAGE_2_EXP_SIZE; |
| 368 | |
| 369 | if (iwl_mvm_has_new_tx_api(mvm)) { |
| 370 | __le64 phy_addr = cpu_to_le64(addr); |
| 371 | |
| 372 | paging_cmd.device_phy_addr.addr64[blk_idx] = phy_addr; |
| 373 | } else { |
| 374 | __le32 phy_addr = cpu_to_le32(addr); |
| 375 | |
| 376 | paging_cmd.device_phy_addr.addr32[blk_idx] = phy_addr; |
| 377 | } |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | return iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(FW_PAGING_BLOCK_CMD, |
| 381 | IWL_ALWAYS_LONG_GROUP, 0), |
Sara Sharon | d975d72 | 2016-07-04 11:52:07 +0300 | [diff] [blame] | 382 | 0, size, &paging_cmd); |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 383 | } |
| 384 | |
Matti Gottlieb | e112018 | 2015-07-19 11:15:07 +0300 | [diff] [blame] | 385 | /* |
| 386 | * Send paging item cmd to FW in case CPU2 has paging image |
| 387 | */ |
| 388 | static int iwl_trans_get_paging_item(struct iwl_mvm *mvm) |
| 389 | { |
| 390 | int ret; |
| 391 | struct iwl_fw_get_item_cmd fw_get_item_cmd = { |
| 392 | .item_id = cpu_to_le32(IWL_FW_ITEM_ID_PAGING), |
| 393 | }; |
| 394 | |
| 395 | struct iwl_fw_get_item_resp *item_resp; |
| 396 | struct iwl_host_cmd cmd = { |
| 397 | .id = iwl_cmd_id(FW_GET_ITEM_CMD, IWL_ALWAYS_LONG_GROUP, 0), |
| 398 | .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL, |
| 399 | .data = { &fw_get_item_cmd, }, |
| 400 | }; |
| 401 | |
| 402 | cmd.len[0] = sizeof(struct iwl_fw_get_item_cmd); |
| 403 | |
| 404 | ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 405 | if (ret) { |
| 406 | IWL_ERR(mvm, |
| 407 | "Paging: Failed to send FW_GET_ITEM_CMD cmd (err = %d)\n", |
| 408 | ret); |
| 409 | return ret; |
| 410 | } |
| 411 | |
| 412 | item_resp = (void *)((struct iwl_rx_packet *)cmd.resp_pkt)->data; |
| 413 | if (item_resp->item_id != cpu_to_le32(IWL_FW_ITEM_ID_PAGING)) { |
| 414 | IWL_ERR(mvm, |
| 415 | "Paging: got wrong item in FW_GET_ITEM_CMD resp (item_id = %u)\n", |
| 416 | le32_to_cpu(item_resp->item_id)); |
| 417 | ret = -EIO; |
| 418 | goto exit; |
| 419 | } |
| 420 | |
Matti Gottlieb | c94d799 | 2016-03-09 10:54:10 +0200 | [diff] [blame] | 421 | /* Add an extra page for headers */ |
| 422 | mvm->trans->paging_download_buf = kzalloc(PAGING_BLOCK_SIZE + |
| 423 | FW_PAGING_SIZE, |
Matti Gottlieb | e112018 | 2015-07-19 11:15:07 +0300 | [diff] [blame] | 424 | GFP_KERNEL); |
| 425 | if (!mvm->trans->paging_download_buf) { |
| 426 | ret = -ENOMEM; |
| 427 | goto exit; |
| 428 | } |
| 429 | mvm->trans->paging_req_addr = le32_to_cpu(item_resp->item_val); |
| 430 | mvm->trans->paging_db = mvm->fw_paging_db; |
| 431 | IWL_DEBUG_FW(mvm, |
| 432 | "Paging: got paging request address (paging_req_addr 0x%08x)\n", |
| 433 | mvm->trans->paging_req_addr); |
| 434 | |
| 435 | exit: |
| 436 | iwl_free_resp(&cmd); |
| 437 | |
| 438 | return ret; |
| 439 | } |
| 440 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 441 | static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait, |
| 442 | struct iwl_rx_packet *pkt, void *data) |
| 443 | { |
| 444 | struct iwl_mvm *mvm = |
| 445 | container_of(notif_wait, struct iwl_mvm, notif_wait); |
| 446 | struct iwl_mvm_alive_data *alive_data = data; |
Emmanuel Grumbach | 7e1223b | 2015-02-03 20:11:48 +0200 | [diff] [blame] | 447 | struct mvm_alive_resp_ver1 *palive1; |
Eran Harary | 01a9ca5 | 2014-02-03 09:29:57 +0200 | [diff] [blame] | 448 | struct mvm_alive_resp_ver2 *palive2; |
Emmanuel Grumbach | 7e1223b | 2015-02-03 20:11:48 +0200 | [diff] [blame] | 449 | struct mvm_alive_resp *palive; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 450 | |
Emmanuel Grumbach | 7e1223b | 2015-02-03 20:11:48 +0200 | [diff] [blame] | 451 | if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive1)) { |
| 452 | palive1 = (void *)pkt->data; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 453 | |
Eran Harary | 01a9ca5 | 2014-02-03 09:29:57 +0200 | [diff] [blame] | 454 | mvm->support_umac_log = false; |
| 455 | mvm->error_event_table = |
Emmanuel Grumbach | 7e1223b | 2015-02-03 20:11:48 +0200 | [diff] [blame] | 456 | le32_to_cpu(palive1->error_event_table_ptr); |
| 457 | mvm->log_event_table = |
| 458 | le32_to_cpu(palive1->log_event_table_ptr); |
| 459 | alive_data->scd_base_addr = le32_to_cpu(palive1->scd_base_ptr); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 460 | |
Emmanuel Grumbach | 7e1223b | 2015-02-03 20:11:48 +0200 | [diff] [blame] | 461 | alive_data->valid = le16_to_cpu(palive1->status) == |
Eran Harary | 01a9ca5 | 2014-02-03 09:29:57 +0200 | [diff] [blame] | 462 | IWL_ALIVE_STATUS_OK; |
| 463 | IWL_DEBUG_FW(mvm, |
| 464 | "Alive VER1 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n", |
Emmanuel Grumbach | 7e1223b | 2015-02-03 20:11:48 +0200 | [diff] [blame] | 465 | le16_to_cpu(palive1->status), palive1->ver_type, |
| 466 | palive1->ver_subtype, palive1->flags); |
| 467 | } else if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive2)) { |
Eran Harary | 01a9ca5 | 2014-02-03 09:29:57 +0200 | [diff] [blame] | 468 | palive2 = (void *)pkt->data; |
| 469 | |
Eran Harary | 01a9ca5 | 2014-02-03 09:29:57 +0200 | [diff] [blame] | 470 | mvm->error_event_table = |
| 471 | le32_to_cpu(palive2->error_event_table_ptr); |
| 472 | mvm->log_event_table = |
| 473 | le32_to_cpu(palive2->log_event_table_ptr); |
| 474 | alive_data->scd_base_addr = le32_to_cpu(palive2->scd_base_ptr); |
| 475 | mvm->umac_error_event_table = |
| 476 | le32_to_cpu(palive2->error_info_addr); |
Eran Harary | 91479b6 | 2014-05-11 08:11:34 +0300 | [diff] [blame] | 477 | mvm->sf_space.addr = le32_to_cpu(palive2->st_fwrd_addr); |
| 478 | mvm->sf_space.size = le32_to_cpu(palive2->st_fwrd_size); |
Eran Harary | 01a9ca5 | 2014-02-03 09:29:57 +0200 | [diff] [blame] | 479 | |
| 480 | alive_data->valid = le16_to_cpu(palive2->status) == |
| 481 | IWL_ALIVE_STATUS_OK; |
Emmanuel Grumbach | ffa7026 | 2014-02-11 16:37:34 +0200 | [diff] [blame] | 482 | if (mvm->umac_error_event_table) |
| 483 | mvm->support_umac_log = true; |
| 484 | |
Eran Harary | 01a9ca5 | 2014-02-03 09:29:57 +0200 | [diff] [blame] | 485 | IWL_DEBUG_FW(mvm, |
| 486 | "Alive VER2 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n", |
| 487 | le16_to_cpu(palive2->status), palive2->ver_type, |
| 488 | palive2->ver_subtype, palive2->flags); |
| 489 | |
| 490 | IWL_DEBUG_FW(mvm, |
| 491 | "UMAC version: Major - 0x%x, Minor - 0x%x\n", |
| 492 | palive2->umac_major, palive2->umac_minor); |
Emmanuel Grumbach | 7e1223b | 2015-02-03 20:11:48 +0200 | [diff] [blame] | 493 | } else if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive)) { |
| 494 | palive = (void *)pkt->data; |
| 495 | |
| 496 | mvm->error_event_table = |
| 497 | le32_to_cpu(palive->error_event_table_ptr); |
| 498 | mvm->log_event_table = |
| 499 | le32_to_cpu(palive->log_event_table_ptr); |
| 500 | alive_data->scd_base_addr = le32_to_cpu(palive->scd_base_ptr); |
| 501 | mvm->umac_error_event_table = |
| 502 | le32_to_cpu(palive->error_info_addr); |
| 503 | mvm->sf_space.addr = le32_to_cpu(palive->st_fwrd_addr); |
| 504 | mvm->sf_space.size = le32_to_cpu(palive->st_fwrd_size); |
| 505 | |
| 506 | alive_data->valid = le16_to_cpu(palive->status) == |
| 507 | IWL_ALIVE_STATUS_OK; |
| 508 | if (mvm->umac_error_event_table) |
| 509 | mvm->support_umac_log = true; |
| 510 | |
| 511 | IWL_DEBUG_FW(mvm, |
| 512 | "Alive VER3 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n", |
| 513 | le16_to_cpu(palive->status), palive->ver_type, |
| 514 | palive->ver_subtype, palive->flags); |
| 515 | |
| 516 | IWL_DEBUG_FW(mvm, |
| 517 | "UMAC version: Major - 0x%x, Minor - 0x%x\n", |
| 518 | le32_to_cpu(palive->umac_major), |
| 519 | le32_to_cpu(palive->umac_minor)); |
Eran Harary | 01a9ca5 | 2014-02-03 09:29:57 +0200 | [diff] [blame] | 520 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 521 | |
| 522 | return true; |
| 523 | } |
| 524 | |
| 525 | static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait, |
| 526 | struct iwl_rx_packet *pkt, void *data) |
| 527 | { |
| 528 | struct iwl_phy_db *phy_db = data; |
| 529 | |
| 530 | if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) { |
| 531 | WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF); |
| 532 | return true; |
| 533 | } |
| 534 | |
Sara Sharon | ce1f277 | 2016-04-10 16:02:12 +0300 | [diff] [blame] | 535 | WARN_ON(iwl_phy_db_set_section(phy_db, pkt)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 536 | |
| 537 | return false; |
| 538 | } |
| 539 | |
| 540 | static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm, |
| 541 | enum iwl_ucode_type ucode_type) |
| 542 | { |
| 543 | struct iwl_notification_wait alive_wait; |
| 544 | struct iwl_mvm_alive_data alive_data; |
| 545 | const struct fw_img *fw; |
| 546 | int ret, i; |
| 547 | enum iwl_ucode_type old_type = mvm->cur_ucode; |
Sara Sharon | 6eb031d | 2015-07-13 14:50:47 +0300 | [diff] [blame] | 548 | static const u16 alive_cmd[] = { MVM_ALIVE }; |
Eran Harary | 91479b6 | 2014-05-11 08:11:34 +0300 | [diff] [blame] | 549 | struct iwl_sf_region st_fwrd_space; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 550 | |
Eran Harary | 61df750 | 2014-12-01 17:40:37 +0200 | [diff] [blame] | 551 | if (ucode_type == IWL_UCODE_REGULAR && |
Golan Ben-Ami | 3d2d442 | 2016-02-23 10:34:48 +0200 | [diff] [blame] | 552 | iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) && |
| 553 | !(fw_has_capa(&mvm->fw->ucode_capa, |
| 554 | IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED))) |
Sharon Dvir | 612da1e | 2016-08-03 10:55:45 +0300 | [diff] [blame] | 555 | fw = iwl_get_ucode_image(mvm->fw, IWL_UCODE_REGULAR_USNIFFER); |
Eran Harary | 61df750 | 2014-12-01 17:40:37 +0200 | [diff] [blame] | 556 | else |
Sharon Dvir | 612da1e | 2016-08-03 10:55:45 +0300 | [diff] [blame] | 557 | fw = iwl_get_ucode_image(mvm->fw, ucode_type); |
Johannes Berg | befe9b6 | 2013-10-25 12:32:51 +0200 | [diff] [blame] | 558 | if (WARN_ON(!fw)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 559 | return -EINVAL; |
Johannes Berg | befe9b6 | 2013-10-25 12:32:51 +0200 | [diff] [blame] | 560 | mvm->cur_ucode = ucode_type; |
| 561 | mvm->ucode_loaded = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 562 | |
| 563 | iwl_init_notification_wait(&mvm->notif_wait, &alive_wait, |
| 564 | alive_cmd, ARRAY_SIZE(alive_cmd), |
| 565 | iwl_alive_fn, &alive_data); |
| 566 | |
| 567 | ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT); |
| 568 | if (ret) { |
| 569 | mvm->cur_ucode = old_type; |
| 570 | iwl_remove_notification(&mvm->notif_wait, &alive_wait); |
| 571 | return ret; |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | * Some things may run in the background now, but we |
| 576 | * just wait for the ALIVE notification here. |
| 577 | */ |
| 578 | ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait, |
| 579 | MVM_UCODE_ALIVE_TIMEOUT); |
| 580 | if (ret) { |
Dor Shaish | 192de2b | 2015-07-15 11:41:21 +0300 | [diff] [blame] | 581 | if (mvm->trans->cfg->device_family == IWL_DEVICE_FAMILY_8000) |
| 582 | IWL_ERR(mvm, |
| 583 | "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n", |
| 584 | iwl_read_prph(mvm->trans, SB_CPU_1_STATUS), |
| 585 | iwl_read_prph(mvm->trans, SB_CPU_2_STATUS)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 586 | mvm->cur_ucode = old_type; |
| 587 | return ret; |
| 588 | } |
| 589 | |
| 590 | if (!alive_data.valid) { |
| 591 | IWL_ERR(mvm, "Loaded ucode is not valid!\n"); |
| 592 | mvm->cur_ucode = old_type; |
| 593 | return -EIO; |
| 594 | } |
| 595 | |
Eran Harary | 91479b6 | 2014-05-11 08:11:34 +0300 | [diff] [blame] | 596 | /* |
| 597 | * update the sdio allocation according to the pointer we get in the |
| 598 | * alive notification. |
| 599 | */ |
| 600 | st_fwrd_space.addr = mvm->sf_space.addr; |
| 601 | st_fwrd_space.size = mvm->sf_space.size; |
| 602 | ret = iwl_trans_update_sf(mvm->trans, &st_fwrd_space); |
Eyal Shapira | 82e8aea | 2014-10-19 14:56:40 +0300 | [diff] [blame] | 603 | if (ret) { |
| 604 | IWL_ERR(mvm, "Failed to update SF size. ret %d\n", ret); |
| 605 | return ret; |
| 606 | } |
Eran Harary | 91479b6 | 2014-05-11 08:11:34 +0300 | [diff] [blame] | 607 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 608 | iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr); |
| 609 | |
| 610 | /* |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 611 | * configure and operate fw paging mechanism. |
| 612 | * driver configures the paging flow only once, CPU2 paging image |
| 613 | * included in the IWL_UCODE_INIT image. |
| 614 | */ |
| 615 | if (fw->paging_mem_size) { |
Matti Gottlieb | e112018 | 2015-07-19 11:15:07 +0300 | [diff] [blame] | 616 | /* |
| 617 | * When dma is not enabled, the driver needs to copy / write |
| 618 | * the downloaded / uploaded page to / from the smem. |
| 619 | * This gets the location of the place were the pages are |
| 620 | * stored. |
| 621 | */ |
| 622 | if (!is_device_dma_capable(mvm->trans->dev)) { |
| 623 | ret = iwl_trans_get_paging_item(mvm); |
| 624 | if (ret) { |
| 625 | IWL_ERR(mvm, "failed to get FW paging item\n"); |
| 626 | return ret; |
| 627 | } |
| 628 | } |
| 629 | |
Matti Gottlieb | a6c4fb4 | 2015-07-15 16:19:29 +0300 | [diff] [blame] | 630 | ret = iwl_save_fw_paging(mvm, fw); |
| 631 | if (ret) { |
| 632 | IWL_ERR(mvm, "failed to save the FW paging image\n"); |
| 633 | return ret; |
| 634 | } |
| 635 | |
| 636 | ret = iwl_send_paging_cmd(mvm, fw); |
| 637 | if (ret) { |
| 638 | IWL_ERR(mvm, "failed to send the paging cmd\n"); |
| 639 | iwl_free_fw_paging(mvm); |
| 640 | return ret; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 645 | * Note: all the queues are enabled as part of the interface |
| 646 | * initialization, but in firmware restart scenarios they |
| 647 | * could be stopped, so wake them up. In firmware restart, |
| 648 | * mac80211 will have the queues stopped as well until the |
| 649 | * reconfiguration completes. During normal startup, they |
| 650 | * will be empty. |
| 651 | */ |
| 652 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 653 | memset(&mvm->queue_info, 0, sizeof(mvm->queue_info)); |
Liad Kaufman | 097129c | 2015-08-09 18:28:43 +0300 | [diff] [blame] | 654 | if (iwl_mvm_is_dqa_supported(mvm)) |
| 655 | mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].hw_queue_refcount = 1; |
| 656 | else |
| 657 | mvm->queue_info[IWL_MVM_CMD_QUEUE].hw_queue_refcount = 1; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 658 | |
Johannes Berg | df197c0 | 2014-08-01 18:14:45 +0200 | [diff] [blame] | 659 | for (i = 0; i < IEEE80211_MAX_QUEUES; i++) |
| 660 | atomic_set(&mvm->mac80211_queue_stop_count[i], 0); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 661 | |
| 662 | mvm->ucode_loaded = true; |
| 663 | |
| 664 | return 0; |
| 665 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 666 | |
| 667 | static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm) |
| 668 | { |
| 669 | struct iwl_phy_cfg_cmd phy_cfg_cmd; |
| 670 | enum iwl_ucode_type ucode_type = mvm->cur_ucode; |
| 671 | |
| 672 | /* Set parameters */ |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 673 | phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 674 | phy_cfg_cmd.calib_control.event_trigger = |
| 675 | mvm->fw->default_calib[ucode_type].event_trigger; |
| 676 | phy_cfg_cmd.calib_control.flow_trigger = |
| 677 | mvm->fw->default_calib[ucode_type].flow_trigger; |
| 678 | |
| 679 | IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n", |
| 680 | phy_cfg_cmd.phy_cfg); |
| 681 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 682 | return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 683 | sizeof(phy_cfg_cmd), &phy_cfg_cmd); |
| 684 | } |
| 685 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 686 | int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm) |
| 687 | { |
| 688 | struct iwl_notification_wait calib_wait; |
Sara Sharon | 6eb031d | 2015-07-13 14:50:47 +0300 | [diff] [blame] | 689 | static const u16 init_complete[] = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 690 | INIT_COMPLETE_NOTIF, |
| 691 | CALIB_RES_NOTIF_PHY_DB |
| 692 | }; |
| 693 | int ret; |
| 694 | |
| 695 | lockdep_assert_held(&mvm->mutex); |
| 696 | |
Eran Harary | 8d193ca | 2015-04-27 10:29:31 +0300 | [diff] [blame] | 697 | if (WARN_ON_ONCE(mvm->calibrating)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 698 | return 0; |
| 699 | |
| 700 | iwl_init_notification_wait(&mvm->notif_wait, |
| 701 | &calib_wait, |
| 702 | init_complete, |
| 703 | ARRAY_SIZE(init_complete), |
| 704 | iwl_wait_phy_db_entry, |
| 705 | mvm->phy_db); |
| 706 | |
| 707 | /* Will also start the device */ |
| 708 | ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT); |
| 709 | if (ret) { |
| 710 | IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret); |
| 711 | goto error; |
| 712 | } |
| 713 | |
Emmanuel Grumbach | ae39747 | 2014-03-30 16:55:18 +0300 | [diff] [blame] | 714 | ret = iwl_send_bt_init_conf(mvm); |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 715 | if (ret) |
| 716 | goto error; |
| 717 | |
Eytan Lifshitz | 81a67e3 | 2013-09-11 12:39:18 +0200 | [diff] [blame] | 718 | /* Read the NVM only at driver load time, no need to do this twice */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 719 | if (read_nvm) { |
| 720 | /* Read nvm */ |
Eran Harary | 14b485f | 2014-04-23 10:46:09 +0300 | [diff] [blame] | 721 | ret = iwl_nvm_init(mvm, true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 722 | if (ret) { |
| 723 | IWL_ERR(mvm, "Failed to read NVM: %d\n", ret); |
| 724 | goto error; |
| 725 | } |
| 726 | } |
| 727 | |
Eytan Lifshitz | 81a67e3 | 2013-09-11 12:39:18 +0200 | [diff] [blame] | 728 | /* In case we read the NVM from external file, load it to the NIC */ |
Eran Harary | e02a9d6 | 2014-05-07 12:27:10 +0300 | [diff] [blame] | 729 | if (mvm->nvm_file_name) |
Eytan Lifshitz | 81a67e3 | 2013-09-11 12:39:18 +0200 | [diff] [blame] | 730 | iwl_mvm_load_nvm_to_nic(mvm); |
| 731 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 732 | ret = iwl_nvm_check_version(mvm->nvm_data, mvm->trans); |
| 733 | WARN_ON(ret); |
| 734 | |
Eran Harary | 4f59334 | 2013-05-13 07:53:26 +0300 | [diff] [blame] | 735 | /* |
| 736 | * abort after reading the nvm in case RF Kill is on, we will complete |
| 737 | * the init seq later when RF kill will switch to off |
| 738 | */ |
Arik Nemtsov | 1a3fe0b | 2015-09-30 11:19:55 +0300 | [diff] [blame] | 739 | if (iwl_mvm_is_radio_hw_killed(mvm)) { |
Eran Harary | 4f59334 | 2013-05-13 07:53:26 +0300 | [diff] [blame] | 740 | IWL_DEBUG_RF_KILL(mvm, |
| 741 | "jump over all phy activities due to RF kill\n"); |
| 742 | iwl_remove_notification(&mvm->notif_wait, &calib_wait); |
Arik Nemtsov | a408284 | 2013-11-24 19:10:46 +0200 | [diff] [blame] | 743 | ret = 1; |
| 744 | goto out; |
Eran Harary | 4f59334 | 2013-05-13 07:53:26 +0300 | [diff] [blame] | 745 | } |
| 746 | |
Emmanuel Grumbach | 31b8b34 | 2014-11-02 15:48:09 +0200 | [diff] [blame] | 747 | mvm->calibrating = true; |
| 748 | |
Dor Shaish | e07cbb5 | 2013-02-27 23:00:27 +0200 | [diff] [blame] | 749 | /* Send TX valid antennas before triggering calibrations */ |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 750 | ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm)); |
Dor Shaish | e07cbb5 | 2013-02-27 23:00:27 +0200 | [diff] [blame] | 751 | if (ret) |
| 752 | goto error; |
| 753 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 754 | /* |
| 755 | * Send phy configurations command to init uCode |
| 756 | * to start the 16.0 uCode init image internal calibrations. |
| 757 | */ |
| 758 | ret = iwl_send_phy_cfg_cmd(mvm); |
| 759 | if (ret) { |
| 760 | IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n", |
| 761 | ret); |
| 762 | goto error; |
| 763 | } |
| 764 | |
| 765 | /* |
| 766 | * Some things may run in the background now, but we |
| 767 | * just wait for the calibration complete notification. |
| 768 | */ |
| 769 | ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait, |
| 770 | MVM_UCODE_CALIB_TIMEOUT); |
Emmanuel Grumbach | 31b8b34 | 2014-11-02 15:48:09 +0200 | [diff] [blame] | 771 | |
Arik Nemtsov | 1a3fe0b | 2015-09-30 11:19:55 +0300 | [diff] [blame] | 772 | if (ret && iwl_mvm_is_radio_hw_killed(mvm)) { |
Emmanuel Grumbach | 31b8b34 | 2014-11-02 15:48:09 +0200 | [diff] [blame] | 773 | IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n"); |
| 774 | ret = 1; |
| 775 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 776 | goto out; |
| 777 | |
| 778 | error: |
| 779 | iwl_remove_notification(&mvm->notif_wait, &calib_wait); |
| 780 | out: |
Emmanuel Grumbach | 31b8b34 | 2014-11-02 15:48:09 +0200 | [diff] [blame] | 781 | mvm->calibrating = false; |
Arik Nemtsov | a408284 | 2013-11-24 19:10:46 +0200 | [diff] [blame] | 782 | if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 783 | /* we want to debug INIT and we have no NVM - fake */ |
| 784 | mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) + |
| 785 | sizeof(struct ieee80211_channel) + |
| 786 | sizeof(struct ieee80211_rate), |
| 787 | GFP_KERNEL); |
| 788 | if (!mvm->nvm_data) |
| 789 | return -ENOMEM; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 790 | mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels; |
| 791 | mvm->nvm_data->bands[0].n_channels = 1; |
| 792 | mvm->nvm_data->bands[0].n_bitrates = 1; |
| 793 | mvm->nvm_data->bands[0].bitrates = |
| 794 | (void *)mvm->nvm_data->channels + 1; |
| 795 | mvm->nvm_data->bands[0].bitrates->hw_value = 10; |
| 796 | } |
| 797 | |
| 798 | return ret; |
| 799 | } |
| 800 | |
Sara Sharon | db06f04 | 2016-07-05 17:37:58 +0300 | [diff] [blame] | 801 | static void iwl_mvm_parse_shared_mem_a000(struct iwl_mvm *mvm, |
| 802 | struct iwl_rx_packet *pkt) |
| 803 | { |
| 804 | struct iwl_shared_mem_cfg *mem_cfg = (void *)pkt->data; |
| 805 | int i; |
| 806 | |
| 807 | mvm->shared_mem_cfg.num_txfifo_entries = |
| 808 | ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); |
| 809 | for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++) |
| 810 | mvm->shared_mem_cfg.txfifo_size[i] = |
| 811 | le32_to_cpu(mem_cfg->txfifo_size[i]); |
| 812 | for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++) |
| 813 | mvm->shared_mem_cfg.rxfifo_size[i] = |
| 814 | le32_to_cpu(mem_cfg->rxfifo_size[i]); |
| 815 | |
| 816 | BUILD_BUG_ON(sizeof(mvm->shared_mem_cfg.internal_txfifo_size) != |
| 817 | sizeof(mem_cfg->internal_txfifo_size)); |
| 818 | |
| 819 | for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.internal_txfifo_size); |
| 820 | i++) |
| 821 | mvm->shared_mem_cfg.internal_txfifo_size[i] = |
| 822 | le32_to_cpu(mem_cfg->internal_txfifo_size[i]); |
| 823 | } |
| 824 | |
| 825 | static void iwl_mvm_parse_shared_mem(struct iwl_mvm *mvm, |
| 826 | struct iwl_rx_packet *pkt) |
| 827 | { |
| 828 | struct iwl_shared_mem_cfg_v1 *mem_cfg = (void *)pkt->data; |
| 829 | int i; |
| 830 | |
| 831 | mvm->shared_mem_cfg.num_txfifo_entries = |
| 832 | ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); |
| 833 | for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++) |
| 834 | mvm->shared_mem_cfg.txfifo_size[i] = |
| 835 | le32_to_cpu(mem_cfg->txfifo_size[i]); |
| 836 | for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++) |
| 837 | mvm->shared_mem_cfg.rxfifo_size[i] = |
| 838 | le32_to_cpu(mem_cfg->rxfifo_size[i]); |
| 839 | |
| 840 | /* new API has more data, from rxfifo_addr field and on */ |
| 841 | if (fw_has_capa(&mvm->fw->ucode_capa, |
| 842 | IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) { |
| 843 | BUILD_BUG_ON(sizeof(mvm->shared_mem_cfg.internal_txfifo_size) != |
| 844 | sizeof(mem_cfg->internal_txfifo_size)); |
| 845 | |
| 846 | for (i = 0; |
| 847 | i < ARRAY_SIZE(mvm->shared_mem_cfg.internal_txfifo_size); |
| 848 | i++) |
| 849 | mvm->shared_mem_cfg.internal_txfifo_size[i] = |
| 850 | le32_to_cpu(mem_cfg->internal_txfifo_size[i]); |
| 851 | } |
| 852 | } |
| 853 | |
Liad Kaufman | 04fd2c2 | 2014-12-15 17:54:16 +0200 | [diff] [blame] | 854 | static void iwl_mvm_get_shared_mem_conf(struct iwl_mvm *mvm) |
| 855 | { |
| 856 | struct iwl_host_cmd cmd = { |
Liad Kaufman | 04fd2c2 | 2014-12-15 17:54:16 +0200 | [diff] [blame] | 857 | .flags = CMD_WANT_SKB, |
| 858 | .data = { NULL, }, |
| 859 | .len = { 0, }, |
| 860 | }; |
Golan Ben-Ami | 5b08641 | 2016-02-09 12:57:16 +0200 | [diff] [blame] | 861 | struct iwl_rx_packet *pkt; |
Liad Kaufman | 04fd2c2 | 2014-12-15 17:54:16 +0200 | [diff] [blame] | 862 | |
| 863 | lockdep_assert_held(&mvm->mutex); |
| 864 | |
Golan Ben-Ami | 5b08641 | 2016-02-09 12:57:16 +0200 | [diff] [blame] | 865 | if (fw_has_capa(&mvm->fw->ucode_capa, |
| 866 | IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) |
| 867 | cmd.id = iwl_cmd_id(SHARED_MEM_CFG_CMD, SYSTEM_GROUP, 0); |
| 868 | else |
| 869 | cmd.id = SHARED_MEM_CFG; |
| 870 | |
Liad Kaufman | 04fd2c2 | 2014-12-15 17:54:16 +0200 | [diff] [blame] | 871 | if (WARN_ON(iwl_mvm_send_cmd(mvm, &cmd))) |
| 872 | return; |
| 873 | |
| 874 | pkt = cmd.resp_pkt; |
Sara Sharon | db06f04 | 2016-07-05 17:37:58 +0300 | [diff] [blame] | 875 | if (iwl_mvm_has_new_tx_api(mvm)) |
| 876 | iwl_mvm_parse_shared_mem_a000(mvm, pkt); |
| 877 | else |
| 878 | iwl_mvm_parse_shared_mem(mvm, pkt); |
Golan Ben-Ami | 5b08641 | 2016-02-09 12:57:16 +0200 | [diff] [blame] | 879 | |
Liad Kaufman | 04fd2c2 | 2014-12-15 17:54:16 +0200 | [diff] [blame] | 880 | IWL_DEBUG_INFO(mvm, "SHARED MEM CFG: got memory offsets/sizes\n"); |
| 881 | |
Liad Kaufman | 04fd2c2 | 2014-12-15 17:54:16 +0200 | [diff] [blame] | 882 | iwl_free_resp(&cmd); |
| 883 | } |
| 884 | |
Emmanuel Grumbach | 84bfffa | 2015-01-13 10:16:30 +0200 | [diff] [blame] | 885 | static int iwl_mvm_config_ltr(struct iwl_mvm *mvm) |
| 886 | { |
| 887 | struct iwl_ltr_config_cmd cmd = { |
| 888 | .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE), |
| 889 | }; |
| 890 | |
| 891 | if (!mvm->trans->ltr_enabled) |
| 892 | return 0; |
| 893 | |
Emmanuel Grumbach | 84bfffa | 2015-01-13 10:16:30 +0200 | [diff] [blame] | 894 | return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0, |
| 895 | sizeof(cmd), &cmd); |
| 896 | } |
| 897 | |
Luca Coelho | da2830a | 2016-05-30 13:00:44 +0300 | [diff] [blame] | 898 | #define ACPI_WRDS_METHOD "WRDS" |
| 899 | #define ACPI_WRDS_WIFI (0x07) |
| 900 | #define ACPI_WRDS_TABLE_SIZE 10 |
| 901 | |
| 902 | struct iwl_mvm_sar_table { |
| 903 | bool enabled; |
| 904 | u8 values[ACPI_WRDS_TABLE_SIZE]; |
| 905 | }; |
| 906 | |
| 907 | #ifdef CONFIG_ACPI |
| 908 | static int iwl_mvm_sar_get_wrds(struct iwl_mvm *mvm, union acpi_object *wrds, |
| 909 | struct iwl_mvm_sar_table *sar_table) |
| 910 | { |
| 911 | union acpi_object *data_pkg; |
| 912 | u32 i; |
| 913 | |
| 914 | /* We need at least two packages, one for the revision and one |
| 915 | * for the data itself. Also check that the revision is valid |
| 916 | * (i.e. it is an integer set to 0). |
| 917 | */ |
| 918 | if (wrds->type != ACPI_TYPE_PACKAGE || |
| 919 | wrds->package.count < 2 || |
| 920 | wrds->package.elements[0].type != ACPI_TYPE_INTEGER || |
| 921 | wrds->package.elements[0].integer.value != 0) { |
| 922 | IWL_DEBUG_RADIO(mvm, "Unsupported wrds structure\n"); |
| 923 | return -EINVAL; |
| 924 | } |
| 925 | |
| 926 | /* loop through all the packages to find the one for WiFi */ |
| 927 | for (i = 1; i < wrds->package.count; i++) { |
| 928 | union acpi_object *domain; |
| 929 | |
| 930 | data_pkg = &wrds->package.elements[i]; |
| 931 | |
| 932 | /* Skip anything that is not a package with the right |
| 933 | * amount of elements (i.e. domain_type, |
| 934 | * enabled/disabled plus the sar table size. |
| 935 | */ |
| 936 | if (data_pkg->type != ACPI_TYPE_PACKAGE || |
| 937 | data_pkg->package.count != ACPI_WRDS_TABLE_SIZE + 2) |
| 938 | continue; |
| 939 | |
| 940 | domain = &data_pkg->package.elements[0]; |
| 941 | if (domain->type == ACPI_TYPE_INTEGER && |
| 942 | domain->integer.value == ACPI_WRDS_WIFI) |
| 943 | break; |
| 944 | |
| 945 | data_pkg = NULL; |
| 946 | } |
| 947 | |
| 948 | if (!data_pkg) |
| 949 | return -ENOENT; |
| 950 | |
| 951 | if (data_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) |
| 952 | return -EINVAL; |
| 953 | |
| 954 | sar_table->enabled = !!(data_pkg->package.elements[1].integer.value); |
| 955 | |
| 956 | for (i = 0; i < ACPI_WRDS_TABLE_SIZE; i++) { |
| 957 | union acpi_object *entry; |
| 958 | |
| 959 | entry = &data_pkg->package.elements[i + 2]; |
| 960 | if ((entry->type != ACPI_TYPE_INTEGER) || |
| 961 | (entry->integer.value > U8_MAX)) |
| 962 | return -EINVAL; |
| 963 | |
| 964 | sar_table->values[i] = entry->integer.value; |
| 965 | } |
| 966 | |
| 967 | return 0; |
| 968 | } |
| 969 | |
| 970 | static int iwl_mvm_sar_get_table(struct iwl_mvm *mvm, |
| 971 | struct iwl_mvm_sar_table *sar_table) |
| 972 | { |
| 973 | acpi_handle root_handle; |
| 974 | acpi_handle handle; |
| 975 | struct acpi_buffer wrds = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 976 | acpi_status status; |
| 977 | int ret; |
| 978 | |
| 979 | root_handle = ACPI_HANDLE(mvm->dev); |
| 980 | if (!root_handle) { |
| 981 | IWL_DEBUG_RADIO(mvm, |
| 982 | "Could not retrieve root port ACPI handle\n"); |
| 983 | return -ENOENT; |
| 984 | } |
| 985 | |
| 986 | /* Get the method's handle */ |
| 987 | status = acpi_get_handle(root_handle, (acpi_string)ACPI_WRDS_METHOD, |
| 988 | &handle); |
| 989 | if (ACPI_FAILURE(status)) { |
| 990 | IWL_DEBUG_RADIO(mvm, "WRDS method not found\n"); |
| 991 | return -ENOENT; |
| 992 | } |
| 993 | |
| 994 | /* Call WRDS with no arguments */ |
| 995 | status = acpi_evaluate_object(handle, NULL, NULL, &wrds); |
| 996 | if (ACPI_FAILURE(status)) { |
| 997 | IWL_DEBUG_RADIO(mvm, "WRDS invocation failed (0x%x)\n", status); |
| 998 | return -ENOENT; |
| 999 | } |
| 1000 | |
| 1001 | ret = iwl_mvm_sar_get_wrds(mvm, wrds.pointer, sar_table); |
| 1002 | kfree(wrds.pointer); |
| 1003 | |
| 1004 | return ret; |
| 1005 | } |
| 1006 | #else /* CONFIG_ACPI */ |
| 1007 | static int iwl_mvm_sar_get_table(struct iwl_mvm *mvm, |
| 1008 | struct iwl_mvm_sar_table *sar_table) |
| 1009 | { |
| 1010 | return -ENOENT; |
| 1011 | } |
| 1012 | #endif /* CONFIG_ACPI */ |
| 1013 | |
| 1014 | static int iwl_mvm_sar_init(struct iwl_mvm *mvm) |
| 1015 | { |
| 1016 | struct iwl_mvm_sar_table sar_table; |
| 1017 | struct iwl_dev_tx_power_cmd cmd = { |
Luca Coelho | 4b87e5a | 2016-09-12 16:03:30 +0300 | [diff] [blame] | 1018 | .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS), |
Luca Coelho | da2830a | 2016-05-30 13:00:44 +0300 | [diff] [blame] | 1019 | }; |
| 1020 | int ret, i, j, idx; |
Luca Coelho | 55bfa4b | 2016-06-29 00:38:40 +0300 | [diff] [blame] | 1021 | int len = sizeof(cmd); |
Luca Coelho | da2830a | 2016-05-30 13:00:44 +0300 | [diff] [blame] | 1022 | |
Luca Coelho | 55bfa4b | 2016-06-29 00:38:40 +0300 | [diff] [blame] | 1023 | if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) |
| 1024 | len = sizeof(cmd.v3); |
| 1025 | |
Luca Coelho | da2830a | 2016-05-30 13:00:44 +0300 | [diff] [blame] | 1026 | ret = iwl_mvm_sar_get_table(mvm, &sar_table); |
| 1027 | if (ret < 0) { |
| 1028 | IWL_DEBUG_RADIO(mvm, |
| 1029 | "SAR BIOS table invalid or unavailable. (%d)\n", |
| 1030 | ret); |
| 1031 | /* we don't fail if the table is not available */ |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
| 1035 | if (!sar_table.enabled) |
| 1036 | return 0; |
| 1037 | |
| 1038 | IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n"); |
| 1039 | |
| 1040 | BUILD_BUG_ON(IWL_NUM_CHAIN_LIMITS * IWL_NUM_SUB_BANDS != |
| 1041 | ACPI_WRDS_TABLE_SIZE); |
| 1042 | |
| 1043 | for (i = 0; i < IWL_NUM_CHAIN_LIMITS; i++) { |
| 1044 | IWL_DEBUG_RADIO(mvm, " Chain[%d]:\n", i); |
| 1045 | for (j = 0; j < IWL_NUM_SUB_BANDS; j++) { |
| 1046 | idx = (i * IWL_NUM_SUB_BANDS) + j; |
Luca Coelho | 55bfa4b | 2016-06-29 00:38:40 +0300 | [diff] [blame] | 1047 | cmd.v3.per_chain_restriction[i][j] = |
Luca Coelho | da2830a | 2016-05-30 13:00:44 +0300 | [diff] [blame] | 1048 | cpu_to_le16(sar_table.values[idx]); |
| 1049 | IWL_DEBUG_RADIO(mvm, " Band[%d] = %d * .125dBm\n", |
| 1050 | j, sar_table.values[idx]); |
| 1051 | } |
| 1052 | } |
| 1053 | |
Luca Coelho | 55bfa4b | 2016-06-29 00:38:40 +0300 | [diff] [blame] | 1054 | ret = iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd); |
Luca Coelho | da2830a | 2016-05-30 13:00:44 +0300 | [diff] [blame] | 1055 | if (ret) |
| 1056 | IWL_ERR(mvm, "failed to set per-chain TX power: %d\n", ret); |
| 1057 | |
| 1058 | return ret; |
| 1059 | } |
| 1060 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1061 | int iwl_mvm_up(struct iwl_mvm *mvm) |
| 1062 | { |
| 1063 | int ret, i; |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 1064 | struct ieee80211_channel *chan; |
| 1065 | struct cfg80211_chan_def chandef; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1066 | |
| 1067 | lockdep_assert_held(&mvm->mutex); |
| 1068 | |
| 1069 | ret = iwl_trans_start_hw(mvm->trans); |
| 1070 | if (ret) |
| 1071 | return ret; |
| 1072 | |
Eytan Lifshitz | ff11637 | 2013-09-03 12:06:11 +0300 | [diff] [blame] | 1073 | /* |
| 1074 | * If we haven't completed the run of the init ucode during |
| 1075 | * module loading, load init ucode now |
| 1076 | * (for example, if we were in RFKILL) |
| 1077 | */ |
Eran Harary | 8d193ca | 2015-04-27 10:29:31 +0300 | [diff] [blame] | 1078 | ret = iwl_run_init_mvm_ucode(mvm, false); |
Sara Sharon | f2082a5 | 2016-08-31 14:13:53 +0300 | [diff] [blame] | 1079 | |
| 1080 | if (iwlmvm_mod_params.init_dbg) |
| 1081 | return 0; |
| 1082 | |
| 1083 | if (ret) { |
Eran Harary | 8d193ca | 2015-04-27 10:29:31 +0300 | [diff] [blame] | 1084 | IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret); |
| 1085 | /* this can't happen */ |
| 1086 | if (WARN_ON(ret > 0)) |
| 1087 | ret = -ERFKILL; |
| 1088 | goto error; |
| 1089 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1090 | |
Sara Sharon | f2082a5 | 2016-08-31 14:13:53 +0300 | [diff] [blame] | 1091 | /* |
| 1092 | * Stop and start the transport without entering low power |
| 1093 | * mode. This will save the state of other components on the |
| 1094 | * device that are triggered by the INIT firwmare (MFUART). |
| 1095 | */ |
| 1096 | _iwl_trans_stop_device(mvm->trans, false); |
| 1097 | ret = _iwl_trans_start_hw(mvm->trans, false); |
| 1098 | if (ret) |
| 1099 | goto error; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1100 | |
| 1101 | ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR); |
| 1102 | if (ret) { |
| 1103 | IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret); |
| 1104 | goto error; |
| 1105 | } |
| 1106 | |
Sara Sharon | 6c7d32c | 2015-06-07 09:34:57 +0300 | [diff] [blame] | 1107 | iwl_mvm_get_shared_mem_conf(mvm); |
Liad Kaufman | 04fd2c2 | 2014-12-15 17:54:16 +0200 | [diff] [blame] | 1108 | |
Lilach Edelstein | 1f3b0ff | 2013-10-06 13:03:32 +0200 | [diff] [blame] | 1109 | ret = iwl_mvm_sf_update(mvm, NULL, false); |
| 1110 | if (ret) |
| 1111 | IWL_ERR(mvm, "Failed to initialize Smart Fifo\n"); |
| 1112 | |
Liad Kaufman | 6a95126 | 2014-11-17 11:36:21 +0200 | [diff] [blame] | 1113 | mvm->fw_dbg_conf = FW_DBG_INVALID; |
Emmanuel Grumbach | 945d420 | 2015-02-15 17:16:16 +0200 | [diff] [blame] | 1114 | /* if we have a destination, assume EARLY START */ |
| 1115 | if (mvm->fw->dbg_dest_tlv) |
| 1116 | mvm->fw_dbg_conf = FW_DBG_START_FROM_ALIVE; |
Emmanuel Grumbach | d2709ad | 2015-01-29 14:58:06 +0200 | [diff] [blame] | 1117 | iwl_mvm_start_fw_dbg_conf(mvm, FW_DBG_START_FROM_ALIVE); |
Liad Kaufman | 6a95126 | 2014-11-17 11:36:21 +0200 | [diff] [blame] | 1118 | |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 1119 | ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1120 | if (ret) |
| 1121 | goto error; |
| 1122 | |
Emmanuel Grumbach | 931d416 | 2013-01-17 09:42:25 +0200 | [diff] [blame] | 1123 | ret = iwl_send_bt_init_conf(mvm); |
| 1124 | if (ret) |
| 1125 | goto error; |
| 1126 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1127 | /* Send phy db control command and then phy db calibration*/ |
| 1128 | ret = iwl_send_phy_db_data(mvm->phy_db); |
| 1129 | if (ret) |
| 1130 | goto error; |
| 1131 | |
| 1132 | ret = iwl_send_phy_cfg_cmd(mvm); |
| 1133 | if (ret) |
| 1134 | goto error; |
| 1135 | |
Sara Sharon | 43413a9 | 2015-12-31 11:49:18 +0200 | [diff] [blame] | 1136 | /* Init RSS configuration */ |
| 1137 | if (iwl_mvm_has_new_rx_api(mvm)) { |
| 1138 | ret = iwl_send_rss_cfg_cmd(mvm); |
| 1139 | if (ret) { |
| 1140 | IWL_ERR(mvm, "Failed to configure RSS queues: %d\n", |
| 1141 | ret); |
| 1142 | goto error; |
| 1143 | } |
| 1144 | } |
| 1145 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1146 | /* init the fw <-> mac80211 STA mapping */ |
| 1147 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) |
| 1148 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL); |
| 1149 | |
Arik Nemtsov | 1d3c3f6 | 2014-10-23 18:03:10 +0300 | [diff] [blame] | 1150 | mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT; |
| 1151 | |
Johannes Berg | b2b7875 | 2014-09-08 16:42:54 +0200 | [diff] [blame] | 1152 | /* reset quota debouncing buffer - 0xff will yield invalid data */ |
| 1153 | memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd)); |
| 1154 | |
Liad Kaufman | 97d5be7 | 2015-08-31 14:33:23 +0300 | [diff] [blame] | 1155 | /* Enable DQA-mode if required */ |
| 1156 | if (iwl_mvm_is_dqa_supported(mvm)) { |
| 1157 | ret = iwl_mvm_send_dqa_cmd(mvm); |
| 1158 | if (ret) |
| 1159 | goto error; |
| 1160 | } else { |
| 1161 | IWL_DEBUG_FW(mvm, "Working in non-DQA mode\n"); |
| 1162 | } |
| 1163 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1164 | /* Add auxiliary station for scanning */ |
| 1165 | ret = iwl_mvm_add_aux_sta(mvm); |
| 1166 | if (ret) |
| 1167 | goto error; |
| 1168 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 1169 | /* Add all the PHY contexts */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1170 | chan = &mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[0]; |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 1171 | cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT); |
| 1172 | for (i = 0; i < NUM_PHY_CTX; i++) { |
| 1173 | /* |
| 1174 | * The channel used here isn't relevant as it's |
| 1175 | * going to be overwritten in the other flows. |
| 1176 | * For now use the first channel we have. |
| 1177 | */ |
| 1178 | ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i], |
| 1179 | &chandef, 1, 1); |
| 1180 | if (ret) |
| 1181 | goto error; |
| 1182 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1183 | |
Chaya Rachel Ivgi | c221daf | 2015-12-29 09:54:49 +0200 | [diff] [blame] | 1184 | #ifdef CONFIG_THERMAL |
| 1185 | if (iwl_mvm_is_tt_in_fw(mvm)) { |
| 1186 | /* in order to give the responsibility of ct-kill and |
| 1187 | * TX backoff to FW we need to send empty temperature reporting |
| 1188 | * cmd during init time |
| 1189 | */ |
| 1190 | iwl_mvm_send_temp_report_ths_cmd(mvm); |
| 1191 | } else { |
| 1192 | /* Initialize tx backoffs to the minimal possible */ |
| 1193 | iwl_mvm_tt_tx_backoff(mvm, 0); |
| 1194 | } |
Chaya Rachel Ivgi | 5c89e7b | 2016-01-05 10:34:47 +0200 | [diff] [blame] | 1195 | |
| 1196 | /* TODO: read the budget from BIOS / Platform NVM */ |
Luca Coelho | 75cfe33 | 2016-09-14 11:54:36 +0300 | [diff] [blame] | 1197 | if (iwl_mvm_is_ctdp_supported(mvm) && mvm->cooling_dev.cur_state > 0) { |
Chaya Rachel Ivgi | 5c89e7b | 2016-01-05 10:34:47 +0200 | [diff] [blame] | 1198 | ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START, |
| 1199 | mvm->cooling_dev.cur_state); |
Luca Coelho | 75cfe33 | 2016-09-14 11:54:36 +0300 | [diff] [blame] | 1200 | if (ret) |
| 1201 | goto error; |
| 1202 | } |
Chaya Rachel Ivgi | c221daf | 2015-12-29 09:54:49 +0200 | [diff] [blame] | 1203 | #else |
Ido Yariv | 0c0e2c7 | 2014-01-16 21:12:02 -0500 | [diff] [blame] | 1204 | /* Initialize tx backoffs to the minimal possible */ |
| 1205 | iwl_mvm_tt_tx_backoff(mvm, 0); |
Chaya Rachel Ivgi | c221daf | 2015-12-29 09:54:49 +0200 | [diff] [blame] | 1206 | #endif |
Ido Yariv | 0c0e2c7 | 2014-01-16 21:12:02 -0500 | [diff] [blame] | 1207 | |
Emmanuel Grumbach | 84bfffa | 2015-01-13 10:16:30 +0200 | [diff] [blame] | 1208 | WARN_ON(iwl_mvm_config_ltr(mvm)); |
Emmanuel Grumbach | 9180ac5 | 2014-09-23 23:02:41 +0300 | [diff] [blame] | 1209 | |
Emmanuel Grumbach | c1cb92f | 2014-01-28 10:17:18 +0200 | [diff] [blame] | 1210 | ret = iwl_mvm_power_update_device(mvm); |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 1211 | if (ret) |
| 1212 | goto error; |
| 1213 | |
Arik Nemtsov | 35af15d | 2015-03-04 15:08:00 +0200 | [diff] [blame] | 1214 | /* |
| 1215 | * RTNL is not taken during Ct-kill, but we don't need to scan/Tx |
| 1216 | * anyway, so don't init MCC. |
| 1217 | */ |
| 1218 | if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) { |
| 1219 | ret = iwl_mvm_init_mcc(mvm); |
| 1220 | if (ret) |
| 1221 | goto error; |
| 1222 | } |
Arik Nemtsov | 90d4f7d | 2014-03-04 19:58:46 +0200 | [diff] [blame] | 1223 | |
Johannes Berg | 859d914 | 2015-06-01 17:11:11 +0200 | [diff] [blame] | 1224 | if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { |
Emmanuel Grumbach | 4ca87a5 | 2016-01-03 22:23:40 +0200 | [diff] [blame] | 1225 | mvm->scan_type = IWL_SCAN_TYPE_NOT_SET; |
David Spinadel | d249622 | 2014-05-20 12:46:37 +0300 | [diff] [blame] | 1226 | ret = iwl_mvm_config_scan(mvm); |
| 1227 | if (ret) |
| 1228 | goto error; |
| 1229 | } |
| 1230 | |
Avri Altman | 93190fb | 2014-12-27 09:09:47 +0200 | [diff] [blame] | 1231 | if (iwl_mvm_is_csum_supported(mvm) && |
| 1232 | mvm->cfg->features & NETIF_F_RXCSUM) |
| 1233 | iwl_trans_write_prph(mvm->trans, RX_EN_CSUM, 0x3); |
| 1234 | |
Eliad Peller | 7498cf4 | 2014-01-16 17:10:44 +0200 | [diff] [blame] | 1235 | /* allow FW/transport low power modes if not during restart */ |
| 1236 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
| 1237 | iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN); |
| 1238 | |
Luca Coelho | da2830a | 2016-05-30 13:00:44 +0300 | [diff] [blame] | 1239 | ret = iwl_mvm_sar_init(mvm); |
| 1240 | if (ret) |
| 1241 | goto error; |
| 1242 | |
Ilan Peer | 53a9d61 | 2013-04-28 11:55:08 +0300 | [diff] [blame] | 1243 | IWL_DEBUG_INFO(mvm, "RT uCode started.\n"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1244 | return 0; |
| 1245 | error: |
Chaya Rachel Ivgi | fcb6b92 | 2016-02-22 10:21:41 +0200 | [diff] [blame] | 1246 | iwl_mvm_stop_device(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1247 | return ret; |
| 1248 | } |
| 1249 | |
| 1250 | int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm) |
| 1251 | { |
| 1252 | int ret, i; |
| 1253 | |
| 1254 | lockdep_assert_held(&mvm->mutex); |
| 1255 | |
| 1256 | ret = iwl_trans_start_hw(mvm->trans); |
| 1257 | if (ret) |
| 1258 | return ret; |
| 1259 | |
| 1260 | ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN); |
| 1261 | if (ret) { |
| 1262 | IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret); |
| 1263 | goto error; |
| 1264 | } |
| 1265 | |
Moshe Harel | a054427 | 2014-12-08 21:13:14 +0200 | [diff] [blame] | 1266 | ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1267 | if (ret) |
| 1268 | goto error; |
| 1269 | |
| 1270 | /* Send phy db control command and then phy db calibration*/ |
| 1271 | ret = iwl_send_phy_db_data(mvm->phy_db); |
| 1272 | if (ret) |
| 1273 | goto error; |
| 1274 | |
| 1275 | ret = iwl_send_phy_cfg_cmd(mvm); |
| 1276 | if (ret) |
| 1277 | goto error; |
| 1278 | |
| 1279 | /* init the fw <-> mac80211 STA mapping */ |
| 1280 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) |
| 1281 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL); |
| 1282 | |
| 1283 | /* Add auxiliary station for scanning */ |
| 1284 | ret = iwl_mvm_add_aux_sta(mvm); |
| 1285 | if (ret) |
| 1286 | goto error; |
| 1287 | |
| 1288 | return 0; |
| 1289 | error: |
Chaya Rachel Ivgi | fcb6b92 | 2016-02-22 10:21:41 +0200 | [diff] [blame] | 1290 | iwl_mvm_stop_device(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1291 | return ret; |
| 1292 | } |
| 1293 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 1294 | void iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm, |
| 1295 | struct iwl_rx_cmd_buffer *rxb) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1296 | { |
| 1297 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 1298 | struct iwl_card_state_notif *card_state_notif = (void *)pkt->data; |
| 1299 | u32 flags = le32_to_cpu(card_state_notif->flags); |
| 1300 | |
| 1301 | IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n", |
| 1302 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", |
| 1303 | (flags & SW_CARD_DISABLED) ? "Kill" : "On", |
| 1304 | (flags & CT_KILL_CARD_DISABLED) ? |
| 1305 | "Reached" : "Not reached"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1306 | } |
| 1307 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 1308 | void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm, |
| 1309 | struct iwl_rx_cmd_buffer *rxb) |
Chaya Rachel Ivgy | 30269c1 | 2014-11-15 21:08:29 +0200 | [diff] [blame] | 1310 | { |
| 1311 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 1312 | struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data; |
| 1313 | |
| 1314 | IWL_DEBUG_INFO(mvm, |
| 1315 | "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n", |
| 1316 | le32_to_cpu(mfuart_notif->installed_ver), |
| 1317 | le32_to_cpu(mfuart_notif->external_ver), |
| 1318 | le32_to_cpu(mfuart_notif->status), |
| 1319 | le32_to_cpu(mfuart_notif->duration)); |
Chaya Rachel Ivgy | 30269c1 | 2014-11-15 21:08:29 +0200 | [diff] [blame] | 1320 | } |