xref: /openbmc/linux/drivers/net/wireless/ath/ath10k/coredump.h (revision b240b419db5d624ce7a5a397d6f62a1a686009ec)
1 /*
2  * Copyright (c) 2011-2017 Qualcomm Atheros, Inc.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef _COREDUMP_H_
18 #define _COREDUMP_H_
19 
20 #include "core.h"
21 
22 #define ATH10K_FW_CRASH_DUMP_VERSION 1
23 
24 /**
25  * enum ath10k_fw_crash_dump_type - types of data in the dump file
26  * @ATH10K_FW_CRASH_DUMP_REGDUMP: Register crash dump in binary format
27  */
28 enum ath10k_fw_crash_dump_type {
29 	ATH10K_FW_CRASH_DUMP_REGISTERS = 0,
30 	ATH10K_FW_CRASH_DUMP_CE_DATA = 1,
31 
32 	/* contains multiple struct ath10k_dump_ram_data_hdr */
33 	ATH10K_FW_CRASH_DUMP_RAM_DATA = 2,
34 
35 	ATH10K_FW_CRASH_DUMP_MAX,
36 };
37 
38 struct ath10k_tlv_dump_data {
39 	/* see ath10k_fw_crash_dump_type above */
40 	__le32 type;
41 
42 	/* in bytes */
43 	__le32 tlv_len;
44 
45 	/* pad to 32-bit boundaries as needed */
46 	u8 tlv_data[];
47 } __packed;
48 
49 struct ath10k_dump_file_data {
50 	/* dump file information */
51 
52 	/* "ATH10K-FW-DUMP" */
53 	char df_magic[16];
54 
55 	__le32 len;
56 
57 	/* file dump version */
58 	__le32 version;
59 
60 	/* some info we can get from ath10k struct that might help */
61 
62 	guid_t guid;
63 
64 	__le32 chip_id;
65 
66 	/* 0 for now, in place for later hardware */
67 	__le32 bus_type;
68 
69 	__le32 target_version;
70 	__le32 fw_version_major;
71 	__le32 fw_version_minor;
72 	__le32 fw_version_release;
73 	__le32 fw_version_build;
74 	__le32 phy_capability;
75 	__le32 hw_min_tx_power;
76 	__le32 hw_max_tx_power;
77 	__le32 ht_cap_info;
78 	__le32 vht_cap_info;
79 	__le32 num_rf_chains;
80 
81 	/* firmware version string */
82 	char fw_ver[ETHTOOL_FWVERS_LEN];
83 
84 	/* Kernel related information */
85 
86 	/* time-of-day stamp */
87 	__le64 tv_sec;
88 
89 	/* time-of-day stamp, nano-seconds */
90 	__le64 tv_nsec;
91 
92 	/* LINUX_VERSION_CODE */
93 	__le32 kernel_ver_code;
94 
95 	/* VERMAGIC_STRING */
96 	char kernel_ver[64];
97 
98 	/* room for growth w/out changing binary format */
99 	u8 unused[128];
100 
101 	/* struct ath10k_tlv_dump_data + more */
102 	u8 data[0];
103 } __packed;
104 
105 struct ath10k_dump_ram_data_hdr {
106 	/* enum ath10k_mem_region_type */
107 	__le32 region_type;
108 
109 	__le32 start;
110 
111 	/* length of payload data, not including this header */
112 	__le32 length;
113 
114 	u8 data[0];
115 };
116 
117 /* magic number to fill the holes not copied due to sections in regions */
118 #define ATH10K_MAGIC_NOT_COPIED		0xAA
119 
120 /* part of user space ABI */
121 enum ath10k_mem_region_type {
122 	ATH10K_MEM_REGION_TYPE_REG	= 1,
123 	ATH10K_MEM_REGION_TYPE_DRAM	= 2,
124 	ATH10K_MEM_REGION_TYPE_AXI	= 3,
125 	ATH10K_MEM_REGION_TYPE_IRAM1	= 4,
126 	ATH10K_MEM_REGION_TYPE_IRAM2	= 5,
127 	ATH10K_MEM_REGION_TYPE_IOSRAM	= 6,
128 	ATH10K_MEM_REGION_TYPE_IOREG	= 7,
129 };
130 
131 /* Define a section of the region which should be copied. As not all parts
132  * of the memory is possible to copy, for example some of the registers can
133  * be like that, sections can be used to define what is safe to copy.
134  *
135  * To minimize the size of the array, the list must obey the format:
136  * '{start0,stop0},{start1,stop1},{start2,stop2}....' The values below must
137  * also obey to 'start0 < stop0 < start1 < stop1 < start2 < ...', otherwise
138  * we may encouter error in the dump processing.
139  */
140 struct ath10k_mem_section {
141 	u32 start;
142 	u32 end;
143 };
144 
145 /* One region of a memory layout. If the sections field is null entire
146  * region is copied. If sections is non-null only the areas specified in
147  * sections are copied and rest of the areas are filled with
148  * ATH10K_MAGIC_NOT_COPIED.
149  */
150 struct ath10k_mem_region {
151 	enum ath10k_mem_region_type type;
152 	u32 start;
153 	u32 len;
154 
155 	const char *name;
156 
157 	struct {
158 		const struct ath10k_mem_section *sections;
159 		u32 size;
160 	} section_table;
161 };
162 
163 /* Contains the memory layout of a hardware version identified with the
164  * hardware id, split into regions.
165  */
166 struct ath10k_hw_mem_layout {
167 	u32 hw_id;
168 
169 	struct {
170 		const struct ath10k_mem_region *regions;
171 		int size;
172 	} region_table;
173 };
174 
175 /* FIXME: where to put this? */
176 extern unsigned long ath10k_coredump_mask;
177 
178 #ifdef CONFIG_DEV_COREDUMP
179 
180 int ath10k_coredump_submit(struct ath10k *ar);
181 struct ath10k_fw_crash_data *ath10k_coredump_new(struct ath10k *ar);
182 int ath10k_coredump_create(struct ath10k *ar);
183 int ath10k_coredump_register(struct ath10k *ar);
184 void ath10k_coredump_unregister(struct ath10k *ar);
185 void ath10k_coredump_destroy(struct ath10k *ar);
186 
187 const struct ath10k_hw_mem_layout *ath10k_coredump_get_mem_layout(struct ath10k *ar);
188 
189 #else /* CONFIG_DEV_COREDUMP */
190 
191 static inline int ath10k_coredump_submit(struct ath10k *ar)
192 {
193 	return 0;
194 }
195 
196 static inline struct ath10k_fw_crash_data *ath10k_coredump_new(struct ath10k *ar)
197 {
198 	return NULL;
199 }
200 
201 static inline int ath10k_coredump_create(struct ath10k *ar)
202 {
203 	return 0;
204 }
205 
206 static inline int ath10k_coredump_register(struct ath10k *ar)
207 {
208 	return 0;
209 }
210 
211 static inline void ath10k_coredump_unregister(struct ath10k *ar)
212 {
213 }
214 
215 static inline void ath10k_coredump_destroy(struct ath10k *ar)
216 {
217 }
218 
219 static inline const struct ath10k_hw_mem_layout *
220 ath10k_coredump_get_mem_layout(struct ath10k *ar)
221 {
222 	return NULL;
223 }
224 
225 #endif /* CONFIG_DEV_COREDUMP */
226 
227 #endif /* _COREDUMP_H_ */
228