greybus: tracing: fix hd traces
[cascardo/linux.git] / drivers / staging / greybus / greybus_trace.h
1 /*
2  * Greybus driver and device API
3  *
4  * Copyright 2015 Google Inc.
5  * Copyright 2015 Linaro Ltd.
6  *
7  * Released under the GPLv2 only.
8  */
9 #undef TRACE_SYSTEM
10 #define TRACE_SYSTEM greybus
11
12 #if !defined(_TRACE_GREYBUS_H) || defined(TRACE_HEADER_MULTI_READ)
13 #define _TRACE_GREYBUS_H
14
15 #include <linux/tracepoint.h>
16
17 struct gb_message;
18 struct gb_operation;
19 struct gb_host_device;
20
21 #define gb_bundle_name(message)                                         \
22         (message->operation->connection->bundle ?                       \
23         dev_name(&message->operation->connection->bundle->dev) :        \
24         dev_name(&message->operation->connection->hd->svc->dev))
25
26 DECLARE_EVENT_CLASS(gb_message,
27
28         TP_PROTO(struct gb_message *message),
29
30         TP_ARGS(message),
31
32         TP_STRUCT__entry(
33                 __string(name, gb_bundle_name(message))
34                 __field(u16, op_id)
35                 __field(u16, intf_cport_id)
36                 __field(u16, hd_cport_id)
37                 __field(size_t, payload_size)
38         ),
39
40         TP_fast_assign(
41                 __assign_str(name, gb_bundle_name(message))
42                 __entry->op_id = message->operation->id;
43                 __entry->intf_cport_id =
44                         message->operation->connection->intf_cport_id;
45                 __entry->hd_cport_id =
46                         message->operation->connection->hd_cport_id;
47                 __entry->payload_size = message->payload_size;
48         ),
49
50         TP_printk("greybus:%s op=%04x if_id=%u hd_id=%u l=%zu",
51                   __get_str(name), __entry->op_id, __entry->intf_cport_id,
52                   __entry->hd_cport_id, __entry->payload_size)
53 );
54
55 #define DEFINE_MESSAGE_EVENT(name)                                      \
56                 DEFINE_EVENT(gb_message, name,                          \
57                                 TP_PROTO(struct gb_message *message),   \
58                                 TP_ARGS(message))
59
60 /*
61  * Occurs immediately before calling a host device's message_send()
62  * method.
63  */
64 DEFINE_MESSAGE_EVENT(gb_message_send);
65
66 /*
67  * Occurs after an incoming request message has been received
68  */
69 DEFINE_MESSAGE_EVENT(gb_message_recv_request);
70
71 /*
72  * Occurs after an incoming response message has been received,
73  * after its matching request has been found.
74  */
75 DEFINE_MESSAGE_EVENT(gb_message_recv_response);
76
77 /*
78  * Occurs after an operation has been canceled, possibly before the
79  * cancellation is complete.
80  */
81 DEFINE_MESSAGE_EVENT(gb_message_cancel_outgoing);
82
83 /*
84  * Occurs when an incoming request is cancelled; if the response has
85  * been queued for sending, this occurs after it is sent.
86  */
87 DEFINE_MESSAGE_EVENT(gb_message_cancel_incoming);
88
89 #undef DEFINE_MESSAGE_EVENT
90
91 DECLARE_EVENT_CLASS(gb_operation,
92
93         TP_PROTO(struct gb_operation *operation),
94
95         TP_ARGS(operation),
96
97         TP_STRUCT__entry(
98                 __field(u16, cport_id)  /* CPort of HD side of connection */
99                 __field(u16, id)        /* Operation ID */
100                 __field(u8, type)
101                 __field(unsigned long, flags)
102                 __field(int, active)
103                 __field(int, waiters)
104                 __field(int, errno)
105         ),
106
107         TP_fast_assign(
108                 __entry->cport_id = operation->connection->hd_cport_id;
109                 __entry->id = operation->id;
110                 __entry->type = operation->type;
111                 __entry->flags = operation->flags;
112                 __entry->active = operation->active;
113                 __entry->waiters = atomic_read(&operation->waiters);
114                 __entry->errno = operation->errno;
115         ),
116
117         TP_printk("id=%04x type=0x%02x cport_id=%04x flags=0x%lx active=%d waiters=%d errno=%d",
118                   __entry->id, __entry->cport_id, __entry->type, __entry->flags,
119                   __entry->active, __entry->waiters, __entry->errno)
120 );
121
122 #define DEFINE_OPERATION_EVENT(name)                                    \
123                 DEFINE_EVENT(gb_operation, name,                        \
124                                 TP_PROTO(struct gb_operation *operation), \
125                                 TP_ARGS(operation))
126
127 /*
128  * Occurs after a new operation is created for an outgoing request
129  * has been successfully created.
130  */
131 DEFINE_OPERATION_EVENT(gb_operation_create);
132
133 /*
134  * Occurs after a new operation has been created for an incoming
135  * request has been successfully created and initialized.
136  */
137 DEFINE_OPERATION_EVENT(gb_operation_create_incoming);
138
139 /*
140  * Occurs when the last reference to an operation has been dropped,
141  * prior to freeing resources.
142  */
143 DEFINE_OPERATION_EVENT(gb_operation_destroy);
144
145 /*
146  * Occurs when an operation has been marked active, after updating
147  * its active count.
148  */
149 DEFINE_OPERATION_EVENT(gb_operation_get_active);
150
151 /*
152  * Occurs when an operation has been marked active, before updating
153  * its active count.
154  */
155 DEFINE_OPERATION_EVENT(gb_operation_put_active);
156
157 #undef DEFINE_OPERATION_EVENT
158
159 DECLARE_EVENT_CLASS(gb_host_device,
160
161         TP_PROTO(struct gb_host_device *hd),
162
163         TP_ARGS(hd),
164
165         TP_STRUCT__entry(
166                 __field(int, bus_id)
167                 __field(u8, num_cports)
168                 __field(size_t, buffer_size_max)
169         ),
170
171         TP_fast_assign(
172                 __entry->bus_id = hd->bus_id;
173                 __entry->num_cports = hd->num_cports;
174                 __entry->buffer_size_max = hd->buffer_size_max;
175         ),
176
177         TP_printk("greybus: bus_id=%d num_cports=%hu mtu=%zu",
178                 __entry->bus_id, __entry->num_cports,
179                 __entry->buffer_size_max)
180 );
181
182 #define DEFINE_HD_EVENT(name)                                           \
183                 DEFINE_EVENT(gb_host_device, name,                      \
184                                 TP_PROTO(struct gb_host_device *hd),    \
185                                 TP_ARGS(hd))
186
187 /*
188  * Occurs after a new host device is successfully created, before
189  * its SVC has been set up.
190  */
191 DEFINE_HD_EVENT(gb_hd_create);
192
193 /*
194  * Occurs after the last reference to a host device has been
195  * dropped.
196  */
197 DEFINE_HD_EVENT(gb_hd_release);
198
199 /*
200  * Occurs after a new host device has been added, after the
201  * connection to its SVC has * been enabled.
202  */
203 DEFINE_HD_EVENT(gb_hd_add);
204
205 /*
206  * Occurs when a host device is being disconnected from the AP USB
207  * host controller.
208  */
209 DEFINE_HD_EVENT(gb_hd_del);
210
211 #undef DEFINE_HD_EVENT
212
213 #endif /* _TRACE_GREYBUS_H */
214
215 /* This part must be outside protection */
216 #undef TRACE_INCLUDE_PATH
217 #define TRACE_INCLUDE_PATH .
218
219 /*
220  * TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal
221  */
222 #undef TRACE_INCLUDE_FILE
223 #define TRACE_INCLUDE_FILE greybus_trace
224 #include <trace/define_trace.h>
225