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