1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 #ifndef __LIB_TRACER_H__
34 #define __LIB_TRACER_H__
35
36 #include <linux/mlx5/driver.h>
37 #include "mlx5_core.h"
38
39 #define STRINGS_DB_SECTIONS_NUM 8
40 #define STRINGS_DB_READ_SIZE_BYTES 256
41 #define STRINGS_DB_LEFTOVER_SIZE_BYTES 64
42 #define TRACER_BUFFER_PAGE_NUM 64
43 #define TRACER_BUFFER_CHUNK 4096
44 #define TRACE_BUFFER_SIZE_BYTE (TRACER_BUFFER_PAGE_NUM * TRACER_BUFFER_CHUNK)
45
46 #define TRACER_BLOCK_SIZE_BYTE 256
47 #define TRACES_PER_BLOCK 32
48
49 #define TRACE_STR_MSG 256
50 #define SAVED_TRACES_NUM 8192
51
52 #define TRACER_MAX_PARAMS 7
53 #define MESSAGE_HASH_BITS 6
54 #define MESSAGE_HASH_SIZE BIT(MESSAGE_HASH_BITS)
55
56 #define MASK_52_7 (0x1FFFFFFFFFFF80)
57 #define MASK_6_0 (0x7F)
58
59 struct mlx5_fw_trace_data {
60 u64 timestamp;
61 bool lost;
62 u8 event_id;
63 char msg[TRACE_STR_MSG];
64 };
65
66 struct mlx5_fw_tracer {
67 struct mlx5_core_dev *dev;
68 struct mlx5_nb nb;
69 bool owner;
70 u8 trc_ver;
71 struct workqueue_struct *work_queue;
72 struct work_struct ownership_change_work;
73 struct work_struct read_fw_strings_work;
74
75
76 struct {
77 u8 first_string_trace;
78 u8 num_string_trace;
79 u32 num_string_db;
80 u32 base_address_out[STRINGS_DB_SECTIONS_NUM];
81 u32 size_out[STRINGS_DB_SECTIONS_NUM];
82 void *buffer[STRINGS_DB_SECTIONS_NUM];
83 bool loaded;
84 } str_db;
85
86
87 struct {
88 u32 pdn;
89 void *log_buf;
90 dma_addr_t dma;
91 u32 size;
92 struct mlx5_core_mkey mkey;
93 u32 consumer_index;
94 } buff;
95
96
97 struct {
98 struct mlx5_fw_trace_data straces[SAVED_TRACES_NUM];
99 u32 saved_traces_index;
100 struct mutex lock;
101 } st_arr;
102
103 u64 last_timestamp;
104 struct work_struct handle_traces_work;
105 struct hlist_head hash[MESSAGE_HASH_SIZE];
106 struct list_head ready_strings_list;
107 };
108
109 struct tracer_string_format {
110 char *string;
111 int params[TRACER_MAX_PARAMS];
112 int num_of_params;
113 int last_param_num;
114 u8 event_id;
115 u32 tmsn;
116 struct hlist_node hlist;
117 struct list_head list;
118 u32 timestamp;
119 bool lost;
120 };
121
122 enum mlx5_fw_tracer_ownership_state {
123 MLX5_FW_TRACER_RELEASE_OWNERSHIP,
124 MLX5_FW_TRACER_ACQUIRE_OWNERSHIP,
125 };
126
127 enum tracer_ctrl_fields_select {
128 TRACE_STATUS = 1 << 0,
129 };
130
131 enum tracer_event_type {
132 TRACER_EVENT_TYPE_STRING,
133 TRACER_EVENT_TYPE_TIMESTAMP = 0xFF,
134 TRACER_EVENT_TYPE_UNRECOGNIZED,
135 };
136
137 enum tracing_mode {
138 TRACE_TO_MEMORY = 1 << 0,
139 };
140
141 struct tracer_timestamp_event {
142 u64 timestamp;
143 u8 unreliable;
144 };
145
146 struct tracer_string_event {
147 u32 timestamp;
148 u32 tmsn;
149 u32 tdsn;
150 u32 string_param;
151 };
152
153 struct tracer_event {
154 bool lost_event;
155 u32 type;
156 u8 event_id;
157 union {
158 struct tracer_string_event string_event;
159 struct tracer_timestamp_event timestamp_event;
160 };
161 };
162
163 struct mlx5_ifc_tracer_event_bits {
164 u8 lost[0x1];
165 u8 timestamp[0x7];
166 u8 event_id[0x8];
167 u8 event_data[0x30];
168 };
169
170 struct mlx5_ifc_tracer_string_event_bits {
171 u8 lost[0x1];
172 u8 timestamp[0x7];
173 u8 event_id[0x8];
174 u8 tmsn[0xd];
175 u8 tdsn[0x3];
176 u8 string_param[0x20];
177 };
178
179 struct mlx5_ifc_tracer_timestamp_event_bits {
180 u8 timestamp7_0[0x8];
181 u8 event_id[0x8];
182 u8 urts[0x3];
183 u8 timestamp52_40[0xd];
184 u8 timestamp39_8[0x20];
185 };
186
187 struct mlx5_fw_tracer *mlx5_fw_tracer_create(struct mlx5_core_dev *dev);
188 int mlx5_fw_tracer_init(struct mlx5_fw_tracer *tracer);
189 void mlx5_fw_tracer_cleanup(struct mlx5_fw_tracer *tracer);
190 void mlx5_fw_tracer_destroy(struct mlx5_fw_tracer *tracer);
191 int mlx5_fw_tracer_trigger_core_dump_general(struct mlx5_core_dev *dev);
192 int mlx5_fw_tracer_get_saved_traces_objects(struct mlx5_fw_tracer *tracer,
193 struct devlink_fmsg *fmsg);
194
195 #endif