summaryrefslogtreecommitdiff
path: root/drivers/greybus/greybus_trace.h
blob: 616a3bd61aa66c500017c0ce3262f139b22c20ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Greybus driver and device API
 *
 * Copyright 2015 Google Inc.
 * Copyright 2015 Linaro Ltd.
 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM greybus

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

#include <linux/tracepoint.h>

struct gb_message;
struct gb_operation;
struct gb_connection;
struct gb_bundle;
struct gb_host_device;

DECLARE_EVENT_CLASS(gb_message,

	TP_PROTO(struct gb_message *message),

	TP_ARGS(message),

	TP_STRUCT__entry(
		__field(u16, size)
		__field(u16, operation_id)
		__field(u8, type)
		__field(u8, result)
	),

	TP_fast_assign(
		__entry->size = le16_to_cpu(message->header->size);
		__entry->operation_id =
			le16_to_cpu(message->header->operation_id);
		__entry->type = message->header->type;
		__entry->result = message->header->result;
	),

	TP_printk("size=%u operation_id=0x%04x type=0x%02x result=0x%02x",
		  __entry->size, __entry->operation_id,
		  __entry->type, __entry->result)
);

#define DEFINE_MESSAGE_EVENT(name)					\
		DEFINE_EVENT(gb_message, name,				\
				TP_PROTO(struct gb_message *message),	\
				TP_ARGS(message))

/*
 * Occurs immediately before calling a host device's message_send()
 * method.
 */
DEFINE_MESSAGE_EVENT(gb_message_send);

/*
 * Occurs after an incoming request message has been received
 */
DEFINE_MESSAGE_EVENT(gb_message_recv_request);

/*
 * Occurs after an incoming response message has been received,
 * after its matching request has been found.
 */
DEFINE_MESSAGE_EVENT(gb_message_recv_response);

/*
 * Occurs after an operation has been canceled, possibly before the
 * cancellation is complete.
 */
DEFINE_MESSAGE_EVENT(gb_message_cancel_outgoing);

/*
 * Occurs when an incoming request is cancelled; if the response has
 * been queued for sending, this occurs after it is sent.
 */
DEFINE_MESSAGE_EVENT(gb_message_cancel_incoming);

/*
 * Occurs in the host driver message_send() function just prior to
 * handing off the data to be processed by hardware.
 */
DEFINE_MESSAGE_EVENT(gb_message_submit);

#undef DEFINE_MESSAGE_EVENT

DECLARE_EVENT_CLASS(gb_operation,

	TP_PROTO(struct gb_operation *operation),

	TP_ARGS(operation),

	TP_STRUCT__entry(
		__field(u16, cport_id)	/* CPort of HD side of connection */
		__field(u16, id)	/* Operation ID */
		__field(u8, type)
		__field(unsigned long, flags)
		__field(int, active)
		__field(int, waiters)
		__field(int, errno)
	),

	TP_fast_assign(
		__entry->cport_id = operation->connection->hd_cport_id;
		__entry->id = operation->id;
		__entry->type = operation->type;
		__entry->flags = operation->flags;
		__entry->active = operation->active;
		__entry->waiters = atomic_read(&operation->waiters);
		__entry->errno = operation->errno;
	),

	TP_printk("id=%04x type=0x%02x cport_id=%04x flags=0x%lx active=%d waiters=%d errno=%d",
		  __entry->id, __entry->cport_id, __entry->type, __entry->flags,
		  __entry->active, __entry->waiters, __entry->errno)
);

#define DEFINE_OPERATION_EVENT(name)					\
		DEFINE_EVENT(gb_operation, name,			\
				TP_PROTO(struct gb_operation *operation), \
				TP_ARGS(operation))

/*
 * Occurs after a new operation is created for an outgoing request
 * has been successfully created.
 */
DEFINE_OPERATION_EVENT(gb_operation_create);

/*
 * Occurs after a new core operation has been created.
 */
DEFINE_OPERATION_EVENT(gb_operation_create_core);

/*
 * Occurs after a new operation has been created for an incoming
 * request has been successfully created and initialized.
 */
DEFINE_OPERATION_EVENT(gb_operation_create_incoming);

/*
 * Occurs when the last reference to an operation has been dropped,
 * prior to freeing resources.
 */
DEFINE_OPERATION_EVENT(gb_operation_destroy);

/*
 * Occurs when an operation has been marked active, after updating
 * its active count.
 */
DEFINE_OPERATION_EVENT(gb_operation_get_active);

/*
 * Occurs when an operation has been marked active, before updating
 * its active count.
 */
DEFINE_OPERATION_EVENT(gb_operation_put_active);

#undef DEFINE_OPERATION_EVENT

