linux/drivers/thunderbolt/trace.h

/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Thunderbolt tracing support
 *
 * Copyright (C) 2024, Intel Corporation
 * Author: Mika Westerberg <[email protected]>
 *	   Gil Fine <[email protected]>
 */

#undef TRACE_SYSTEM
#define TRACE_SYSTEM

#if !defined(TB_TRACE_H_) || defined(TRACE_HEADER_MULTI_READ)
#define TB_TRACE_H_

#include <linux/trace_seq.h>
#include <linux/tracepoint.h>

#include "tb_msgs.h"

#define tb_cfg_type_name(type)
#define show_type_name(val)

#ifndef TB_TRACE_HELPERS
#define TB_TRACE_HELPERS
static inline const char *show_data_read_write(struct trace_seq *p,
					       const u32 *data)
{}

static inline const char *show_data_error(struct trace_seq *p, const u32 *data)
{}

static inline const char *show_data_event(struct trace_seq *p, const u32 *data)
{}

static inline const char *show_route(struct trace_seq *p, const u32 *data)
{}

static inline const char *show_data(struct trace_seq *p, u8 type,
				    const u32 *data, u32 length)
{}
#endif

DECLARE_EVENT_CLASS(tb_raw,
	TP_PROTO(int index, u8 type, const void *data, size_t size),
	TP_ARGS(index, type, data, size),
	TP_STRUCT__entry(
		__field(int, index)
		__field(u8, type)
		__field(size_t, size)
		__dynamic_array(u32, data, size / 4)
	),
	TP_fast_assign(
		__entry->index = index;
		__entry->type = type;
		__entry->size = size / 4;
		memcpy(__get_dynamic_array(data), data, size);
	),
	TP_printk("type=%s, size=%zd, domain=%d, %s",
		  show_type_name(__entry->type), __entry->size, __entry->index,
		  show_data(p, __entry->type, __get_dynamic_array(data),
			    __entry->size)
	)
);

DEFINE_EVENT(tb_raw, tb_tx,
	TP_PROTO(int index, u8 type, const void *data, size_t size),
	TP_ARGS(index, type, data, size)
);

DEFINE_EVENT(tb_raw, tb_event,
	TP_PROTO(int index, u8 type, const void *data, size_t size),
	TP_ARGS(index, type, data, size)
);

TRACE_EVENT(tb_rx,
	TP_PROTO(int index, u8 type, const void *data, size_t size, bool dropped),
	TP_ARGS(index, type, data, size, dropped),
	TP_STRUCT__entry(
		__field(int, index)
		__field(u8, type)
		__field(size_t, size)
		__dynamic_array(u32, data, size / 4)
		__field(bool, dropped)
	),
	TP_fast_assign(
		__entry->index = index;
		__entry->type = type;
		__entry->size = size / 4;
		memcpy(__get_dynamic_array(data), data, size);
		__entry->dropped = dropped;
	),
	TP_printk("type=%s, dropped=%u, size=%zd, domain=%d, %s",
		  show_type_name(__entry->type), __entry->dropped,
		  __entry->size, __entry->index,
		  show_data(p, __entry->type, __get_dynamic_array(data),
			    __entry->size)
	)
);

#endif /* TB_TRACE_H_ */

#undef TRACE_INCLUDE_PATH
#define TRACE_INCLUDE_PATH

#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE

/* This part must be outside protection */
#include <trace/define_trace.h>