blob: 510b4c1be35dfb6f70e11c6ef803fd2fb85bddce [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>
Johannes Berg8ca151b2013-01-24 14:25:36 +010068
69#include "iwl-trans.h"
70#include "iwl-op-mode.h"
71#include "iwl-fw.h"
72#include "iwl-debug.h"
73#include "iwl-csr.h" /* for iwl_mvm_rx_card_state_notif */
74#include "iwl-io.h" /* for iwl_mvm_rx_card_state_notif */
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +020075#include "iwl-prph.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010076#include "iwl-eeprom-parse.h"
77
78#include "mvm.h"
Golan Ben-Ami2f89a5d2015-10-27 19:17:14 +020079#include "fw-dbg.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010080#include "iwl-phy-db.h"
81
82#define MVM_UCODE_ALIVE_TIMEOUT HZ
83#define MVM_UCODE_CALIB_TIMEOUT (2*HZ)
84
85#define UCODE_VALID_OK cpu_to_le32(0x1)
86
Johannes Berg8ca151b2013-01-24 14:25:36 +010087struct iwl_mvm_alive_data {
88 bool valid;
89 u32 scd_base_addr;
90};
91
92static inline const struct fw_img *
93iwl_get_ucode_image(struct iwl_mvm *mvm, enum iwl_ucode_type ucode_type)
94{
95 if (ucode_type >= IWL_UCODE_TYPE_MAX)
96 return NULL;
97
98 return &mvm->fw->img[ucode_type];
99}
100
101static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant)
102{
103 struct iwl_tx_ant_cfg_cmd tx_ant_cmd = {
104 .valid = cpu_to_le32(valid_tx_ant),
105 };
106
Emmanuel Grumbach33223542013-03-09 20:38:19 +0200107 IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant);
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300108 return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100109 sizeof(tx_ant_cmd), &tx_ant_cmd);
110}
111
Sara Sharon43413a92015-12-31 11:49:18 +0200112static int iwl_send_rss_cfg_cmd(struct iwl_mvm *mvm)
113{
114 int i;
115 struct iwl_rss_config_cmd cmd = {
116 .flags = cpu_to_le32(IWL_RSS_ENABLE),
117 .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
Sara Sharon854d7732016-03-22 15:55:58 +0200118 IWL_RSS_HASH_TYPE_IPV4_UDP |
Sara Sharon43413a92015-12-31 11:49:18 +0200119 IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
120 IWL_RSS_HASH_TYPE_IPV6_TCP |
Sara Sharon854d7732016-03-22 15:55:58 +0200121 IWL_RSS_HASH_TYPE_IPV6_UDP |
Sara Sharon43413a92015-12-31 11:49:18 +0200122 IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
123 };
124
Sara Sharonf43495f2016-05-04 14:22:10 +0300125 if (mvm->trans->num_rx_queues == 1)
126 return 0;
127
Sara Sharon854d7732016-03-22 15:55:58 +0200128 /* Do not direct RSS traffic to Q 0 which is our fallback queue */
Sara Sharon43413a92015-12-31 11:49:18 +0200129 for (i = 0; i < ARRAY_SIZE(cmd.indirection_table); i++)
Sara Sharon854d7732016-03-22 15:55:58 +0200130 cmd.indirection_table[i] =
131 1 + (i % (mvm->trans->num_rx_queues - 1));
132 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
Sara Sharon43413a92015-12-31 11:49:18 +0200133
134 return iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd);
135}
136
Liad Kaufman97d5be72015-08-31 14:33:23 +0300137static int iwl_mvm_send_dqa_cmd(struct iwl_mvm *mvm)
138{
139 struct iwl_dqa_enable_cmd dqa_cmd = {
140 .cmd_queue = cpu_to_le32(IWL_MVM_DQA_CMD_QUEUE),
141 };
142 u32 cmd_id = iwl_cmd_id(DQA_ENABLE_CMD, DATA_PATH_GROUP, 0);
143 int ret;
144
145 ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(dqa_cmd), &dqa_cmd);
146 if (ret)
147 IWL_ERR(mvm, "Failed to send DQA enabling command: %d\n", ret);
148 else
149 IWL_DEBUG_FW(mvm, "Working in DQA mode\n");
150
151 return ret;
152}
153
Matti Gottlieb905e36a2016-02-14 17:05:39 +0200154void iwl_free_fw_paging(struct iwl_mvm *mvm)
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300155{
156 int i;
157
158 if (!mvm->fw_paging_db[0].fw_paging_block)
159 return;
160
161 for (i = 0; i < NUM_OF_FW_PAGING_BLOCKS; i++) {
162 if (!mvm->fw_paging_db[i].fw_paging_block) {
163 IWL_DEBUG_FW(mvm,
164 "Paging: block %d already freed, continue to next page\n",
165 i);
166
167 continue;
168 }
169
170 __free_pages(mvm->fw_paging_db[i].fw_paging_block,
171 get_order(mvm->fw_paging_db[i].fw_paging_size));
Matti Gottliebf742aaf2016-04-10 10:53:57 +0300172 mvm->fw_paging_db[i].fw_paging_block = NULL;
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300173 }
Matti Gottliebe1120182015-07-19 11:15:07 +0300174 kfree(mvm->trans->paging_download_buf);
Matti Gottlieb905e36a2016-02-14 17:05:39 +0200175 mvm->trans->paging_download_buf = NULL;
Matti Gottliebf742aaf2016-04-10 10:53:57 +0300176 mvm->trans->paging_db = NULL;
Matti Gottlieb905e36a2016-02-14 17:05:39 +0200177
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300178 memset(mvm->fw_paging_db, 0, sizeof(mvm->fw_paging_db));
179}
180
181static int iwl_fill_paging_mem(struct iwl_mvm *mvm, const struct fw_img *image)
182{
183 int sec_idx, idx;
184 u32 offset = 0;
185
186 /*
187 * find where is the paging image start point:
188 * if CPU2 exist and it's in paging format, then the image looks like:
189 * CPU1 sections (2 or more)
190 * CPU1_CPU2_SEPARATOR_SECTION delimiter - separate between CPU1 to CPU2
191 * CPU2 sections (not paged)
192 * PAGING_SEPARATOR_SECTION delimiter - separate between CPU2
193 * non paged to CPU2 paging sec
194 * CPU2 paging CSS
195 * CPU2 paging image (including instruction and data)
196 */
197 for (sec_idx = 0; sec_idx < IWL_UCODE_SECTION_MAX; sec_idx++) {
198 if (image->sec[sec_idx].offset == PAGING_SEPARATOR_SECTION) {
199 sec_idx++;
200 break;
201 }
202 }
203
Matti Gottliebcd47a3d2016-03-10 16:18:26 +0200204 /*
205 * If paging is enabled there should be at least 2 more sections left
206 * (one for CSS and one for Paging data)
207 */
208 if (sec_idx >= ARRAY_SIZE(image->sec) - 1) {
209 IWL_ERR(mvm, "Paging: Missing CSS and/or paging sections\n");
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300210 iwl_free_fw_paging(mvm);
211 return -EINVAL;
212 }
213
214 /* copy the CSS block to the dram */
215 IWL_DEBUG_FW(mvm, "Paging: load paging CSS to FW, sec = %d\n",
216 sec_idx);
217
218 memcpy(page_address(mvm->fw_paging_db[0].fw_paging_block),
219 image->sec[sec_idx].data,
220 mvm->fw_paging_db[0].fw_paging_size);
221
222 IWL_DEBUG_FW(mvm,
223 "Paging: copied %d CSS bytes to first block\n",
224 mvm->fw_paging_db[0].fw_paging_size);
225
226 sec_idx++;
227
228 /*
229 * copy the paging blocks to the dram
230 * loop index start from 1 since that CSS block already copied to dram
231 * and CSS index is 0.
232 * loop stop at num_of_paging_blk since that last block is not full.
233 */
234 for (idx = 1; idx < mvm->num_of_paging_blk; idx++) {
235 memcpy(page_address(mvm->fw_paging_db[idx].fw_paging_block),
236 image->sec[sec_idx].data + offset,
237 mvm->fw_paging_db[idx].fw_paging_size);
238
239 IWL_DEBUG_FW(mvm,
240 "Paging: copied %d paging bytes to block %d\n",
241 mvm->fw_paging_db[idx].fw_paging_size,
242 idx);
243
244 offset += mvm->fw_paging_db[idx].fw_paging_size;
245 }
246
247 /* copy the last paging block */
248 if (mvm->num_of_pages_in_last_blk > 0) {
249 memcpy(page_address(mvm->fw_paging_db[idx].fw_paging_block),
250 image->sec[sec_idx].data + offset,
251 FW_PAGING_SIZE * mvm->num_of_pages_in_last_blk);
252
253 IWL_DEBUG_FW(mvm,
254 "Paging: copied %d pages in the last block %d\n",
255 mvm->num_of_pages_in_last_blk, idx);
256 }
257
258 return 0;
259}
260
261static int iwl_alloc_fw_paging_mem(struct iwl_mvm *mvm,
262 const struct fw_img *image)
263{
264 struct page *block;
265 dma_addr_t phys = 0;
266 int blk_idx = 0;
267 int order, num_of_pages;
268 int dma_enabled;
269
270 if (mvm->fw_paging_db[0].fw_paging_block)
271 return 0;
272
273 dma_enabled = is_device_dma_capable(mvm->trans->dev);
274
275 /* ensure BLOCK_2_EXP_SIZE is power of 2 of PAGING_BLOCK_SIZE */
276 BUILD_BUG_ON(BIT(BLOCK_2_EXP_SIZE) != PAGING_BLOCK_SIZE);
277
278 num_of_pages = image->paging_mem_size / FW_PAGING_SIZE;
279 mvm->num_of_paging_blk = ((num_of_pages - 1) /
280 NUM_OF_PAGE_PER_GROUP) + 1;
281
282 mvm->num_of_pages_in_last_blk =
283 num_of_pages -
284 NUM_OF_PAGE_PER_GROUP * (mvm->num_of_paging_blk - 1);
285
286 IWL_DEBUG_FW(mvm,
287 "Paging: allocating mem for %d paging blocks, each block holds 8 pages, last block holds %d pages\n",
288 mvm->num_of_paging_blk,
289 mvm->num_of_pages_in_last_blk);
290
291 /* allocate block of 4Kbytes for paging CSS */
292 order = get_order(FW_PAGING_SIZE);
293 block = alloc_pages(GFP_KERNEL, order);
294 if (!block) {
295 /* free all the previous pages since we failed */
296 iwl_free_fw_paging(mvm);
297 return -ENOMEM;
298 }
299
300 mvm->fw_paging_db[blk_idx].fw_paging_block = block;
301 mvm->fw_paging_db[blk_idx].fw_paging_size = FW_PAGING_SIZE;
302
303 if (dma_enabled) {
304 phys = dma_map_page(mvm->trans->dev, block, 0,
305 PAGE_SIZE << order, DMA_BIDIRECTIONAL);
306 if (dma_mapping_error(mvm->trans->dev, phys)) {
307 /*
308 * free the previous pages and the current one since
309 * we failed to map_page.
310 */
311 iwl_free_fw_paging(mvm);
312 return -ENOMEM;
313 }
314 mvm->fw_paging_db[blk_idx].fw_paging_phys = phys;
Matti Gottliebe1120182015-07-19 11:15:07 +0300315 } else {
316 mvm->fw_paging_db[blk_idx].fw_paging_phys = PAGING_ADDR_SIG |
317 blk_idx << BLOCK_2_EXP_SIZE;
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300318 }
319
320 IWL_DEBUG_FW(mvm,
321 "Paging: allocated 4K(CSS) bytes (order %d) for firmware paging.\n",
322 order);
323
324 /*
325 * allocate blocks in dram.
326 * since that CSS allocated in fw_paging_db[0] loop start from index 1
327 */
328 for (blk_idx = 1; blk_idx < mvm->num_of_paging_blk + 1; blk_idx++) {
329 /* allocate block of PAGING_BLOCK_SIZE (32K) */
330 order = get_order(PAGING_BLOCK_SIZE);
331 block = alloc_pages(GFP_KERNEL, order);
332 if (!block) {
333 /* free all the previous pages since we failed */
334 iwl_free_fw_paging(mvm);
335 return -ENOMEM;
336 }
337
338 mvm->fw_paging_db[blk_idx].fw_paging_block = block;
339 mvm->fw_paging_db[blk_idx].fw_paging_size = PAGING_BLOCK_SIZE;
340
341 if (dma_enabled) {
342 phys = dma_map_page(mvm->trans->dev, block, 0,
343 PAGE_SIZE << order,
344 DMA_BIDIRECTIONAL);
345 if (dma_mapping_error(mvm->trans->dev, phys)) {
346 /*
347 * free the previous pages and the current one
348 * since we failed to map_page.
349 */
350 iwl_free_fw_paging(mvm);
351 return -ENOMEM;
352 }
353 mvm->fw_paging_db[blk_idx].fw_paging_phys = phys;
Matti Gottliebe1120182015-07-19 11:15:07 +0300354 } else {
355 mvm->fw_paging_db[blk_idx].fw_paging_phys =
356 PAGING_ADDR_SIG |
357 blk_idx << BLOCK_2_EXP_SIZE;
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300358 }
359
360 IWL_DEBUG_FW(mvm,
361 "Paging: allocated 32K bytes (order %d) for firmware paging.\n",
362 order);
363 }
364
365 return 0;
366}
367
368static int iwl_save_fw_paging(struct iwl_mvm *mvm,
369 const struct fw_img *fw)
370{
371 int ret;
372
373 ret = iwl_alloc_fw_paging_mem(mvm, fw);
374 if (ret)
375 return ret;
376
377 return iwl_fill_paging_mem(mvm, fw);
378}
379
380/* send paging cmd to FW in case CPU2 has paging image */
381static int iwl_send_paging_cmd(struct iwl_mvm *mvm, const struct fw_img *fw)
382{
383 int blk_idx;
384 __le32 dev_phy_addr;
385 struct iwl_fw_paging_cmd fw_paging_cmd = {
386 .flags =
387 cpu_to_le32(PAGING_CMD_IS_SECURED |
388 PAGING_CMD_IS_ENABLED |
389 (mvm->num_of_pages_in_last_blk <<
390 PAGING_CMD_NUM_OF_PAGES_IN_LAST_GRP_POS)),
391 .block_size = cpu_to_le32(BLOCK_2_EXP_SIZE),
392 .block_num = cpu_to_le32(mvm->num_of_paging_blk),
393 };
394
395 /* loop for for all paging blocks + CSS block */
396 for (blk_idx = 0; blk_idx < mvm->num_of_paging_blk + 1; blk_idx++) {
397 dev_phy_addr =
398 cpu_to_le32(mvm->fw_paging_db[blk_idx].fw_paging_phys >>
399 PAGE_2_EXP_SIZE);
400 fw_paging_cmd.device_phy_addr[blk_idx] = dev_phy_addr;
401 }
402
403 return iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(FW_PAGING_BLOCK_CMD,
404 IWL_ALWAYS_LONG_GROUP, 0),
405 0, sizeof(fw_paging_cmd), &fw_paging_cmd);
406}
407
Matti Gottliebe1120182015-07-19 11:15:07 +0300408/*
409 * Send paging item cmd to FW in case CPU2 has paging image
410 */
411static int iwl_trans_get_paging_item(struct iwl_mvm *mvm)
412{
413 int ret;
414 struct iwl_fw_get_item_cmd fw_get_item_cmd = {
415 .item_id = cpu_to_le32(IWL_FW_ITEM_ID_PAGING),
416 };
417
418 struct iwl_fw_get_item_resp *item_resp;
419 struct iwl_host_cmd cmd = {
420 .id = iwl_cmd_id(FW_GET_ITEM_CMD, IWL_ALWAYS_LONG_GROUP, 0),
421 .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
422 .data = { &fw_get_item_cmd, },
423 };
424
425 cmd.len[0] = sizeof(struct iwl_fw_get_item_cmd);
426
427 ret = iwl_mvm_send_cmd(mvm, &cmd);
428 if (ret) {
429 IWL_ERR(mvm,
430 "Paging: Failed to send FW_GET_ITEM_CMD cmd (err = %d)\n",
431 ret);
432 return ret;
433 }
434
435 item_resp = (void *)((struct iwl_rx_packet *)cmd.resp_pkt)->data;
436 if (item_resp->item_id != cpu_to_le32(IWL_FW_ITEM_ID_PAGING)) {
437 IWL_ERR(mvm,
438 "Paging: got wrong item in FW_GET_ITEM_CMD resp (item_id = %u)\n",
439 le32_to_cpu(item_resp->item_id));
440 ret = -EIO;
441 goto exit;
442 }
443
Matti Gottliebc94d7992016-03-09 10:54:10 +0200444 /* Add an extra page for headers */
445 mvm->trans->paging_download_buf = kzalloc(PAGING_BLOCK_SIZE +
446 FW_PAGING_SIZE,
Matti Gottliebe1120182015-07-19 11:15:07 +0300447 GFP_KERNEL);
448 if (!mvm->trans->paging_download_buf) {
449 ret = -ENOMEM;
450 goto exit;
451 }
452 mvm->trans->paging_req_addr = le32_to_cpu(item_resp->item_val);
453 mvm->trans->paging_db = mvm->fw_paging_db;
454 IWL_DEBUG_FW(mvm,
455 "Paging: got paging request address (paging_req_addr 0x%08x)\n",
456 mvm->trans->paging_req_addr);
457
458exit:
459 iwl_free_resp(&cmd);
460
461 return ret;
462}
463
Johannes Berg8ca151b2013-01-24 14:25:36 +0100464static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
465 struct iwl_rx_packet *pkt, void *data)
466{
467 struct iwl_mvm *mvm =
468 container_of(notif_wait, struct iwl_mvm, notif_wait);
469 struct iwl_mvm_alive_data *alive_data = data;
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200470 struct mvm_alive_resp_ver1 *palive1;
Eran Harary01a9ca52014-02-03 09:29:57 +0200471 struct mvm_alive_resp_ver2 *palive2;
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200472 struct mvm_alive_resp *palive;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100473
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200474 if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive1)) {
475 palive1 = (void *)pkt->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100476
Eran Harary01a9ca52014-02-03 09:29:57 +0200477 mvm->support_umac_log = false;
478 mvm->error_event_table =
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200479 le32_to_cpu(palive1->error_event_table_ptr);
480 mvm->log_event_table =
481 le32_to_cpu(palive1->log_event_table_ptr);
482 alive_data->scd_base_addr = le32_to_cpu(palive1->scd_base_ptr);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100483
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200484 alive_data->valid = le16_to_cpu(palive1->status) ==
Eran Harary01a9ca52014-02-03 09:29:57 +0200485 IWL_ALIVE_STATUS_OK;
486 IWL_DEBUG_FW(mvm,
487 "Alive VER1 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n",
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200488 le16_to_cpu(palive1->status), palive1->ver_type,
489 palive1->ver_subtype, palive1->flags);
490 } else if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive2)) {
Eran Harary01a9ca52014-02-03 09:29:57 +0200491 palive2 = (void *)pkt->data;
492
Eran Harary01a9ca52014-02-03 09:29:57 +0200493 mvm->error_event_table =
494 le32_to_cpu(palive2->error_event_table_ptr);
495 mvm->log_event_table =
496 le32_to_cpu(palive2->log_event_table_ptr);
497 alive_data->scd_base_addr = le32_to_cpu(palive2->scd_base_ptr);
498 mvm->umac_error_event_table =
499 le32_to_cpu(palive2->error_info_addr);
Eran Harary91479b62014-05-11 08:11:34 +0300500 mvm->sf_space.addr = le32_to_cpu(palive2->st_fwrd_addr);
501 mvm->sf_space.size = le32_to_cpu(palive2->st_fwrd_size);
Eran Harary01a9ca52014-02-03 09:29:57 +0200502
503 alive_data->valid = le16_to_cpu(palive2->status) ==
504 IWL_ALIVE_STATUS_OK;
Emmanuel Grumbachffa70262014-02-11 16:37:34 +0200505 if (mvm->umac_error_event_table)
506 mvm->support_umac_log = true;
507
Eran Harary01a9ca52014-02-03 09:29:57 +0200508 IWL_DEBUG_FW(mvm,
509 "Alive VER2 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n",
510 le16_to_cpu(palive2->status), palive2->ver_type,
511 palive2->ver_subtype, palive2->flags);
512
513 IWL_DEBUG_FW(mvm,
514 "UMAC version: Major - 0x%x, Minor - 0x%x\n",
515 palive2->umac_major, palive2->umac_minor);
Emmanuel Grumbach7e1223b2015-02-03 20:11:48 +0200516 } else if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive)) {
517 palive = (void *)pkt->data;
518
519 mvm->error_event_table =
520 le32_to_cpu(palive->error_event_table_ptr);
521 mvm->log_event_table =
522 le32_to_cpu(palive->log_event_table_ptr);
523 alive_data->scd_base_addr = le32_to_cpu(palive->scd_base_ptr);
524 mvm->umac_error_event_table =
525 le32_to_cpu(palive->error_info_addr);
526 mvm->sf_space.addr = le32_to_cpu(palive->st_fwrd_addr);
527 mvm->sf_space.size = le32_to_cpu(palive->st_fwrd_size);
528
529 alive_data->valid = le16_to_cpu(palive->status) ==
530 IWL_ALIVE_STATUS_OK;
531 if (mvm->umac_error_event_table)
532 mvm->support_umac_log = true;
533
534 IWL_DEBUG_FW(mvm,
535 "Alive VER3 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n",
536 le16_to_cpu(palive->status), palive->ver_type,
537 palive->ver_subtype, palive->flags);
538
539 IWL_DEBUG_FW(mvm,
540 "UMAC version: Major - 0x%x, Minor - 0x%x\n",
541 le32_to_cpu(palive->umac_major),
542 le32_to_cpu(palive->umac_minor));
Eran Harary01a9ca52014-02-03 09:29:57 +0200543 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100544
545 return true;
546}
547
548static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
549 struct iwl_rx_packet *pkt, void *data)
550{
551 struct iwl_phy_db *phy_db = data;
552
553 if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
554 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
555 return true;
556 }
557
Sara Sharonce1f2772016-04-10 16:02:12 +0300558 WARN_ON(iwl_phy_db_set_section(phy_db, pkt));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100559
560 return false;
561}
562
563static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
564 enum iwl_ucode_type ucode_type)
565{
566 struct iwl_notification_wait alive_wait;
567 struct iwl_mvm_alive_data alive_data;
568 const struct fw_img *fw;
569 int ret, i;
570 enum iwl_ucode_type old_type = mvm->cur_ucode;
Sara Sharon6eb031d2015-07-13 14:50:47 +0300571 static const u16 alive_cmd[] = { MVM_ALIVE };
Eran Harary91479b62014-05-11 08:11:34 +0300572 struct iwl_sf_region st_fwrd_space;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100573
Eran Harary61df7502014-12-01 17:40:37 +0200574 if (ucode_type == IWL_UCODE_REGULAR &&
Golan Ben-Ami3d2d4422016-02-23 10:34:48 +0200575 iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) &&
576 !(fw_has_capa(&mvm->fw->ucode_capa,
577 IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED)))
Eran Harary61df7502014-12-01 17:40:37 +0200578 fw = iwl_get_ucode_image(mvm, IWL_UCODE_REGULAR_USNIFFER);
579 else
580 fw = iwl_get_ucode_image(mvm, ucode_type);
Johannes Bergbefe9b62013-10-25 12:32:51 +0200581 if (WARN_ON(!fw))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100582 return -EINVAL;
Johannes Bergbefe9b62013-10-25 12:32:51 +0200583 mvm->cur_ucode = ucode_type;
584 mvm->ucode_loaded = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100585
586 iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
587 alive_cmd, ARRAY_SIZE(alive_cmd),
588 iwl_alive_fn, &alive_data);
589
590 ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT);
591 if (ret) {
592 mvm->cur_ucode = old_type;
593 iwl_remove_notification(&mvm->notif_wait, &alive_wait);
594 return ret;
595 }
596
597 /*
598 * Some things may run in the background now, but we
599 * just wait for the ALIVE notification here.
600 */
601 ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
602 MVM_UCODE_ALIVE_TIMEOUT);
603 if (ret) {
Dor Shaish192de2b2015-07-15 11:41:21 +0300604 if (mvm->trans->cfg->device_family == IWL_DEVICE_FAMILY_8000)
605 IWL_ERR(mvm,
606 "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
607 iwl_read_prph(mvm->trans, SB_CPU_1_STATUS),
608 iwl_read_prph(mvm->trans, SB_CPU_2_STATUS));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100609 mvm->cur_ucode = old_type;
610 return ret;
611 }
612
613 if (!alive_data.valid) {
614 IWL_ERR(mvm, "Loaded ucode is not valid!\n");
615 mvm->cur_ucode = old_type;
616 return -EIO;
617 }
618
Eran Harary91479b62014-05-11 08:11:34 +0300619 /*
620 * update the sdio allocation according to the pointer we get in the
621 * alive notification.
622 */
623 st_fwrd_space.addr = mvm->sf_space.addr;
624 st_fwrd_space.size = mvm->sf_space.size;
625 ret = iwl_trans_update_sf(mvm->trans, &st_fwrd_space);
Eyal Shapira82e8aea2014-10-19 14:56:40 +0300626 if (ret) {
627 IWL_ERR(mvm, "Failed to update SF size. ret %d\n", ret);
628 return ret;
629 }
Eran Harary91479b62014-05-11 08:11:34 +0300630
Johannes Berg8ca151b2013-01-24 14:25:36 +0100631 iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
632
633 /*
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300634 * configure and operate fw paging mechanism.
635 * driver configures the paging flow only once, CPU2 paging image
636 * included in the IWL_UCODE_INIT image.
637 */
638 if (fw->paging_mem_size) {
Matti Gottliebe1120182015-07-19 11:15:07 +0300639 /*
640 * When dma is not enabled, the driver needs to copy / write
641 * the downloaded / uploaded page to / from the smem.
642 * This gets the location of the place were the pages are
643 * stored.
644 */
645 if (!is_device_dma_capable(mvm->trans->dev)) {
646 ret = iwl_trans_get_paging_item(mvm);
647 if (ret) {
648 IWL_ERR(mvm, "failed to get FW paging item\n");
649 return ret;
650 }
651 }
652
Matti Gottlieba6c4fb42015-07-15 16:19:29 +0300653 ret = iwl_save_fw_paging(mvm, fw);
654 if (ret) {
655 IWL_ERR(mvm, "failed to save the FW paging image\n");
656 return ret;
657 }
658
659 ret = iwl_send_paging_cmd(mvm, fw);
660 if (ret) {
661 IWL_ERR(mvm, "failed to send the paging cmd\n");
662 iwl_free_fw_paging(mvm);
663 return ret;
664 }
665 }
666
667 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +0100668 * Note: all the queues are enabled as part of the interface
669 * initialization, but in firmware restart scenarios they
670 * could be stopped, so wake them up. In firmware restart,
671 * mac80211 will have the queues stopped as well until the
672 * reconfiguration completes. During normal startup, they
673 * will be empty.
674 */
675
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300676 memset(&mvm->queue_info, 0, sizeof(mvm->queue_info));
Liad Kaufman097129c2015-08-09 18:28:43 +0300677 if (iwl_mvm_is_dqa_supported(mvm))
678 mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].hw_queue_refcount = 1;
679 else
680 mvm->queue_info[IWL_MVM_CMD_QUEUE].hw_queue_refcount = 1;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100681
Johannes Bergdf197c02014-08-01 18:14:45 +0200682 for (i = 0; i < IEEE80211_MAX_QUEUES; i++)
683 atomic_set(&mvm->mac80211_queue_stop_count[i], 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100684
685 mvm->ucode_loaded = true;
686
687 return 0;
688}
Johannes Berg8ca151b2013-01-24 14:25:36 +0100689
690static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
691{
692 struct iwl_phy_cfg_cmd phy_cfg_cmd;
693 enum iwl_ucode_type ucode_type = mvm->cur_ucode;
694
695 /* Set parameters */
Moshe Harela0544272014-12-08 21:13:14 +0200696 phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100697 phy_cfg_cmd.calib_control.event_trigger =
698 mvm->fw->default_calib[ucode_type].event_trigger;
699 phy_cfg_cmd.calib_control.flow_trigger =
700 mvm->fw->default_calib[ucode_type].flow_trigger;
701
702 IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
703 phy_cfg_cmd.phy_cfg);
704
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300705 return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100706 sizeof(phy_cfg_cmd), &phy_cfg_cmd);
707}
708
Johannes Berg8ca151b2013-01-24 14:25:36 +0100709int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
710{
711 struct iwl_notification_wait calib_wait;
Sara Sharon6eb031d2015-07-13 14:50:47 +0300712 static const u16 init_complete[] = {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100713 INIT_COMPLETE_NOTIF,
714 CALIB_RES_NOTIF_PHY_DB
715 };
716 int ret;
717
718 lockdep_assert_held(&mvm->mutex);
719
Eran Harary8d193ca2015-04-27 10:29:31 +0300720 if (WARN_ON_ONCE(mvm->calibrating))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100721 return 0;
722
723 iwl_init_notification_wait(&mvm->notif_wait,
724 &calib_wait,
725 init_complete,
726 ARRAY_SIZE(init_complete),
727 iwl_wait_phy_db_entry,
728 mvm->phy_db);
729
730 /* Will also start the device */
731 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
732 if (ret) {
733 IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
734 goto error;
735 }
736
Emmanuel Grumbachae397472014-03-30 16:55:18 +0300737 ret = iwl_send_bt_init_conf(mvm);
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200738 if (ret)
739 goto error;
740
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200741 /* Read the NVM only at driver load time, no need to do this twice */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100742 if (read_nvm) {
743 /* Read nvm */
Eran Harary14b485f2014-04-23 10:46:09 +0300744 ret = iwl_nvm_init(mvm, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100745 if (ret) {
746 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
747 goto error;
748 }
749 }
750
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200751 /* In case we read the NVM from external file, load it to the NIC */
Eran Hararye02a9d62014-05-07 12:27:10 +0300752 if (mvm->nvm_file_name)
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200753 iwl_mvm_load_nvm_to_nic(mvm);
754
Johannes Berg8ca151b2013-01-24 14:25:36 +0100755 ret = iwl_nvm_check_version(mvm->nvm_data, mvm->trans);
756 WARN_ON(ret);
757
Eran Harary4f593342013-05-13 07:53:26 +0300758 /*
759 * abort after reading the nvm in case RF Kill is on, we will complete
760 * the init seq later when RF kill will switch to off
761 */
Arik Nemtsov1a3fe0b2015-09-30 11:19:55 +0300762 if (iwl_mvm_is_radio_hw_killed(mvm)) {
Eran Harary4f593342013-05-13 07:53:26 +0300763 IWL_DEBUG_RF_KILL(mvm,
764 "jump over all phy activities due to RF kill\n");
765 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
Arik Nemtsova4082842013-11-24 19:10:46 +0200766 ret = 1;
767 goto out;
Eran Harary4f593342013-05-13 07:53:26 +0300768 }
769
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200770 mvm->calibrating = true;
771
Dor Shaishe07cbb52013-02-27 23:00:27 +0200772 /* Send TX valid antennas before triggering calibrations */
Moshe Harela0544272014-12-08 21:13:14 +0200773 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Dor Shaishe07cbb52013-02-27 23:00:27 +0200774 if (ret)
775 goto error;
776
Johannes Berg8ca151b2013-01-24 14:25:36 +0100777 /*
778 * Send phy configurations command to init uCode
779 * to start the 16.0 uCode init image internal calibrations.
780 */
781 ret = iwl_send_phy_cfg_cmd(mvm);
782 if (ret) {
783 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
784 ret);
785 goto error;
786 }
787
788 /*
789 * Some things may run in the background now, but we
790 * just wait for the calibration complete notification.
791 */
792 ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
793 MVM_UCODE_CALIB_TIMEOUT);
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200794
Arik Nemtsov1a3fe0b2015-09-30 11:19:55 +0300795 if (ret && iwl_mvm_is_radio_hw_killed(mvm)) {
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200796 IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
797 ret = 1;
798 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100799 goto out;
800
801error:
802 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
803out:
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200804 mvm->calibrating = false;
Arik Nemtsova4082842013-11-24 19:10:46 +0200805 if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100806 /* we want to debug INIT and we have no NVM - fake */
807 mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
808 sizeof(struct ieee80211_channel) +
809 sizeof(struct ieee80211_rate),
810 GFP_KERNEL);
811 if (!mvm->nvm_data)
812 return -ENOMEM;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100813 mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
814 mvm->nvm_data->bands[0].n_channels = 1;
815 mvm->nvm_data->bands[0].n_bitrates = 1;
816 mvm->nvm_data->bands[0].bitrates =
817 (void *)mvm->nvm_data->channels + 1;
818 mvm->nvm_data->bands[0].bitrates->hw_value = 10;
819 }
820
821 return ret;
822}
823
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200824static void iwl_mvm_get_shared_mem_conf(struct iwl_mvm *mvm)
825{
826 struct iwl_host_cmd cmd = {
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200827 .flags = CMD_WANT_SKB,
828 .data = { NULL, },
829 .len = { 0, },
830 };
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200831 struct iwl_shared_mem_cfg *mem_cfg;
Golan Ben-Ami5b086412016-02-09 12:57:16 +0200832 struct iwl_rx_packet *pkt;
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200833 u32 i;
834
835 lockdep_assert_held(&mvm->mutex);
836
Golan Ben-Ami5b086412016-02-09 12:57:16 +0200837 if (fw_has_capa(&mvm->fw->ucode_capa,
838 IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG))
839 cmd.id = iwl_cmd_id(SHARED_MEM_CFG_CMD, SYSTEM_GROUP, 0);
840 else
841 cmd.id = SHARED_MEM_CFG;
842
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200843 if (WARN_ON(iwl_mvm_send_cmd(mvm, &cmd)))
844 return;
845
846 pkt = cmd.resp_pkt;
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200847 mem_cfg = (void *)pkt->data;
848
849 mvm->shared_mem_cfg.shared_mem_addr =
850 le32_to_cpu(mem_cfg->shared_mem_addr);
851 mvm->shared_mem_cfg.shared_mem_size =
852 le32_to_cpu(mem_cfg->shared_mem_size);
853 mvm->shared_mem_cfg.sample_buff_addr =
854 le32_to_cpu(mem_cfg->sample_buff_addr);
855 mvm->shared_mem_cfg.sample_buff_size =
856 le32_to_cpu(mem_cfg->sample_buff_size);
857 mvm->shared_mem_cfg.txfifo_addr = le32_to_cpu(mem_cfg->txfifo_addr);
858 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++)
859 mvm->shared_mem_cfg.txfifo_size[i] =
860 le32_to_cpu(mem_cfg->txfifo_size[i]);
861 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++)
862 mvm->shared_mem_cfg.rxfifo_size[i] =
863 le32_to_cpu(mem_cfg->rxfifo_size[i]);
864 mvm->shared_mem_cfg.page_buff_addr =
865 le32_to_cpu(mem_cfg->page_buff_addr);
866 mvm->shared_mem_cfg.page_buff_size =
867 le32_to_cpu(mem_cfg->page_buff_size);
Golan Ben-Ami5b086412016-02-09 12:57:16 +0200868
869 /* new API has more data */
870 if (fw_has_capa(&mvm->fw->ucode_capa,
871 IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) {
872 mvm->shared_mem_cfg.rxfifo_addr =
873 le32_to_cpu(mem_cfg->rxfifo_addr);
874 mvm->shared_mem_cfg.internal_txfifo_addr =
875 le32_to_cpu(mem_cfg->internal_txfifo_addr);
876
877 BUILD_BUG_ON(sizeof(mvm->shared_mem_cfg.internal_txfifo_size) !=
878 sizeof(mem_cfg->internal_txfifo_size));
879
880 for (i = 0;
881 i < ARRAY_SIZE(mvm->shared_mem_cfg.internal_txfifo_size);
882 i++)
883 mvm->shared_mem_cfg.internal_txfifo_size[i] =
884 le32_to_cpu(mem_cfg->internal_txfifo_size[i]);
885 }
886
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200887 IWL_DEBUG_INFO(mvm, "SHARED MEM CFG: got memory offsets/sizes\n");
888
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200889 iwl_free_resp(&cmd);
890}
891
Emmanuel Grumbach84bfffa2015-01-13 10:16:30 +0200892static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
893{
894 struct iwl_ltr_config_cmd cmd = {
895 .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
896 };
897
898 if (!mvm->trans->ltr_enabled)
899 return 0;
900
Emmanuel Grumbach84bfffa2015-01-13 10:16:30 +0200901 return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
902 sizeof(cmd), &cmd);
903}
904
Johannes Berg8ca151b2013-01-24 14:25:36 +0100905int iwl_mvm_up(struct iwl_mvm *mvm)
906{
907 int ret, i;
Ilan Peer53a9d612013-04-28 11:55:08 +0300908 struct ieee80211_channel *chan;
909 struct cfg80211_chan_def chandef;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100910
911 lockdep_assert_held(&mvm->mutex);
912
913 ret = iwl_trans_start_hw(mvm->trans);
914 if (ret)
915 return ret;
916
Eytan Lifshitzff116372013-09-03 12:06:11 +0300917 /*
918 * If we haven't completed the run of the init ucode during
919 * module loading, load init ucode now
920 * (for example, if we were in RFKILL)
921 */
Eran Harary8d193ca2015-04-27 10:29:31 +0300922 ret = iwl_run_init_mvm_ucode(mvm, false);
923 if (ret && !iwlmvm_mod_params.init_dbg) {
924 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
925 /* this can't happen */
926 if (WARN_ON(ret > 0))
927 ret = -ERFKILL;
928 goto error;
929 }
930 if (!iwlmvm_mod_params.init_dbg) {
931 /*
932 * Stop and start the transport without entering low power
933 * mode. This will save the state of other components on the
934 * device that are triggered by the INIT firwmare (MFUART).
935 */
936 _iwl_trans_stop_device(mvm->trans, false);
Johannes Bergd643c432015-05-07 14:47:50 +0200937 ret = _iwl_trans_start_hw(mvm->trans, false);
Eran Harary8d193ca2015-04-27 10:29:31 +0300938 if (ret)
Johannes Bergd643c432015-05-07 14:47:50 +0200939 goto error;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100940 }
941
942 if (iwlmvm_mod_params.init_dbg)
943 return 0;
944
945 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
946 if (ret) {
947 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
948 goto error;
949 }
950
Sara Sharon6c7d32c2015-06-07 09:34:57 +0300951 iwl_mvm_get_shared_mem_conf(mvm);
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200952
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +0200953 ret = iwl_mvm_sf_update(mvm, NULL, false);
954 if (ret)
955 IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
956
Liad Kaufman6a951262014-11-17 11:36:21 +0200957 mvm->fw_dbg_conf = FW_DBG_INVALID;
Emmanuel Grumbach945d4202015-02-15 17:16:16 +0200958 /* if we have a destination, assume EARLY START */
959 if (mvm->fw->dbg_dest_tlv)
960 mvm->fw_dbg_conf = FW_DBG_START_FROM_ALIVE;
Emmanuel Grumbachd2709ad2015-01-29 14:58:06 +0200961 iwl_mvm_start_fw_dbg_conf(mvm, FW_DBG_START_FROM_ALIVE);
Liad Kaufman6a951262014-11-17 11:36:21 +0200962
Moshe Harela0544272014-12-08 21:13:14 +0200963 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100964 if (ret)
965 goto error;
966
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200967 ret = iwl_send_bt_init_conf(mvm);
968 if (ret)
969 goto error;
970
Johannes Berg8ca151b2013-01-24 14:25:36 +0100971 /* Send phy db control command and then phy db calibration*/
972 ret = iwl_send_phy_db_data(mvm->phy_db);
973 if (ret)
974 goto error;
975
976 ret = iwl_send_phy_cfg_cmd(mvm);
977 if (ret)
978 goto error;
979
Sara Sharon43413a92015-12-31 11:49:18 +0200980 /* Init RSS configuration */
981 if (iwl_mvm_has_new_rx_api(mvm)) {
982 ret = iwl_send_rss_cfg_cmd(mvm);
983 if (ret) {
984 IWL_ERR(mvm, "Failed to configure RSS queues: %d\n",
985 ret);
986 goto error;
987 }
988 }
989
Johannes Berg8ca151b2013-01-24 14:25:36 +0100990 /* init the fw <-> mac80211 STA mapping */
991 for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
992 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
993
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +0300994 mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT;
995
Johannes Bergb2b78752014-09-08 16:42:54 +0200996 /* reset quota debouncing buffer - 0xff will yield invalid data */
997 memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
998
Liad Kaufman97d5be72015-08-31 14:33:23 +0300999 /* Enable DQA-mode if required */
1000 if (iwl_mvm_is_dqa_supported(mvm)) {
1001 ret = iwl_mvm_send_dqa_cmd(mvm);
1002 if (ret)
1003 goto error;
1004 } else {
1005 IWL_DEBUG_FW(mvm, "Working in non-DQA mode\n");
1006 }
1007
Johannes Berg8ca151b2013-01-24 14:25:36 +01001008 /* Add auxiliary station for scanning */
1009 ret = iwl_mvm_add_aux_sta(mvm);
1010 if (ret)
1011 goto error;
1012
Ilan Peer53a9d612013-04-28 11:55:08 +03001013 /* Add all the PHY contexts */
Johannes Berg57fbcce2016-04-12 15:56:15 +02001014 chan = &mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[0];
Ilan Peer53a9d612013-04-28 11:55:08 +03001015 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
1016 for (i = 0; i < NUM_PHY_CTX; i++) {
1017 /*
1018 * The channel used here isn't relevant as it's
1019 * going to be overwritten in the other flows.
1020 * For now use the first channel we have.
1021 */
1022 ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
1023 &chandef, 1, 1);
1024 if (ret)
1025 goto error;
1026 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001027
Chaya Rachel Ivgic221daf2015-12-29 09:54:49 +02001028#ifdef CONFIG_THERMAL
1029 if (iwl_mvm_is_tt_in_fw(mvm)) {
1030 /* in order to give the responsibility of ct-kill and
1031 * TX backoff to FW we need to send empty temperature reporting
1032 * cmd during init time
1033 */
1034 iwl_mvm_send_temp_report_ths_cmd(mvm);
1035 } else {
1036 /* Initialize tx backoffs to the minimal possible */
1037 iwl_mvm_tt_tx_backoff(mvm, 0);
1038 }
Chaya Rachel Ivgi5c89e7b2016-01-05 10:34:47 +02001039
1040 /* TODO: read the budget from BIOS / Platform NVM */
1041 if (iwl_mvm_is_ctdp_supported(mvm) && mvm->cooling_dev.cur_state > 0)
1042 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START,
1043 mvm->cooling_dev.cur_state);
Chaya Rachel Ivgic221daf2015-12-29 09:54:49 +02001044#else
Ido Yariv0c0e2c72014-01-16 21:12:02 -05001045 /* Initialize tx backoffs to the minimal possible */
1046 iwl_mvm_tt_tx_backoff(mvm, 0);
Chaya Rachel Ivgic221daf2015-12-29 09:54:49 +02001047#endif
Ido Yariv0c0e2c72014-01-16 21:12:02 -05001048
Emmanuel Grumbach84bfffa2015-01-13 10:16:30 +02001049 WARN_ON(iwl_mvm_config_ltr(mvm));
Emmanuel Grumbach9180ac52014-09-23 23:02:41 +03001050
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +02001051 ret = iwl_mvm_power_update_device(mvm);
Alexander Bondar64b928c2013-09-03 14:18:03 +03001052 if (ret)
1053 goto error;
1054
Arik Nemtsov35af15d2015-03-04 15:08:00 +02001055 /*
1056 * RTNL is not taken during Ct-kill, but we don't need to scan/Tx
1057 * anyway, so don't init MCC.
1058 */
1059 if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) {
1060 ret = iwl_mvm_init_mcc(mvm);
1061 if (ret)
1062 goto error;
1063 }
Arik Nemtsov90d4f7d2014-03-04 19:58:46 +02001064
Johannes Berg859d9142015-06-01 17:11:11 +02001065 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
Emmanuel Grumbach4ca87a52016-01-03 22:23:40 +02001066 mvm->scan_type = IWL_SCAN_TYPE_NOT_SET;
David Spinadeld2496222014-05-20 12:46:37 +03001067 ret = iwl_mvm_config_scan(mvm);
1068 if (ret)
1069 goto error;
1070 }
1071
Avri Altman93190fb2014-12-27 09:09:47 +02001072 if (iwl_mvm_is_csum_supported(mvm) &&
1073 mvm->cfg->features & NETIF_F_RXCSUM)
1074 iwl_trans_write_prph(mvm->trans, RX_EN_CSUM, 0x3);
1075
Eliad Peller7498cf42014-01-16 17:10:44 +02001076 /* allow FW/transport low power modes if not during restart */
1077 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1078 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1079
Ilan Peer53a9d612013-04-28 11:55:08 +03001080 IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001081 return 0;
1082 error:
Chaya Rachel Ivgifcb6b922016-02-22 10:21:41 +02001083 iwl_mvm_stop_device(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001084 return ret;
1085}
1086
1087int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
1088{
1089 int ret, i;
1090
1091 lockdep_assert_held(&mvm->mutex);
1092
1093 ret = iwl_trans_start_hw(mvm->trans);
1094 if (ret)
1095 return ret;
1096
1097 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
1098 if (ret) {
1099 IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
1100 goto error;
1101 }
1102
Moshe Harela0544272014-12-08 21:13:14 +02001103 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001104 if (ret)
1105 goto error;
1106
1107 /* Send phy db control command and then phy db calibration*/
1108 ret = iwl_send_phy_db_data(mvm->phy_db);
1109 if (ret)
1110 goto error;
1111
1112 ret = iwl_send_phy_cfg_cmd(mvm);
1113 if (ret)
1114 goto error;
1115
1116 /* init the fw <-> mac80211 STA mapping */
1117 for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
1118 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1119
1120 /* Add auxiliary station for scanning */
1121 ret = iwl_mvm_add_aux_sta(mvm);
1122 if (ret)
1123 goto error;
1124
1125 return 0;
1126 error:
Chaya Rachel Ivgifcb6b922016-02-22 10:21:41 +02001127 iwl_mvm_stop_device(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001128 return ret;
1129}
1130
Johannes Berg04168412015-06-23 21:22:09 +02001131void iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
1132 struct iwl_rx_cmd_buffer *rxb)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001133{
1134 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1135 struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
1136 u32 flags = le32_to_cpu(card_state_notif->flags);
1137
1138 IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
1139 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1140 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
1141 (flags & CT_KILL_CARD_DISABLED) ?
1142 "Reached" : "Not reached");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001143}
1144
Johannes Berg04168412015-06-23 21:22:09 +02001145void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
1146 struct iwl_rx_cmd_buffer *rxb)
Chaya Rachel Ivgy30269c12014-11-15 21:08:29 +02001147{
1148 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1149 struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data;
1150
1151 IWL_DEBUG_INFO(mvm,
1152 "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n",
1153 le32_to_cpu(mfuart_notif->installed_ver),
1154 le32_to_cpu(mfuart_notif->external_ver),
1155 le32_to_cpu(mfuart_notif->status),
1156 le32_to_cpu(mfuart_notif->duration));
Chaya Rachel Ivgy30269c12014-11-15 21:08:29 +02001157}