1 /******************************************************************************
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.
8 * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2015 Intel Deutschland GmbH
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.
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.
21 * You should have received a copy of the GNU General Public License
22 * along with this program;
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
27 * Contact Information:
28 * Intel Linux Wireless <linuxwifi@intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
34 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
35 * Copyright(c) 2015 Intel Deutschland GmbH
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *****************************************************************************/
65 #include <linux/devcoredump.h>
73 static ssize_t iwl_mvm_read_coredump(char *buffer, loff_t offset, size_t count,
74 const void *data, size_t datalen)
76 const struct iwl_mvm_dump_ptrs *dump_ptrs = data;
78 ssize_t bytes_read_trans;
80 if (offset < dump_ptrs->op_mode_len) {
81 bytes_read = min_t(ssize_t, count,
82 dump_ptrs->op_mode_len - offset);
83 memcpy(buffer, (u8 *)dump_ptrs->op_mode_ptr + offset,
94 if (!dump_ptrs->trans_ptr)
97 offset -= dump_ptrs->op_mode_len;
98 bytes_read_trans = min_t(ssize_t, count,
99 dump_ptrs->trans_ptr->len - offset);
100 memcpy(buffer + bytes_read,
101 (u8 *)dump_ptrs->trans_ptr->data + offset,
104 return bytes_read + bytes_read_trans;
107 static void iwl_mvm_free_coredump(const void *data)
109 const struct iwl_mvm_dump_ptrs *fw_error_dump = data;
111 vfree(fw_error_dump->op_mode_ptr);
112 vfree(fw_error_dump->trans_ptr);
113 kfree(fw_error_dump);
116 #define RADIO_REG_MAX_READ 0x2ad
117 static void iwl_mvm_read_radio_reg(struct iwl_mvm *mvm,
118 struct iwl_fw_error_dump_data **dump_data)
120 u8 *pos = (void *)(*dump_data)->data;
124 if (!iwl_trans_grab_nic_access(mvm->trans, &flags))
127 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RADIO_REG);
128 (*dump_data)->len = cpu_to_le32(RADIO_REG_MAX_READ);
130 for (i = 0; i < RADIO_REG_MAX_READ; i++) {
131 u32 rd_cmd = RADIO_RSP_RD_CMD;
133 rd_cmd |= i << RADIO_RSP_ADDR_POS;
134 iwl_write_prph_no_grab(mvm->trans, RSP_RADIO_CMD, rd_cmd);
135 *pos = (u8)iwl_read_prph_no_grab(mvm->trans, RSP_RADIO_RDDAT);
140 *dump_data = iwl_fw_error_next_data(*dump_data);
142 iwl_trans_release_nic_access(mvm->trans, &flags);
145 static void iwl_mvm_dump_fifos(struct iwl_mvm *mvm,
146 struct iwl_fw_error_dump_data **dump_data)
148 struct iwl_fw_error_dump_fifo *fifo_hdr;
154 if (!iwl_trans_grab_nic_access(mvm->trans, &flags))
157 /* Pull RXF data from all RXFs */
158 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++) {
160 * Keep aside the additional offset that might be needed for
163 u32 offset_diff = RXF_DIFF_FROM_PREV * i;
165 fifo_hdr = (void *)(*dump_data)->data;
166 fifo_data = (void *)fifo_hdr->data;
167 fifo_len = mvm->shared_mem_cfg.rxfifo_size[i];
169 /* No need to try to read the data if the length is 0 */
173 /* Add a TLV for the RXF */
174 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_RXF);
175 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
177 fifo_hdr->fifo_num = cpu_to_le32(i);
178 fifo_hdr->available_bytes =
179 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
183 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
187 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
190 fifo_hdr->fence_ptr =
191 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
194 fifo_hdr->fence_mode =
195 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
200 iwl_trans_write_prph(mvm->trans,
201 RXF_SET_FENCE_MODE + offset_diff, 0x1);
202 /* Set fence pointer to the same place like WR pointer */
203 iwl_trans_write_prph(mvm->trans,
204 RXF_LD_WR2FENCE + offset_diff, 0x1);
205 /* Set fence offset */
206 iwl_trans_write_prph(mvm->trans,
207 RXF_LD_FENCE_OFFSET_ADDR + offset_diff,
211 fifo_len /= sizeof(u32); /* Size in DWORDS */
212 for (j = 0; j < fifo_len; j++)
213 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
214 RXF_FIFO_RD_FENCE_INC +
216 *dump_data = iwl_fw_error_next_data(*dump_data);
219 /* Pull TXF data from all TXFs */
220 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++) {
221 /* Mark the number of TXF we're pulling now */
222 iwl_trans_write_prph(mvm->trans, TXF_LARC_NUM, i);
224 fifo_hdr = (void *)(*dump_data)->data;
225 fifo_data = (void *)fifo_hdr->data;
226 fifo_len = mvm->shared_mem_cfg.txfifo_size[i];
228 /* No need to try to read the data if the length is 0 */
232 /* Add a TLV for the FIFO */
233 (*dump_data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_TXF);
234 (*dump_data)->len = cpu_to_le32(fifo_len + sizeof(*fifo_hdr));
236 fifo_hdr->fifo_num = cpu_to_le32(i);
237 fifo_hdr->available_bytes =
238 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
241 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
244 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
246 fifo_hdr->fence_ptr =
247 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
249 fifo_hdr->fence_mode =
250 cpu_to_le32(iwl_trans_read_prph(mvm->trans,
253 /* Set the TXF_READ_MODIFY_ADDR to TXF_WR_PTR */
254 iwl_trans_write_prph(mvm->trans, TXF_READ_MODIFY_ADDR,
257 /* Dummy-read to advance the read pointer to the head */
258 iwl_trans_read_prph(mvm->trans, TXF_READ_MODIFY_DATA);
261 fifo_len /= sizeof(u32); /* Size in DWORDS */
262 for (j = 0; j < fifo_len; j++)
263 fifo_data[j] = iwl_trans_read_prph(mvm->trans,
264 TXF_READ_MODIFY_DATA);
265 *dump_data = iwl_fw_error_next_data(*dump_data);
268 iwl_trans_release_nic_access(mvm->trans, &flags);
271 void iwl_mvm_free_fw_dump_desc(struct iwl_mvm *mvm)
273 if (mvm->fw_dump_desc == &iwl_mvm_dump_desc_assert)
276 kfree(mvm->fw_dump_desc);
277 mvm->fw_dump_desc = NULL;
280 #define IWL8260_ICCM_OFFSET 0x44000 /* Only for B-step */
281 #define IWL8260_ICCM_LEN 0xC000 /* Only for B-step */
283 static const struct {
285 } iwl_prph_dump_addr[] = {
286 { .start = 0x00a00000, .end = 0x00a00000 },
287 { .start = 0x00a0000c, .end = 0x00a00024 },
288 { .start = 0x00a0002c, .end = 0x00a0003c },
289 { .start = 0x00a00410, .end = 0x00a00418 },
290 { .start = 0x00a00420, .end = 0x00a00420 },
291 { .start = 0x00a00428, .end = 0x00a00428 },
292 { .start = 0x00a00430, .end = 0x00a0043c },
293 { .start = 0x00a00444, .end = 0x00a00444 },
294 { .start = 0x00a004c0, .end = 0x00a004cc },
295 { .start = 0x00a004d8, .end = 0x00a004d8 },
296 { .start = 0x00a004e0, .end = 0x00a004f0 },
297 { .start = 0x00a00840, .end = 0x00a00840 },
298 { .start = 0x00a00850, .end = 0x00a00858 },
299 { .start = 0x00a01004, .end = 0x00a01008 },
300 { .start = 0x00a01010, .end = 0x00a01010 },
301 { .start = 0x00a01018, .end = 0x00a01018 },
302 { .start = 0x00a01024, .end = 0x00a01024 },
303 { .start = 0x00a0102c, .end = 0x00a01034 },
304 { .start = 0x00a0103c, .end = 0x00a01040 },
305 { .start = 0x00a01048, .end = 0x00a01094 },
306 { .start = 0x00a01c00, .end = 0x00a01c20 },
307 { .start = 0x00a01c58, .end = 0x00a01c58 },
308 { .start = 0x00a01c7c, .end = 0x00a01c7c },
309 { .start = 0x00a01c28, .end = 0x00a01c54 },
310 { .start = 0x00a01c5c, .end = 0x00a01c5c },
311 { .start = 0x00a01c60, .end = 0x00a01cdc },
312 { .start = 0x00a01ce0, .end = 0x00a01d0c },
313 { .start = 0x00a01d18, .end = 0x00a01d20 },
314 { .start = 0x00a01d2c, .end = 0x00a01d30 },
315 { .start = 0x00a01d40, .end = 0x00a01d5c },
316 { .start = 0x00a01d80, .end = 0x00a01d80 },
317 { .start = 0x00a01d98, .end = 0x00a01d9c },
318 { .start = 0x00a01da8, .end = 0x00a01da8 },
319 { .start = 0x00a01db8, .end = 0x00a01df4 },
320 { .start = 0x00a01dc0, .end = 0x00a01dfc },
321 { .start = 0x00a01e00, .end = 0x00a01e2c },
322 { .start = 0x00a01e40, .end = 0x00a01e60 },
323 { .start = 0x00a01e68, .end = 0x00a01e6c },
324 { .start = 0x00a01e74, .end = 0x00a01e74 },
325 { .start = 0x00a01e84, .end = 0x00a01e90 },
326 { .start = 0x00a01e9c, .end = 0x00a01ec4 },
327 { .start = 0x00a01ed0, .end = 0x00a01ee0 },
328 { .start = 0x00a01f00, .end = 0x00a01f1c },
329 { .start = 0x00a01f44, .end = 0x00a01ffc },
330 { .start = 0x00a02000, .end = 0x00a02048 },
331 { .start = 0x00a02068, .end = 0x00a020f0 },
332 { .start = 0x00a02100, .end = 0x00a02118 },
333 { .start = 0x00a02140, .end = 0x00a0214c },
334 { .start = 0x00a02168, .end = 0x00a0218c },
335 { .start = 0x00a021c0, .end = 0x00a021c0 },
336 { .start = 0x00a02400, .end = 0x00a02410 },
337 { .start = 0x00a02418, .end = 0x00a02420 },
338 { .start = 0x00a02428, .end = 0x00a0242c },
339 { .start = 0x00a02434, .end = 0x00a02434 },
340 { .start = 0x00a02440, .end = 0x00a02460 },
341 { .start = 0x00a02468, .end = 0x00a024b0 },
342 { .start = 0x00a024c8, .end = 0x00a024cc },
343 { .start = 0x00a02500, .end = 0x00a02504 },
344 { .start = 0x00a0250c, .end = 0x00a02510 },
345 { .start = 0x00a02540, .end = 0x00a02554 },
346 { .start = 0x00a02580, .end = 0x00a025f4 },
347 { .start = 0x00a02600, .end = 0x00a0260c },
348 { .start = 0x00a02648, .end = 0x00a02650 },
349 { .start = 0x00a02680, .end = 0x00a02680 },
350 { .start = 0x00a026c0, .end = 0x00a026d0 },
351 { .start = 0x00a02700, .end = 0x00a0270c },
352 { .start = 0x00a02804, .end = 0x00a02804 },
353 { .start = 0x00a02818, .end = 0x00a0281c },
354 { .start = 0x00a02c00, .end = 0x00a02db4 },
355 { .start = 0x00a02df4, .end = 0x00a02fb0 },
356 { .start = 0x00a03000, .end = 0x00a03014 },
357 { .start = 0x00a0301c, .end = 0x00a0302c },
358 { .start = 0x00a03034, .end = 0x00a03038 },
359 { .start = 0x00a03040, .end = 0x00a03048 },
360 { .start = 0x00a03060, .end = 0x00a03068 },
361 { .start = 0x00a03070, .end = 0x00a03074 },
362 { .start = 0x00a0307c, .end = 0x00a0307c },
363 { .start = 0x00a03080, .end = 0x00a03084 },
364 { .start = 0x00a0308c, .end = 0x00a03090 },
365 { .start = 0x00a03098, .end = 0x00a03098 },
366 { .start = 0x00a030a0, .end = 0x00a030a0 },
367 { .start = 0x00a030a8, .end = 0x00a030b4 },
368 { .start = 0x00a030bc, .end = 0x00a030bc },
369 { .start = 0x00a030c0, .end = 0x00a0312c },
370 { .start = 0x00a03c00, .end = 0x00a03c5c },
371 { .start = 0x00a04400, .end = 0x00a04454 },
372 { .start = 0x00a04460, .end = 0x00a04474 },
373 { .start = 0x00a044c0, .end = 0x00a044ec },
374 { .start = 0x00a04500, .end = 0x00a04504 },
375 { .start = 0x00a04510, .end = 0x00a04538 },
376 { .start = 0x00a04540, .end = 0x00a04548 },
377 { .start = 0x00a04560, .end = 0x00a0457c },
378 { .start = 0x00a04590, .end = 0x00a04598 },
379 { .start = 0x00a045c0, .end = 0x00a045f4 },
380 { .start = 0x00a44000, .end = 0x00a7bf80 },
383 static u32 iwl_dump_prph(struct iwl_trans *trans,
384 struct iwl_fw_error_dump_data **data)
386 struct iwl_fw_error_dump_prph *prph;
390 if (!iwl_trans_grab_nic_access(trans, &flags))
393 for (i = 0; i < ARRAY_SIZE(iwl_prph_dump_addr); i++) {
394 /* The range includes both boundaries */
395 int num_bytes_in_chunk = iwl_prph_dump_addr[i].end -
396 iwl_prph_dump_addr[i].start + 4;
400 prph_len += sizeof(**data) + sizeof(*prph) + num_bytes_in_chunk;
402 (*data)->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PRPH);
403 (*data)->len = cpu_to_le32(sizeof(*prph) +
405 prph = (void *)(*data)->data;
406 prph->prph_start = cpu_to_le32(iwl_prph_dump_addr[i].start);
407 val = (void *)prph->data;
409 for (reg = iwl_prph_dump_addr[i].start;
410 reg <= iwl_prph_dump_addr[i].end;
412 *val++ = cpu_to_le32(iwl_read_prph_no_grab(trans,
415 *data = iwl_fw_error_next_data(*data);
418 iwl_trans_release_nic_access(trans, &flags);
423 void iwl_mvm_fw_error_dump(struct iwl_mvm *mvm)
425 struct iwl_fw_error_dump_file *dump_file;
426 struct iwl_fw_error_dump_data *dump_data;
427 struct iwl_fw_error_dump_info *dump_info;
428 struct iwl_fw_error_dump_mem *dump_mem;
429 struct iwl_fw_error_dump_trigger_desc *dump_trig;
430 struct iwl_mvm_dump_ptrs *fw_error_dump;
431 u32 sram_len, sram_ofs;
432 u32 file_len, fifo_data_len = 0, prph_len = 0, radio_len = 0;
433 u32 smem_len = mvm->cfg->smem_len;
434 u32 sram2_len = mvm->cfg->dccm2_len;
435 bool monitor_dump_only = false;
438 if (!IWL_MVM_COLLECT_FW_ERR_DUMP &&
439 !mvm->trans->dbg_dest_tlv)
442 lockdep_assert_held(&mvm->mutex);
444 /* there's no point in fw dump if the bus is dead */
445 if (test_bit(STATUS_TRANS_DEAD, &mvm->trans->status)) {
446 IWL_ERR(mvm, "Skip fw error dump since bus is dead\n");
450 if (mvm->fw_dump_trig &&
451 mvm->fw_dump_trig->mode & IWL_FW_DBG_TRIGGER_MONITOR_ONLY)
452 monitor_dump_only = true;
454 fw_error_dump = kzalloc(sizeof(*fw_error_dump), GFP_KERNEL);
458 /* SRAM - include stack CCM if driver knows the values for it */
459 if (!mvm->cfg->dccm_offset || !mvm->cfg->dccm_len) {
460 const struct fw_img *img;
462 img = &mvm->fw->img[mvm->cur_ucode];
463 sram_ofs = img->sec[IWL_UCODE_SECTION_DATA].offset;
464 sram_len = img->sec[IWL_UCODE_SECTION_DATA].len;
466 sram_ofs = mvm->cfg->dccm_offset;
467 sram_len = mvm->cfg->dccm_len;
470 /* reading RXF/TXF sizes */
471 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
472 struct iwl_mvm_shared_mem_cfg *mem_cfg = &mvm->shared_mem_cfg;
477 for (i = 0; i < ARRAY_SIZE(mem_cfg->rxfifo_size); i++) {
478 if (!mem_cfg->rxfifo_size[i])
481 /* Add header info */
482 fifo_data_len += mem_cfg->rxfifo_size[i] +
484 sizeof(struct iwl_fw_error_dump_fifo);
487 for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++) {
488 if (!mem_cfg->txfifo_size[i])
491 /* Add header info */
492 fifo_data_len += mem_cfg->txfifo_size[i] +
494 sizeof(struct iwl_fw_error_dump_fifo);
497 /* Make room for PRPH registers */
498 for (i = 0; i < ARRAY_SIZE(iwl_prph_dump_addr); i++) {
499 /* The range includes both boundaries */
500 int num_bytes_in_chunk = iwl_prph_dump_addr[i].end -
501 iwl_prph_dump_addr[i].start + 4;
503 prph_len += sizeof(*dump_data) +
504 sizeof(struct iwl_fw_error_dump_prph) +
508 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000)
509 radio_len = sizeof(*dump_data) + RADIO_REG_MAX_READ;
512 file_len = sizeof(*dump_file) +
513 sizeof(*dump_data) * 2 +
514 sram_len + sizeof(*dump_mem) +
520 /* Make room for the SMEM, if it exists */
522 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + smem_len;
524 /* Make room for the secondary SRAM, if it exists */
526 file_len += sizeof(*dump_data) + sizeof(*dump_mem) + sram2_len;
528 /* Make room for fw's virtual image pages, if it exists */
529 if (mvm->fw->img[mvm->cur_ucode].paging_mem_size)
530 file_len += mvm->num_of_paging_blk *
531 (sizeof(*dump_data) +
532 sizeof(struct iwl_fw_error_dump_paging) +
535 /* If we only want a monitor dump, reset the file length */
536 if (monitor_dump_only) {
537 file_len = sizeof(*dump_file) + sizeof(*dump_data) +
542 * In 8000 HW family B-step include the ICCM (which resides separately)
544 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
545 CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_B_STEP)
546 file_len += sizeof(*dump_data) + sizeof(*dump_mem) +
549 if (mvm->fw_dump_desc)
550 file_len += sizeof(*dump_data) + sizeof(*dump_trig) +
551 mvm->fw_dump_desc->len;
553 dump_file = vzalloc(file_len);
555 kfree(fw_error_dump);
559 fw_error_dump->op_mode_ptr = dump_file;
561 dump_file->barker = cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER);
562 dump_data = (void *)dump_file->data;
564 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO);
565 dump_data->len = cpu_to_le32(sizeof(*dump_info));
566 dump_info = (void *)dump_data->data;
567 dump_info->device_family =
568 mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000 ?
569 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7) :
570 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8);
571 dump_info->hw_step = cpu_to_le32(CSR_HW_REV_STEP(mvm->trans->hw_rev));
572 memcpy(dump_info->fw_human_readable, mvm->fw->human_readable,
573 sizeof(dump_info->fw_human_readable));
574 strncpy(dump_info->dev_human_readable, mvm->cfg->name,
575 sizeof(dump_info->dev_human_readable));
576 strncpy(dump_info->bus_human_readable, mvm->dev->bus->name,
577 sizeof(dump_info->bus_human_readable));
579 dump_data = iwl_fw_error_next_data(dump_data);
580 /* We only dump the FIFOs if the FW is in error state */
581 if (test_bit(STATUS_FW_ERROR, &mvm->trans->status)) {
582 iwl_mvm_dump_fifos(mvm, &dump_data);
584 iwl_mvm_read_radio_reg(mvm, &dump_data);
587 if (mvm->fw_dump_desc) {
588 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_ERROR_INFO);
589 dump_data->len = cpu_to_le32(sizeof(*dump_trig) +
590 mvm->fw_dump_desc->len);
591 dump_trig = (void *)dump_data->data;
592 memcpy(dump_trig, &mvm->fw_dump_desc->trig_desc,
593 sizeof(*dump_trig) + mvm->fw_dump_desc->len);
595 dump_data = iwl_fw_error_next_data(dump_data);
598 /* In case we only want monitor dump, skip to dump trasport data */
599 if (monitor_dump_only)
600 goto dump_trans_data;
602 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
603 dump_data->len = cpu_to_le32(sram_len + sizeof(*dump_mem));
604 dump_mem = (void *)dump_data->data;
605 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
606 dump_mem->offset = cpu_to_le32(sram_ofs);
607 iwl_trans_read_mem_bytes(mvm->trans, sram_ofs, dump_mem->data,
611 dump_data = iwl_fw_error_next_data(dump_data);
612 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
613 dump_data->len = cpu_to_le32(smem_len + sizeof(*dump_mem));
614 dump_mem = (void *)dump_data->data;
615 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SMEM);
616 dump_mem->offset = cpu_to_le32(mvm->cfg->smem_offset);
617 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->smem_offset,
618 dump_mem->data, smem_len);
622 dump_data = iwl_fw_error_next_data(dump_data);
623 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
624 dump_data->len = cpu_to_le32(sram2_len + sizeof(*dump_mem));
625 dump_mem = (void *)dump_data->data;
626 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
627 dump_mem->offset = cpu_to_le32(mvm->cfg->dccm2_offset);
628 iwl_trans_read_mem_bytes(mvm->trans, mvm->cfg->dccm2_offset,
629 dump_mem->data, sram2_len);
632 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_8000 &&
633 CSR_HW_REV_STEP(mvm->trans->hw_rev) == SILICON_B_STEP) {
634 dump_data = iwl_fw_error_next_data(dump_data);
635 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM);
636 dump_data->len = cpu_to_le32(IWL8260_ICCM_LEN +
638 dump_mem = (void *)dump_data->data;
639 dump_mem->type = cpu_to_le32(IWL_FW_ERROR_DUMP_MEM_SRAM);
640 dump_mem->offset = cpu_to_le32(IWL8260_ICCM_OFFSET);
641 iwl_trans_read_mem_bytes(mvm->trans, IWL8260_ICCM_OFFSET,
642 dump_mem->data, IWL8260_ICCM_LEN);
645 /* Dump fw's virtual image */
646 if (mvm->fw->img[mvm->cur_ucode].paging_mem_size) {
647 for (i = 1; i < mvm->num_of_paging_blk + 1; i++) {
648 struct iwl_fw_error_dump_paging *paging;
650 mvm->fw_paging_db[i].fw_paging_block;
652 dump_data = iwl_fw_error_next_data(dump_data);
653 dump_data->type = cpu_to_le32(IWL_FW_ERROR_DUMP_PAGING);
654 dump_data->len = cpu_to_le32(sizeof(*paging) +
656 paging = (void *)dump_data->data;
657 paging->index = cpu_to_le32(i);
658 memcpy(paging->data, page_address(pages),
663 dump_data = iwl_fw_error_next_data(dump_data);
665 iwl_dump_prph(mvm->trans, &dump_data);
668 fw_error_dump->trans_ptr = iwl_trans_dump_data(mvm->trans,
670 fw_error_dump->op_mode_len = file_len;
671 if (fw_error_dump->trans_ptr)
672 file_len += fw_error_dump->trans_ptr->len;
673 dump_file->file_len = cpu_to_le32(file_len);
675 dev_coredumpm(mvm->trans->dev, THIS_MODULE, fw_error_dump, 0,
676 GFP_KERNEL, iwl_mvm_read_coredump, iwl_mvm_free_coredump);
679 iwl_mvm_free_fw_dump_desc(mvm);
680 mvm->fw_dump_trig = NULL;
681 clear_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status);
684 const struct iwl_mvm_dump_desc iwl_mvm_dump_desc_assert = {
686 .type = cpu_to_le32(FW_DBG_TRIGGER_FW_ASSERT),
690 int iwl_mvm_fw_dbg_collect_desc(struct iwl_mvm *mvm,
691 const struct iwl_mvm_dump_desc *desc,
692 const struct iwl_fw_dbg_trigger_tlv *trigger)
694 unsigned int delay = 0;
697 delay = msecs_to_jiffies(le32_to_cpu(trigger->stop_delay));
699 if (test_and_set_bit(IWL_MVM_STATUS_DUMPING_FW_LOG, &mvm->status))
702 if (WARN_ON(mvm->fw_dump_desc))
703 iwl_mvm_free_fw_dump_desc(mvm);
705 IWL_WARN(mvm, "Collecting data: trigger %d fired.\n",
706 le32_to_cpu(desc->trig_desc.type));
708 mvm->fw_dump_desc = desc;
709 mvm->fw_dump_trig = trigger;
711 queue_delayed_work(system_wq, &mvm->fw_dump_wk, delay);
716 int iwl_mvm_fw_dbg_collect(struct iwl_mvm *mvm, enum iwl_fw_dbg_trigger trig,
717 const char *str, size_t len,
718 const struct iwl_fw_dbg_trigger_tlv *trigger)
720 struct iwl_mvm_dump_desc *desc;
722 desc = kzalloc(sizeof(*desc) + len, GFP_ATOMIC);
727 desc->trig_desc.type = cpu_to_le32(trig);
728 memcpy(desc->trig_desc.data, str, len);
730 return iwl_mvm_fw_dbg_collect_desc(mvm, desc, trigger);
733 int iwl_mvm_fw_dbg_collect_trig(struct iwl_mvm *mvm,
734 struct iwl_fw_dbg_trigger_tlv *trigger,
735 const char *fmt, ...)
737 u16 occurrences = le16_to_cpu(trigger->occurrences);
747 buf[sizeof(buf) - 1] = '\0';
750 vsnprintf(buf, sizeof(buf), fmt, ap);
753 /* check for truncation */
754 if (WARN_ON_ONCE(buf[sizeof(buf) - 1]))
755 buf[sizeof(buf) - 1] = '\0';
757 len = strlen(buf) + 1;
760 ret = iwl_mvm_fw_dbg_collect(mvm, le32_to_cpu(trigger->id), buf, len,
766 trigger->occurrences = cpu_to_le16(occurrences - 1);
770 static inline void iwl_mvm_restart_early_start(struct iwl_mvm *mvm)
772 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000)
773 iwl_clear_bits_prph(mvm->trans, MON_BUFF_SAMPLE_CTL, 0x100);
775 iwl_write_prph(mvm->trans, DBGC_IN_SAMPLE, 1);
778 int iwl_mvm_start_fw_dbg_conf(struct iwl_mvm *mvm, u8 conf_id)
784 if (WARN_ONCE(conf_id >= ARRAY_SIZE(mvm->fw->dbg_conf_tlv),
785 "Invalid configuration %d\n", conf_id))
788 /* EARLY START - firmware's configuration is hard coded */
789 if ((!mvm->fw->dbg_conf_tlv[conf_id] ||
790 !mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds) &&
791 conf_id == FW_DBG_START_FROM_ALIVE) {
792 iwl_mvm_restart_early_start(mvm);
796 if (!mvm->fw->dbg_conf_tlv[conf_id])
799 if (mvm->fw_dbg_conf != FW_DBG_INVALID)
800 IWL_WARN(mvm, "FW already configured (%d) - re-configuring\n",
803 /* Send all HCMDs for configuring the FW debug */
804 ptr = (void *)&mvm->fw->dbg_conf_tlv[conf_id]->hcmd;
805 for (i = 0; i < mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds; i++) {
806 struct iwl_fw_dbg_conf_hcmd *cmd = (void *)ptr;
808 ret = iwl_mvm_send_cmd_pdu(mvm, cmd->id, 0,
809 le16_to_cpu(cmd->len), cmd->data);
814 ptr += le16_to_cpu(cmd->len);
817 mvm->fw_dbg_conf = conf_id;