Loading...
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Trace points for SSAM/SSH.
4 *
5 * Copyright (C) 2020-2022 Maximilian Luz <luzmaximilian@gmail.com>
6 */
7
8#undef TRACE_SYSTEM
9#define TRACE_SYSTEM surface_aggregator
10
11#if !defined(_SURFACE_AGGREGATOR_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
12#define _SURFACE_AGGREGATOR_TRACE_H
13
14#include <linux/surface_aggregator/serial_hub.h>
15
16#include <linux/unaligned.h>
17#include <linux/tracepoint.h>
18
19TRACE_DEFINE_ENUM(SSH_FRAME_TYPE_DATA_SEQ);
20TRACE_DEFINE_ENUM(SSH_FRAME_TYPE_DATA_NSQ);
21TRACE_DEFINE_ENUM(SSH_FRAME_TYPE_ACK);
22TRACE_DEFINE_ENUM(SSH_FRAME_TYPE_NAK);
23
24TRACE_DEFINE_ENUM(SSH_PACKET_SF_LOCKED_BIT);
25TRACE_DEFINE_ENUM(SSH_PACKET_SF_QUEUED_BIT);
26TRACE_DEFINE_ENUM(SSH_PACKET_SF_PENDING_BIT);
27TRACE_DEFINE_ENUM(SSH_PACKET_SF_TRANSMITTING_BIT);
28TRACE_DEFINE_ENUM(SSH_PACKET_SF_TRANSMITTED_BIT);
29TRACE_DEFINE_ENUM(SSH_PACKET_SF_ACKED_BIT);
30TRACE_DEFINE_ENUM(SSH_PACKET_SF_CANCELED_BIT);
31TRACE_DEFINE_ENUM(SSH_PACKET_SF_COMPLETED_BIT);
32
33TRACE_DEFINE_ENUM(SSH_PACKET_TY_FLUSH_BIT);
34TRACE_DEFINE_ENUM(SSH_PACKET_TY_SEQUENCED_BIT);
35TRACE_DEFINE_ENUM(SSH_PACKET_TY_BLOCKING_BIT);
36
37TRACE_DEFINE_ENUM(SSH_PACKET_FLAGS_SF_MASK);
38TRACE_DEFINE_ENUM(SSH_PACKET_FLAGS_TY_MASK);
39
40TRACE_DEFINE_ENUM(SSH_REQUEST_SF_LOCKED_BIT);
41TRACE_DEFINE_ENUM(SSH_REQUEST_SF_QUEUED_BIT);
42TRACE_DEFINE_ENUM(SSH_REQUEST_SF_PENDING_BIT);
43TRACE_DEFINE_ENUM(SSH_REQUEST_SF_TRANSMITTING_BIT);
44TRACE_DEFINE_ENUM(SSH_REQUEST_SF_TRANSMITTED_BIT);
45TRACE_DEFINE_ENUM(SSH_REQUEST_SF_RSPRCVD_BIT);
46TRACE_DEFINE_ENUM(SSH_REQUEST_SF_CANCELED_BIT);
47TRACE_DEFINE_ENUM(SSH_REQUEST_SF_COMPLETED_BIT);
48
49TRACE_DEFINE_ENUM(SSH_REQUEST_TY_FLUSH_BIT);
50TRACE_DEFINE_ENUM(SSH_REQUEST_TY_HAS_RESPONSE_BIT);
51
52TRACE_DEFINE_ENUM(SSH_REQUEST_FLAGS_SF_MASK);
53TRACE_DEFINE_ENUM(SSH_REQUEST_FLAGS_TY_MASK);
54
55TRACE_DEFINE_ENUM(SSAM_SSH_TC_SAM);
56TRACE_DEFINE_ENUM(SSAM_SSH_TC_BAT);
57TRACE_DEFINE_ENUM(SSAM_SSH_TC_TMP);
58TRACE_DEFINE_ENUM(SSAM_SSH_TC_PMC);
59TRACE_DEFINE_ENUM(SSAM_SSH_TC_FAN);
60TRACE_DEFINE_ENUM(SSAM_SSH_TC_PoM);
61TRACE_DEFINE_ENUM(SSAM_SSH_TC_DBG);
62TRACE_DEFINE_ENUM(SSAM_SSH_TC_KBD);
63TRACE_DEFINE_ENUM(SSAM_SSH_TC_FWU);
64TRACE_DEFINE_ENUM(SSAM_SSH_TC_UNI);
65TRACE_DEFINE_ENUM(SSAM_SSH_TC_LPC);
66TRACE_DEFINE_ENUM(SSAM_SSH_TC_TCL);
67TRACE_DEFINE_ENUM(SSAM_SSH_TC_SFL);
68TRACE_DEFINE_ENUM(SSAM_SSH_TC_KIP);
69TRACE_DEFINE_ENUM(SSAM_SSH_TC_EXT);
70TRACE_DEFINE_ENUM(SSAM_SSH_TC_BLD);
71TRACE_DEFINE_ENUM(SSAM_SSH_TC_BAS);
72TRACE_DEFINE_ENUM(SSAM_SSH_TC_SEN);
73TRACE_DEFINE_ENUM(SSAM_SSH_TC_SRQ);
74TRACE_DEFINE_ENUM(SSAM_SSH_TC_MCU);
75TRACE_DEFINE_ENUM(SSAM_SSH_TC_HID);
76TRACE_DEFINE_ENUM(SSAM_SSH_TC_TCH);
77TRACE_DEFINE_ENUM(SSAM_SSH_TC_BKL);
78TRACE_DEFINE_ENUM(SSAM_SSH_TC_TAM);
79TRACE_DEFINE_ENUM(SSAM_SSH_TC_ACC0);
80TRACE_DEFINE_ENUM(SSAM_SSH_TC_UFI);
81TRACE_DEFINE_ENUM(SSAM_SSH_TC_USC);
82TRACE_DEFINE_ENUM(SSAM_SSH_TC_PEN);
83TRACE_DEFINE_ENUM(SSAM_SSH_TC_VID);
84TRACE_DEFINE_ENUM(SSAM_SSH_TC_AUD);
85TRACE_DEFINE_ENUM(SSAM_SSH_TC_SMC);
86TRACE_DEFINE_ENUM(SSAM_SSH_TC_KPD);
87TRACE_DEFINE_ENUM(SSAM_SSH_TC_REG);
88TRACE_DEFINE_ENUM(SSAM_SSH_TC_SPT);
89TRACE_DEFINE_ENUM(SSAM_SSH_TC_SYS);
90TRACE_DEFINE_ENUM(SSAM_SSH_TC_ACC1);
91TRACE_DEFINE_ENUM(SSAM_SSH_TC_SHB);
92TRACE_DEFINE_ENUM(SSAM_SSH_TC_POS);
93
94#define SSAM_PTR_UID_LEN 9
95#define SSAM_U8_FIELD_NOT_APPLICABLE ((u16)-1)
96#define SSAM_SEQ_NOT_APPLICABLE ((u16)-1)
97#define SSAM_RQID_NOT_APPLICABLE ((u32)-1)
98#define SSAM_SSH_TC_NOT_APPLICABLE 0
99#define SSAM_SSH_TID_NOT_APPLICABLE ((u8)-1)
100
101#ifndef _SURFACE_AGGREGATOR_TRACE_HELPERS
102#define _SURFACE_AGGREGATOR_TRACE_HELPERS
103
104/**
105 * ssam_trace_ptr_uid() - Convert the pointer to a non-pointer UID string.
106 * @ptr: The pointer to convert.
107 * @uid_str: A buffer of length SSAM_PTR_UID_LEN where the UID will be stored.
108 *
109 * Converts the given pointer into a UID string that is safe to be shared
110 * with userspace and logs, i.e. doesn't give away the real memory location.
111 */
112static inline void ssam_trace_ptr_uid(const void *ptr, char *uid_str)
113{
114 char buf[2 * sizeof(void *) + 1];
115
116 BUILD_BUG_ON(ARRAY_SIZE(buf) < SSAM_PTR_UID_LEN);
117
118 snprintf(buf, ARRAY_SIZE(buf), "%p", ptr);
119 memcpy(uid_str, &buf[ARRAY_SIZE(buf) - SSAM_PTR_UID_LEN],
120 SSAM_PTR_UID_LEN);
121}
122
123/**
124 * ssam_trace_get_packet_seq() - Read the packet's sequence ID.
125 * @p: The packet.
126 *
127 * Return: Returns the packet's sequence ID (SEQ) field if present, or
128 * %SSAM_SEQ_NOT_APPLICABLE if not (e.g. flush packet).
129 */
130static inline u16 ssam_trace_get_packet_seq(const struct ssh_packet *p)
131{
132 if (!p->data.ptr || p->data.len < SSH_MESSAGE_LENGTH(0))
133 return SSAM_SEQ_NOT_APPLICABLE;
134
135 return p->data.ptr[SSH_MSGOFFSET_FRAME(seq)];
136}
137
138/**
139 * ssam_trace_get_request_id() - Read the packet's request ID.
140 * @p: The packet.
141 *
142 * Return: Returns the packet's request ID (RQID) field if the packet
143 * represents a request with command data, or %SSAM_RQID_NOT_APPLICABLE if not
144 * (e.g. flush request, control packet).
145 */
146static inline u32 ssam_trace_get_request_id(const struct ssh_packet *p)
147{
148 if (!p->data.ptr || p->data.len < SSH_COMMAND_MESSAGE_LENGTH(0))
149 return SSAM_RQID_NOT_APPLICABLE;
150
151 return get_unaligned_le16(&p->data.ptr[SSH_MSGOFFSET_COMMAND(rqid)]);
152}
153
154/**
155 * ssam_trace_get_request_tid() - Read the packet's request target ID.
156 * @p: The packet.
157 *
158 * Return: Returns the packet's request target ID (TID) field if the packet
159 * represents a request with command data, or %SSAM_SSH_TID_NOT_APPLICABLE
160 * if not (e.g. flush request, control packet).
161 */
162static inline u32 ssam_trace_get_request_tid(const struct ssh_packet *p)
163{
164 if (!p->data.ptr || p->data.len < SSH_COMMAND_MESSAGE_LENGTH(0))
165 return SSAM_SSH_TID_NOT_APPLICABLE;
166
167 return get_unaligned_le16(&p->data.ptr[SSH_MSGOFFSET_COMMAND(tid)]);
168}
169
170/**
171 * ssam_trace_get_request_sid() - Read the packet's request source ID.
172 * @p: The packet.
173 *
174 * Return: Returns the packet's request source ID (SID) field if the packet
175 * represents a request with command data, or %SSAM_SSH_TID_NOT_APPLICABLE
176 * if not (e.g. flush request, control packet).
177 */
178static inline u32 ssam_trace_get_request_sid(const struct ssh_packet *p)
179{
180 if (!p->data.ptr || p->data.len < SSH_COMMAND_MESSAGE_LENGTH(0))
181 return SSAM_SSH_TID_NOT_APPLICABLE;
182
183 return get_unaligned_le16(&p->data.ptr[SSH_MSGOFFSET_COMMAND(sid)]);
184}
185
186/**
187 * ssam_trace_get_request_tc() - Read the packet's request target category.
188 * @p: The packet.
189 *
190 * Return: Returns the packet's request target category (TC) field if the
191 * packet represents a request with command data, or %SSAM_SSH_TC_NOT_APPLICABLE
192 * if not (e.g. flush request, control packet).
193 */
194static inline u32 ssam_trace_get_request_tc(const struct ssh_packet *p)
195{
196 if (!p->data.ptr || p->data.len < SSH_COMMAND_MESSAGE_LENGTH(0))
197 return SSAM_SSH_TC_NOT_APPLICABLE;
198
199 return get_unaligned_le16(&p->data.ptr[SSH_MSGOFFSET_COMMAND(tc)]);
200}
201
202#endif /* _SURFACE_AGGREGATOR_TRACE_HELPERS */
203
204#define ssam_trace_get_command_field_u8(packet, field) \
205 ((!(packet) || (packet)->data.len < SSH_COMMAND_MESSAGE_LENGTH(0)) \
206 ? 0 : (packet)->data.ptr[SSH_MSGOFFSET_COMMAND(field)])
207
208#define ssam_show_generic_u8_field(value) \
209 __print_symbolic(value, \
210 { SSAM_U8_FIELD_NOT_APPLICABLE, "N/A" } \
211 )
212
213#define ssam_show_frame_type(ty) \
214 __print_symbolic(ty, \
215 { SSH_FRAME_TYPE_DATA_SEQ, "DSEQ" }, \
216 { SSH_FRAME_TYPE_DATA_NSQ, "DNSQ" }, \
217 { SSH_FRAME_TYPE_ACK, "ACK" }, \
218 { SSH_FRAME_TYPE_NAK, "NAK" } \
219 )
220
221#define ssam_show_packet_type(type) \
222 __print_flags(flags & SSH_PACKET_FLAGS_TY_MASK, "", \
223 { BIT(SSH_PACKET_TY_FLUSH_BIT), "F" }, \
224 { BIT(SSH_PACKET_TY_SEQUENCED_BIT), "S" }, \
225 { BIT(SSH_PACKET_TY_BLOCKING_BIT), "B" } \
226 )
227
228#define ssam_show_packet_state(state) \
229 __print_flags(flags & SSH_PACKET_FLAGS_SF_MASK, "", \
230 { BIT(SSH_PACKET_SF_LOCKED_BIT), "L" }, \
231 { BIT(SSH_PACKET_SF_QUEUED_BIT), "Q" }, \
232 { BIT(SSH_PACKET_SF_PENDING_BIT), "P" }, \
233 { BIT(SSH_PACKET_SF_TRANSMITTING_BIT), "S" }, \
234 { BIT(SSH_PACKET_SF_TRANSMITTED_BIT), "T" }, \
235 { BIT(SSH_PACKET_SF_ACKED_BIT), "A" }, \
236 { BIT(SSH_PACKET_SF_CANCELED_BIT), "C" }, \
237 { BIT(SSH_PACKET_SF_COMPLETED_BIT), "F" } \
238 )
239
240#define ssam_show_packet_seq(seq) \
241 __print_symbolic(seq, \
242 { SSAM_SEQ_NOT_APPLICABLE, "N/A" } \
243 )
244
245#define ssam_show_request_type(flags) \
246 __print_flags((flags) & SSH_REQUEST_FLAGS_TY_MASK, "", \
247 { BIT(SSH_REQUEST_TY_FLUSH_BIT), "F" }, \
248 { BIT(SSH_REQUEST_TY_HAS_RESPONSE_BIT), "R" } \
249 )
250
251#define ssam_show_request_state(flags) \
252 __print_flags((flags) & SSH_REQUEST_FLAGS_SF_MASK, "", \
253 { BIT(SSH_REQUEST_SF_LOCKED_BIT), "L" }, \
254 { BIT(SSH_REQUEST_SF_QUEUED_BIT), "Q" }, \
255 { BIT(SSH_REQUEST_SF_PENDING_BIT), "P" }, \
256 { BIT(SSH_REQUEST_SF_TRANSMITTING_BIT), "S" }, \
257 { BIT(SSH_REQUEST_SF_TRANSMITTED_BIT), "T" }, \
258 { BIT(SSH_REQUEST_SF_RSPRCVD_BIT), "A" }, \
259 { BIT(SSH_REQUEST_SF_CANCELED_BIT), "C" }, \
260 { BIT(SSH_REQUEST_SF_COMPLETED_BIT), "F" } \
261 )
262
263#define ssam_show_request_id(rqid) \
264 __print_symbolic(rqid, \
265 { SSAM_RQID_NOT_APPLICABLE, "N/A" } \
266 )
267
268#define ssam_show_ssh_tid(tid) \
269 __print_symbolic(tid, \
270 { SSAM_SSH_TID_NOT_APPLICABLE, "N/A" }, \
271 { SSAM_SSH_TID_HOST, "Host" }, \
272 { SSAM_SSH_TID_SAM, "SAM" }, \
273 { SSAM_SSH_TID_KIP, "KIP" }, \
274 { SSAM_SSH_TID_DEBUG, "Debug" }, \
275 { SSAM_SSH_TID_SURFLINK, "SurfLink" } \
276 )
277
278#define ssam_show_ssh_tc(tc) \
279 __print_symbolic(tc, \
280 { SSAM_SSH_TC_NOT_APPLICABLE, "N/A" }, \
281 { SSAM_SSH_TC_SAM, "SAM" }, \
282 { SSAM_SSH_TC_BAT, "BAT" }, \
283 { SSAM_SSH_TC_TMP, "TMP" }, \
284 { SSAM_SSH_TC_PMC, "PMC" }, \
285 { SSAM_SSH_TC_FAN, "FAN" }, \
286 { SSAM_SSH_TC_PoM, "PoM" }, \
287 { SSAM_SSH_TC_DBG, "DBG" }, \
288 { SSAM_SSH_TC_KBD, "KBD" }, \
289 { SSAM_SSH_TC_FWU, "FWU" }, \
290 { SSAM_SSH_TC_UNI, "UNI" }, \
291 { SSAM_SSH_TC_LPC, "LPC" }, \
292 { SSAM_SSH_TC_TCL, "TCL" }, \
293 { SSAM_SSH_TC_SFL, "SFL" }, \
294 { SSAM_SSH_TC_KIP, "KIP" }, \
295 { SSAM_SSH_TC_EXT, "EXT" }, \
296 { SSAM_SSH_TC_BLD, "BLD" }, \
297 { SSAM_SSH_TC_BAS, "BAS" }, \
298 { SSAM_SSH_TC_SEN, "SEN" }, \
299 { SSAM_SSH_TC_SRQ, "SRQ" }, \
300 { SSAM_SSH_TC_MCU, "MCU" }, \
301 { SSAM_SSH_TC_HID, "HID" }, \
302 { SSAM_SSH_TC_TCH, "TCH" }, \
303 { SSAM_SSH_TC_BKL, "BKL" }, \
304 { SSAM_SSH_TC_TAM, "TAM" }, \
305 { SSAM_SSH_TC_ACC0, "ACC0" }, \
306 { SSAM_SSH_TC_UFI, "UFI" }, \
307 { SSAM_SSH_TC_USC, "USC" }, \
308 { SSAM_SSH_TC_PEN, "PEN" }, \
309 { SSAM_SSH_TC_VID, "VID" }, \
310 { SSAM_SSH_TC_AUD, "AUD" }, \
311 { SSAM_SSH_TC_SMC, "SMC" }, \
312 { SSAM_SSH_TC_KPD, "KPD" }, \
313 { SSAM_SSH_TC_REG, "REG" }, \
314 { SSAM_SSH_TC_SPT, "SPT" }, \
315 { SSAM_SSH_TC_SYS, "SYS" }, \
316 { SSAM_SSH_TC_ACC1, "ACC1" }, \
317 { SSAM_SSH_TC_SHB, "SMB" }, \
318 { SSAM_SSH_TC_POS, "POS" } \
319 )
320
321DECLARE_EVENT_CLASS(ssam_frame_class,
322 TP_PROTO(const struct ssh_frame *frame),
323
324 TP_ARGS(frame),
325
326 TP_STRUCT__entry(
327 __field(u8, type)
328 __field(u8, seq)
329 __field(u16, len)
330 ),
331
332 TP_fast_assign(
333 __entry->type = frame->type;
334 __entry->seq = frame->seq;
335 __entry->len = get_unaligned_le16(&frame->len);
336 ),
337
338 TP_printk("ty=%s, seq=%#04x, len=%u",
339 ssam_show_frame_type(__entry->type),
340 __entry->seq,
341 __entry->len
342 )
343);
344
345#define DEFINE_SSAM_FRAME_EVENT(name) \
346 DEFINE_EVENT(ssam_frame_class, ssam_##name, \
347 TP_PROTO(const struct ssh_frame *frame), \
348 TP_ARGS(frame) \
349 )
350
351DECLARE_EVENT_CLASS(ssam_command_class,
352 TP_PROTO(const struct ssh_command *cmd, u16 len),
353
354 TP_ARGS(cmd, len),
355
356 TP_STRUCT__entry(
357 __field(u16, rqid)
358 __field(u16, len)
359 __field(u8, tid)
360 __field(u8, sid)
361 __field(u8, tc)
362 __field(u8, cid)
363 __field(u8, iid)
364 ),
365
366 TP_fast_assign(
367 __entry->rqid = get_unaligned_le16(&cmd->rqid);
368 __entry->tid = cmd->tid;
369 __entry->sid = cmd->sid;
370 __entry->tc = cmd->tc;
371 __entry->cid = cmd->cid;
372 __entry->iid = cmd->iid;
373 __entry->len = len;
374 ),
375
376 TP_printk("rqid=%#06x, tid=%s, sid=%s, tc=%s, cid=%#04x, iid=%#04x, len=%u",
377 __entry->rqid,
378 ssam_show_ssh_tid(__entry->tid),
379 ssam_show_ssh_tid(__entry->sid),
380 ssam_show_ssh_tc(__entry->tc),
381 __entry->cid,
382 __entry->iid,
383 __entry->len
384 )
385);
386
387#define DEFINE_SSAM_COMMAND_EVENT(name) \
388 DEFINE_EVENT(ssam_command_class, ssam_##name, \
389 TP_PROTO(const struct ssh_command *cmd, u16 len), \
390 TP_ARGS(cmd, len) \
391 )
392
393DECLARE_EVENT_CLASS(ssam_packet_class,
394 TP_PROTO(const struct ssh_packet *packet),
395
396 TP_ARGS(packet),
397
398 TP_STRUCT__entry(
399 __field(unsigned long, state)
400 __array(char, uid, SSAM_PTR_UID_LEN)
401 __field(u8, priority)
402 __field(u16, length)
403 __field(u16, seq)
404 ),
405
406 TP_fast_assign(
407 __entry->state = READ_ONCE(packet->state);
408 ssam_trace_ptr_uid(packet, __entry->uid);
409 __entry->priority = READ_ONCE(packet->priority);
410 __entry->length = packet->data.len;
411 __entry->seq = ssam_trace_get_packet_seq(packet);
412 ),
413
414 TP_printk("uid=%s, seq=%s, ty=%s, pri=%#04x, len=%u, sta=%s",
415 __entry->uid,
416 ssam_show_packet_seq(__entry->seq),
417 ssam_show_packet_type(__entry->state),
418 __entry->priority,
419 __entry->length,
420 ssam_show_packet_state(__entry->state)
421 )
422);
423
424#define DEFINE_SSAM_PACKET_EVENT(name) \
425 DEFINE_EVENT(ssam_packet_class, ssam_##name, \
426 TP_PROTO(const struct ssh_packet *packet), \
427 TP_ARGS(packet) \
428 )
429
430DECLARE_EVENT_CLASS(ssam_packet_status_class,
431 TP_PROTO(const struct ssh_packet *packet, int status),
432
433 TP_ARGS(packet, status),
434
435 TP_STRUCT__entry(
436 __field(unsigned long, state)
437 __field(int, status)
438 __array(char, uid, SSAM_PTR_UID_LEN)
439 __field(u8, priority)
440 __field(u16, length)
441 __field(u16, seq)
442 ),
443
444 TP_fast_assign(
445 __entry->state = READ_ONCE(packet->state);
446 __entry->status = status;
447 ssam_trace_ptr_uid(packet, __entry->uid);
448 __entry->priority = READ_ONCE(packet->priority);
449 __entry->length = packet->data.len;
450 __entry->seq = ssam_trace_get_packet_seq(packet);
451 ),
452
453 TP_printk("uid=%s, seq=%s, ty=%s, pri=%#04x, len=%u, sta=%s, status=%d",
454 __entry->uid,
455 ssam_show_packet_seq(__entry->seq),
456 ssam_show_packet_type(__entry->state),
457 __entry->priority,
458 __entry->length,
459 ssam_show_packet_state(__entry->state),
460 __entry->status
461 )
462);
463
464#define DEFINE_SSAM_PACKET_STATUS_EVENT(name) \
465 DEFINE_EVENT(ssam_packet_status_class, ssam_##name, \
466 TP_PROTO(const struct ssh_packet *packet, int status), \
467 TP_ARGS(packet, status) \
468 )
469
470DECLARE_EVENT_CLASS(ssam_request_class,
471 TP_PROTO(const struct ssh_request *request),
472
473 TP_ARGS(request),
474
475 TP_STRUCT__entry(
476 __field(unsigned long, state)
477 __field(u32, rqid)
478 __array(char, uid, SSAM_PTR_UID_LEN)
479 __field(u8, tc)
480 __field(u16, cid)
481 __field(u16, iid)
482 __field(u8, tid)
483 __field(u8, sid)
484 ),
485
486 TP_fast_assign(
487 const struct ssh_packet *p = &request->packet;
488
489 /* Use packet for UID so we can match requests to packets. */
490 __entry->state = READ_ONCE(request->state);
491 __entry->rqid = ssam_trace_get_request_id(p);
492 ssam_trace_ptr_uid(p, __entry->uid);
493 __entry->tid = ssam_trace_get_request_tid(p);
494 __entry->sid = ssam_trace_get_request_sid(p);
495 __entry->tc = ssam_trace_get_request_tc(p);
496 __entry->cid = ssam_trace_get_command_field_u8(p, cid);
497 __entry->iid = ssam_trace_get_command_field_u8(p, iid);
498 ),
499
500 TP_printk("uid=%s, rqid=%s, ty=%s, sta=%s, tid=%s, sid=%s, tc=%s, cid=%s, iid=%s",
501 __entry->uid,
502 ssam_show_request_id(__entry->rqid),
503 ssam_show_request_type(__entry->state),
504 ssam_show_request_state(__entry->state),
505 ssam_show_ssh_tid(__entry->tid),
506 ssam_show_ssh_tid(__entry->sid),
507 ssam_show_ssh_tc(__entry->tc),
508 ssam_show_generic_u8_field(__entry->cid),
509 ssam_show_generic_u8_field(__entry->iid)
510 )
511);
512
513#define DEFINE_SSAM_REQUEST_EVENT(name) \
514 DEFINE_EVENT(ssam_request_class, ssam_##name, \
515 TP_PROTO(const struct ssh_request *request), \
516 TP_ARGS(request) \
517 )
518
519DECLARE_EVENT_CLASS(ssam_request_status_class,
520 TP_PROTO(const struct ssh_request *request, int status),
521
522 TP_ARGS(request, status),
523
524 TP_STRUCT__entry(
525 __field(unsigned long, state)
526 __field(u32, rqid)
527 __field(int, status)
528 __array(char, uid, SSAM_PTR_UID_LEN)
529 __field(u8, tc)
530 __field(u16, cid)
531 __field(u16, iid)
532 __field(u8, tid)
533 __field(u8, sid)
534 ),
535
536 TP_fast_assign(
537 const struct ssh_packet *p = &request->packet;
538
539 /* Use packet for UID so we can match requests to packets. */
540 __entry->state = READ_ONCE(request->state);
541 __entry->rqid = ssam_trace_get_request_id(p);
542 __entry->status = status;
543 ssam_trace_ptr_uid(p, __entry->uid);
544 __entry->tid = ssam_trace_get_request_tid(p);
545 __entry->sid = ssam_trace_get_request_sid(p);
546 __entry->tc = ssam_trace_get_request_tc(p);
547 __entry->cid = ssam_trace_get_command_field_u8(p, cid);
548 __entry->iid = ssam_trace_get_command_field_u8(p, iid);
549 ),
550
551 TP_printk("uid=%s, rqid=%s, ty=%s, sta=%s, tid=%s, sid=%s, tc=%s, cid=%s, iid=%s, status=%d",
552 __entry->uid,
553 ssam_show_request_id(__entry->rqid),
554 ssam_show_request_type(__entry->state),
555 ssam_show_request_state(__entry->state),
556 ssam_show_ssh_tid(__entry->tid),
557 ssam_show_ssh_tid(__entry->sid),
558 ssam_show_ssh_tc(__entry->tc),
559 ssam_show_generic_u8_field(__entry->cid),
560 ssam_show_generic_u8_field(__entry->iid),
561 __entry->status
562 )
563);
564
565#define DEFINE_SSAM_REQUEST_STATUS_EVENT(name) \
566 DEFINE_EVENT(ssam_request_status_class, ssam_##name, \
567 TP_PROTO(const struct ssh_request *request, int status),\
568 TP_ARGS(request, status) \
569 )
570
571DECLARE_EVENT_CLASS(ssam_alloc_class,
572 TP_PROTO(void *ptr, size_t len),
573
574 TP_ARGS(ptr, len),
575
576 TP_STRUCT__entry(
577 __field(size_t, len)
578 __array(char, uid, SSAM_PTR_UID_LEN)
579 ),
580
581 TP_fast_assign(
582 __entry->len = len;
583 ssam_trace_ptr_uid(ptr, __entry->uid);
584 ),
585
586 TP_printk("uid=%s, len=%zu", __entry->uid, __entry->len)
587);
588
589#define DEFINE_SSAM_ALLOC_EVENT(name) \
590 DEFINE_EVENT(ssam_alloc_class, ssam_##name, \
591 TP_PROTO(void *ptr, size_t len), \
592 TP_ARGS(ptr, len) \
593 )
594
595DECLARE_EVENT_CLASS(ssam_free_class,
596 TP_PROTO(void *ptr),
597
598 TP_ARGS(ptr),
599
600 TP_STRUCT__entry(
601 __array(char, uid, SSAM_PTR_UID_LEN)
602 ),
603
604 TP_fast_assign(
605 ssam_trace_ptr_uid(ptr, __entry->uid);
606 ),
607
608 TP_printk("uid=%s", __entry->uid)
609);
610
611#define DEFINE_SSAM_FREE_EVENT(name) \
612 DEFINE_EVENT(ssam_free_class, ssam_##name, \
613 TP_PROTO(void *ptr), \
614 TP_ARGS(ptr) \
615 )
616
617DECLARE_EVENT_CLASS(ssam_pending_class,
618 TP_PROTO(unsigned int pending),
619
620 TP_ARGS(pending),
621
622 TP_STRUCT__entry(
623 __field(unsigned int, pending)
624 ),
625
626 TP_fast_assign(
627 __entry->pending = pending;
628 ),
629
630 TP_printk("pending=%u", __entry->pending)
631);
632
633#define DEFINE_SSAM_PENDING_EVENT(name) \
634 DEFINE_EVENT(ssam_pending_class, ssam_##name, \
635 TP_PROTO(unsigned int pending), \
636 TP_ARGS(pending) \
637 )
638
639DECLARE_EVENT_CLASS(ssam_data_class,
640 TP_PROTO(size_t length),
641
642 TP_ARGS(length),
643
644 TP_STRUCT__entry(
645 __field(size_t, length)
646 ),
647
648 TP_fast_assign(
649 __entry->length = length;
650 ),
651
652 TP_printk("length=%zu", __entry->length)
653);
654
655#define DEFINE_SSAM_DATA_EVENT(name) \
656 DEFINE_EVENT(ssam_data_class, ssam_##name, \
657 TP_PROTO(size_t length), \
658 TP_ARGS(length) \
659 )
660
661DEFINE_SSAM_FRAME_EVENT(rx_frame_received);
662DEFINE_SSAM_COMMAND_EVENT(rx_response_received);
663DEFINE_SSAM_COMMAND_EVENT(rx_event_received);
664
665DEFINE_SSAM_PACKET_EVENT(packet_release);
666DEFINE_SSAM_PACKET_EVENT(packet_submit);
667DEFINE_SSAM_PACKET_EVENT(packet_resubmit);
668DEFINE_SSAM_PACKET_EVENT(packet_timeout);
669DEFINE_SSAM_PACKET_EVENT(packet_cancel);
670DEFINE_SSAM_PACKET_STATUS_EVENT(packet_complete);
671DEFINE_SSAM_PENDING_EVENT(ptl_timeout_reap);
672
673DEFINE_SSAM_REQUEST_EVENT(request_submit);
674DEFINE_SSAM_REQUEST_EVENT(request_timeout);
675DEFINE_SSAM_REQUEST_EVENT(request_cancel);
676DEFINE_SSAM_REQUEST_STATUS_EVENT(request_complete);
677DEFINE_SSAM_PENDING_EVENT(rtl_timeout_reap);
678
679DEFINE_SSAM_PACKET_EVENT(ei_tx_drop_ack_packet);
680DEFINE_SSAM_PACKET_EVENT(ei_tx_drop_nak_packet);
681DEFINE_SSAM_PACKET_EVENT(ei_tx_drop_dsq_packet);
682DEFINE_SSAM_PACKET_STATUS_EVENT(ei_tx_fail_write);
683DEFINE_SSAM_PACKET_EVENT(ei_tx_corrupt_data);
684DEFINE_SSAM_DATA_EVENT(ei_rx_corrupt_syn);
685DEFINE_SSAM_FRAME_EVENT(ei_rx_corrupt_data);
686DEFINE_SSAM_REQUEST_EVENT(ei_rx_drop_response);
687
688DEFINE_SSAM_ALLOC_EVENT(ctrl_packet_alloc);
689DEFINE_SSAM_FREE_EVENT(ctrl_packet_free);
690
691DEFINE_SSAM_ALLOC_EVENT(event_item_alloc);
692DEFINE_SSAM_FREE_EVENT(event_item_free);
693
694#endif /* _SURFACE_AGGREGATOR_TRACE_H */
695
696/* This part must be outside protection */
697#undef TRACE_INCLUDE_PATH
698#undef TRACE_INCLUDE_FILE
699
700#define TRACE_INCLUDE_PATH .
701#define TRACE_INCLUDE_FILE trace
702
703#include <trace/define_trace.h>
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Trace points for SSAM/SSH.
4 *
5 * Copyright (C) 2020-2021 Maximilian Luz <luzmaximilian@gmail.com>
6 */
7
8#undef TRACE_SYSTEM
9#define TRACE_SYSTEM surface_aggregator
10
11#if !defined(_SURFACE_AGGREGATOR_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
12#define _SURFACE_AGGREGATOR_TRACE_H
13
14#include <linux/surface_aggregator/serial_hub.h>
15
16#include <asm/unaligned.h>
17#include <linux/tracepoint.h>
18
19TRACE_DEFINE_ENUM(SSH_FRAME_TYPE_DATA_SEQ);
20TRACE_DEFINE_ENUM(SSH_FRAME_TYPE_DATA_NSQ);
21TRACE_DEFINE_ENUM(SSH_FRAME_TYPE_ACK);
22TRACE_DEFINE_ENUM(SSH_FRAME_TYPE_NAK);
23
24TRACE_DEFINE_ENUM(SSH_PACKET_SF_LOCKED_BIT);
25TRACE_DEFINE_ENUM(SSH_PACKET_SF_QUEUED_BIT);
26TRACE_DEFINE_ENUM(SSH_PACKET_SF_PENDING_BIT);
27TRACE_DEFINE_ENUM(SSH_PACKET_SF_TRANSMITTING_BIT);
28TRACE_DEFINE_ENUM(SSH_PACKET_SF_TRANSMITTED_BIT);
29TRACE_DEFINE_ENUM(SSH_PACKET_SF_ACKED_BIT);
30TRACE_DEFINE_ENUM(SSH_PACKET_SF_CANCELED_BIT);
31TRACE_DEFINE_ENUM(SSH_PACKET_SF_COMPLETED_BIT);
32
33TRACE_DEFINE_ENUM(SSH_PACKET_TY_FLUSH_BIT);
34TRACE_DEFINE_ENUM(SSH_PACKET_TY_SEQUENCED_BIT);
35TRACE_DEFINE_ENUM(SSH_PACKET_TY_BLOCKING_BIT);
36
37TRACE_DEFINE_ENUM(SSH_PACKET_FLAGS_SF_MASK);
38TRACE_DEFINE_ENUM(SSH_PACKET_FLAGS_TY_MASK);
39
40TRACE_DEFINE_ENUM(SSH_REQUEST_SF_LOCKED_BIT);
41TRACE_DEFINE_ENUM(SSH_REQUEST_SF_QUEUED_BIT);
42TRACE_DEFINE_ENUM(SSH_REQUEST_SF_PENDING_BIT);
43TRACE_DEFINE_ENUM(SSH_REQUEST_SF_TRANSMITTING_BIT);
44TRACE_DEFINE_ENUM(SSH_REQUEST_SF_TRANSMITTED_BIT);
45TRACE_DEFINE_ENUM(SSH_REQUEST_SF_RSPRCVD_BIT);
46TRACE_DEFINE_ENUM(SSH_REQUEST_SF_CANCELED_BIT);
47TRACE_DEFINE_ENUM(SSH_REQUEST_SF_COMPLETED_BIT);
48
49TRACE_DEFINE_ENUM(SSH_REQUEST_TY_FLUSH_BIT);
50TRACE_DEFINE_ENUM(SSH_REQUEST_TY_HAS_RESPONSE_BIT);
51
52TRACE_DEFINE_ENUM(SSH_REQUEST_FLAGS_SF_MASK);
53TRACE_DEFINE_ENUM(SSH_REQUEST_FLAGS_TY_MASK);
54
55TRACE_DEFINE_ENUM(SSAM_SSH_TC_SAM);
56TRACE_DEFINE_ENUM(SSAM_SSH_TC_BAT);
57TRACE_DEFINE_ENUM(SSAM_SSH_TC_TMP);
58TRACE_DEFINE_ENUM(SSAM_SSH_TC_PMC);
59TRACE_DEFINE_ENUM(SSAM_SSH_TC_FAN);
60TRACE_DEFINE_ENUM(SSAM_SSH_TC_PoM);
61TRACE_DEFINE_ENUM(SSAM_SSH_TC_DBG);
62TRACE_DEFINE_ENUM(SSAM_SSH_TC_KBD);
63TRACE_DEFINE_ENUM(SSAM_SSH_TC_FWU);
64TRACE_DEFINE_ENUM(SSAM_SSH_TC_UNI);
65TRACE_DEFINE_ENUM(SSAM_SSH_TC_LPC);
66TRACE_DEFINE_ENUM(SSAM_SSH_TC_TCL);
67TRACE_DEFINE_ENUM(SSAM_SSH_TC_SFL);
68TRACE_DEFINE_ENUM(SSAM_SSH_TC_KIP);
69TRACE_DEFINE_ENUM(SSAM_SSH_TC_EXT);
70TRACE_DEFINE_ENUM(SSAM_SSH_TC_BLD);
71TRACE_DEFINE_ENUM(SSAM_SSH_TC_BAS);
72TRACE_DEFINE_ENUM(SSAM_SSH_TC_SEN);
73TRACE_DEFINE_ENUM(SSAM_SSH_TC_SRQ);
74TRACE_DEFINE_ENUM(SSAM_SSH_TC_MCU);
75TRACE_DEFINE_ENUM(SSAM_SSH_TC_HID);
76TRACE_DEFINE_ENUM(SSAM_SSH_TC_TCH);
77TRACE_DEFINE_ENUM(SSAM_SSH_TC_BKL);
78TRACE_DEFINE_ENUM(SSAM_SSH_TC_TAM);
79TRACE_DEFINE_ENUM(SSAM_SSH_TC_ACC);
80TRACE_DEFINE_ENUM(SSAM_SSH_TC_UFI);
81TRACE_DEFINE_ENUM(SSAM_SSH_TC_USC);
82TRACE_DEFINE_ENUM(SSAM_SSH_TC_PEN);
83TRACE_DEFINE_ENUM(SSAM_SSH_TC_VID);
84TRACE_DEFINE_ENUM(SSAM_SSH_TC_AUD);
85TRACE_DEFINE_ENUM(SSAM_SSH_TC_SMC);
86TRACE_DEFINE_ENUM(SSAM_SSH_TC_KPD);
87TRACE_DEFINE_ENUM(SSAM_SSH_TC_REG);
88
89#define SSAM_PTR_UID_LEN 9
90#define SSAM_U8_FIELD_NOT_APPLICABLE ((u16)-1)
91#define SSAM_SEQ_NOT_APPLICABLE ((u16)-1)
92#define SSAM_RQID_NOT_APPLICABLE ((u32)-1)
93#define SSAM_SSH_TC_NOT_APPLICABLE 0
94
95#ifndef _SURFACE_AGGREGATOR_TRACE_HELPERS
96#define _SURFACE_AGGREGATOR_TRACE_HELPERS
97
98/**
99 * ssam_trace_ptr_uid() - Convert the pointer to a non-pointer UID string.
100 * @ptr: The pointer to convert.
101 * @uid_str: A buffer of length SSAM_PTR_UID_LEN where the UID will be stored.
102 *
103 * Converts the given pointer into a UID string that is safe to be shared
104 * with userspace and logs, i.e. doesn't give away the real memory location.
105 */
106static inline void ssam_trace_ptr_uid(const void *ptr, char *uid_str)
107{
108 char buf[2 * sizeof(void *) + 1];
109
110 BUILD_BUG_ON(ARRAY_SIZE(buf) < SSAM_PTR_UID_LEN);
111
112 snprintf(buf, ARRAY_SIZE(buf), "%p", ptr);
113 memcpy(uid_str, &buf[ARRAY_SIZE(buf) - SSAM_PTR_UID_LEN],
114 SSAM_PTR_UID_LEN);
115}
116
117/**
118 * ssam_trace_get_packet_seq() - Read the packet's sequence ID.
119 * @p: The packet.
120 *
121 * Return: Returns the packet's sequence ID (SEQ) field if present, or
122 * %SSAM_SEQ_NOT_APPLICABLE if not (e.g. flush packet).
123 */
124static inline u16 ssam_trace_get_packet_seq(const struct ssh_packet *p)
125{
126 if (!p->data.ptr || p->data.len < SSH_MESSAGE_LENGTH(0))
127 return SSAM_SEQ_NOT_APPLICABLE;
128
129 return p->data.ptr[SSH_MSGOFFSET_FRAME(seq)];
130}
131
132/**
133 * ssam_trace_get_request_id() - Read the packet's request ID.
134 * @p: The packet.
135 *
136 * Return: Returns the packet's request ID (RQID) field if the packet
137 * represents a request with command data, or %SSAM_RQID_NOT_APPLICABLE if not
138 * (e.g. flush request, control packet).
139 */
140static inline u32 ssam_trace_get_request_id(const struct ssh_packet *p)
141{
142 if (!p->data.ptr || p->data.len < SSH_COMMAND_MESSAGE_LENGTH(0))
143 return SSAM_RQID_NOT_APPLICABLE;
144
145 return get_unaligned_le16(&p->data.ptr[SSH_MSGOFFSET_COMMAND(rqid)]);
146}
147
148/**
149 * ssam_trace_get_request_tc() - Read the packet's request target category.
150 * @p: The packet.
151 *
152 * Return: Returns the packet's request target category (TC) field if the
153 * packet represents a request with command data, or %SSAM_TC_NOT_APPLICABLE
154 * if not (e.g. flush request, control packet).
155 */
156static inline u32 ssam_trace_get_request_tc(const struct ssh_packet *p)
157{
158 if (!p->data.ptr || p->data.len < SSH_COMMAND_MESSAGE_LENGTH(0))
159 return SSAM_SSH_TC_NOT_APPLICABLE;
160
161 return get_unaligned_le16(&p->data.ptr[SSH_MSGOFFSET_COMMAND(tc)]);
162}
163
164#endif /* _SURFACE_AGGREGATOR_TRACE_HELPERS */
165
166#define ssam_trace_get_command_field_u8(packet, field) \
167 ((!(packet) || (packet)->data.len < SSH_COMMAND_MESSAGE_LENGTH(0)) \
168 ? 0 : (packet)->data.ptr[SSH_MSGOFFSET_COMMAND(field)])
169
170#define ssam_show_generic_u8_field(value) \
171 __print_symbolic(value, \
172 { SSAM_U8_FIELD_NOT_APPLICABLE, "N/A" } \
173 )
174
175#define ssam_show_frame_type(ty) \
176 __print_symbolic(ty, \
177 { SSH_FRAME_TYPE_DATA_SEQ, "DSEQ" }, \
178 { SSH_FRAME_TYPE_DATA_NSQ, "DNSQ" }, \
179 { SSH_FRAME_TYPE_ACK, "ACK" }, \
180 { SSH_FRAME_TYPE_NAK, "NAK" } \
181 )
182
183#define ssam_show_packet_type(type) \
184 __print_flags(flags & SSH_PACKET_FLAGS_TY_MASK, "", \
185 { BIT(SSH_PACKET_TY_FLUSH_BIT), "F" }, \
186 { BIT(SSH_PACKET_TY_SEQUENCED_BIT), "S" }, \
187 { BIT(SSH_PACKET_TY_BLOCKING_BIT), "B" } \
188 )
189
190#define ssam_show_packet_state(state) \
191 __print_flags(flags & SSH_PACKET_FLAGS_SF_MASK, "", \
192 { BIT(SSH_PACKET_SF_LOCKED_BIT), "L" }, \
193 { BIT(SSH_PACKET_SF_QUEUED_BIT), "Q" }, \
194 { BIT(SSH_PACKET_SF_PENDING_BIT), "P" }, \
195 { BIT(SSH_PACKET_SF_TRANSMITTING_BIT), "S" }, \
196 { BIT(SSH_PACKET_SF_TRANSMITTED_BIT), "T" }, \
197 { BIT(SSH_PACKET_SF_ACKED_BIT), "A" }, \
198 { BIT(SSH_PACKET_SF_CANCELED_BIT), "C" }, \
199 { BIT(SSH_PACKET_SF_COMPLETED_BIT), "F" } \
200 )
201
202#define ssam_show_packet_seq(seq) \
203 __print_symbolic(seq, \
204 { SSAM_SEQ_NOT_APPLICABLE, "N/A" } \
205 )
206
207#define ssam_show_request_type(flags) \
208 __print_flags((flags) & SSH_REQUEST_FLAGS_TY_MASK, "", \
209 { BIT(SSH_REQUEST_TY_FLUSH_BIT), "F" }, \
210 { BIT(SSH_REQUEST_TY_HAS_RESPONSE_BIT), "R" } \
211 )
212
213#define ssam_show_request_state(flags) \
214 __print_flags((flags) & SSH_REQUEST_FLAGS_SF_MASK, "", \
215 { BIT(SSH_REQUEST_SF_LOCKED_BIT), "L" }, \
216 { BIT(SSH_REQUEST_SF_QUEUED_BIT), "Q" }, \
217 { BIT(SSH_REQUEST_SF_PENDING_BIT), "P" }, \
218 { BIT(SSH_REQUEST_SF_TRANSMITTING_BIT), "S" }, \
219 { BIT(SSH_REQUEST_SF_TRANSMITTED_BIT), "T" }, \
220 { BIT(SSH_REQUEST_SF_RSPRCVD_BIT), "A" }, \
221 { BIT(SSH_REQUEST_SF_CANCELED_BIT), "C" }, \
222 { BIT(SSH_REQUEST_SF_COMPLETED_BIT), "F" } \
223 )
224
225#define ssam_show_request_id(rqid) \
226 __print_symbolic(rqid, \
227 { SSAM_RQID_NOT_APPLICABLE, "N/A" } \
228 )
229
230#define ssam_show_ssh_tc(rqid) \
231 __print_symbolic(rqid, \
232 { SSAM_SSH_TC_NOT_APPLICABLE, "N/A" }, \
233 { SSAM_SSH_TC_SAM, "SAM" }, \
234 { SSAM_SSH_TC_BAT, "BAT" }, \
235 { SSAM_SSH_TC_TMP, "TMP" }, \
236 { SSAM_SSH_TC_PMC, "PMC" }, \
237 { SSAM_SSH_TC_FAN, "FAN" }, \
238 { SSAM_SSH_TC_PoM, "PoM" }, \
239 { SSAM_SSH_TC_DBG, "DBG" }, \
240 { SSAM_SSH_TC_KBD, "KBD" }, \
241 { SSAM_SSH_TC_FWU, "FWU" }, \
242 { SSAM_SSH_TC_UNI, "UNI" }, \
243 { SSAM_SSH_TC_LPC, "LPC" }, \
244 { SSAM_SSH_TC_TCL, "TCL" }, \
245 { SSAM_SSH_TC_SFL, "SFL" }, \
246 { SSAM_SSH_TC_KIP, "KIP" }, \
247 { SSAM_SSH_TC_EXT, "EXT" }, \
248 { SSAM_SSH_TC_BLD, "BLD" }, \
249 { SSAM_SSH_TC_BAS, "BAS" }, \
250 { SSAM_SSH_TC_SEN, "SEN" }, \
251 { SSAM_SSH_TC_SRQ, "SRQ" }, \
252 { SSAM_SSH_TC_MCU, "MCU" }, \
253 { SSAM_SSH_TC_HID, "HID" }, \
254 { SSAM_SSH_TC_TCH, "TCH" }, \
255 { SSAM_SSH_TC_BKL, "BKL" }, \
256 { SSAM_SSH_TC_TAM, "TAM" }, \
257 { SSAM_SSH_TC_ACC, "ACC" }, \
258 { SSAM_SSH_TC_UFI, "UFI" }, \
259 { SSAM_SSH_TC_USC, "USC" }, \
260 { SSAM_SSH_TC_PEN, "PEN" }, \
261 { SSAM_SSH_TC_VID, "VID" }, \
262 { SSAM_SSH_TC_AUD, "AUD" }, \
263 { SSAM_SSH_TC_SMC, "SMC" }, \
264 { SSAM_SSH_TC_KPD, "KPD" }, \
265 { SSAM_SSH_TC_REG, "REG" } \
266 )
267
268DECLARE_EVENT_CLASS(ssam_frame_class,
269 TP_PROTO(const struct ssh_frame *frame),
270
271 TP_ARGS(frame),
272
273 TP_STRUCT__entry(
274 __field(u8, type)
275 __field(u8, seq)
276 __field(u16, len)
277 ),
278
279 TP_fast_assign(
280 __entry->type = frame->type;
281 __entry->seq = frame->seq;
282 __entry->len = get_unaligned_le16(&frame->len);
283 ),
284
285 TP_printk("ty=%s, seq=%#04x, len=%u",
286 ssam_show_frame_type(__entry->type),
287 __entry->seq,
288 __entry->len
289 )
290);
291
292#define DEFINE_SSAM_FRAME_EVENT(name) \
293 DEFINE_EVENT(ssam_frame_class, ssam_##name, \
294 TP_PROTO(const struct ssh_frame *frame), \
295 TP_ARGS(frame) \
296 )
297
298DECLARE_EVENT_CLASS(ssam_command_class,
299 TP_PROTO(const struct ssh_command *cmd, u16 len),
300
301 TP_ARGS(cmd, len),
302
303 TP_STRUCT__entry(
304 __field(u16, rqid)
305 __field(u16, len)
306 __field(u8, tc)
307 __field(u8, cid)
308 __field(u8, iid)
309 ),
310
311 TP_fast_assign(
312 __entry->rqid = get_unaligned_le16(&cmd->rqid);
313 __entry->tc = cmd->tc;
314 __entry->cid = cmd->cid;
315 __entry->iid = cmd->iid;
316 __entry->len = len;
317 ),
318
319 TP_printk("rqid=%#06x, tc=%s, cid=%#04x, iid=%#04x, len=%u",
320 __entry->rqid,
321 ssam_show_ssh_tc(__entry->tc),
322 __entry->cid,
323 __entry->iid,
324 __entry->len
325 )
326);
327
328#define DEFINE_SSAM_COMMAND_EVENT(name) \
329 DEFINE_EVENT(ssam_command_class, ssam_##name, \
330 TP_PROTO(const struct ssh_command *cmd, u16 len), \
331 TP_ARGS(cmd, len) \
332 )
333
334DECLARE_EVENT_CLASS(ssam_packet_class,
335 TP_PROTO(const struct ssh_packet *packet),
336
337 TP_ARGS(packet),
338
339 TP_STRUCT__entry(
340 __field(unsigned long, state)
341 __array(char, uid, SSAM_PTR_UID_LEN)
342 __field(u8, priority)
343 __field(u16, length)
344 __field(u16, seq)
345 ),
346
347 TP_fast_assign(
348 __entry->state = READ_ONCE(packet->state);
349 ssam_trace_ptr_uid(packet, __entry->uid);
350 __entry->priority = READ_ONCE(packet->priority);
351 __entry->length = packet->data.len;
352 __entry->seq = ssam_trace_get_packet_seq(packet);
353 ),
354
355 TP_printk("uid=%s, seq=%s, ty=%s, pri=%#04x, len=%u, sta=%s",
356 __entry->uid,
357 ssam_show_packet_seq(__entry->seq),
358 ssam_show_packet_type(__entry->state),
359 __entry->priority,
360 __entry->length,
361 ssam_show_packet_state(__entry->state)
362 )
363);
364
365#define DEFINE_SSAM_PACKET_EVENT(name) \
366 DEFINE_EVENT(ssam_packet_class, ssam_##name, \
367 TP_PROTO(const struct ssh_packet *packet), \
368 TP_ARGS(packet) \
369 )
370
371DECLARE_EVENT_CLASS(ssam_packet_status_class,
372 TP_PROTO(const struct ssh_packet *packet, int status),
373
374 TP_ARGS(packet, status),
375
376 TP_STRUCT__entry(
377 __field(unsigned long, state)
378 __field(int, status)
379 __array(char, uid, SSAM_PTR_UID_LEN)
380 __field(u8, priority)
381 __field(u16, length)
382 __field(u16, seq)
383 ),
384
385 TP_fast_assign(
386 __entry->state = READ_ONCE(packet->state);
387 __entry->status = status;
388 ssam_trace_ptr_uid(packet, __entry->uid);
389 __entry->priority = READ_ONCE(packet->priority);
390 __entry->length = packet->data.len;
391 __entry->seq = ssam_trace_get_packet_seq(packet);
392 ),
393
394 TP_printk("uid=%s, seq=%s, ty=%s, pri=%#04x, len=%u, sta=%s, status=%d",
395 __entry->uid,
396 ssam_show_packet_seq(__entry->seq),
397 ssam_show_packet_type(__entry->state),
398 __entry->priority,
399 __entry->length,
400 ssam_show_packet_state(__entry->state),
401 __entry->status
402 )
403);
404
405#define DEFINE_SSAM_PACKET_STATUS_EVENT(name) \
406 DEFINE_EVENT(ssam_packet_status_class, ssam_##name, \
407 TP_PROTO(const struct ssh_packet *packet, int status), \
408 TP_ARGS(packet, status) \
409 )
410
411DECLARE_EVENT_CLASS(ssam_request_class,
412 TP_PROTO(const struct ssh_request *request),
413
414 TP_ARGS(request),
415
416 TP_STRUCT__entry(
417 __field(unsigned long, state)
418 __field(u32, rqid)
419 __array(char, uid, SSAM_PTR_UID_LEN)
420 __field(u8, tc)
421 __field(u16, cid)
422 __field(u16, iid)
423 ),
424
425 TP_fast_assign(
426 const struct ssh_packet *p = &request->packet;
427
428 /* Use packet for UID so we can match requests to packets. */
429 __entry->state = READ_ONCE(request->state);
430 __entry->rqid = ssam_trace_get_request_id(p);
431 ssam_trace_ptr_uid(p, __entry->uid);
432 __entry->tc = ssam_trace_get_request_tc(p);
433 __entry->cid = ssam_trace_get_command_field_u8(p, cid);
434 __entry->iid = ssam_trace_get_command_field_u8(p, iid);
435 ),
436
437 TP_printk("uid=%s, rqid=%s, ty=%s, sta=%s, tc=%s, cid=%s, iid=%s",
438 __entry->uid,
439 ssam_show_request_id(__entry->rqid),
440 ssam_show_request_type(__entry->state),
441 ssam_show_request_state(__entry->state),
442 ssam_show_ssh_tc(__entry->tc),
443 ssam_show_generic_u8_field(__entry->cid),
444 ssam_show_generic_u8_field(__entry->iid)
445 )
446);
447
448#define DEFINE_SSAM_REQUEST_EVENT(name) \
449 DEFINE_EVENT(ssam_request_class, ssam_##name, \
450 TP_PROTO(const struct ssh_request *request), \
451 TP_ARGS(request) \
452 )
453
454DECLARE_EVENT_CLASS(ssam_request_status_class,
455 TP_PROTO(const struct ssh_request *request, int status),
456
457 TP_ARGS(request, status),
458
459 TP_STRUCT__entry(
460 __field(unsigned long, state)
461 __field(u32, rqid)
462 __field(int, status)
463 __array(char, uid, SSAM_PTR_UID_LEN)
464 __field(u8, tc)
465 __field(u16, cid)
466 __field(u16, iid)
467 ),
468
469 TP_fast_assign(
470 const struct ssh_packet *p = &request->packet;
471
472 /* Use packet for UID so we can match requests to packets. */
473 __entry->state = READ_ONCE(request->state);
474 __entry->rqid = ssam_trace_get_request_id(p);
475 __entry->status = status;
476 ssam_trace_ptr_uid(p, __entry->uid);
477 __entry->tc = ssam_trace_get_request_tc(p);
478 __entry->cid = ssam_trace_get_command_field_u8(p, cid);
479 __entry->iid = ssam_trace_get_command_field_u8(p, iid);
480 ),
481
482 TP_printk("uid=%s, rqid=%s, ty=%s, sta=%s, tc=%s, cid=%s, iid=%s, status=%d",
483 __entry->uid,
484 ssam_show_request_id(__entry->rqid),
485 ssam_show_request_type(__entry->state),
486 ssam_show_request_state(__entry->state),
487 ssam_show_ssh_tc(__entry->tc),
488 ssam_show_generic_u8_field(__entry->cid),
489 ssam_show_generic_u8_field(__entry->iid),
490 __entry->status
491 )
492);
493
494#define DEFINE_SSAM_REQUEST_STATUS_EVENT(name) \
495 DEFINE_EVENT(ssam_request_status_class, ssam_##name, \
496 TP_PROTO(const struct ssh_request *request, int status),\
497 TP_ARGS(request, status) \
498 )
499
500DECLARE_EVENT_CLASS(ssam_alloc_class,
501 TP_PROTO(void *ptr, size_t len),
502
503 TP_ARGS(ptr, len),
504
505 TP_STRUCT__entry(
506 __field(size_t, len)
507 __array(char, uid, SSAM_PTR_UID_LEN)
508 ),
509
510 TP_fast_assign(
511 __entry->len = len;
512 ssam_trace_ptr_uid(ptr, __entry->uid);
513 ),
514
515 TP_printk("uid=%s, len=%zu", __entry->uid, __entry->len)
516);
517
518#define DEFINE_SSAM_ALLOC_EVENT(name) \
519 DEFINE_EVENT(ssam_alloc_class, ssam_##name, \
520 TP_PROTO(void *ptr, size_t len), \
521 TP_ARGS(ptr, len) \
522 )
523
524DECLARE_EVENT_CLASS(ssam_free_class,
525 TP_PROTO(void *ptr),
526
527 TP_ARGS(ptr),
528
529 TP_STRUCT__entry(
530 __array(char, uid, SSAM_PTR_UID_LEN)
531 ),
532
533 TP_fast_assign(
534 ssam_trace_ptr_uid(ptr, __entry->uid);
535 ),
536
537 TP_printk("uid=%s", __entry->uid)
538);
539
540#define DEFINE_SSAM_FREE_EVENT(name) \
541 DEFINE_EVENT(ssam_free_class, ssam_##name, \
542 TP_PROTO(void *ptr), \
543 TP_ARGS(ptr) \
544 )
545
546DECLARE_EVENT_CLASS(ssam_pending_class,
547 TP_PROTO(unsigned int pending),
548
549 TP_ARGS(pending),
550
551 TP_STRUCT__entry(
552 __field(unsigned int, pending)
553 ),
554
555 TP_fast_assign(
556 __entry->pending = pending;
557 ),
558
559 TP_printk("pending=%u", __entry->pending)
560);
561
562#define DEFINE_SSAM_PENDING_EVENT(name) \
563 DEFINE_EVENT(ssam_pending_class, ssam_##name, \
564 TP_PROTO(unsigned int pending), \
565 TP_ARGS(pending) \
566 )
567
568DECLARE_EVENT_CLASS(ssam_data_class,
569 TP_PROTO(size_t length),
570
571 TP_ARGS(length),
572
573 TP_STRUCT__entry(
574 __field(size_t, length)
575 ),
576
577 TP_fast_assign(
578 __entry->length = length;
579 ),
580
581 TP_printk("length=%zu", __entry->length)
582);
583
584#define DEFINE_SSAM_DATA_EVENT(name) \
585 DEFINE_EVENT(ssam_data_class, ssam_##name, \
586 TP_PROTO(size_t length), \
587 TP_ARGS(length) \
588 )
589
590DEFINE_SSAM_FRAME_EVENT(rx_frame_received);
591DEFINE_SSAM_COMMAND_EVENT(rx_response_received);
592DEFINE_SSAM_COMMAND_EVENT(rx_event_received);
593
594DEFINE_SSAM_PACKET_EVENT(packet_release);
595DEFINE_SSAM_PACKET_EVENT(packet_submit);
596DEFINE_SSAM_PACKET_EVENT(packet_resubmit);
597DEFINE_SSAM_PACKET_EVENT(packet_timeout);
598DEFINE_SSAM_PACKET_EVENT(packet_cancel);
599DEFINE_SSAM_PACKET_STATUS_EVENT(packet_complete);
600DEFINE_SSAM_PENDING_EVENT(ptl_timeout_reap);
601
602DEFINE_SSAM_REQUEST_EVENT(request_submit);
603DEFINE_SSAM_REQUEST_EVENT(request_timeout);
604DEFINE_SSAM_REQUEST_EVENT(request_cancel);
605DEFINE_SSAM_REQUEST_STATUS_EVENT(request_complete);
606DEFINE_SSAM_PENDING_EVENT(rtl_timeout_reap);
607
608DEFINE_SSAM_PACKET_EVENT(ei_tx_drop_ack_packet);
609DEFINE_SSAM_PACKET_EVENT(ei_tx_drop_nak_packet);
610DEFINE_SSAM_PACKET_EVENT(ei_tx_drop_dsq_packet);
611DEFINE_SSAM_PACKET_STATUS_EVENT(ei_tx_fail_write);
612DEFINE_SSAM_PACKET_EVENT(ei_tx_corrupt_data);
613DEFINE_SSAM_DATA_EVENT(ei_rx_corrupt_syn);
614DEFINE_SSAM_FRAME_EVENT(ei_rx_corrupt_data);
615DEFINE_SSAM_REQUEST_EVENT(ei_rx_drop_response);
616
617DEFINE_SSAM_ALLOC_EVENT(ctrl_packet_alloc);
618DEFINE_SSAM_FREE_EVENT(ctrl_packet_free);
619
620DEFINE_SSAM_ALLOC_EVENT(event_item_alloc);
621DEFINE_SSAM_FREE_EVENT(event_item_free);
622
623#endif /* _SURFACE_AGGREGATOR_TRACE_H */
624
625/* This part must be outside protection */
626#undef TRACE_INCLUDE_PATH
627#undef TRACE_INCLUDE_FILE
628
629#define TRACE_INCLUDE_PATH .
630#define TRACE_INCLUDE_FILE trace
631
632#include <trace/define_trace.h>