blob: 4db1d84749abb69221a62beedb55a58fbb72f357 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
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 Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Eran Harary8d193ca2015-04-27 10:29:31 +03009 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Sara Sharon43413a92015-12-31 11:49:18 +020010 * Copyright(c) 2016 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010011 *
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 Grumbach410dc5a2013-02-18 09:22:28 +020027 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010028 *
29 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020030 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg8ca151b2013-01-24 14:25:36 +010031 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020035 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Eran Harary8d193ca2015-04-27 10:29:31 +030036 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010037 * 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 Sharon854d7732016-03-22 15:55:58 +020067#include <linux/netdevice.h>
Luca Coelhoda2830a2016-05-30 13:00:44 +030068#include <linux/acpi.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010069
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 Grumbach8c23f952014-12-04 10:07:47 +020076#include "iwl-prph.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010077#include "iwl-eeprom-parse.h"
78
79#include "mvm.h"
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +020080#include "fw-dbg.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010081#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 Berg8ca151b2013-01-24 14:25:36 +010088struct iwl_mvm_alive_data {
89 bool valid;
90 u32 scd_base_addr;
91};
92
93static inline const struct fw_img *
94iwl_get_ucode_image(struct iwl_mvm *mvm, enum iwl_ucode_type ucode_type)
95{
96 if (ucode_type >= IWL_UCODE_TYPE_MAX)
97 return NULL;
98
99 return &mvm->fw->img[ucode_type];
100}
101
102static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant)
103{
104 struct iwl_tx_ant_cfg_cmd tx_ant_cmd = {
105 .valid = cpu_to_le32(valid_tx_ant),
106 };
107
Emmanuel Grumbach33223542013-03-09 20:38:19 +0200108 IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant);
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300109 return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100110 sizeof(tx_ant_cmd), &tx_ant_cmd);
111}
112
Sara Sharon43413a92015-12-31 11:49:18 +0200113static int iwl_send_rss_cfg_cmd(struct iwl_mvm *mvm)
114{
115 int i;
116 struct iwl_rss_config_cmd cmd = {
117 .flags = cpu_to_le32(IWL_RSS_ENABLE),
118 .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
Sara Sharon854d7732016-03-22 15:55:58 +0200119 IWL_RSS_HASH_TYPE_IPV4_UDP |
Sara Sharon43413a92015-12-31 11:49:18 +0200120 IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
121 IWL_RSS_HASH_TYPE_IPV6_TCP |
Sara Sharon854d7732016-03-22 15:55:58 +0200122 IWL_RSS_HASH_TYPE_IPV6_UDP |
Sara Sharon43413a92015-12-31 11:49:18 +0200123 IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
124 };
125
Sara Sharonf43495f2016-05-04 14:22:10 +0300126 if (mvm->trans->num_rx_queues == 1)
127 return 0;
128
Sara Sharon854d7732016-03-22 15:55:58 +0200129 /* Do not direct RSS traffic to Q 0 which is our fallback queue */
Sara Sharon43413a92015-12-31 11:49:18 +0200130 for (i = 0; i < ARRAY_SIZE(cmd.indirection_table); i++)
Sara Sharon854d7732016-03-22 15:55:58 +0200131 cmd.indirection_table[i] =
132 1 + (i % (mvm->trans->num_rx_queues - 1));
133 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
Sara Sharon43413a92015-12-31 11:49:18 +0200134
135 return iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd);
136}
137
Liad Kaufman97d5be72015-08-31 14:33:23 +0300138static int iwl_mvm_send_dqa_cmd(struct iwl_mvm *mvm)
139{
140 struct iwl_dqa_enable_cmd dqa_cmd = {
141 .cmd_queue = cpu_to_le32(IWL_MVM_DQA_CMD_QUEUE),
142 };
143 u32 cmd_id = iwl_cmd_id(DQA_ENABLE_CMD, DATA_PATH_GROUP, 0);
144 int ret;
145
146 ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(dqa_cmd), &dqa_cmd);
147 if (ret)
148 IWL_ERR(mvm, "Failed to send DQA enabling command: %d\n", ret);
149 else
150 IWL_DEBUG_FW(mvm, "Working in DQA mode\n");
151
152 return ret;
153}
154
Matti Gottlieb905e36a2016-02-14 17:05:39 +0200155void iwl_free_fw_paging(struct iwl_mvm *mvm)
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300156{
157 int i;
158
159 if (!mvm->fw_paging_db[0].fw_paging_block)
160 return;
161
162 for (i = 0; i < NUM_OF_FW_PAGING_BLOCKS; i++) {
163 if (!mvm->fw_paging_db[i].fw_paging_block) {
164 IWL_DEBUG_FW(mvm,
165 "Paging: block %d already freed, continue to next page\n",
166 i);
167
168 continue;
169 }
170
171 __free_pages(mvm->fw_paging_db[i].fw_paging_block,
172 get_order(mvm->fw_paging_db[i].fw_paging_size));
Matti Gottliebf742aaf2016-04-10 10:53:57 +0300173 mvm->fw_paging_db[i].fw_paging_block = NULL;
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300174 }
Matti Gottliebe1120182015-07-19 11:15:07 +0300175 kfree(mvm->trans->paging_download_buf);
Matti Gottlieb905e36a2016-02-14 17:05:39 +0200176 mvm->trans->paging_download_buf = NULL;
Matti Gottliebf742aaf2016-04-10 10:53:57 +0300177 mvm->trans->paging_db = NULL;
Matti Gottlieb905e36a2016-02-14 17:05:39 +0200178
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300179 memset(mvm->fw_paging_db, 0, sizeof(mvm->fw_paging_db));
180}
181
182static int iwl_fill_paging_mem(struct iwl_mvm *mvm, const struct fw_img *image)
183{
184 int sec_idx, idx;
185 u32 offset = 0;
186
187 /*
188 * find where is the paging image start point:
189 * if CPU2 exist and it's in paging format, then the image looks like:
190 * CPU1 sections (2 or more)
191 * CPU1_CPU2_SEPARATOR_SECTION delimiter - separate between CPU1 to CPU2
192 * CPU2 sections (not paged)
193 * PAGING_SEPARATOR_SECTION delimiter - separate between CPU2
194 * non paged to CPU2 paging sec
195 * CPU2 paging CSS
196 * CPU2 paging image (including instruction and data)
197 */
198 for (sec_idx = 0; sec_idx < IWL_UCODE_SECTION_MAX; sec_idx++) {
199 if (image->sec[sec_idx].offset == PAGING_SEPARATOR_SECTION) {
200 sec_idx++;
201 break;
202 }
203 }
204
Matti Gottliebcd47a3d2016-03-10 16:18:26 +0200205 /*
206 * If paging is enabled there should be at least 2 more sections left
207 * (one for CSS and one for Paging data)
208 */
209 if (sec_idx >= ARRAY_SIZE(image->sec) - 1) {
210 IWL_ERR(mvm, "Paging: Missing CSS and/or paging sections\n");
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300211 iwl_free_fw_paging(mvm);
212 return -EINVAL;
213 }
214
215 /* copy the CSS block to the dram */
216 IWL_DEBUG_FW(mvm, "Paging: load paging CSS to FW, sec = %d\n",
217 sec_idx);
218
219 memcpy(page_address(mvm->fw_paging_db[0].fw_paging_block),
220 image->sec[sec_idx].data,
221 mvm->fw_paging_db[0].fw_paging_size);
222
223 IWL_DEBUG_FW(mvm,
224 "Paging: copied %d CSS bytes to first block\n",
225 mvm->fw_paging_db[0].fw_paging_size);
226
227 sec_idx++;
228
229 /*
230 * copy the paging blocks to the dram
231 * loop index start from 1 since that CSS block already copied to dram
232 * and CSS index is 0.
233 * loop stop at num_of_paging_blk since that last block is not full.
234 */
235 for (idx = 1; idx < mvm->num_of_paging_blk; idx++) {
236 memcpy(page_address(mvm->fw_paging_db[idx].fw_paging_block),
237 image->sec[sec_idx].data + offset,
238 mvm->fw_paging_db[idx].fw_paging_size);
239
240 IWL_DEBUG_FW(mvm,
241 "Paging: copied %d paging bytes to block %d\n",
242 mvm->fw_paging_db[idx].fw_paging_size,
243 idx);
244
245 offset += mvm->fw_paging_db[idx].fw_paging_size;
246 }
247
248 /* copy the last paging block */
249 if (mvm->num_of_pages_in_last_blk > 0) {
250 memcpy(page_address(mvm->fw_paging_db[idx].fw_paging_block),
251 image->sec[sec_idx].data + offset,
252 FW_PAGING_SIZE * mvm->num_of_pages_in_last_blk);
253
254 IWL_DEBUG_FW(mvm,
255 "Paging: copied %d pages in the last block %d\n",
256 mvm->num_of_pages_in_last_blk, idx);
257 }
258
259 return 0;
260}
261
262static int iwl_alloc_fw_paging_mem(struct iwl_mvm *mvm,
263 const struct fw_img *image)
264{
265 struct page *block;
266 dma_addr_t phys = 0;
267 int blk_idx = 0;
268 int order, num_of_pages;
269 int dma_enabled;
270
271 if (mvm->fw_paging_db[0].fw_paging_block)
272 return 0;
273
274 dma_enabled = is_device_dma_capable(mvm->trans->dev);
275
276 /* ensure BLOCK_2_EXP_SIZE is power of 2 of PAGING_BLOCK_SIZE */
277 BUILD_BUG_ON(BIT(BLOCK_2_EXP_SIZE) != PAGING_BLOCK_SIZE);
278
279 num_of_pages = image->paging_mem_size / FW_PAGING_SIZE;
280 mvm->num_of_paging_blk = ((num_of_pages - 1) /
281 NUM_OF_PAGE_PER_GROUP) + 1;
282
283 mvm->num_of_pages_in_last_blk =
284 num_of_pages -
285 NUM_OF_PAGE_PER_GROUP * (mvm->num_of_paging_blk - 1);
286
287 IWL_DEBUG_FW(mvm,
288 "Paging: allocating mem for %d paging blocks, each block holds 8 pages, last block holds %d pages\n",
289 mvm->num_of_paging_blk,
290 mvm->num_of_pages_in_last_blk);
291
292 /* allocate block of 4Kbytes for paging CSS */
293 order = get_order(FW_PAGING_SIZE);
294 block = alloc_pages(GFP_KERNEL, order);
295 if (!block) {
296 /* free all the previous pages since we failed */
297 iwl_free_fw_paging(mvm);
298 return -ENOMEM;
299 }
300
301 mvm->fw_paging_db[blk_idx].fw_paging_block = block;
302 mvm->fw_paging_db[blk_idx].fw_paging_size = FW_PAGING_SIZE;
303
304 if (dma_enabled) {
305 phys = dma_map_page(mvm->trans->dev, block, 0,
306 PAGE_SIZE << order, DMA_BIDIRECTIONAL);
307 if (dma_mapping_error(mvm->trans->dev, phys)) {
308 /*
309 * free the previous pages and the current one since
310 * we failed to map_page.
311 */
312 iwl_free_fw_paging(mvm);
313 return -ENOMEM;
314 }
315 mvm->fw_paging_db[blk_idx].fw_paging_phys = phys;
Matti Gottliebe1120182015-07-19 11:15:07 +0300316 } else {
317 mvm->fw_paging_db[blk_idx].fw_paging_phys = PAGING_ADDR_SIG |
318 blk_idx << BLOCK_2_EXP_SIZE;
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300319 }
320
321 IWL_DEBUG_FW(mvm,
322 "Paging: allocated 4K(CSS) bytes (order %d) for firmware paging.\n",
323 order);
324
325 /*
326 * allocate blocks in dram.
327 * since that CSS allocated in fw_paging_db[0] loop start from index 1
328 */
329 for (blk_idx = 1; blk_idx < mvm->num_of_paging_blk + 1; blk_idx++) {
330 /* allocate block of PAGING_BLOCK_SIZE (32K) */
331 order = get_order(PAGING_BLOCK_SIZE);
332 block = alloc_pages(GFP_KERNEL, order);
333 if (!block) {
334 /* free all the previous pages since we failed */
335 iwl_free_fw_paging(mvm);
336 return -ENOMEM;
337 }
338
339 mvm->fw_paging_db[blk_idx].fw_paging_block = block;
340 mvm->fw_paging_db[blk_idx].fw_paging_size = PAGING_BLOCK_SIZE;
341
342 if (dma_enabled) {
343 phys = dma_map_page(mvm->trans->dev, block, 0,
344 PAGE_SIZE << order,
345 DMA_BIDIRECTIONAL);
346 if (dma_mapping_error(mvm->trans->dev, phys)) {
347 /*
348 * free the previous pages and the current one
349 * since we failed to map_page.
350 */
351 iwl_free_fw_paging(mvm);
352 return -ENOMEM;
353 }
354 mvm->fw_paging_db[blk_idx].fw_paging_phys = phys;
Matti Gottliebe1120182015-07-19 11:15:07 +0300355 } else {
356 mvm->fw_paging_db[blk_idx].fw_paging_phys =
357 PAGING_ADDR_SIG |
358 blk_idx << BLOCK_2_EXP_SIZE;
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300359 }
360
361 IWL_DEBUG_FW(mvm,
362 "Paging: allocated 32K bytes (order %d) for firmware paging.\n",
363 order);
364 }
365
366 return 0;
367}
368
369static int iwl_save_fw_paging(struct iwl_mvm *mvm,
370 const struct fw_img *fw)
371{
372 int ret;
373
374 ret = iwl_alloc_fw_paging_mem(mvm, fw);
375 if (ret)
376 return ret;
377
378 return iwl_fill_paging_mem(mvm, fw);
379}
380
381/* send paging cmd to FW in case CPU2 has paging image */
382static int iwl_send_paging_cmd(struct iwl_mvm *mvm, const struct fw_img *fw)
383{
384 int blk_idx;
385 __le32 dev_phy_addr;
386 struct iwl_fw_paging_cmd fw_paging_cmd = {
387 .flags =
388 cpu_to_le32(PAGING_CMD_IS_SECURED |
389 PAGING_CMD_IS_ENABLED |
390 (mvm->num_of_pages_in_last_blk <<
391 PAGING_CMD_NUM_OF_PAGES_IN_LAST_GRP_POS)),
392 .block_size = cpu_to_le32(BLOCK_2_EXP_SIZE),
393 .block_num = cpu_to_le32(mvm->num_of_paging_blk),
394 };
395
396 /* loop for for all paging blocks + CSS block */
397 for (blk_idx = 0; blk_idx < mvm->num_of_paging_blk + 1; blk_idx++) {
398 dev_phy_addr =
399 cpu_to_le32(mvm->fw_paging_db[blk_idx].fw_paging_phys >>
400 PAGE_2_EXP_SIZE);
401 fw_paging_cmd.device_phy_addr[blk_idx] = dev_phy_addr;
402 }
403
404 return iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(FW_PAGING_BLOCK_CMD,
405 IWL_ALWAYS_LONG_GROUP, 0),
406 0, sizeof(fw_paging_cmd), &fw_paging_cmd);
407}
408
Matti Gottliebe1120182015-07-19 11:15:07 +0300409/*
410 * Send paging item cmd to FW in case CPU2 has paging image
411 */
412static int iwl_trans_get_paging_item(struct iwl_mvm *mvm)
413{
414 int ret;
415 struct iwl_fw_get_item_cmd fw_get_item_cmd = {
416 .item_id = cpu_to_le32(IWL_FW_ITEM_ID_PAGING),
417 };
418
419 struct iwl_fw_get_item_resp *item_resp;
420 struct iwl_host_cmd cmd = {
421 .id = iwl_cmd_id(FW_GET_ITEM_CMD, IWL_ALWAYS_LONG_GROUP, 0),
422 .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
423 .data = { &fw_get_item_cmd, },
424 };
425
426 cmd.len[0] = sizeof(struct iwl_fw_get_item_cmd);
427
428 ret = iwl_mvm_send_cmd(mvm, &cmd);
429 if (ret) {
430 IWL_ERR(mvm,
431 "Paging: Failed to send FW_GET_ITEM_CMD cmd (err = %d)\n",
432 ret);
433 return ret;
434 }
435
436 item_resp = (void *)((struct iwl_rx_packet *)cmd.resp_pkt)->data;
437 if (item_resp->item_id != cpu_to_le32(IWL_FW_ITEM_ID_PAGING)) {
438 IWL_ERR(mvm,
439 "Paging: got wrong item in FW_GET_ITEM_CMD resp (item_id = %u)\n",
440 le32_to_cpu(item_resp->item_id));
441 ret = -EIO;
442 goto exit;
443 }
444
Matti Gottliebc94d7992016-03-09 10:54:10 +0200445 /* Add an extra page for headers */
446 mvm->trans->paging_download_buf = kzalloc(PAGING_BLOCK_SIZE +
447 FW_PAGING_SIZE,
Matti Gottliebe1120182015-07-19 11:15:07 +0300448 GFP_KERNEL);
449 if (!mvm->trans->paging_download_buf) {
450 ret = -ENOMEM;
451 goto exit;
452 }
453 mvm->trans->paging_req_addr = le32_to_cpu(item_resp->item_val);
454 mvm->trans->paging_db = mvm->fw_paging_db;
455 IWL_DEBUG_FW(mvm,
456 "Paging: got paging request address (paging_req_addr 0x%08x)\n",
457 mvm->trans->paging_req_addr);
458
459exit:
460 iwl_free_resp(&cmd);
461
462 return ret;
463}
464
Johannes Berg8ca151b2013-01-24 14:25:36 +0100465static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
466 struct iwl_rx_packet *pkt, void *data)
467{
468 struct iwl_mvm *mvm =
469 container_of(notif_wait, struct iwl_mvm, notif_wait);
470 struct iwl_mvm_alive_data *alive_data = data;
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200471 struct mvm_alive_resp_ver1 *palive1;
Eran Harary01a9ca52014-02-03 09:29:57 +0200472 struct mvm_alive_resp_ver2 *palive2;
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200473 struct mvm_alive_resp *palive;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100474
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200475 if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive1)) {
476 palive1 = (void *)pkt->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100477
Eran Harary01a9ca52014-02-03 09:29:57 +0200478 mvm->support_umac_log = false;
479 mvm->error_event_table =
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200480 le32_to_cpu(palive1->error_event_table_ptr);
481 mvm->log_event_table =
482 le32_to_cpu(palive1->log_event_table_ptr);
483 alive_data->scd_base_addr = le32_to_cpu(palive1->scd_base_ptr);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100484
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200485 alive_data->valid = le16_to_cpu(palive1->status) ==
Eran Harary01a9ca52014-02-03 09:29:57 +0200486 IWL_ALIVE_STATUS_OK;
487 IWL_DEBUG_FW(mvm,
488 "Alive VER1 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n",
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200489 le16_to_cpu(palive1->status), palive1->ver_type,
490 palive1->ver_subtype, palive1->flags);
491 } else if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive2)) {
Eran Harary01a9ca52014-02-03 09:29:57 +0200492 palive2 = (void *)pkt->data;
493
Eran Harary01a9ca52014-02-03 09:29:57 +0200494 mvm->error_event_table =
495 le32_to_cpu(palive2->error_event_table_ptr);
496 mvm->log_event_table =
497 le32_to_cpu(palive2->log_event_table_ptr);
498 alive_data->scd_base_addr = le32_to_cpu(palive2->scd_base_ptr);
499 mvm->umac_error_event_table =
500 le32_to_cpu(palive2->error_info_addr);
Eran Harary91479b62014-05-11 08:11:34 +0300501 mvm->sf_space.addr = le32_to_cpu(palive2->st_fwrd_addr);
502 mvm->sf_space.size = le32_to_cpu(palive2->st_fwrd_size);
Eran Harary01a9ca52014-02-03 09:29:57 +0200503
504 alive_data->valid = le16_to_cpu(palive2->status) ==
505 IWL_ALIVE_STATUS_OK;
Emmanuel Grumbachffa70262014-02-11 16:37:34 +0200506 if (mvm->umac_error_event_table)
507 mvm->support_umac_log = true;
508
Eran Harary01a9ca52014-02-03 09:29:57 +0200509 IWL_DEBUG_FW(mvm,
510 "Alive VER2 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n",
511 le16_to_cpu(palive2->status), palive2->ver_type,
512 palive2->ver_subtype, palive2->flags);
513
514 IWL_DEBUG_FW(mvm,
515 "UMAC version: Major - 0x%x, Minor - 0x%x\n",
516 palive2->umac_major, palive2->umac_minor);
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200517 } else if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive)) {
518 palive = (void *)pkt->data;
519
520 mvm->error_event_table =
521 le32_to_cpu(palive->error_event_table_ptr);
522 mvm->log_event_table =
523 le32_to_cpu(palive->log_event_table_ptr);
524 alive_data->scd_base_addr = le32_to_cpu(palive->scd_base_ptr);
525 mvm->umac_error_event_table =
526 le32_to_cpu(palive->error_info_addr);
527 mvm->sf_space.addr = le32_to_cpu(palive->st_fwrd_addr);
528 mvm->sf_space.size = le32_to_cpu(palive->st_fwrd_size);
529
530 alive_data->valid = le16_to_cpu(palive->status) ==
531 IWL_ALIVE_STATUS_OK;
532 if (mvm->umac_error_event_table)
533 mvm->support_umac_log = true;
534
535 IWL_DEBUG_FW(mvm,
536 "Alive VER3 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n",
537 le16_to_cpu(palive->status), palive->ver_type,
538 palive->ver_subtype, palive->flags);
539
540 IWL_DEBUG_FW(mvm,
541 "UMAC version: Major - 0x%x, Minor - 0x%x\n",
542 le32_to_cpu(palive->umac_major),
543 le32_to_cpu(palive->umac_minor));
Eran Harary01a9ca52014-02-03 09:29:57 +0200544 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100545
546 return true;
547}
548
549static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
550 struct iwl_rx_packet *pkt, void *data)
551{
552 struct iwl_phy_db *phy_db = data;
553
554 if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
555 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
556 return true;
557 }
558
Sara Sharonce1f2772016-04-10 16:02:12 +0300559 WARN_ON(iwl_phy_db_set_section(phy_db, pkt));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100560
561 return false;
562}
563
564static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
565 enum iwl_ucode_type ucode_type)
566{
567 struct iwl_notification_wait alive_wait;
568 struct iwl_mvm_alive_data alive_data;
569 const struct fw_img *fw;
570 int ret, i;
571 enum iwl_ucode_type old_type = mvm->cur_ucode;
Sara Sharon6eb031d2015-07-13 14:50:47 +0300572 static const u16 alive_cmd[] = { MVM_ALIVE };
Eran Harary91479b62014-05-11 08:11:34 +0300573 struct iwl_sf_region st_fwrd_space;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100574
Eran Harary61df7502014-12-01 17:40:37 +0200575 if (ucode_type == IWL_UCODE_REGULAR &&
Golan Ben-Ami3d2d4422016-02-23 10:34:48 +0200576 iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) &&
577 !(fw_has_capa(&mvm->fw->ucode_capa,
578 IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED)))
Eran Harary61df7502014-12-01 17:40:37 +0200579 fw = iwl_get_ucode_image(mvm, IWL_UCODE_REGULAR_USNIFFER);
580 else
581 fw = iwl_get_ucode_image(mvm, ucode_type);
Johannes Bergbefe9b62013-10-25 12:32:51 +0200582 if (WARN_ON(!fw))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100583 return -EINVAL;
Johannes Bergbefe9b62013-10-25 12:32:51 +0200584 mvm->cur_ucode = ucode_type;
585 mvm->ucode_loaded = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100586
587 iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
588 alive_cmd, ARRAY_SIZE(alive_cmd),
589 iwl_alive_fn, &alive_data);
590
591 ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT);
592 if (ret) {
593 mvm->cur_ucode = old_type;
594 iwl_remove_notification(&mvm->notif_wait, &alive_wait);
595 return ret;
596 }
597
598 /*
599 * Some things may run in the background now, but we
600 * just wait for the ALIVE notification here.
601 */
602 ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
603 MVM_UCODE_ALIVE_TIMEOUT);
604 if (ret) {
Dor Shaish192de2b2015-07-15 11:41:21 +0300605 if (mvm->trans->cfg->device_family == IWL_DEVICE_FAMILY_8000)
606 IWL_ERR(mvm,
607 "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
608 iwl_read_prph(mvm->trans, SB_CPU_1_STATUS),
609 iwl_read_prph(mvm->trans, SB_CPU_2_STATUS));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100610 mvm->cur_ucode = old_type;
611 return ret;
612 }
613
614 if (!alive_data.valid) {
615 IWL_ERR(mvm, "Loaded ucode is not valid!\n");
616 mvm->cur_ucode = old_type;
617 return -EIO;
618 }
619
Eran Harary91479b62014-05-11 08:11:34 +0300620 /*
621 * update the sdio allocation according to the pointer we get in the
622 * alive notification.
623 */
624 st_fwrd_space.addr = mvm->sf_space.addr;
625 st_fwrd_space.size = mvm->sf_space.size;
626 ret = iwl_trans_update_sf(mvm->trans, &st_fwrd_space);
Eyal Shapira82e8aea2014-10-19 14:56:40 +0300627 if (ret) {
628 IWL_ERR(mvm, "Failed to update SF size. ret %d\n", ret);
629 return ret;
630 }
Eran Harary91479b62014-05-11 08:11:34 +0300631
Johannes Berg8ca151b2013-01-24 14:25:36 +0100632 iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
633
634 /*
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300635 * configure and operate fw paging mechanism.
636 * driver configures the paging flow only once, CPU2 paging image
637 * included in the IWL_UCODE_INIT image.
638 */
639 if (fw->paging_mem_size) {
Matti Gottliebe1120182015-07-19 11:15:07 +0300640 /*
641 * When dma is not enabled, the driver needs to copy / write
642 * the downloaded / uploaded page to / from the smem.
643 * This gets the location of the place were the pages are
644 * stored.
645 */
646 if (!is_device_dma_capable(mvm->trans->dev)) {
647 ret = iwl_trans_get_paging_item(mvm);
648 if (ret) {
649 IWL_ERR(mvm, "failed to get FW paging item\n");
650 return ret;
651 }
652 }
653
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300654 ret = iwl_save_fw_paging(mvm, fw);
655 if (ret) {
656 IWL_ERR(mvm, "failed to save the FW paging image\n");
657 return ret;
658 }
659
660 ret = iwl_send_paging_cmd(mvm, fw);
661 if (ret) {
662 IWL_ERR(mvm, "failed to send the paging cmd\n");
663 iwl_free_fw_paging(mvm);
664 return ret;
665 }
666 }
667
668 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +0100669 * Note: all the queues are enabled as part of the interface
670 * initialization, but in firmware restart scenarios they
671 * could be stopped, so wake them up. In firmware restart,
672 * mac80211 will have the queues stopped as well until the
673 * reconfiguration completes. During normal startup, they
674 * will be empty.
675 */
676
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300677 memset(&mvm->queue_info, 0, sizeof(mvm->queue_info));
Liad Kaufman097129c2015-08-09 18:28:43 +0300678 if (iwl_mvm_is_dqa_supported(mvm))
679 mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].hw_queue_refcount = 1;
680 else
681 mvm->queue_info[IWL_MVM_CMD_QUEUE].hw_queue_refcount = 1;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100682
Johannes Bergdf197c02014-08-01 18:14:45 +0200683 for (i = 0; i < IEEE80211_MAX_QUEUES; i++)
684 atomic_set(&mvm->mac80211_queue_stop_count[i], 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100685
686 mvm->ucode_loaded = true;
687
688 return 0;
689}
Johannes Berg8ca151b2013-01-24 14:25:36 +0100690
691static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
692{
693 struct iwl_phy_cfg_cmd phy_cfg_cmd;
694 enum iwl_ucode_type ucode_type = mvm->cur_ucode;
695
696 /* Set parameters */
Moshe Harela0544272014-12-08 21:13:14 +0200697 phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100698 phy_cfg_cmd.calib_control.event_trigger =
699 mvm->fw->default_calib[ucode_type].event_trigger;
700 phy_cfg_cmd.calib_control.flow_trigger =
701 mvm->fw->default_calib[ucode_type].flow_trigger;
702
703 IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
704 phy_cfg_cmd.phy_cfg);
705
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300706 return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100707 sizeof(phy_cfg_cmd), &phy_cfg_cmd);
708}
709
Johannes Berg8ca151b2013-01-24 14:25:36 +0100710int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
711{
712 struct iwl_notification_wait calib_wait;
Sara Sharon6eb031d2015-07-13 14:50:47 +0300713 static const u16 init_complete[] = {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100714 INIT_COMPLETE_NOTIF,
715 CALIB_RES_NOTIF_PHY_DB
716 };
717 int ret;
718
719 lockdep_assert_held(&mvm->mutex);
720
Eran Harary8d193ca2015-04-27 10:29:31 +0300721 if (WARN_ON_ONCE(mvm->calibrating))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100722 return 0;
723
724 iwl_init_notification_wait(&mvm->notif_wait,
725 &calib_wait,
726 init_complete,
727 ARRAY_SIZE(init_complete),
728 iwl_wait_phy_db_entry,
729 mvm->phy_db);
730
731 /* Will also start the device */
732 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
733 if (ret) {
734 IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
735 goto error;
736 }
737
Emmanuel Grumbachae397472014-03-30 16:55:18 +0300738 ret = iwl_send_bt_init_conf(mvm);
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200739 if (ret)
740 goto error;
741
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200742 /* Read the NVM only at driver load time, no need to do this twice */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100743 if (read_nvm) {
744 /* Read nvm */
Eran Harary14b485f2014-04-23 10:46:09 +0300745 ret = iwl_nvm_init(mvm, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100746 if (ret) {
747 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
748 goto error;
749 }
750 }
751
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200752 /* In case we read the NVM from external file, load it to the NIC */
Eran Hararye02a9d62014-05-07 12:27:10 +0300753 if (mvm->nvm_file_name)
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200754 iwl_mvm_load_nvm_to_nic(mvm);
755
Johannes Berg8ca151b2013-01-24 14:25:36 +0100756 ret = iwl_nvm_check_version(mvm->nvm_data, mvm->trans);
757 WARN_ON(ret);
758
Eran Harary4f593342013-05-13 07:53:26 +0300759 /*
760 * abort after reading the nvm in case RF Kill is on, we will complete
761 * the init seq later when RF kill will switch to off
762 */
Arik Nemtsov1a3fe0b2015-09-30 11:19:55 +0300763 if (iwl_mvm_is_radio_hw_killed(mvm)) {
Eran Harary4f593342013-05-13 07:53:26 +0300764 IWL_DEBUG_RF_KILL(mvm,
765 "jump over all phy activities due to RF kill\n");
766 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
Arik Nemtsova4082842013-11-24 19:10:46 +0200767 ret = 1;
768 goto out;
Eran Harary4f593342013-05-13 07:53:26 +0300769 }
770
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200771 mvm->calibrating = true;
772
Dor Shaishe07cbb52013-02-27 23:00:27 +0200773 /* Send TX valid antennas before triggering calibrations */
Moshe Harela0544272014-12-08 21:13:14 +0200774 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Dor Shaishe07cbb52013-02-27 23:00:27 +0200775 if (ret)
776 goto error;
777
Johannes Berg8ca151b2013-01-24 14:25:36 +0100778 /*
779 * Send phy configurations command to init uCode
780 * to start the 16.0 uCode init image internal calibrations.
781 */
782 ret = iwl_send_phy_cfg_cmd(mvm);
783 if (ret) {
784 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
785 ret);
786 goto error;
787 }
788
789 /*
790 * Some things may run in the background now, but we
791 * just wait for the calibration complete notification.
792 */
793 ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
794 MVM_UCODE_CALIB_TIMEOUT);
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200795
Arik Nemtsov1a3fe0b2015-09-30 11:19:55 +0300796 if (ret && iwl_mvm_is_radio_hw_killed(mvm)) {
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200797 IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
798 ret = 1;
799 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100800 goto out;
801
802error:
803 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
804out:
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200805 mvm->calibrating = false;
Arik Nemtsova4082842013-11-24 19:10:46 +0200806 if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100807 /* we want to debug INIT and we have no NVM - fake */
808 mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
809 sizeof(struct ieee80211_channel) +
810 sizeof(struct ieee80211_rate),
811 GFP_KERNEL);
812 if (!mvm->nvm_data)
813 return -ENOMEM;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100814 mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
815 mvm->nvm_data->bands[0].n_channels = 1;
816 mvm->nvm_data->bands[0].n_bitrates = 1;
817 mvm->nvm_data->bands[0].bitrates =
818 (void *)mvm->nvm_data->channels + 1;
819 mvm->nvm_data->bands[0].bitrates->hw_value = 10;
820 }
821
822 return ret;
823}
824
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200825static void iwl_mvm_get_shared_mem_conf(struct iwl_mvm *mvm)
826{
827 struct iwl_host_cmd cmd = {
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200828 .flags = CMD_WANT_SKB,
829 .data = { NULL, },
830 .len = { 0, },
831 };
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200832 struct iwl_shared_mem_cfg *mem_cfg;
Golan Ben-Ami5b086412016-02-09 12:57:16 +0200833 struct iwl_rx_packet *pkt;
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200834 u32 i;
835
836 lockdep_assert_held(&mvm->mutex);
837
Golan Ben-Ami5b086412016-02-09 12:57:16 +0200838 if (fw_has_capa(&mvm->fw->ucode_capa,
839 IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG))
840 cmd.id = iwl_cmd_id(SHARED_MEM_CFG_CMD, SYSTEM_GROUP, 0);
841 else
842 cmd.id = SHARED_MEM_CFG;
843
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200844 if (WARN_ON(iwl_mvm_send_cmd(mvm, &cmd)))
845 return;
846
847 pkt = cmd.resp_pkt;
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200848 mem_cfg = (void *)pkt->data;
849
850 mvm->shared_mem_cfg.shared_mem_addr =
851 le32_to_cpu(mem_cfg->shared_mem_addr);
852 mvm->shared_mem_cfg.shared_mem_size =
853 le32_to_cpu(mem_cfg->shared_mem_size);
854 mvm->shared_mem_cfg.sample_buff_addr =
855 le32_to_cpu(mem_cfg->sample_buff_addr);
856 mvm->shared_mem_cfg.sample_buff_size =
857 le32_to_cpu(mem_cfg->sample_buff_size);
858 mvm->shared_mem_cfg.txfifo_addr = le32_to_cpu(mem_cfg->txfifo_addr);
859 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++)
860 mvm->shared_mem_cfg.txfifo_size[i] =
861 le32_to_cpu(mem_cfg->txfifo_size[i]);
862 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++)
863 mvm->shared_mem_cfg.rxfifo_size[i] =
864 le32_to_cpu(mem_cfg->rxfifo_size[i]);
865 mvm->shared_mem_cfg.page_buff_addr =
866 le32_to_cpu(mem_cfg->page_buff_addr);
867 mvm->shared_mem_cfg.page_buff_size =
868 le32_to_cpu(mem_cfg->page_buff_size);
Golan Ben-Ami5b086412016-02-09 12:57:16 +0200869
870 /* new API has more data */
871 if (fw_has_capa(&mvm->fw->ucode_capa,
872 IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) {
873 mvm->shared_mem_cfg.rxfifo_addr =
874 le32_to_cpu(mem_cfg->rxfifo_addr);
875 mvm->shared_mem_cfg.internal_txfifo_addr =
876 le32_to_cpu(mem_cfg->internal_txfifo_addr);
877
878 BUILD_BUG_ON(sizeof(mvm->shared_mem_cfg.internal_txfifo_size) !=
879 sizeof(mem_cfg->internal_txfifo_size));
880
881 for (i = 0;
882 i < ARRAY_SIZE(mvm->shared_mem_cfg.internal_txfifo_size);
883 i++)
884 mvm->shared_mem_cfg.internal_txfifo_size[i] =
885 le32_to_cpu(mem_cfg->internal_txfifo_size[i]);
886 }
887
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200888 IWL_DEBUG_INFO(mvm, "SHARED MEM CFG: got memory offsets/sizes\n");
889
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200890 iwl_free_resp(&cmd);
891}
892
Emmanuel Grumbach84bfffa2015-01-13 10:16:30 +0200893static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
894{
895 struct iwl_ltr_config_cmd cmd = {
896 .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
897 };
898
899 if (!mvm->trans->ltr_enabled)
900 return 0;
901
Emmanuel Grumbach84bfffa2015-01-13 10:16:30 +0200902 return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
903 sizeof(cmd), &cmd);
904}
905
Luca Coelhoda2830a2016-05-30 13:00:44 +0300906#define ACPI_WRDS_METHOD "WRDS"
907#define ACPI_WRDS_WIFI (0x07)
908#define ACPI_WRDS_TABLE_SIZE 10
909
910struct iwl_mvm_sar_table {
911 bool enabled;
912 u8 values[ACPI_WRDS_TABLE_SIZE];
913};
914
915#ifdef CONFIG_ACPI
916static int iwl_mvm_sar_get_wrds(struct iwl_mvm *mvm, union acpi_object *wrds,
917 struct iwl_mvm_sar_table *sar_table)
918{
919 union acpi_object *data_pkg;
920 u32 i;
921
922 /* We need at least two packages, one for the revision and one
923 * for the data itself. Also check that the revision is valid
924 * (i.e. it is an integer set to 0).
925 */
926 if (wrds->type != ACPI_TYPE_PACKAGE ||
927 wrds->package.count < 2 ||
928 wrds->package.elements[0].type != ACPI_TYPE_INTEGER ||
929 wrds->package.elements[0].integer.value != 0) {
930 IWL_DEBUG_RADIO(mvm, "Unsupported wrds structure\n");
931 return -EINVAL;
932 }
933
934 /* loop through all the packages to find the one for WiFi */
935 for (i = 1; i < wrds->package.count; i++) {
936 union acpi_object *domain;
937
938 data_pkg = &wrds->package.elements[i];
939
940 /* Skip anything that is not a package with the right
941 * amount of elements (i.e. domain_type,
942 * enabled/disabled plus the sar table size.
943 */
944 if (data_pkg->type != ACPI_TYPE_PACKAGE ||
945 data_pkg->package.count != ACPI_WRDS_TABLE_SIZE + 2)
946 continue;
947
948 domain = &data_pkg->package.elements[0];
949 if (domain->type == ACPI_TYPE_INTEGER &&
950 domain->integer.value == ACPI_WRDS_WIFI)
951 break;
952
953 data_pkg = NULL;
954 }
955
956 if (!data_pkg)
957 return -ENOENT;
958
959 if (data_pkg->package.elements[1].type != ACPI_TYPE_INTEGER)
960 return -EINVAL;
961
962 sar_table->enabled = !!(data_pkg->package.elements[1].integer.value);
963
964 for (i = 0; i < ACPI_WRDS_TABLE_SIZE; i++) {
965 union acpi_object *entry;
966
967 entry = &data_pkg->package.elements[i + 2];
968 if ((entry->type != ACPI_TYPE_INTEGER) ||
969 (entry->integer.value > U8_MAX))
970 return -EINVAL;
971
972 sar_table->values[i] = entry->integer.value;
973 }
974
975 return 0;
976}
977
978static int iwl_mvm_sar_get_table(struct iwl_mvm *mvm,
979 struct iwl_mvm_sar_table *sar_table)
980{
981 acpi_handle root_handle;
982 acpi_handle handle;
983 struct acpi_buffer wrds = {ACPI_ALLOCATE_BUFFER, NULL};
984 acpi_status status;
985 int ret;
986
987 root_handle = ACPI_HANDLE(mvm->dev);
988 if (!root_handle) {
989 IWL_DEBUG_RADIO(mvm,
990 "Could not retrieve root port ACPI handle\n");
991 return -ENOENT;
992 }
993
994 /* Get the method's handle */
995 status = acpi_get_handle(root_handle, (acpi_string)ACPI_WRDS_METHOD,
996 &handle);
997 if (ACPI_FAILURE(status)) {
998 IWL_DEBUG_RADIO(mvm, "WRDS method not found\n");
999 return -ENOENT;
1000 }
1001
1002 /* Call WRDS with no arguments */
1003 status = acpi_evaluate_object(handle, NULL, NULL, &wrds);
1004 if (ACPI_FAILURE(status)) {
1005 IWL_DEBUG_RADIO(mvm, "WRDS invocation failed (0x%x)\n", status);
1006 return -ENOENT;
1007 }
1008
1009 ret = iwl_mvm_sar_get_wrds(mvm, wrds.pointer, sar_table);
1010 kfree(wrds.pointer);
1011
1012 return ret;
1013}
1014#else /* CONFIG_ACPI */
1015static int iwl_mvm_sar_get_table(struct iwl_mvm *mvm,
1016 struct iwl_mvm_sar_table *sar_table)
1017{
1018 return -ENOENT;
1019}
1020#endif /* CONFIG_ACPI */
1021
1022static int iwl_mvm_sar_init(struct iwl_mvm *mvm)
1023{
1024 struct iwl_mvm_sar_table sar_table;
1025 struct iwl_dev_tx_power_cmd cmd = {
1026 .v2.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS),
1027 };
1028 int ret, i, j, idx;
1029
1030 /* we can't do anything with the table if the FW doesn't support it */
1031 if (!fw_has_api(&mvm->fw->ucode_capa,
1032 IWL_UCODE_TLV_API_TX_POWER_CHAIN)) {
1033 IWL_DEBUG_RADIO(mvm,
1034 "FW doesn't support per-chain TX power settings.\n");
1035 return 0;
1036 }
1037
1038 ret = iwl_mvm_sar_get_table(mvm, &sar_table);
1039 if (ret < 0) {
1040 IWL_DEBUG_RADIO(mvm,
1041 "SAR BIOS table invalid or unavailable. (%d)\n",
1042 ret);
1043 /* we don't fail if the table is not available */
1044 return 0;
1045 }
1046
1047 if (!sar_table.enabled)
1048 return 0;
1049
1050 IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n");
1051
1052 BUILD_BUG_ON(IWL_NUM_CHAIN_LIMITS * IWL_NUM_SUB_BANDS !=
1053 ACPI_WRDS_TABLE_SIZE);
1054
1055 for (i = 0; i < IWL_NUM_CHAIN_LIMITS; i++) {
1056 IWL_DEBUG_RADIO(mvm, " Chain[%d]:\n", i);
1057 for (j = 0; j < IWL_NUM_SUB_BANDS; j++) {
1058 idx = (i * IWL_NUM_SUB_BANDS) + j;
1059 cmd.per_chain_restriction[i][j] =
1060 cpu_to_le16(sar_table.values[idx]);
1061 IWL_DEBUG_RADIO(mvm, " Band[%d] = %d * .125dBm\n",
1062 j, sar_table.values[idx]);
1063 }
1064 }
1065
1066 ret = iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0,
1067 sizeof(cmd), &cmd);
1068 if (ret)
1069 IWL_ERR(mvm, "failed to set per-chain TX power: %d\n", ret);
1070
1071 return ret;
1072}
1073
Johannes Berg8ca151b2013-01-24 14:25:36 +01001074int iwl_mvm_up(struct iwl_mvm *mvm)
1075{
1076 int ret, i;
Ilan Peer53a9d612013-04-28 11:55:08 +03001077 struct ieee80211_channel *chan;
1078 struct cfg80211_chan_def chandef;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001079
1080 lockdep_assert_held(&mvm->mutex);
1081
1082 ret = iwl_trans_start_hw(mvm->trans);
1083 if (ret)
1084 return ret;
1085
Eytan Lifshitzff116372013-09-03 12:06:11 +03001086 /*
1087 * If we haven't completed the run of the init ucode during
1088 * module loading, load init ucode now
1089 * (for example, if we were in RFKILL)
1090 */
Eran Harary8d193ca2015-04-27 10:29:31 +03001091 ret = iwl_run_init_mvm_ucode(mvm, false);
1092 if (ret && !iwlmvm_mod_params.init_dbg) {
1093 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
1094 /* this can't happen */
1095 if (WARN_ON(ret > 0))
1096 ret = -ERFKILL;
1097 goto error;
1098 }
1099 if (!iwlmvm_mod_params.init_dbg) {
1100 /*
1101 * Stop and start the transport without entering low power
1102 * mode. This will save the state of other components on the
1103 * device that are triggered by the INIT firwmare (MFUART).
1104 */
1105 _iwl_trans_stop_device(mvm->trans, false);
Johannes Bergd643c432015-05-07 14:47:50 +02001106 ret = _iwl_trans_start_hw(mvm->trans, false);
Eran Harary8d193ca2015-04-27 10:29:31 +03001107 if (ret)
Johannes Bergd643c432015-05-07 14:47:50 +02001108 goto error;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001109 }
1110
1111 if (iwlmvm_mod_params.init_dbg)
1112 return 0;
1113
1114 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
1115 if (ret) {
1116 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
1117 goto error;
1118 }
1119
Sara Sharon6c7d32c2015-06-07 09:34:57 +03001120 iwl_mvm_get_shared_mem_conf(mvm);
Liad Kaufman04fd2c22014-12-15 17:54:16 +02001121
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +02001122 ret = iwl_mvm_sf_update(mvm, NULL, false);
1123 if (ret)
1124 IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
1125
Liad Kaufman6a951262014-11-17 11:36:21 +02001126 mvm->fw_dbg_conf = FW_DBG_INVALID;
Emmanuel Grumbach945d4202015-02-15 17:16:16 +02001127 /* if we have a destination, assume EARLY START */
1128 if (mvm->fw->dbg_dest_tlv)
1129 mvm->fw_dbg_conf = FW_DBG_START_FROM_ALIVE;
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +02001130 iwl_mvm_start_fw_dbg_conf(mvm, FW_DBG_START_FROM_ALIVE);
Liad Kaufman6a951262014-11-17 11:36:21 +02001131
Moshe Harela0544272014-12-08 21:13:14 +02001132 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001133 if (ret)
1134 goto error;
1135
Emmanuel Grumbach931d4162013-01-17 09:42:25 +02001136 ret = iwl_send_bt_init_conf(mvm);
1137 if (ret)
1138 goto error;
1139
Johannes Berg8ca151b2013-01-24 14:25:36 +01001140 /* Send phy db control command and then phy db calibration*/
1141 ret = iwl_send_phy_db_data(mvm->phy_db);
1142 if (ret)
1143 goto error;
1144
1145 ret = iwl_send_phy_cfg_cmd(mvm);
1146 if (ret)
1147 goto error;
1148
Sara Sharon43413a92015-12-31 11:49:18 +02001149 /* Init RSS configuration */
1150 if (iwl_mvm_has_new_rx_api(mvm)) {
1151 ret = iwl_send_rss_cfg_cmd(mvm);
1152 if (ret) {
1153 IWL_ERR(mvm, "Failed to configure RSS queues: %d\n",
1154 ret);
1155 goto error;
1156 }
1157 }
1158
Johannes Berg8ca151b2013-01-24 14:25:36 +01001159 /* init the fw <-> mac80211 STA mapping */
1160 for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
1161 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1162
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +03001163 mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT;
1164
Johannes Bergb2b78752014-09-08 16:42:54 +02001165 /* reset quota debouncing buffer - 0xff will yield invalid data */
1166 memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
1167
Liad Kaufman97d5be72015-08-31 14:33:23 +03001168 /* Enable DQA-mode if required */
1169 if (iwl_mvm_is_dqa_supported(mvm)) {
1170 ret = iwl_mvm_send_dqa_cmd(mvm);
1171 if (ret)
1172 goto error;
1173 } else {
1174 IWL_DEBUG_FW(mvm, "Working in non-DQA mode\n");
1175 }
1176
Johannes Berg8ca151b2013-01-24 14:25:36 +01001177 /* Add auxiliary station for scanning */
1178 ret = iwl_mvm_add_aux_sta(mvm);
1179 if (ret)
1180 goto error;
1181
Ilan Peer53a9d612013-04-28 11:55:08 +03001182 /* Add all the PHY contexts */
Johannes Berg57fbcce2016-04-12 15:56:15 +02001183 chan = &mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[0];
Ilan Peer53a9d612013-04-28 11:55:08 +03001184 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
1185 for (i = 0; i < NUM_PHY_CTX; i++) {
1186 /*
1187 * The channel used here isn't relevant as it's
1188 * going to be overwritten in the other flows.
1189 * For now use the first channel we have.
1190 */
1191 ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
1192 &chandef, 1, 1);
1193 if (ret)
1194 goto error;
1195 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001196
Chaya Rachel Ivgic221daf2015-12-29 09:54:49 +02001197#ifdef CONFIG_THERMAL
1198 if (iwl_mvm_is_tt_in_fw(mvm)) {
1199 /* in order to give the responsibility of ct-kill and
1200 * TX backoff to FW we need to send empty temperature reporting
1201 * cmd during init time
1202 */
1203 iwl_mvm_send_temp_report_ths_cmd(mvm);
1204 } else {
1205 /* Initialize tx backoffs to the minimal possible */
1206 iwl_mvm_tt_tx_backoff(mvm, 0);
1207 }
Chaya Rachel Ivgi5c89e7b2016-01-05 10:34:47 +02001208
1209 /* TODO: read the budget from BIOS / Platform NVM */
1210 if (iwl_mvm_is_ctdp_supported(mvm) && mvm->cooling_dev.cur_state > 0)
1211 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START,
1212 mvm->cooling_dev.cur_state);
Chaya Rachel Ivgic221daf2015-12-29 09:54:49 +02001213#else
Ido Yariv0c0e2c72014-01-16 21:12:02 -05001214 /* Initialize tx backoffs to the minimal possible */
1215 iwl_mvm_tt_tx_backoff(mvm, 0);
Chaya Rachel Ivgic221daf2015-12-29 09:54:49 +02001216#endif
Ido Yariv0c0e2c72014-01-16 21:12:02 -05001217
Emmanuel Grumbach84bfffa2015-01-13 10:16:30 +02001218 WARN_ON(iwl_mvm_config_ltr(mvm));
Emmanuel Grumbach9180ac52014-09-23 23:02:41 +03001219
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +02001220 ret = iwl_mvm_power_update_device(mvm);
Alexander Bondar64b928c2013-09-03 14:18:03 +03001221 if (ret)
1222 goto error;
1223
Arik Nemtsov35af15d2015-03-04 15:08:00 +02001224 /*
1225 * RTNL is not taken during Ct-kill, but we don't need to scan/Tx
1226 * anyway, so don't init MCC.
1227 */
1228 if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) {
1229 ret = iwl_mvm_init_mcc(mvm);
1230 if (ret)
1231 goto error;
1232 }
Arik Nemtsov90d4f7d2014-03-04 19:58:46 +02001233
Johannes Berg859d9142015-06-01 17:11:11 +02001234 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
Emmanuel Grumbach4ca87a52016-01-03 22:23:40 +02001235 mvm->scan_type = IWL_SCAN_TYPE_NOT_SET;
David Spinadeld2496222014-05-20 12:46:37 +03001236 ret = iwl_mvm_config_scan(mvm);
1237 if (ret)
1238 goto error;
1239 }
1240
Avri Altman93190fb2014-12-27 09:09:47 +02001241 if (iwl_mvm_is_csum_supported(mvm) &&
1242 mvm->cfg->features & NETIF_F_RXCSUM)
1243 iwl_trans_write_prph(mvm->trans, RX_EN_CSUM, 0x3);
1244
Eliad Peller7498cf42014-01-16 17:10:44 +02001245 /* allow FW/transport low power modes if not during restart */
1246 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1247 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1248
Luca Coelhoda2830a2016-05-30 13:00:44 +03001249 ret = iwl_mvm_sar_init(mvm);
1250 if (ret)
1251 goto error;
1252
Ilan Peer53a9d612013-04-28 11:55:08 +03001253 IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001254 return 0;
1255 error:
Chaya Rachel Ivgifcb6b922016-02-22 10:21:41 +02001256 iwl_mvm_stop_device(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001257 return ret;
1258}
1259
1260int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
1261{
1262 int ret, i;
1263
1264 lockdep_assert_held(&mvm->mutex);
1265
1266 ret = iwl_trans_start_hw(mvm->trans);
1267 if (ret)
1268 return ret;
1269
1270 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
1271 if (ret) {
1272 IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
1273 goto error;
1274 }
1275
Moshe Harela0544272014-12-08 21:13:14 +02001276 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001277 if (ret)
1278 goto error;
1279
1280 /* Send phy db control command and then phy db calibration*/
1281 ret = iwl_send_phy_db_data(mvm->phy_db);
1282 if (ret)
1283 goto error;
1284
1285 ret = iwl_send_phy_cfg_cmd(mvm);
1286 if (ret)
1287 goto error;
1288
1289 /* init the fw <-> mac80211 STA mapping */
1290 for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
1291 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1292
1293 /* Add auxiliary station for scanning */
1294 ret = iwl_mvm_add_aux_sta(mvm);
1295 if (ret)
1296 goto error;
1297
1298 return 0;
1299 error:
Chaya Rachel Ivgifcb6b922016-02-22 10:21:41 +02001300 iwl_mvm_stop_device(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001301 return ret;
1302}
1303
Johannes Berg04168412015-06-23 21:22:09 +02001304void iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
1305 struct iwl_rx_cmd_buffer *rxb)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001306{
1307 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1308 struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
1309 u32 flags = le32_to_cpu(card_state_notif->flags);
1310
1311 IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
1312 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1313 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
1314 (flags & CT_KILL_CARD_DISABLED) ?
1315 "Reached" : "Not reached");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001316}
1317
Johannes Berg04168412015-06-23 21:22:09 +02001318void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
1319 struct iwl_rx_cmd_buffer *rxb)
Chaya Rachel Ivgy30269c12014-11-15 21:08:29 +02001320{
1321 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1322 struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data;
1323
1324 IWL_DEBUG_INFO(mvm,
1325 "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n",
1326 le32_to_cpu(mfuart_notif->installed_ver),
1327 le32_to_cpu(mfuart_notif->external_ver),
1328 le32_to_cpu(mfuart_notif->status),
1329 le32_to_cpu(mfuart_notif->duration));
Chaya Rachel Ivgy30269c12014-11-15 21:08:29 +02001330}