1 /* SPDX-License-Identifier: ISC */
2 /* Copyright (C) 2022 MediaTek Inc. */
3 
4 #ifndef _COREDUMP_H_
5 #define _COREDUMP_H_
6 
7 #include "mt7915.h"
8 
9 struct trace {
10 	u32 id;
11 	u32 timestamp;
12 };
13 
14 struct mt7915_coredump {
15 	char magic[16];
16 
17 	u32 len;
18 
19 	guid_t guid;
20 
21 	/* time-of-day stamp */
22 	u64 tv_sec;
23 	/* time-of-day stamp, nano-seconds */
24 	u64 tv_nsec;
25 	/* kernel version */
26 	char kernel[64];
27 	/* firmware version */
28 	char fw_ver[ETHTOOL_FWVERS_LEN];
29 
30 	u32 device_id;
31 
32 	/* exception state */
33 	char fw_state[12];
34 
35 	u32 last_msg_id;
36 	u32 eint_info_idx;
37 	u32 irq_info_idx;
38 	u32 sched_info_idx;
39 
40 	/* schedule info */
41 	char trace_sched[32];
42 	struct {
43 		struct trace t;
44 		u32 pc;
45 	} sched[60];
46 
47 	/* irq info */
48 	char trace_irq[32];
49 	struct trace irq[60];
50 
51 	/* task queue status */
52 	char task_qid[32];
53 	struct {
54 		u32 read;
55 		u32 write;
56 	} taskq[2];
57 
58 	/* task stack info */
59 	char task_info[32];
60 	struct {
61 		u32 start;
62 		u32 end;
63 		u32 size;
64 	} taski[2];
65 
66 	/* firmware context */
67 	char fw_context[24];
68 	struct {
69 		u32 idx;
70 		u32 handler;
71 	} context;
72 
73 	/* link registers calltrace */
74 	u32 call_stack[16];
75 
76 	/* memory content */
77 	u8 data[];
78 } __packed;
79 
80 struct mt7915_coredump_mem {
81 	u32 len;
82 	u8 data[];
83 } __packed;
84 
85 struct mt7915_mem_hdr {
86 	u32 start;
87 	u32 len;
88 	u8 data[];
89 };
90 
91 struct mt7915_mem_region {
92 	u32 start;
93 	size_t len;
94 
95 	const char *name;
96 };
97 
98 #ifdef CONFIG_DEV_COREDUMP
99 
100 const struct mt7915_mem_region *
101 mt7915_coredump_get_mem_layout(struct mt7915_dev *dev, u32 *num);
102 struct mt7915_crash_data *mt7915_coredump_new(struct mt7915_dev *dev);
103 int mt7915_coredump_submit(struct mt7915_dev *dev);
104 int mt7915_coredump_register(struct mt7915_dev *dev);
105 void mt7915_coredump_unregister(struct mt7915_dev *dev);
106 
107 #else /* CONFIG_DEV_COREDUMP */
108 
109 static inline const struct mt7915_mem_region *
mt7915_coredump_get_mem_layout(struct mt7915_dev * dev,u32 * num)110 mt7915_coredump_get_mem_layout(struct mt7915_dev *dev, u32 *num)
111 {
112 	return NULL;
113 }
114 
mt7915_coredump_submit(struct mt7915_dev * dev)115 static inline int mt7915_coredump_submit(struct mt7915_dev *dev)
116 {
117 	return 0;
118 }
119 
mt7915_coredump_new(struct mt7915_dev * dev)120 static inline struct mt7915_crash_data *mt7915_coredump_new(struct mt7915_dev *dev)
121 {
122 	return NULL;
123 }
124 
mt7915_coredump_register(struct mt7915_dev * dev)125 static inline int mt7915_coredump_register(struct mt7915_dev *dev)
126 {
127 	return 0;
128 }
129 
mt7915_coredump_unregister(struct mt7915_dev * dev)130 static inline void mt7915_coredump_unregister(struct mt7915_dev *dev)
131 {
132 }
133 
134 #endif /* CONFIG_DEV_COREDUMP */
135 
136 #endif /* _COREDUMP_H_ */
137