93e04a85506f437c6f0404e61c85e84b68310ad5
[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_module,
160
161         TP_PROTO(struct gb_module *module),
162
163         TP_ARGS(module),
164
165         TP_STRUCT__entry(
166                 __field(int, hd_bus_id)
167                 __field(u8, module_id)
168                 __field(u8, num_interfaces)
169                 __field(bool, disconnected)
170         ),
171
172         TP_fast_assign(
173                 __entry->hd_bus_id = module->hd->bus_id;
174                 __entry->module_id = module->module_id;
175                 __entry->disconnected = module->disconnected;
176         ),
177
178         TP_printk("greybus: hd_bus_id=%d module_id=%hhu disconnected=%u",
179                 __entry->hd_bus_id, __entry->module_id, __entry->disconnected)
180 );
181
182 #define DEFINE_MODULE_EVENT(name)                                       \
183                 DEFINE_EVENT(gb_module, name,                           \
184                                 TP_PROTO(struct gb_module *module),     \
185                                 TP_ARGS(module))
186
187 /*
188  * Occurs after a new module is successfully created, before
189  * creating any of its interfaces.
190  */
191 DEFINE_MODULE_EVENT(gb_module_create);
192
193 /*
194  * Occurs after the last reference to a module has been dropped.
195  */
196 DEFINE_MODULE_EVENT(gb_module_release);
197
198 /*
199  * Occurs after a module is successfully created, before registering
200  * any of its interfaces.
201  */
202 DEFINE_MODULE_EVENT(gb_module_add);
203
204 /*
205  * Occurs when a module is deleted, before deregistering its
206  * interfaces.
207  */
208 DEFINE_MODULE_EVENT(gb_module_del);
209
210 #undef DEFINE_MODULE_EVENT
211
212 DECLARE_EVENT_CLASS(gb_interface,
213
214         TP_PROTO(struct gb_interface *intf),
215
216         TP_ARGS(intf),
217
218         TP_STRUCT__entry(
219                 __field(u8, id)         /* Interface id */
220                 __field(u8, module_id)
221                 __field(u8, device_id)
222                 __field(bool, disconnected)
223                 __field(bool, ejected)
224                 __field(bool, active)
225                 __field(bool, enabled)
226         ),
227
228         TP_fast_assign(
229                 __entry->id = intf->interface_id;
230                 __entry->module_id = intf->module->module_id;
231                 __entry->device_id = intf->device_id;
232                 __entry->disconnected = intf->disconnected;
233                 __entry->ejected = intf->ejected;
234                 __entry->active = intf->active;
235                 __entry->enabled = intf->enabled;
236         ),
237
238         TP_printk("greybus: intf_id=%hhu device_id=%hhu module_id=%hhu D=%u J=%u A=%u E=%u",
239                 __entry->id, __entry->device_id, __entry->module_id,
240                 __entry->disconnected, __entry->ejected, __entry->active,
241                 __entry->enabled)
242 );
243
244 #define DEFINE_INTERFACE_EVENT(name)                                    \
245                 DEFINE_EVENT(gb_interface, name,                        \
246                                 TP_PROTO(struct gb_interface *intf),    \
247                                 TP_ARGS(intf))
248
249 /*
250  * Occurs after a new interface is successfully created.
251  */
252 DEFINE_INTERFACE_EVENT(gb_interface_create);
253
254 /*
255  * Occurs after the last reference to an interface has been dropped.
256  */
257 DEFINE_INTERFACE_EVENT(gb_interface_release);
258
259 /*
260  * Occurs after an interface been registerd.
261  */
262 DEFINE_INTERFACE_EVENT(gb_interface_add);
263
264 /*
265  * Occurs when a registered interface gets deregisterd.
266  */
267 DEFINE_INTERFACE_EVENT(gb_interface_del);
268
269 /*
270  * Occurs when a registered interface has been successfully
271  * activated.
272  */
273 DEFINE_INTERFACE_EVENT(gb_interface_activate);
274
275 /*
276  * Occurs when an activated interface is being deactivated.
277  */
278 DEFINE_INTERFACE_EVENT(gb_interface_deactivate);
279
280 /*
281  * Occurs when an interface has been successfully enabled.
282  */
283 DEFINE_INTERFACE_EVENT(gb_interface_enable);
284
285 /*
286  * Occurs when an enabled interface is being disabled.
287  */
288 DEFINE_INTERFACE_EVENT(gb_interface_disable);
289
290 #undef DEFINE_INTERFACE_EVENT
291
292 DECLARE_EVENT_CLASS(gb_host_device,
293
294         TP_PROTO(struct gb_host_device *hd),
295
296         TP_ARGS(hd),
297
298         TP_STRUCT__entry(
299                 __field(int, bus_id)
300                 __field(u8, num_cports)
301                 __field(size_t, buffer_size_max)
302         ),
303
304         TP_fast_assign(
305                 __entry->bus_id = hd->bus_id;
306                 __entry->num_cports = hd->num_cports;
307                 __entry->buffer_size_max = hd->buffer_size_max;
308         ),
309
310         TP_printk("greybus: bus_id=%d num_cports=%hu mtu=%zu",
311                 __entry->bus_id, __entry->num_cports,
312                 __entry->buffer_size_max)
313 );
314
315 #define DEFINE_HD_EVENT(name)                                           \
316                 DEFINE_EVENT(gb_host_device, name,                      \
317                                 TP_PROTO(struct gb_host_device *hd),    \
318                                 TP_ARGS(hd))
319
320 /*
321  * Occurs after a new host device is successfully created, before
322  * its SVC has been set up.
323  */
324 DEFINE_HD_EVENT(gb_hd_create);
325
326 /*
327  * Occurs after the last reference to a host device has been
328  * dropped.
329  */
330 DEFINE_HD_EVENT(gb_hd_release);
331
332 /*
333  * Occurs after a new host device has been added, after the
334  * connection to its SVC has * been enabled.
335  */
336 DEFINE_HD_EVENT(gb_hd_add);
337
338 /*
339  * Occurs when a host device is being disconnected from the AP USB
340  * host controller.
341  */
342 DEFINE_HD_EVENT(gb_hd_del);
343
344 #undef DEFINE_HD_EVENT
345
346 #endif /* _TRACE_GREYBUS_H */
347
348 /* This part must be outside protection */
349 #undef TRACE_INCLUDE_PATH
350 #define TRACE_INCLUDE_PATH .
351
352 /*
353  * TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal
354  */
355 #undef TRACE_INCLUDE_FILE
356 #define TRACE_INCLUDE_FILE greybus_trace
357 #include <trace/define_trace.h>
358