GNU Linux-libre 4.14.332-gnu1
[releases.git] / drivers / usb / host / xhci-trace.h
1 /*
2  * xHCI host controller driver
3  *
4  * Copyright (C) 2013 Xenia Ragiadakou
5  *
6  * Author: Xenia Ragiadakou
7  * Email : burzalodowa@gmail.com
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #undef TRACE_SYSTEM
15 #define TRACE_SYSTEM xhci-hcd
16
17 /*
18  * The TRACE_SYSTEM_VAR defaults to TRACE_SYSTEM, but must be a
19  * legitimate C variable. It is not exported to user space.
20  */
21 #undef TRACE_SYSTEM_VAR
22 #define TRACE_SYSTEM_VAR xhci_hcd
23
24 #if !defined(__XHCI_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
25 #define __XHCI_TRACE_H
26
27 #include <linux/tracepoint.h>
28 #include "xhci.h"
29
30 #define XHCI_MSG_MAX    500
31
32 DECLARE_EVENT_CLASS(xhci_log_msg,
33         TP_PROTO(struct va_format *vaf),
34         TP_ARGS(vaf),
35         TP_STRUCT__entry(__dynamic_array(char, msg, XHCI_MSG_MAX)),
36         TP_fast_assign(
37                 vsnprintf(__get_str(msg), XHCI_MSG_MAX, vaf->fmt, *vaf->va);
38         ),
39         TP_printk("%s", __get_str(msg))
40 );
41
42 DEFINE_EVENT(xhci_log_msg, xhci_dbg_address,
43         TP_PROTO(struct va_format *vaf),
44         TP_ARGS(vaf)
45 );
46
47 DEFINE_EVENT(xhci_log_msg, xhci_dbg_context_change,
48         TP_PROTO(struct va_format *vaf),
49         TP_ARGS(vaf)
50 );
51
52 DEFINE_EVENT(xhci_log_msg, xhci_dbg_quirks,
53         TP_PROTO(struct va_format *vaf),
54         TP_ARGS(vaf)
55 );
56
57 DEFINE_EVENT(xhci_log_msg, xhci_dbg_reset_ep,
58         TP_PROTO(struct va_format *vaf),
59         TP_ARGS(vaf)
60 );
61
62 DEFINE_EVENT(xhci_log_msg, xhci_dbg_cancel_urb,
63         TP_PROTO(struct va_format *vaf),
64         TP_ARGS(vaf)
65 );
66
67 DEFINE_EVENT(xhci_log_msg, xhci_dbg_init,
68         TP_PROTO(struct va_format *vaf),
69         TP_ARGS(vaf)
70 );
71
72 DEFINE_EVENT(xhci_log_msg, xhci_dbg_ring_expansion,
73         TP_PROTO(struct va_format *vaf),
74         TP_ARGS(vaf)
75 );
76
77 DECLARE_EVENT_CLASS(xhci_log_ctx,
78         TP_PROTO(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx,
79                  unsigned int ep_num),
80         TP_ARGS(xhci, ctx, ep_num),
81         TP_STRUCT__entry(
82                 __field(int, ctx_64)
83                 __field(unsigned, ctx_type)
84                 __field(dma_addr_t, ctx_dma)
85                 __field(u8 *, ctx_va)
86                 __field(unsigned, ctx_ep_num)
87                 __field(int, slot_id)
88                 __dynamic_array(u32, ctx_data,
89                         ((HCC_64BYTE_CONTEXT(xhci->hcc_params) + 1) * 8) *
90                         ((ctx->type == XHCI_CTX_TYPE_INPUT) + ep_num + 1))
91         ),
92         TP_fast_assign(
93                 struct usb_device *udev;
94
95                 udev = to_usb_device(xhci_to_hcd(xhci)->self.controller);
96                 __entry->ctx_64 = HCC_64BYTE_CONTEXT(xhci->hcc_params);
97                 __entry->ctx_type = ctx->type;
98                 __entry->ctx_dma = ctx->dma;
99                 __entry->ctx_va = ctx->bytes;
100                 __entry->slot_id = udev->slot_id;
101                 __entry->ctx_ep_num = ep_num;
102                 memcpy(__get_dynamic_array(ctx_data), ctx->bytes,
103                         ((HCC_64BYTE_CONTEXT(xhci->hcc_params) + 1) * 32) *
104                         ((ctx->type == XHCI_CTX_TYPE_INPUT) + ep_num + 1));
105         ),
106         TP_printk("ctx_64=%d, ctx_type=%u, ctx_dma=@%llx, ctx_va=@%p",
107                         __entry->ctx_64, __entry->ctx_type,
108                         (unsigned long long) __entry->ctx_dma, __entry->ctx_va
109         )
110 );
111
112 DEFINE_EVENT(xhci_log_ctx, xhci_address_ctx,
113         TP_PROTO(struct xhci_hcd *xhci, struct xhci_container_ctx *ctx,
114                  unsigned int ep_num),
115         TP_ARGS(xhci, ctx, ep_num)
116 );
117
118 DECLARE_EVENT_CLASS(xhci_log_trb,
119         TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
120         TP_ARGS(ring, trb),
121         TP_STRUCT__entry(
122                 __field(u32, type)
123                 __field(u32, field0)
124                 __field(u32, field1)
125                 __field(u32, field2)
126                 __field(u32, field3)
127         ),
128         TP_fast_assign(
129                 __entry->type = ring->type;
130                 __entry->field0 = le32_to_cpu(trb->field[0]);
131                 __entry->field1 = le32_to_cpu(trb->field[1]);
132                 __entry->field2 = le32_to_cpu(trb->field[2]);
133                 __entry->field3 = le32_to_cpu(trb->field[3]);
134         ),
135         TP_printk("%s: %s", xhci_ring_type_string(__entry->type),
136                         xhci_decode_trb(__entry->field0, __entry->field1,
137                                         __entry->field2, __entry->field3)
138         )
139 );
140
141 DEFINE_EVENT(xhci_log_trb, xhci_handle_event,
142         TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
143         TP_ARGS(ring, trb)
144 );
145
146 DEFINE_EVENT(xhci_log_trb, xhci_handle_command,
147         TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
148         TP_ARGS(ring, trb)
149 );
150
151 DEFINE_EVENT(xhci_log_trb, xhci_handle_transfer,
152         TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
153         TP_ARGS(ring, trb)
154 );
155
156 DEFINE_EVENT(xhci_log_trb, xhci_queue_trb,
157         TP_PROTO(struct xhci_ring *ring, struct xhci_generic_trb *trb),
158         TP_ARGS(ring, trb)
159 );
160
161 DECLARE_EVENT_CLASS(xhci_log_free_virt_dev,
162         TP_PROTO(struct xhci_virt_device *vdev),
163         TP_ARGS(vdev),
164         TP_STRUCT__entry(
165                 __field(void *, vdev)
166                 __field(unsigned long long, out_ctx)
167                 __field(unsigned long long, in_ctx)
168                 __field(u8, fake_port)
169                 __field(u8, real_port)
170                 __field(u16, current_mel)
171
172         ),
173         TP_fast_assign(
174                 __entry->vdev = vdev;
175                 __entry->in_ctx = (unsigned long long) vdev->in_ctx->dma;
176                 __entry->out_ctx = (unsigned long long) vdev->out_ctx->dma;
177                 __entry->fake_port = (u8) vdev->fake_port;
178                 __entry->real_port = (u8) vdev->real_port;
179                 __entry->current_mel = (u16) vdev->current_mel;
180                 ),
181         TP_printk("vdev %p ctx %llx | %llx fake_port %d real_port %d current_mel %d",
182                 __entry->vdev, __entry->in_ctx, __entry->out_ctx,
183                 __entry->fake_port, __entry->real_port, __entry->current_mel
184         )
185 );
186
187 DEFINE_EVENT(xhci_log_free_virt_dev, xhci_free_virt_device,
188         TP_PROTO(struct xhci_virt_device *vdev),
189         TP_ARGS(vdev)
190 );
191
192 DECLARE_EVENT_CLASS(xhci_log_virt_dev,
193         TP_PROTO(struct xhci_virt_device *vdev),
194         TP_ARGS(vdev),
195         TP_STRUCT__entry(
196                 __field(void *, vdev)
197                 __field(unsigned long long, out_ctx)
198                 __field(unsigned long long, in_ctx)
199                 __field(int, devnum)
200                 __field(int, state)
201                 __field(int, speed)
202                 __field(u8, portnum)
203                 __field(u8, level)
204                 __field(int, slot_id)
205         ),
206         TP_fast_assign(
207                 __entry->vdev = vdev;
208                 __entry->in_ctx = (unsigned long long) vdev->in_ctx->dma;
209                 __entry->out_ctx = (unsigned long long) vdev->out_ctx->dma;
210                 __entry->devnum = vdev->udev->devnum;
211                 __entry->state = vdev->udev->state;
212                 __entry->speed = vdev->udev->speed;
213                 __entry->portnum = vdev->udev->portnum;
214                 __entry->level = vdev->udev->level;
215                 __entry->slot_id = vdev->udev->slot_id;
216         ),
217         TP_printk("vdev %p ctx %llx | %llx num %d state %d speed %d port %d level %d slot %d",
218                 __entry->vdev, __entry->in_ctx, __entry->out_ctx,
219                 __entry->devnum, __entry->state, __entry->speed,
220                 __entry->portnum, __entry->level, __entry->slot_id
221         )
222 );
223
224 DEFINE_EVENT(xhci_log_virt_dev, xhci_alloc_virt_device,
225         TP_PROTO(struct xhci_virt_device *vdev),
226         TP_ARGS(vdev)
227 );
228
229 DEFINE_EVENT(xhci_log_virt_dev, xhci_setup_device,
230         TP_PROTO(struct xhci_virt_device *vdev),
231         TP_ARGS(vdev)
232 );
233
234 DEFINE_EVENT(xhci_log_virt_dev, xhci_setup_addressable_virt_device,
235         TP_PROTO(struct xhci_virt_device *vdev),
236         TP_ARGS(vdev)
237 );
238
239 DEFINE_EVENT(xhci_log_virt_dev, xhci_stop_device,
240         TP_PROTO(struct xhci_virt_device *vdev),
241         TP_ARGS(vdev)
242 );
243
244 DECLARE_EVENT_CLASS(xhci_log_urb,
245         TP_PROTO(struct urb *urb),
246         TP_ARGS(urb),
247         TP_STRUCT__entry(
248                 __field(void *, urb)
249                 __field(unsigned int, pipe)
250                 __field(unsigned int, stream)
251                 __field(int, status)
252                 __field(unsigned int, flags)
253                 __field(int, num_mapped_sgs)
254                 __field(int, num_sgs)
255                 __field(int, length)
256                 __field(int, actual)
257                 __field(int, epnum)
258                 __field(int, dir_in)
259                 __field(int, type)
260                 __field(int, slot_id)
261         ),
262         TP_fast_assign(
263                 __entry->urb = urb;
264                 __entry->pipe = urb->pipe;
265                 __entry->stream = urb->stream_id;
266                 __entry->status = urb->status;
267                 __entry->flags = urb->transfer_flags;
268                 __entry->num_mapped_sgs = urb->num_mapped_sgs;
269                 __entry->num_sgs = urb->num_sgs;
270                 __entry->length = urb->transfer_buffer_length;
271                 __entry->actual = urb->actual_length;
272                 __entry->epnum = usb_endpoint_num(&urb->ep->desc);
273                 __entry->dir_in = usb_endpoint_dir_in(&urb->ep->desc);
274                 __entry->type = usb_endpoint_type(&urb->ep->desc);
275                 __entry->slot_id = urb->dev->slot_id;
276         ),
277         TP_printk("ep%d%s-%s: urb %p pipe %u slot %d length %d/%d sgs %d/%d stream %d flags %08x",
278                         __entry->epnum, __entry->dir_in ? "in" : "out",
279                         __print_symbolic(__entry->type,
280                                    { USB_ENDPOINT_XFER_INT,     "intr" },
281                                    { USB_ENDPOINT_XFER_CONTROL, "control" },
282                                    { USB_ENDPOINT_XFER_BULK,    "bulk" },
283                                    { USB_ENDPOINT_XFER_ISOC,    "isoc" }),
284                         __entry->urb, __entry->pipe, __entry->slot_id,
285                         __entry->actual, __entry->length, __entry->num_mapped_sgs,
286                         __entry->num_sgs, __entry->stream, __entry->flags
287                 )
288 );
289
290 DEFINE_EVENT(xhci_log_urb, xhci_urb_enqueue,
291         TP_PROTO(struct urb *urb),
292         TP_ARGS(urb)
293 );
294
295 DEFINE_EVENT(xhci_log_urb, xhci_urb_giveback,
296         TP_PROTO(struct urb *urb),
297         TP_ARGS(urb)
298 );
299
300 DEFINE_EVENT(xhci_log_urb, xhci_urb_dequeue,
301         TP_PROTO(struct urb *urb),
302         TP_ARGS(urb)
303 );
304
305 DECLARE_EVENT_CLASS(xhci_log_ep_ctx,
306         TP_PROTO(struct xhci_ep_ctx *ctx),
307         TP_ARGS(ctx),
308         TP_STRUCT__entry(
309                 __field(u32, info)
310                 __field(u32, info2)
311                 __field(u64, deq)
312                 __field(u32, tx_info)
313         ),
314         TP_fast_assign(
315                 __entry->info = le32_to_cpu(ctx->ep_info);
316                 __entry->info2 = le32_to_cpu(ctx->ep_info2);
317                 __entry->deq = le64_to_cpu(ctx->deq);
318                 __entry->tx_info = le32_to_cpu(ctx->tx_info);
319         ),
320         TP_printk("%s", xhci_decode_ep_context(__entry->info,
321                 __entry->info2, __entry->deq, __entry->tx_info)
322         )
323 );
324
325 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_stop_ep,
326         TP_PROTO(struct xhci_ep_ctx *ctx),
327         TP_ARGS(ctx)
328 );
329
330 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_set_deq_ep,
331         TP_PROTO(struct xhci_ep_ctx *ctx),
332         TP_ARGS(ctx)
333 );
334
335 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_reset_ep,
336         TP_PROTO(struct xhci_ep_ctx *ctx),
337         TP_ARGS(ctx)
338 );
339
340 DEFINE_EVENT(xhci_log_ep_ctx, xhci_handle_cmd_config_ep,
341         TP_PROTO(struct xhci_ep_ctx *ctx),
342         TP_ARGS(ctx)
343 );
344
345 DECLARE_EVENT_CLASS(xhci_log_slot_ctx,
346         TP_PROTO(struct xhci_slot_ctx *ctx),
347         TP_ARGS(ctx),
348         TP_STRUCT__entry(
349                 __field(u32, info)
350                 __field(u32, info2)
351                 __field(u32, tt_info)
352                 __field(u32, state)
353         ),
354         TP_fast_assign(
355                 __entry->info = le32_to_cpu(ctx->dev_info);
356                 __entry->info2 = le32_to_cpu(ctx->dev_info2);
357                 __entry->tt_info = le64_to_cpu(ctx->tt_info);
358                 __entry->state = le32_to_cpu(ctx->dev_state);
359         ),
360         TP_printk("%s", xhci_decode_slot_context(__entry->info,
361                         __entry->info2, __entry->tt_info,
362                         __entry->state)
363         )
364 );
365
366 DEFINE_EVENT(xhci_log_slot_ctx, xhci_alloc_dev,
367         TP_PROTO(struct xhci_slot_ctx *ctx),
368         TP_ARGS(ctx)
369 );
370
371 DEFINE_EVENT(xhci_log_slot_ctx, xhci_free_dev,
372         TP_PROTO(struct xhci_slot_ctx *ctx),
373         TP_ARGS(ctx)
374 );
375
376 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_disable_slot,
377         TP_PROTO(struct xhci_slot_ctx *ctx),
378         TP_ARGS(ctx)
379 );
380
381 DEFINE_EVENT(xhci_log_slot_ctx, xhci_discover_or_reset_device,
382         TP_PROTO(struct xhci_slot_ctx *ctx),
383         TP_ARGS(ctx)
384 );
385
386 DEFINE_EVENT(xhci_log_slot_ctx, xhci_setup_device_slot,
387         TP_PROTO(struct xhci_slot_ctx *ctx),
388         TP_ARGS(ctx)
389 );
390
391 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_addr_dev,
392         TP_PROTO(struct xhci_slot_ctx *ctx),
393         TP_ARGS(ctx)
394 );
395
396 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_reset_dev,
397         TP_PROTO(struct xhci_slot_ctx *ctx),
398         TP_ARGS(ctx)
399 );
400
401 DEFINE_EVENT(xhci_log_slot_ctx, xhci_handle_cmd_set_deq,
402         TP_PROTO(struct xhci_slot_ctx *ctx),
403         TP_ARGS(ctx)
404 );
405
406 DECLARE_EVENT_CLASS(xhci_log_ring,
407         TP_PROTO(struct xhci_ring *ring),
408         TP_ARGS(ring),
409         TP_STRUCT__entry(
410                 __field(u32, type)
411                 __field(void *, ring)
412                 __field(dma_addr_t, enq)
413                 __field(dma_addr_t, deq)
414                 __field(dma_addr_t, enq_seg)
415                 __field(dma_addr_t, deq_seg)
416                 __field(unsigned int, num_segs)
417                 __field(unsigned int, stream_id)
418                 __field(unsigned int, cycle_state)
419                 __field(unsigned int, num_trbs_free)
420                 __field(unsigned int, bounce_buf_len)
421         ),
422         TP_fast_assign(
423                 __entry->ring = ring;
424                 __entry->type = ring->type;
425                 __entry->num_segs = ring->num_segs;
426                 __entry->stream_id = ring->stream_id;
427                 __entry->enq_seg = ring->enq_seg->dma;
428                 __entry->deq_seg = ring->deq_seg->dma;
429                 __entry->cycle_state = ring->cycle_state;
430                 __entry->num_trbs_free = ring->num_trbs_free;
431                 __entry->bounce_buf_len = ring->bounce_buf_len;
432                 __entry->enq = xhci_trb_virt_to_dma(ring->enq_seg, ring->enqueue);
433                 __entry->deq = xhci_trb_virt_to_dma(ring->deq_seg, ring->dequeue);
434         ),
435         TP_printk("%s %p: enq %pad(%pad) deq %pad(%pad) segs %d stream %d free_trbs %d bounce %d cycle %d",
436                         xhci_ring_type_string(__entry->type), __entry->ring,
437                         &__entry->enq, &__entry->enq_seg,
438                         &__entry->deq, &__entry->deq_seg,
439                         __entry->num_segs,
440                         __entry->stream_id,
441                         __entry->num_trbs_free,
442                         __entry->bounce_buf_len,
443                         __entry->cycle_state
444                 )
445 );
446
447 DEFINE_EVENT(xhci_log_ring, xhci_ring_alloc,
448         TP_PROTO(struct xhci_ring *ring),
449         TP_ARGS(ring)
450 );
451
452 DEFINE_EVENT(xhci_log_ring, xhci_ring_free,
453         TP_PROTO(struct xhci_ring *ring),
454         TP_ARGS(ring)
455 );
456
457 DEFINE_EVENT(xhci_log_ring, xhci_ring_expansion,
458         TP_PROTO(struct xhci_ring *ring),
459         TP_ARGS(ring)
460 );
461
462 DEFINE_EVENT(xhci_log_ring, xhci_inc_enq,
463         TP_PROTO(struct xhci_ring *ring),
464         TP_ARGS(ring)
465 );
466
467 DEFINE_EVENT(xhci_log_ring, xhci_inc_deq,
468         TP_PROTO(struct xhci_ring *ring),
469         TP_ARGS(ring)
470 );
471
472 DECLARE_EVENT_CLASS(xhci_log_portsc,
473                     TP_PROTO(u32 portnum, u32 portsc),
474                     TP_ARGS(portnum, portsc),
475                     TP_STRUCT__entry(
476                                      __field(u32, portnum)
477                                      __field(u32, portsc)
478                                      ),
479                     TP_fast_assign(
480                                    __entry->portnum = portnum;
481                                    __entry->portsc = portsc;
482                                    ),
483                     TP_printk("port-%d: %s",
484                               __entry->portnum,
485                               xhci_decode_portsc(__entry->portsc)
486                               )
487 );
488
489 DEFINE_EVENT(xhci_log_portsc, xhci_handle_port_status,
490              TP_PROTO(u32 portnum, u32 portsc),
491              TP_ARGS(portnum, portsc)
492 );
493
494 #endif /* __XHCI_TRACE_H */
495
496 /* this part must be outside header guard */
497
498 #undef TRACE_INCLUDE_PATH
499 #define TRACE_INCLUDE_PATH .
500
501 #undef TRACE_INCLUDE_FILE
502 #define TRACE_INCLUDE_FILE xhci-trace
503
504 #include <trace/define_trace.h>