DECLARE_EVENT_CLASS(gb_connection,

	TP_PROTO(struct gb_connection *connection),

	TP_ARGS(connection),

	TP_STRUCT__entry(
		__field(int, hd_bus_id)
		__field(u8, bundle_id)
		/* name contains "hd_cport_id/intf_id:cport_id" */
		__dynamic_array(char, name, sizeof(connection->name))
		__field(enum gb_connection_state, state)
		__field(unsigned long, flags)
	),

	TP_fast_assign(
		__entry->hd_bus_id = connection->hd->bus_id;
		__entry->bundle_id = connection->bundle ?
				connection->bundle->id : BUNDLE_ID_NONE;
		memcpy(__get_str(name), connection->name,
					sizeof(connection->name));
		__entry->state = connection->state;
		__entry->flags = connection->flags;
	),

	TP_printk("hd_bus_id=%d bundle_id=0x%02x name=\"%s\" state=%u flags=0x%lx",
		  __entry->hd_bus_id, __entry->bundle_id, __get_str(name),
		  (unsigned int)__entry->state, __entry->flags)
);

#define DEFINE_CONNECTION_EVENT(name)					\
		DEFINE_EVENT(gb_connection, name,			\
				TP_PROTO(struct gb_connection *connection), \
				TP_ARGS(connection))

/*
 * Occurs after a new connection is successfully created.
 */
DEFINE_CONNECTION_EVENT(gb_connection_create);

/*
 * Occurs when the last reference to a connection has been dropped,
 * before its resources are freed.
 */
DEFINE_CONNECTION_EVENT(gb_connection_release);

/*
 * Occurs when a new reference to connection is added, currently
 * only when a message over the connection is received.
 */
DEFINE_CONNECTION_EVENT(gb_connection_get);

/*
 * Occurs when a new reference to connection is dropped, after a
 * a received message is handled, or when the connection is
 * destroyed.
 */
DEFINE_CONNECTION_EVENT(gb_connection_put);

/*
 * Occurs when a request to enable a connection is made, either for
 * transmit only, or for both transmit and receive.
 */
DEFINE_CONNECTION_EVENT(gb_connection_enable);

/*
 * Occurs when a request to disable a connection is made, either for
 * receive only, or for both transmit and receive.  Also occurs when
 * a request to forcefully disable a connection is made.
 */
DEFINE_CONNECTION_EVENT(gb_connection_disable);

#undef DEFINE_CONNECTION_EVENT

DECLARE_EVENT_CLASS(gb_bundle,

	TP_PROTO(struct gb_bundle *bundle),

	TP_ARGS(bundle),

	TP_STRUCT__entry(
		__field(u8, intf_id)
		__field(u8, id)
		__field(u8, class)
		__field(size_t, num_cports)
	),

	TP_fast_assign(
		__entry->intf_id = bundle->intf->interface_id;
		__entry->id = bundle->id;
		__entry->class = bundle->class;
		__entry->num_cports = bundle->num_cports;
	),

	TP_printk("intf_id=0x%02x id=%02x class=0x%02x num_cports=%zu",
		  __entry->intf_id, __entry->id, __entry->class,
		  __entry->num_cports)
);

#define DEFINE_BUNDLE_EVENT(name)					\
		DEFINE_EVENT(gb_bundle, name,			\
				TP_PROTO(struct gb_bundle *bundle), \
				TP_ARGS(bundle))

/*
 * Occurs after a new bundle is successfully created.
 */
DEFINE_BUNDLE_EVENT(gb_bundle_create);

/*
 * Occurs when the last reference to a bundle has been dropped,
 * before its resources are freed.
 */
DEFINE_BUNDLE_EVENT(gb_bundle_release);

/*
 * Occurs when a bundle is added to an interface when the interface
 * is enabled.
 */
DEFINE_BUNDLE_EVENT(gb_bundle_add);

/*
 * Occurs when a registered bundle gets destroyed, normally at the
 * time an interface is disabled.
 */
DEFINE_BUNDLE_EVENT(gb_bundle_destroy);

#undef DEFINE_BUNDLE_EVENT

DECLARE_EVENT_CLASS(gb_interface,

	TP_PROTO(struct gb_interface *intf),

	TP_ARGS(intf),

	TP_STRUCT__entry(
		__field(u8, module_id)
		__field(u8, id)		/* Interface id */
		__field(u8, device_id)
		__field(int, disconnected)	/* bool */
		__field(int, ejected)		/* bool */
		__field(int, active)		/* bool */
		__field(int, enabled)		/* bool */
		__field(int, mode_switch)	/* bool */
	),

	TP_fast_assign(
		__entry->module_id = intf->module->module_id;
		__entry->id = intf->interface_id;
		__entry->device_id = intf->device_id;
		__entry->disconnected = intf->disconnected;
		__entry->ejected = intf->ejected;
		__entry->active = intf->active;
		__entry->enabled = intf->enabled;
		__entry->mode_switch = intf->mode_switch;
	),

	TP_printk("intf_id=%u device_id=%u module_id=%u D=%d J=%d A=%d E=%d M=%d",
		__entry->id, __entry->device_id, __entry->module_id,
		__entry->disconnected, __entry->ejected, __entry->active,
		__entry->enabled, __entry->mode_switch)
);

