1/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2/*
3* Copyright(c) 2015 - 2018 Intel Corporation.
4*/
5
6#if !defined(__HFI1_TRACE_EXTRA_H) || defined(TRACE_HEADER_MULTI_READ)
7#define __HFI1_TRACE_EXTRA_H
8
9#include <linux/tracepoint.h>
10#include <linux/trace_seq.h>
11
12#include "hfi.h"
13
14/*
15 * Note:
16 * This produces a REALLY ugly trace in the console output when the string is
17 * too long.
18 */
19
20#undef TRACE_SYSTEM
21#define TRACE_SYSTEM hfi1_dbg
22
23#define MAX_MSG_LEN 512
24
25#pragma GCC diagnostic push
26#ifndef __clang__
27#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
28#endif
29
30DECLARE_EVENT_CLASS(hfi1_trace_template,
31 TP_PROTO(const char *function, struct va_format *vaf),
32 TP_ARGS(function, vaf),
33 TP_STRUCT__entry(__string(function, function)
34 __vstring(msg, vaf->fmt, vaf->va)
35 ),
36 TP_fast_assign(__assign_str(function, function);
37 __assign_vstr(msg, vaf->fmt, vaf->va);
38 ),
39 TP_printk("(%s) %s",
40 __get_str(function),
41 __get_str(msg))
42);
43
44#pragma GCC diagnostic pop
45
46/*
47 * It may be nice to macroize the __hfi1_trace but the va_* stuff requires an
48 * actual function to work and can not be in a macro.
49 */
50#define __hfi1_trace_def(lvl) \
51void __printf(2, 3) __hfi1_trace_##lvl(const char *funct, char *fmt, ...); \
52 \
53DEFINE_EVENT(hfi1_trace_template, hfi1_ ##lvl, \
54 TP_PROTO(const char *function, struct va_format *vaf), \
55 TP_ARGS(function, vaf))
56
57#define __hfi1_trace_fn(lvl) \
58void __printf(2, 3) __hfi1_trace_##lvl(const char *func, char *fmt, ...)\
59{ \
60 struct va_format vaf = { \
61 .fmt = fmt, \
62 }; \
63 va_list args; \
64 \
65 va_start(args, fmt); \
66 vaf.va = &args; \
67 trace_hfi1_ ##lvl(func, &vaf); \
68 va_end(args); \
69 return; \
70}
71
72/*
73 * To create a new trace level simply define it below and as a __hfi1_trace_fn
74 * in trace.c. This will create all the hooks for calling
75 * hfi1_cdbg(LVL, fmt, ...); as well as take care of all
76 * the debugfs stuff.
77 */
78__hfi1_trace_def(AFFINITY);
79__hfi1_trace_def(PKT);
80__hfi1_trace_def(PROC);
81__hfi1_trace_def(SDMA);
82__hfi1_trace_def(LINKVERB);
83__hfi1_trace_def(DEBUG);
84__hfi1_trace_def(SNOOP);
85__hfi1_trace_def(CNTR);
86__hfi1_trace_def(PIO);
87__hfi1_trace_def(DC8051);
88__hfi1_trace_def(FIRMWARE);
89__hfi1_trace_def(RCVCTRL);
90__hfi1_trace_def(TID);
91__hfi1_trace_def(MMU);
92__hfi1_trace_def(IOCTL);
93
94#define hfi1_cdbg(which, fmt, ...) \
95 __hfi1_trace_##which(__func__, fmt, ##__VA_ARGS__)
96
97#define hfi1_dbg(fmt, ...) \
98 hfi1_cdbg(DEBUG, fmt, ##__VA_ARGS__)
99
100/*
101 * Define HFI1_EARLY_DBG at compile time or here to enable early trace
102 * messages. Do not check in an enablement for this.
103 */
104
105#ifdef HFI1_EARLY_DBG
106#define hfi1_dbg_early(fmt, ...) \
107 trace_printk(fmt, ##__VA_ARGS__)
108#else
109#define hfi1_dbg_early(fmt, ...)
110#endif
111
112#endif /* __HFI1_TRACE_EXTRA_H */
113
114#undef TRACE_INCLUDE_PATH
115#undef TRACE_INCLUDE_FILE
116#define TRACE_INCLUDE_PATH .
117#define TRACE_INCLUDE_FILE trace_dbg
118#include <trace/define_trace.h>
119

source code of linux/drivers/infiniband/hw/hfi1/trace_dbg.h