xref: /linux/drivers/net/wireless/intel/iwlwifi/fw/dump.c (revision 425d66d8ddfc4aaf692030aea67932dc59f69abf)
14db7cf1eSJohannes Berg // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
24db7cf1eSJohannes Berg /*
34db7cf1eSJohannes Berg  * Copyright (C) 2012-2014, 2018-2021 Intel Corporation
44db7cf1eSJohannes Berg  * Copyright (C) 2013-2014 Intel Mobile Communications GmbH
54db7cf1eSJohannes Berg  * Copyright (C) 2015-2017 Intel Deutschland GmbH
64db7cf1eSJohannes Berg  */
74db7cf1eSJohannes Berg #include <linux/devcoredump.h>
84db7cf1eSJohannes Berg #include "iwl-drv.h"
94db7cf1eSJohannes Berg #include "runtime.h"
104db7cf1eSJohannes Berg #include "dbg.h"
114db7cf1eSJohannes Berg #include "debugfs.h"
124db7cf1eSJohannes Berg #include "iwl-io.h"
134db7cf1eSJohannes Berg #include "iwl-prph.h"
144db7cf1eSJohannes Berg #include "iwl-csr.h"
154db7cf1eSJohannes Berg 
164db7cf1eSJohannes Berg /*
174db7cf1eSJohannes Berg  * Note: This structure is read from the device with IO accesses,
184db7cf1eSJohannes Berg  * and the reading already does the endian conversion. As it is
194db7cf1eSJohannes Berg  * read with u32-sized accesses, any members with a different size
204db7cf1eSJohannes Berg  * need to be ordered correctly though!
214db7cf1eSJohannes Berg  */
224db7cf1eSJohannes Berg struct iwl_error_event_table_v1 {
234db7cf1eSJohannes Berg 	u32 valid;		/* (nonzero) valid, (0) log is empty */
244db7cf1eSJohannes Berg 	u32 error_id;		/* type of error */
254db7cf1eSJohannes Berg 	u32 pc;			/* program counter */
264db7cf1eSJohannes Berg 	u32 blink1;		/* branch link */
274db7cf1eSJohannes Berg 	u32 blink2;		/* branch link */
284db7cf1eSJohannes Berg 	u32 ilink1;		/* interrupt link */
294db7cf1eSJohannes Berg 	u32 ilink2;		/* interrupt link */
304db7cf1eSJohannes Berg 	u32 data1;		/* error-specific data */
314db7cf1eSJohannes Berg 	u32 data2;		/* error-specific data */
324db7cf1eSJohannes Berg 	u32 data3;		/* error-specific data */
334db7cf1eSJohannes Berg 	u32 bcon_time;		/* beacon timer */
344db7cf1eSJohannes Berg 	u32 tsf_low;		/* network timestamp function timer */
354db7cf1eSJohannes Berg 	u32 tsf_hi;		/* network timestamp function timer */
364db7cf1eSJohannes Berg 	u32 gp1;		/* GP1 timer register */
374db7cf1eSJohannes Berg 	u32 gp2;		/* GP2 timer register */
384db7cf1eSJohannes Berg 	u32 gp3;		/* GP3 timer register */
394db7cf1eSJohannes Berg 	u32 ucode_ver;		/* uCode version */
404db7cf1eSJohannes Berg 	u32 hw_ver;		/* HW Silicon version */
414db7cf1eSJohannes Berg 	u32 brd_ver;		/* HW board version */
424db7cf1eSJohannes Berg 	u32 log_pc;		/* log program counter */
434db7cf1eSJohannes Berg 	u32 frame_ptr;		/* frame pointer */
444db7cf1eSJohannes Berg 	u32 stack_ptr;		/* stack pointer */
454db7cf1eSJohannes Berg 	u32 hcmd;		/* last host command header */
464db7cf1eSJohannes Berg 	u32 isr0;		/* isr status register LMPM_NIC_ISR0:
474db7cf1eSJohannes Berg 				 * rxtx_flag */
484db7cf1eSJohannes Berg 	u32 isr1;		/* isr status register LMPM_NIC_ISR1:
494db7cf1eSJohannes Berg 				 * host_flag */
504db7cf1eSJohannes Berg 	u32 isr2;		/* isr status register LMPM_NIC_ISR2:
514db7cf1eSJohannes Berg 				 * enc_flag */
524db7cf1eSJohannes Berg 	u32 isr3;		/* isr status register LMPM_NIC_ISR3:
534db7cf1eSJohannes Berg 				 * time_flag */
544db7cf1eSJohannes Berg 	u32 isr4;		/* isr status register LMPM_NIC_ISR4:
554db7cf1eSJohannes Berg 				 * wico interrupt */
564db7cf1eSJohannes Berg 	u32 isr_pref;		/* isr status register LMPM_NIC_PREF_STAT */
574db7cf1eSJohannes Berg 	u32 wait_event;		/* wait event() caller address */
584db7cf1eSJohannes Berg 	u32 l2p_control;	/* L2pControlField */
594db7cf1eSJohannes Berg 	u32 l2p_duration;	/* L2pDurationField */
604db7cf1eSJohannes Berg 	u32 l2p_mhvalid;	/* L2pMhValidBits */
614db7cf1eSJohannes Berg 	u32 l2p_addr_match;	/* L2pAddrMatchStat */
624db7cf1eSJohannes Berg 	u32 lmpm_pmg_sel;	/* indicate which clocks are turned on
634db7cf1eSJohannes Berg 				 * (LMPM_PMG_SEL) */
644db7cf1eSJohannes Berg 	u32 u_timestamp;	/* indicate when the date and time of the
654db7cf1eSJohannes Berg 				 * compilation */
664db7cf1eSJohannes Berg 	u32 flow_handler;	/* FH read/write pointers, RX credit */
674db7cf1eSJohannes Berg } __packed /* LOG_ERROR_TABLE_API_S_VER_1 */;
684db7cf1eSJohannes Berg 
694db7cf1eSJohannes Berg struct iwl_error_event_table {
704db7cf1eSJohannes Berg 	u32 valid;		/* (nonzero) valid, (0) log is empty */
714db7cf1eSJohannes Berg 	u32 error_id;		/* type of error */
724db7cf1eSJohannes Berg 	u32 trm_hw_status0;	/* TRM HW status */
734db7cf1eSJohannes Berg 	u32 trm_hw_status1;	/* TRM HW status */
744db7cf1eSJohannes Berg 	u32 blink2;		/* branch link */
754db7cf1eSJohannes Berg 	u32 ilink1;		/* interrupt link */
764db7cf1eSJohannes Berg 	u32 ilink2;		/* interrupt link */
774db7cf1eSJohannes Berg 	u32 data1;		/* error-specific data */
784db7cf1eSJohannes Berg 	u32 data2;		/* error-specific data */
794db7cf1eSJohannes Berg 	u32 data3;		/* error-specific data */
804db7cf1eSJohannes Berg 	u32 bcon_time;		/* beacon timer */
814db7cf1eSJohannes Berg 	u32 tsf_low;		/* network timestamp function timer */
824db7cf1eSJohannes Berg 	u32 tsf_hi;		/* network timestamp function timer */
834db7cf1eSJohannes Berg 	u32 gp1;		/* GP1 timer register */
844db7cf1eSJohannes Berg 	u32 gp2;		/* GP2 timer register */
854db7cf1eSJohannes Berg 	u32 fw_rev_type;	/* firmware revision type */
864db7cf1eSJohannes Berg 	u32 major;		/* uCode version major */
874db7cf1eSJohannes Berg 	u32 minor;		/* uCode version minor */
884db7cf1eSJohannes Berg 	u32 hw_ver;		/* HW Silicon version */
894db7cf1eSJohannes Berg 	u32 brd_ver;		/* HW board version */
904db7cf1eSJohannes Berg 	u32 log_pc;		/* log program counter */
914db7cf1eSJohannes Berg 	u32 frame_ptr;		/* frame pointer */
924db7cf1eSJohannes Berg 	u32 stack_ptr;		/* stack pointer */
934db7cf1eSJohannes Berg 	u32 hcmd;		/* last host command header */
944db7cf1eSJohannes Berg 	u32 isr0;		/* isr status register LMPM_NIC_ISR0:
954db7cf1eSJohannes Berg 				 * rxtx_flag */
964db7cf1eSJohannes Berg 	u32 isr1;		/* isr status register LMPM_NIC_ISR1:
974db7cf1eSJohannes Berg 				 * host_flag */
984db7cf1eSJohannes Berg 	u32 isr2;		/* isr status register LMPM_NIC_ISR2:
994db7cf1eSJohannes Berg 				 * enc_flag */
1004db7cf1eSJohannes Berg 	u32 isr3;		/* isr status register LMPM_NIC_ISR3:
1014db7cf1eSJohannes Berg 				 * time_flag */
1024db7cf1eSJohannes Berg 	u32 isr4;		/* isr status register LMPM_NIC_ISR4:
1034db7cf1eSJohannes Berg 				 * wico interrupt */
1044db7cf1eSJohannes Berg 	u32 last_cmd_id;	/* last HCMD id handled by the firmware */
1054db7cf1eSJohannes Berg 	u32 wait_event;		/* wait event() caller address */
1064db7cf1eSJohannes Berg 	u32 l2p_control;	/* L2pControlField */
1074db7cf1eSJohannes Berg 	u32 l2p_duration;	/* L2pDurationField */
1084db7cf1eSJohannes Berg 	u32 l2p_mhvalid;	/* L2pMhValidBits */
1094db7cf1eSJohannes Berg 	u32 l2p_addr_match;	/* L2pAddrMatchStat */
1104db7cf1eSJohannes Berg 	u32 lmpm_pmg_sel;	/* indicate which clocks are turned on
1114db7cf1eSJohannes Berg 				 * (LMPM_PMG_SEL) */
1124db7cf1eSJohannes Berg 	u32 u_timestamp;	/* indicate when the date and time of the
1134db7cf1eSJohannes Berg 				 * compilation */
1144db7cf1eSJohannes Berg 	u32 flow_handler;	/* FH read/write pointers, RX credit */
1154db7cf1eSJohannes Berg } __packed /* LOG_ERROR_TABLE_API_S_VER_3 */;
1164db7cf1eSJohannes Berg 
1174db7cf1eSJohannes Berg /*
1184db7cf1eSJohannes Berg  * UMAC error struct - relevant starting from family 8000 chip.
1194db7cf1eSJohannes Berg  * Note: This structure is read from the device with IO accesses,
1204db7cf1eSJohannes Berg  * and the reading already does the endian conversion. As it is
1214db7cf1eSJohannes Berg  * read with u32-sized accesses, any members with a different size
1224db7cf1eSJohannes Berg  * need to be ordered correctly though!
1234db7cf1eSJohannes Berg  */
1244db7cf1eSJohannes Berg struct iwl_umac_error_event_table {
1254db7cf1eSJohannes Berg 	u32 valid;		/* (nonzero) valid, (0) log is empty */
1264db7cf1eSJohannes Berg 	u32 error_id;		/* type of error */
1274db7cf1eSJohannes Berg 	u32 blink1;		/* branch link */
1284db7cf1eSJohannes Berg 	u32 blink2;		/* branch link */
1294db7cf1eSJohannes Berg 	u32 ilink1;		/* interrupt link */
1304db7cf1eSJohannes Berg 	u32 ilink2;		/* interrupt link */
1314db7cf1eSJohannes Berg 	u32 data1;		/* error-specific data */
1324db7cf1eSJohannes Berg 	u32 data2;		/* error-specific data */
1334db7cf1eSJohannes Berg 	u32 data3;		/* error-specific data */
1344db7cf1eSJohannes Berg 	u32 umac_major;
1354db7cf1eSJohannes Berg 	u32 umac_minor;
1364db7cf1eSJohannes Berg 	u32 frame_pointer;	/* core register 27*/
1374db7cf1eSJohannes Berg 	u32 stack_pointer;	/* core register 28 */
1384db7cf1eSJohannes Berg 	u32 cmd_header;		/* latest host cmd sent to UMAC */
1394db7cf1eSJohannes Berg 	u32 nic_isr_pref;	/* ISR status register */
1404db7cf1eSJohannes Berg } __packed;
1414db7cf1eSJohannes Berg 
1424db7cf1eSJohannes Berg #define ERROR_START_OFFSET  (1 * sizeof(u32))
1434db7cf1eSJohannes Berg #define ERROR_ELEM_SIZE     (7 * sizeof(u32))
1444db7cf1eSJohannes Berg 
1454db7cf1eSJohannes Berg static void iwl_fwrt_dump_umac_error_log(struct iwl_fw_runtime *fwrt)
1464db7cf1eSJohannes Berg {
1474db7cf1eSJohannes Berg 	struct iwl_trans *trans = fwrt->trans;
1484db7cf1eSJohannes Berg 	struct iwl_umac_error_event_table table = {};
1494db7cf1eSJohannes Berg 	u32 base = fwrt->trans->dbg.umac_error_event_table;
1504db7cf1eSJohannes Berg 
1514db7cf1eSJohannes Berg 	if (!base &&
1524db7cf1eSJohannes Berg 	    !(fwrt->trans->dbg.error_event_table_tlv_status &
1534db7cf1eSJohannes Berg 	      IWL_ERROR_EVENT_TABLE_UMAC))
1544db7cf1eSJohannes Berg 		return;
1554db7cf1eSJohannes Berg 
1564db7cf1eSJohannes Berg 	iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
1574db7cf1eSJohannes Berg 
1584db7cf1eSJohannes Berg 	if (table.valid)
1594db7cf1eSJohannes Berg 		fwrt->dump.umac_err_id = table.error_id;
1604db7cf1eSJohannes Berg 
1614db7cf1eSJohannes Berg 	if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
1624db7cf1eSJohannes Berg 		IWL_ERR(trans, "Start IWL Error Log Dump:\n");
1634db7cf1eSJohannes Berg 		IWL_ERR(trans, "Transport status: 0x%08lX, valid: %d\n",
1644db7cf1eSJohannes Berg 			fwrt->trans->status, table.valid);
1654db7cf1eSJohannes Berg 	}
1664db7cf1eSJohannes Berg 
1674db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | %s\n", table.error_id,
1684db7cf1eSJohannes Berg 		iwl_fw_lookup_assert_desc(table.error_id));
1694db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | umac branchlink1\n", table.blink1);
1704db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | umac branchlink2\n", table.blink2);
1714db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | umac interruptlink1\n", table.ilink1);
1724db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | umac interruptlink2\n", table.ilink2);
1734db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | umac data1\n", table.data1);
1744db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | umac data2\n", table.data2);
1754db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | umac data3\n", table.data3);
1764db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | umac major\n", table.umac_major);
1774db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | umac minor\n", table.umac_minor);
1784db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | frame pointer\n", table.frame_pointer);
1794db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | stack pointer\n", table.stack_pointer);
1804db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | last host cmd\n", table.cmd_header);
1814db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | isr status reg\n", table.nic_isr_pref);
1824db7cf1eSJohannes Berg }
1834db7cf1eSJohannes Berg 
1844db7cf1eSJohannes Berg static void iwl_fwrt_dump_lmac_error_log(struct iwl_fw_runtime *fwrt, u8 lmac_num)
1854db7cf1eSJohannes Berg {
1864db7cf1eSJohannes Berg 	struct iwl_trans *trans = fwrt->trans;
1874db7cf1eSJohannes Berg 	struct iwl_error_event_table table = {};
1884db7cf1eSJohannes Berg 	u32 val, base = fwrt->trans->dbg.lmac_error_event_table[lmac_num];
1894db7cf1eSJohannes Berg 
1904db7cf1eSJohannes Berg 	if (fwrt->cur_fw_img == IWL_UCODE_INIT) {
1914db7cf1eSJohannes Berg 		if (!base)
1924db7cf1eSJohannes Berg 			base = fwrt->fw->init_errlog_ptr;
1934db7cf1eSJohannes Berg 	} else {
1944db7cf1eSJohannes Berg 		if (!base)
1954db7cf1eSJohannes Berg 			base = fwrt->fw->inst_errlog_ptr;
1964db7cf1eSJohannes Berg 	}
1974db7cf1eSJohannes Berg 
1984db7cf1eSJohannes Berg 	if (base < 0x400000) {
1994db7cf1eSJohannes Berg 		IWL_ERR(fwrt,
2004db7cf1eSJohannes Berg 			"Not valid error log pointer 0x%08X for %s uCode\n",
2014db7cf1eSJohannes Berg 			base,
2024db7cf1eSJohannes Berg 			(fwrt->cur_fw_img == IWL_UCODE_INIT)
2034db7cf1eSJohannes Berg 			? "Init" : "RT");
2044db7cf1eSJohannes Berg 		return;
2054db7cf1eSJohannes Berg 	}
2064db7cf1eSJohannes Berg 
2074db7cf1eSJohannes Berg 	/* check if there is a HW error */
2084db7cf1eSJohannes Berg 	val = iwl_trans_read_mem32(trans, base);
2094db7cf1eSJohannes Berg 	if (((val & ~0xf) == 0xa5a5a5a0) || ((val & ~0xf) == 0x5a5a5a50)) {
2104db7cf1eSJohannes Berg 		int err;
2114db7cf1eSJohannes Berg 
2124db7cf1eSJohannes Berg 		IWL_ERR(trans, "HW error, resetting before reading\n");
2134db7cf1eSJohannes Berg 
2144db7cf1eSJohannes Berg 		/* reset the device */
2154db7cf1eSJohannes Berg 		iwl_trans_sw_reset(trans);
2164db7cf1eSJohannes Berg 
217*425d66d8SJohannes Berg 		err = iwl_finish_nic_init(trans);
2184db7cf1eSJohannes Berg 		if (err)
2194db7cf1eSJohannes Berg 			return;
2204db7cf1eSJohannes Berg 	}
2214db7cf1eSJohannes Berg 
2224db7cf1eSJohannes Berg 	iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
2234db7cf1eSJohannes Berg 
2244db7cf1eSJohannes Berg 	if (table.valid)
2254db7cf1eSJohannes Berg 		fwrt->dump.lmac_err_id[lmac_num] = table.error_id;
2264db7cf1eSJohannes Berg 
2274db7cf1eSJohannes Berg 	if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
2284db7cf1eSJohannes Berg 		IWL_ERR(trans, "Start IWL Error Log Dump:\n");
2294db7cf1eSJohannes Berg 		IWL_ERR(trans, "Transport status: 0x%08lX, valid: %d\n",
2304db7cf1eSJohannes Berg 			fwrt->trans->status, table.valid);
2314db7cf1eSJohannes Berg 	}
2324db7cf1eSJohannes Berg 
2334db7cf1eSJohannes Berg 	/* Do not change this output - scripts rely on it */
2344db7cf1eSJohannes Berg 
2354db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "Loaded firmware version: %s\n", fwrt->fw->fw_version);
2364db7cf1eSJohannes Berg 
2374db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | %-28s\n", table.error_id,
2384db7cf1eSJohannes Berg 		iwl_fw_lookup_assert_desc(table.error_id));
2394db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | trm_hw_status0\n", table.trm_hw_status0);
2404db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | trm_hw_status1\n", table.trm_hw_status1);
2414db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | branchlink2\n", table.blink2);
2424db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | interruptlink1\n", table.ilink1);
2434db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | interruptlink2\n", table.ilink2);
2444db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | data1\n", table.data1);
2454db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | data2\n", table.data2);
2464db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | data3\n", table.data3);
2474db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | beacon time\n", table.bcon_time);
2484db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | tsf low\n", table.tsf_low);
2494db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | tsf hi\n", table.tsf_hi);
2504db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | time gp1\n", table.gp1);
2514db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | time gp2\n", table.gp2);
2524db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | uCode revision type\n", table.fw_rev_type);
2534db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | uCode version major\n", table.major);
2544db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | uCode version minor\n", table.minor);
2554db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | hw version\n", table.hw_ver);
2564db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | board version\n", table.brd_ver);
2574db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | hcmd\n", table.hcmd);
2584db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | isr0\n", table.isr0);
2594db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | isr1\n", table.isr1);
2604db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | isr2\n", table.isr2);
2614db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | isr3\n", table.isr3);
2624db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | isr4\n", table.isr4);
2634db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | last cmd Id\n", table.last_cmd_id);
2644db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | wait_event\n", table.wait_event);
2654db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | l2p_control\n", table.l2p_control);
2664db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | l2p_duration\n", table.l2p_duration);
2674db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
2684db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
2694db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
2704db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | timestamp\n", table.u_timestamp);
2714db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | flow_handler\n", table.flow_handler);
2724db7cf1eSJohannes Berg }
2734db7cf1eSJohannes Berg 
27448d0c8d5SJohannes Berg /*
27548d0c8d5SJohannes Berg  * TCM error struct.
27648d0c8d5SJohannes Berg  * Note: This structure is read from the device with IO accesses,
27748d0c8d5SJohannes Berg  * and the reading already does the endian conversion. As it is
27848d0c8d5SJohannes Berg  * read with u32-sized accesses, any members with a different size
27948d0c8d5SJohannes Berg  * need to be ordered correctly though!
28048d0c8d5SJohannes Berg  */
28148d0c8d5SJohannes Berg struct iwl_tcm_error_event_table {
28248d0c8d5SJohannes Berg 	u32 valid;
28348d0c8d5SJohannes Berg 	u32 error_id;
28448d0c8d5SJohannes Berg 	u32 blink2;
28548d0c8d5SJohannes Berg 	u32 ilink1;
28648d0c8d5SJohannes Berg 	u32 ilink2;
28748d0c8d5SJohannes Berg 	u32 data1, data2, data3;
28848d0c8d5SJohannes Berg 	u32 logpc;
28948d0c8d5SJohannes Berg 	u32 frame_pointer;
29048d0c8d5SJohannes Berg 	u32 stack_pointer;
29148d0c8d5SJohannes Berg 	u32 msgid;
29248d0c8d5SJohannes Berg 	u32 isr;
29348d0c8d5SJohannes Berg 	u32 hw_status[5];
29448d0c8d5SJohannes Berg 	u32 sw_status[1];
29548d0c8d5SJohannes Berg 	u32 reserved[4];
29648d0c8d5SJohannes Berg } __packed; /* TCM_LOG_ERROR_TABLE_API_S_VER_1 */
29748d0c8d5SJohannes Berg 
29848d0c8d5SJohannes Berg static void iwl_fwrt_dump_tcm_error_log(struct iwl_fw_runtime *fwrt)
29948d0c8d5SJohannes Berg {
30048d0c8d5SJohannes Berg 	struct iwl_trans *trans = fwrt->trans;
30148d0c8d5SJohannes Berg 	struct iwl_tcm_error_event_table table = {};
30248d0c8d5SJohannes Berg 	u32 base = fwrt->trans->dbg.tcm_error_event_table;
30348d0c8d5SJohannes Berg 	int i;
30448d0c8d5SJohannes Berg 
30548d0c8d5SJohannes Berg 	if (!base ||
30648d0c8d5SJohannes Berg 	    !(fwrt->trans->dbg.error_event_table_tlv_status &
30748d0c8d5SJohannes Berg 	      IWL_ERROR_EVENT_TABLE_TCM))
30848d0c8d5SJohannes Berg 		return;
30948d0c8d5SJohannes Berg 
31048d0c8d5SJohannes Berg 	iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
31148d0c8d5SJohannes Berg 
31248d0c8d5SJohannes Berg 	IWL_ERR(fwrt, "TCM status:\n");
31348d0c8d5SJohannes Berg 	IWL_ERR(fwrt, "0x%08X | error ID\n", table.error_id);
31448d0c8d5SJohannes Berg 	IWL_ERR(fwrt, "0x%08X | tcm branchlink2\n", table.blink2);
31548d0c8d5SJohannes Berg 	IWL_ERR(fwrt, "0x%08X | tcm interruptlink1\n", table.ilink1);
31648d0c8d5SJohannes Berg 	IWL_ERR(fwrt, "0x%08X | tcm interruptlink2\n", table.ilink2);
31748d0c8d5SJohannes Berg 	IWL_ERR(fwrt, "0x%08X | tcm data1\n", table.data1);
31848d0c8d5SJohannes Berg 	IWL_ERR(fwrt, "0x%08X | tcm data2\n", table.data2);
31948d0c8d5SJohannes Berg 	IWL_ERR(fwrt, "0x%08X | tcm data3\n", table.data3);
32048d0c8d5SJohannes Berg 	IWL_ERR(fwrt, "0x%08X | tcm log PC\n", table.logpc);
32148d0c8d5SJohannes Berg 	IWL_ERR(fwrt, "0x%08X | tcm frame pointer\n", table.frame_pointer);
32248d0c8d5SJohannes Berg 	IWL_ERR(fwrt, "0x%08X | tcm stack pointer\n", table.stack_pointer);
32348d0c8d5SJohannes Berg 	IWL_ERR(fwrt, "0x%08X | tcm msg ID\n", table.msgid);
32448d0c8d5SJohannes Berg 	IWL_ERR(fwrt, "0x%08X | tcm ISR status\n", table.isr);
32548d0c8d5SJohannes Berg 	for (i = 0; i < ARRAY_SIZE(table.hw_status); i++)
32648d0c8d5SJohannes Berg 		IWL_ERR(fwrt, "0x%08X | tcm HW status[%d]\n",
32748d0c8d5SJohannes Berg 			table.hw_status[i], i);
32848d0c8d5SJohannes Berg 	for (i = 0; i < ARRAY_SIZE(table.sw_status); i++)
32948d0c8d5SJohannes Berg 		IWL_ERR(fwrt, "0x%08X | tcm SW status[%d]\n",
33048d0c8d5SJohannes Berg 			table.sw_status[i], i);
331595c230bSMatti Gottlieb 
332595c230bSMatti Gottlieb 	if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_BZ) {
333595c230bSMatti Gottlieb 		u32 scratch = iwl_read32(trans, CSR_FUNC_SCRATCH);
334595c230bSMatti Gottlieb 
335595c230bSMatti Gottlieb 		IWL_ERR(fwrt, "Function Scratch status:\n");
336595c230bSMatti Gottlieb 		IWL_ERR(fwrt, "0x%08X | Func Scratch\n", scratch);
337595c230bSMatti Gottlieb 	}
33848d0c8d5SJohannes Berg }
33948d0c8d5SJohannes Berg 
3404db7cf1eSJohannes Berg static void iwl_fwrt_dump_iml_error_log(struct iwl_fw_runtime *fwrt)
3414db7cf1eSJohannes Berg {
3424db7cf1eSJohannes Berg 	struct iwl_trans *trans = fwrt->trans;
3434db7cf1eSJohannes Berg 	u32 error, data1;
3444db7cf1eSJohannes Berg 
3454db7cf1eSJohannes Berg 	if (fwrt->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22000) {
3464db7cf1eSJohannes Berg 		error = UMAG_SB_CPU_2_STATUS;
3474db7cf1eSJohannes Berg 		data1 = UMAG_SB_CPU_1_STATUS;
3484db7cf1eSJohannes Berg 	} else if (fwrt->trans->trans_cfg->device_family >=
3494db7cf1eSJohannes Berg 		   IWL_DEVICE_FAMILY_8000) {
3504db7cf1eSJohannes Berg 		error = SB_CPU_2_STATUS;
3514db7cf1eSJohannes Berg 		data1 = SB_CPU_1_STATUS;
3524db7cf1eSJohannes Berg 	} else {
3534db7cf1eSJohannes Berg 		return;
3544db7cf1eSJohannes Berg 	}
3554db7cf1eSJohannes Berg 
3564db7cf1eSJohannes Berg 	error = iwl_read_umac_prph(trans, UMAG_SB_CPU_2_STATUS);
3574db7cf1eSJohannes Berg 
3584db7cf1eSJohannes Berg 	IWL_ERR(trans, "IML/ROM dump:\n");
3594db7cf1eSJohannes Berg 
3604db7cf1eSJohannes Berg 	if (error & 0xFFFF0000)
3614db7cf1eSJohannes Berg 		IWL_ERR(trans, "0x%04X | IML/ROM SYSASSERT\n", error >> 16);
3624db7cf1eSJohannes Berg 
3634db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | IML/ROM error/state\n", error);
3644db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "0x%08X | IML/ROM data1\n",
3654db7cf1eSJohannes Berg 		iwl_read_umac_prph(trans, data1));
3664db7cf1eSJohannes Berg 
3674db7cf1eSJohannes Berg 	if (fwrt->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22000)
3684db7cf1eSJohannes Berg 		IWL_ERR(fwrt, "0x%08X | IML/ROM WFPM_AUTH_KEY_0\n",
3694db7cf1eSJohannes Berg 			iwl_read_umac_prph(trans, SB_MODIFY_CFG_FLAG));
3704db7cf1eSJohannes Berg }
3714db7cf1eSJohannes Berg 
3724db7cf1eSJohannes Berg #define FSEQ_REG(x) { .addr = (x), .str = #x, }
3734db7cf1eSJohannes Berg 
3744db7cf1eSJohannes Berg static void iwl_fwrt_dump_fseq_regs(struct iwl_fw_runtime *fwrt)
3754db7cf1eSJohannes Berg {
3764db7cf1eSJohannes Berg 	struct iwl_trans *trans = fwrt->trans;
3774db7cf1eSJohannes Berg 	int i;
3784db7cf1eSJohannes Berg 	struct {
3794db7cf1eSJohannes Berg 		u32 addr;
3804db7cf1eSJohannes Berg 		const char *str;
3814db7cf1eSJohannes Berg 	} fseq_regs[] = {
3824db7cf1eSJohannes Berg 		FSEQ_REG(FSEQ_ERROR_CODE),
3834db7cf1eSJohannes Berg 		FSEQ_REG(FSEQ_TOP_INIT_VERSION),
3844db7cf1eSJohannes Berg 		FSEQ_REG(FSEQ_CNVIO_INIT_VERSION),
3854db7cf1eSJohannes Berg 		FSEQ_REG(FSEQ_OTP_VERSION),
3864db7cf1eSJohannes Berg 		FSEQ_REG(FSEQ_TOP_CONTENT_VERSION),
3874db7cf1eSJohannes Berg 		FSEQ_REG(FSEQ_ALIVE_TOKEN),
3884db7cf1eSJohannes Berg 		FSEQ_REG(FSEQ_CNVI_ID),
3894db7cf1eSJohannes Berg 		FSEQ_REG(FSEQ_CNVR_ID),
3904db7cf1eSJohannes Berg 		FSEQ_REG(CNVI_AUX_MISC_CHIP),
3914db7cf1eSJohannes Berg 		FSEQ_REG(CNVR_AUX_MISC_CHIP),
3924db7cf1eSJohannes Berg 		FSEQ_REG(CNVR_SCU_SD_REGS_SD_REG_DIG_DCDC_VTRIM),
3934db7cf1eSJohannes Berg 		FSEQ_REG(CNVR_SCU_SD_REGS_SD_REG_ACTIVE_VDIG_MIRROR),
3944db7cf1eSJohannes Berg 	};
3954db7cf1eSJohannes Berg 
3964db7cf1eSJohannes Berg 	if (!iwl_trans_grab_nic_access(trans))
3974db7cf1eSJohannes Berg 		return;
3984db7cf1eSJohannes Berg 
3994db7cf1eSJohannes Berg 	IWL_ERR(fwrt, "Fseq Registers:\n");
4004db7cf1eSJohannes Berg 
4014db7cf1eSJohannes Berg 	for (i = 0; i < ARRAY_SIZE(fseq_regs); i++)
4024db7cf1eSJohannes Berg 		IWL_ERR(fwrt, "0x%08X | %s\n",
4034db7cf1eSJohannes Berg 			iwl_read_prph_no_grab(trans, fseq_regs[i].addr),
4044db7cf1eSJohannes Berg 			fseq_regs[i].str);
4054db7cf1eSJohannes Berg 
4064db7cf1eSJohannes Berg 	iwl_trans_release_nic_access(trans);
4074db7cf1eSJohannes Berg }
4084db7cf1eSJohannes Berg 
4094db7cf1eSJohannes Berg void iwl_fwrt_dump_error_logs(struct iwl_fw_runtime *fwrt)
4104db7cf1eSJohannes Berg {
4114db7cf1eSJohannes Berg 	if (!test_bit(STATUS_DEVICE_ENABLED, &fwrt->trans->status)) {
4124db7cf1eSJohannes Berg 		IWL_ERR(fwrt,
4134db7cf1eSJohannes Berg 			"DEVICE_ENABLED bit is not set. Aborting dump.\n");
4144db7cf1eSJohannes Berg 		return;
4154db7cf1eSJohannes Berg 	}
4164db7cf1eSJohannes Berg 
4174db7cf1eSJohannes Berg 	iwl_fwrt_dump_lmac_error_log(fwrt, 0);
4184db7cf1eSJohannes Berg 	if (fwrt->trans->dbg.lmac_error_event_table[1])
4194db7cf1eSJohannes Berg 		iwl_fwrt_dump_lmac_error_log(fwrt, 1);
4204db7cf1eSJohannes Berg 	iwl_fwrt_dump_umac_error_log(fwrt);
42148d0c8d5SJohannes Berg 	iwl_fwrt_dump_tcm_error_log(fwrt);
4224db7cf1eSJohannes Berg 	iwl_fwrt_dump_iml_error_log(fwrt);
4234db7cf1eSJohannes Berg 	iwl_fwrt_dump_fseq_regs(fwrt);
4244db7cf1eSJohannes Berg }
4254db7cf1eSJohannes Berg IWL_EXPORT_SYMBOL(iwl_fwrt_dump_error_logs);
426