1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3  * Copyright(c) 2019 - 2021 Intel Corporation
4  */
5 
6 #include "img.h"
7 
8 u8 iwl_fw_lookup_cmd_ver(const struct iwl_fw *fw, u8 grp, u8 cmd, u8 def)
9 {
10 	const struct iwl_fw_cmd_version *entry;
11 	unsigned int i;
12 
13 	if (!fw->ucode_capa.cmd_versions ||
14 	    !fw->ucode_capa.n_cmd_versions)
15 		return def;
16 
17 	entry = fw->ucode_capa.cmd_versions;
18 	for (i = 0; i < fw->ucode_capa.n_cmd_versions; i++, entry++) {
19 		if (entry->group == grp && entry->cmd == cmd) {
20 			if (entry->cmd_ver == IWL_FW_CMD_VER_UNKNOWN)
21 				return def;
22 			return entry->cmd_ver;
23 		}
24 	}
25 
26 	return def;
27 }
28 EXPORT_SYMBOL_GPL(iwl_fw_lookup_cmd_ver);
29 
30 u8 iwl_fw_lookup_notif_ver(const struct iwl_fw *fw, u8 grp, u8 cmd, u8 def)
31 {
32 	const struct iwl_fw_cmd_version *entry;
33 	unsigned int i;
34 
35 	if (!fw->ucode_capa.cmd_versions ||
36 	    !fw->ucode_capa.n_cmd_versions)
37 		return def;
38 
39 	entry = fw->ucode_capa.cmd_versions;
40 	for (i = 0; i < fw->ucode_capa.n_cmd_versions; i++, entry++) {
41 		if (entry->group == grp && entry->cmd == cmd) {
42 			if (entry->notif_ver == IWL_FW_CMD_VER_UNKNOWN)
43 				return def;
44 			return entry->notif_ver;
45 		}
46 	}
47 
48 	return def;
49 }
50 EXPORT_SYMBOL_GPL(iwl_fw_lookup_notif_ver);
51 
52 static const struct {
53 	const char *name;
54 	u32 num;
55 } advanced_lookup[] = {
56 	{ "NMI_INTERRUPT_WDG", 0x34 },
57 	{ "SYSASSERT", 0x35 },
58 	{ "UCODE_VERSION_MISMATCH", 0x37 },
59 	{ "BAD_COMMAND", 0x38 },
60 	{ "BAD_COMMAND", 0x39 },
61 	{ "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
62 	{ "FATAL_ERROR", 0x3D },
63 	{ "NMI_TRM_HW_ERR", 0x46 },
64 	{ "NMI_INTERRUPT_TRM", 0x4C },
65 	{ "NMI_INTERRUPT_BREAK_POINT", 0x54 },
66 	{ "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
67 	{ "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
68 	{ "NMI_INTERRUPT_HOST", 0x66 },
69 	{ "NMI_INTERRUPT_LMAC_FATAL", 0x70 },
70 	{ "NMI_INTERRUPT_UMAC_FATAL", 0x71 },
71 	{ "NMI_INTERRUPT_OTHER_LMAC_FATAL", 0x73 },
72 	{ "NMI_INTERRUPT_ACTION_PT", 0x7C },
73 	{ "NMI_INTERRUPT_UNKNOWN", 0x84 },
74 	{ "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
75 	{ "PNVM_MISSING", FW_SYSASSERT_PNVM_MISSING },
76 	{ "ADVANCED_SYSASSERT", 0 },
77 };
78 
79 const char *iwl_fw_lookup_assert_desc(u32 num)
80 {
81 	int i;
82 
83 	for (i = 0; i < ARRAY_SIZE(advanced_lookup) - 1; i++)
84 		if (advanced_lookup[i].num == (num & ~FW_SYSASSERT_CPU_MASK))
85 			return advanced_lookup[i].name;
86 
87 	/* No entry matches 'num', so it is the last: ADVANCED_SYSASSERT */
88 	return advanced_lookup[i].name;
89 }
90 EXPORT_SYMBOL_GPL(iwl_fw_lookup_assert_desc);
91