#define DEFINE_INTERFACE_EVENT(name)					\
		DEFINE_EVENT(gb_interface, name,			\
				TP_PROTO(struct gb_interface *intf),	\
				TP_ARGS(intf))

/*
 * Occurs after a new interface is successfully created.
 */
DEFINE_INTERFACE_EVENT(gb_interface_create);

/*
 * Occurs after the last reference to an interface has been dropped.
 */
DEFINE_INTERFACE_EVENT(gb_interface_release);

/*
 * Occurs after an interface been registerd.
 */
DEFINE_INTERFACE_EVENT(gb_interface_add);

/*
 * Occurs when a registered interface gets deregisterd.
 */
DEFINE_INTERFACE_EVENT(gb_interface_del);

/*
 * Occurs when a registered interface has been successfully
 * activated.
 */
DEFINE_INTERFACE_EVENT(gb_interface_activate);

/*
 * Occurs when an activated interface is being deactivated.
 */
DEFINE_INTERFACE_EVENT(gb_interface_deactivate);

/*
 * Occurs when an interface has been successfully enabled.
 */
DEFINE_INTERFACE_EVENT(gb_interface_enable);

/*
 * Occurs when an enabled interface is being disabled.
 */
DEFINE_INTERFACE_EVENT(gb_interface_disable);

#undef DEFINE_INTERFACE_EVENT

DECLARE_EVENT_CLASS(gb_module,

	TP_PROTO(struct gb_module *module),

	TP_ARGS(module),

	TP_STRUCT__entry(
		__field(int, hd_bus_id)
		__field(u8, module_id)
		__field(size_t, num_interfaces)
		__field(int, disconnected)	/* bool */
	),

	TP_fast_assign(
		__entry->hd_bus_id = module->hd->bus_id;
		__entry->module_id = module->module_id;
		__entry->num_interfaces = module->num_interfaces;
		__entry->disconnected = module->disconnected;
	),

	TP_printk("hd_bus_id=%d module_id=%u num_interfaces=%zu disconnected=%d",
		__entry->hd_bus_id, __entry->module_id,
		__entry->num_interfaces, __entry->disconnected)
);

#define DEFINE_MODULE_EVENT(name)					\
		DEFINE_EVENT(gb_module, name,				\
				TP_PROTO(struct gb_module *module),	\
				TP_ARGS(module))

/*
 * Occurs after a new module is successfully created, before
 * creating any of its interfaces.
 */
DEFINE_MODULE_EVENT(gb_module_create);

/*
 * Occurs after the last reference to a module has been dropped.
 */
DEFINE_MODULE_EVENT(gb_module_release);

/*
 * Occurs after a module is successfully created, before registering
 * any of its interfaces.
 */
DEFINE_MODULE_EVENT(gb_module_add);

/*
 * Occurs when a module is deleted, before deregistering its
 * interfaces.
 */
DEFINE_MODULE_EVENT(gb_module_del);

#undef DEFINE_MODULE_EVENT

DECLARE_EVENT_CLASS(gb_host_device,

	TP_PROTO(struct gb_host_device *hd),

	TP_ARGS(hd),

	TP_STRUCT__entry(
		__field(int, bus_id)
		__field(size_t, num_cports)
		__field(size_t, buffer_size_max)
	),

	TP_fast_assign(
		__entry->bus_id = hd->bus_id;
		__entry->num_cports = hd->num_cports;
		__entry->buffer_size_max = hd->buffer_size_max;
	),

	TP_printk("bus_id=%d num_cports=%zu mtu=%zu",
		__entry->bus_id, __entry->num_cports,
		__entry->buffer_size_max)
);

#define DEFINE_HD_EVENT(name)						\
		DEFINE_EVENT(gb_host_device, name,			\
				TP_PROTO(struct gb_host_device *hd),	\
				TP_ARGS(hd))

/*
 * Occurs after a new host device is successfully created, before
 * its SVC has been set up.
 */
DEFINE_HD_EVENT(gb_hd_create);

/*
 * Occurs after the last reference to a host device has been
 * dropped.
 */
DEFINE_HD_EVENT(gb_hd_release);

/*
 * Occurs after a new host device has been added, after the
 * connection to its SVC has been enabled.
 */
DEFINE_HD_EVENT(gb_hd_add);

/*
 * Occurs when a host device is being disconnected from the AP USB
 * host controller.
 */
DEFINE_HD_EVENT(gb_hd_del);

/*
 * Occurs when a host device has passed received data to the Greybus
 * core, after it has been determined it is destined for a valid
 * CPort.
 */
DEFINE_HD_EVENT(gb_hd_in);

#undef DEFINE_HD_EVENT

#endif /* _TRACE_GREYBUS_H */

/* This part must be outside protection */
#undef TRACE_INCLUDE_PATH
#define TRACE_INCLUDE_PATH .

/*
 * TRACE_INCLUDE_FILE is not needed if the filename and TRACE_SYSTEM are equal
 */
#undef TRACE_INCLUDE_FILE
#define TRACE_INCLUDE_FILE greybus_trace
#include <trace/define_trace.h>